1 // SALOME RessourcesCatalog : implementation of catalog resources parsing (SALOME_ModuleCatalog.idl)
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SALOME_RessourcesCatalog_Handler.cxx
25 // Author : Estelle Deville
29 #include "SALOME_RessourcesCatalog_Handler.hxx"
31 #include "utilities.h"
35 ListOfParserressources _ressources_list;
37 //----------------------------------------------------------------------
38 //Function : SALOME_RessourcesCatalog_Handler
39 //Purpose: Constructor
40 //----------------------------------------------------------------------
41 SALOME_RessourcesCatalog_Handler::SALOME_RessourcesCatalog_Handler()
43 MESSAGE("SALOME_RessourcesCatalog_Handler creation");
44 //XML tags initialisation
45 test_computer = "computer";
46 test_computer_name="name";
47 test_computer_OS="OS";
48 test_computer_OS_version = "OS-version";
50 test_proc_number ="number" ;
51 test_proc_model= "model" ;
52 test_proc_cpu= "CPU-MHz" ;
53 test_proc_cache = "cache" ;
54 test_proc_list = "proc-list" ;
55 test_container_type = "containertype" ;
56 test_container_type_list = "containertype-list" ;
59 //----------------------------------------------------------------------
60 //Function : ~SALOME_RessourcesCatalog_Handler
62 //----------------------------------------------------------------------
63 SALOME_RessourcesCatalog_Handler::~SALOME_RessourcesCatalog_Handler()
65 MESSAGE("SALOME_RessourcesCatalog_Handler destruction");
68 //----------------------------------------------------------------------
69 //Function : startDocument
70 //Purpose: overload handler function
71 //----------------------------------------------------------------------
73 SALOME_RessourcesCatalog_Handler::startDocument()
75 MESSAGE("Begin parse document");
76 // Empty private elements
77 _procs_list.resize(0);
78 _ressources_list.resize(0);
79 _container_list.resize(0);
83 //----------------------------------------------------------------------
84 //Function : startElement
85 //Purpose: overload handler function
86 //----------------------------------------------------------------------
88 SALOME_RessourcesCatalog_Handler::startElement(const QString&,
91 const QXmlAttributes& atts)
96 //----------------------------------------------------------------------
97 //Function : endElement
98 //Purpose: overload handler function
99 //----------------------------------------------------------------------
101 SALOME_RessourcesCatalog_Handler::endElement(const QString&, const QString&,
102 const QString& qName)
106 // tag test_computer_name
107 if((qName.compare(QString(test_computer_name))==0))
108 _a_ressource.Parsername = content;
110 // tag test_computer_OS
111 if((qName.compare(QString(test_computer_OS))==0))
112 _a_ressource.ParserOS = content;
114 // tag test_computer_OS_version
115 if((qName.compare(QString(test_computer_OS_version))==0))
116 _a_ressource.ParserOS_version = content;
118 //tag test_proc_number
119 if((qName.compare(QString(test_proc_number))==0))
120 _a_proc.Parsernumber = atol(content.c_str());
122 //tag test_proc_model
123 if((qName.compare(QString(test_proc_model))==0))
124 _a_proc.Parsermodel_name = content;
127 if((qName.compare(QString(test_proc_cpu))==0))
128 _a_proc.Parsercpu_mhz = atof(content.c_str());
130 //tag test_proc_cache
131 if((qName.compare(QString(test_proc_cache))==0))
132 _a_proc.Parsercache_size = atof(content.c_str());
135 if((qName.compare(QString(test_proc))==0))
137 _procs_list.push_back(_a_proc);
139 // Empty temporary structures
140 _a_proc.Parsernumber = 0;
141 _a_proc.Parsermodel_name = "";
142 _a_proc.Parsercpu_mhz = 0;
143 _a_proc.Parsercache_size = 0;
147 if((qName.compare(QString(test_proc_list))==0))
149 _a_ressource.Parserprocs = _procs_list;
151 // Empty temporary structures
152 _procs_list.resize(0);
155 //tag test_container_type
156 if((qName.compare(QString(test_container_type))==0))
158 // We just have to compare the first character of content
164 _container_list.push_back(Cpp) ;
167 _container_list.push_back(python) ;
170 _container_list.push_back(NP) ;
174 // If it'not in all theses cases, the type is affected to Cpp
175 _container_list.push_back(Cpp) ;
180 //tag test container_type_list
181 if((qName.compare(QString(test_container_type_list))==0))
183 _a_ressource.Parsercontainertype = _container_list;
185 // Empty temporary structures
186 _container_list.resize(0);
190 if((qName.compare(QString(test_computer))==0))
192 _ressources_list.push_back(_a_ressource);
194 // Empty temporary structures
195 _a_ressource.Parsername = "";
196 _a_ressource.ParserOS="";
197 _a_ressource.ParserOS_version="";
198 _a_ressource.Parserprocs.resize(0);
199 _a_ressource.Parsercontainertype.resize(0);
205 //----------------------------------------------------------------------
206 //Function : characters
207 //Purpose: overload handler function
208 //----------------------------------------------------------------------
209 bool SALOME_RessourcesCatalog_Handler::characters(const QString& chars)
211 content = (const char *)chars ;
215 //----------------------------------------------------------------------
216 //Function : endDocument
217 //Purpose: overload handler function
218 //----------------------------------------------------------------------
219 bool SALOME_RessourcesCatalog_Handler::endDocument()
222 for (unsigned int ind = 0; ind < _ressources_list.size(); ind++)
224 MESSAGE("Ressources name :"<<_ressources_list[ind].Parsername);
225 MESSAGE("OS :"<<_ressources_list[ind].ParserOS);
226 MESSAGE("OS version :"<<_ressources_list[ind].ParserOS_version);
227 for (unsigned int i = 0; i < _ressources_list[ind].Parserprocs.size(); i++)
229 MESSAGE("Proc number :" << _ressources_list[ind].Parserprocs[i].Parsernumber);
230 MESSAGE("Model name :" << _ressources_list[ind].Parserprocs[i].Parsermodel_name);
231 MESSAGE("CPU(MHz) :" << _ressources_list[ind].Parserprocs[i].Parsercpu_mhz);
232 MESSAGE("Cache :" << _ressources_list[ind].Parserprocs[i].Parsercache_size);
234 for (unsigned int j = 0; j < _ressources_list[ind].Parsercontainertype.size(); j++)
235 MESSAGE("Container Type :" << _ressources_list[ind].Parsercontainertype[j]);
241 //----------------------------------------------------------------------
242 //Function : errorProtocol
243 //Purpose: overload handler function
244 //----------------------------------------------------------------------
245 QString SALOME_RessourcesCatalog_Handler::errorProtocol()
250 //----------------------------------------------------------------------
251 //Function : fatalError
252 //Purpose: overload handler function
253 //----------------------------------------------------------------------
255 SALOME_RessourcesCatalog_Handler::fatalError(const QXmlParseException& exception)
257 errorProt += QString( "fatal parsing error: %1 in line %2, column %3\n" )
258 .arg( exception.message() )
259 .arg( exception.lineNumber() )
260 .arg( exception.columnNumber() );
262 return QXmlDefaultHandler::fatalError( exception );