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"
33 #include "SALOME_RessourcesCatalog_Handler.hxx"
35 #include "utilities.h"
39 ListOfParserressources _ressources_list;
41 //----------------------------------------------------------------------
42 //Function : SALOME_RessourcesCatalog_Handler
43 //Purpose: Constructor
44 //----------------------------------------------------------------------
45 SALOME_RessourcesCatalog_Handler::SALOME_RessourcesCatalog_Handler()
47 MESSAGE("SALOME_RessourcesCatalog_Handler creation");
48 //XML tags initialisation
49 test_computer = "computer";
50 test_computer_name="name";
51 test_computer_OS="OS";
52 test_computer_OS_version = "OS-version";
54 test_proc_number ="number" ;
55 test_proc_model= "model" ;
56 test_proc_cpu= "CPU-MHz" ;
57 test_proc_cache = "cache" ;
58 test_proc_list = "proc-list" ;
59 test_container_type = "containertype" ;
60 test_container_type_list = "containertype-list" ;
63 //----------------------------------------------------------------------
64 //Function : ~SALOME_RessourcesCatalog_Handler
66 //----------------------------------------------------------------------
67 SALOME_RessourcesCatalog_Handler::~SALOME_RessourcesCatalog_Handler()
69 MESSAGE("SALOME_RessourcesCatalog_Handler destruction");
72 //----------------------------------------------------------------------
73 //Function : startDocument
74 //Purpose: overload handler function
75 //----------------------------------------------------------------------
77 SALOME_RessourcesCatalog_Handler::startDocument()
79 MESSAGE("Begin parse document");
80 // Empty private elements
81 _procs_list.resize(0);
82 _ressources_list.resize(0);
83 _container_list.resize(0);
87 //----------------------------------------------------------------------
88 //Function : startElement
89 //Purpose: overload handler function
90 //----------------------------------------------------------------------
92 SALOME_RessourcesCatalog_Handler::startElement(const QString&,
95 const QXmlAttributes& atts)
100 //----------------------------------------------------------------------
101 //Function : endElement
102 //Purpose: overload handler function
103 //----------------------------------------------------------------------
105 SALOME_RessourcesCatalog_Handler::endElement(const QString&, const QString&,
106 const QString& qName)
110 // tag test_computer_name
111 if((qName.compare(QString(test_computer_name))==0))
112 _a_ressource.Parsername = content;
114 // tag test_computer_OS
115 if((qName.compare(QString(test_computer_OS))==0))
116 _a_ressource.ParserOS = content;
118 // tag test_computer_OS_version
119 if((qName.compare(QString(test_computer_OS_version))==0))
120 _a_ressource.ParserOS_version = content;
122 //tag test_proc_number
123 if((qName.compare(QString(test_proc_number))==0))
124 _a_proc.Parsernumber = atol(content.c_str());
126 //tag test_proc_model
127 if((qName.compare(QString(test_proc_model))==0))
128 _a_proc.Parsermodel_name = content;
131 if((qName.compare(QString(test_proc_cpu))==0))
132 _a_proc.Parsercpu_mhz = atof(content.c_str());
134 //tag test_proc_cache
135 if((qName.compare(QString(test_proc_cache))==0))
136 _a_proc.Parsercache_size = atof(content.c_str());
139 if((qName.compare(QString(test_proc))==0))
141 _procs_list.push_back(_a_proc);
143 // Empty temporary structures
144 _a_proc.Parsernumber = 0;
145 _a_proc.Parsermodel_name = "";
146 _a_proc.Parsercpu_mhz = 0;
147 _a_proc.Parsercache_size = 0;
151 if((qName.compare(QString(test_proc_list))==0))
153 _a_ressource.Parserprocs = _procs_list;
155 // Empty temporary structures
156 _procs_list.resize(0);
159 //tag test_container_type
160 if((qName.compare(QString(test_container_type))==0))
162 // We just have to compare the first character of content
168 _container_list.push_back(Cpp) ;
171 _container_list.push_back(python) ;
174 _container_list.push_back(NP) ;
178 // If it'not in all theses cases, the type is affected to Cpp
179 _container_list.push_back(Cpp) ;
184 //tag test container_type_list
185 if((qName.compare(QString(test_container_type_list))==0))
187 _a_ressource.Parsercontainertype = _container_list;
189 // Empty temporary structures
190 _container_list.resize(0);
194 if((qName.compare(QString(test_computer))==0))
196 _ressources_list.push_back(_a_ressource);
198 // Empty temporary structures
199 _a_ressource.Parsername = "";
200 _a_ressource.ParserOS="";
201 _a_ressource.ParserOS_version="";
202 _a_ressource.Parserprocs.resize(0);
203 _a_ressource.Parsercontainertype.resize(0);
209 //----------------------------------------------------------------------
210 //Function : characters
211 //Purpose: overload handler function
212 //----------------------------------------------------------------------
213 bool SALOME_RessourcesCatalog_Handler::characters(const QString& chars)
215 content = (const char *)chars ;
219 //----------------------------------------------------------------------
220 //Function : endDocument
221 //Purpose: overload handler function
222 //----------------------------------------------------------------------
223 bool SALOME_RessourcesCatalog_Handler::endDocument()
226 for (unsigned int ind = 0; ind < _ressources_list.size(); ind++)
228 MESSAGE("Ressources name :"<<_ressources_list[ind].Parsername);
229 MESSAGE("OS :"<<_ressources_list[ind].ParserOS);
230 MESSAGE("OS version :"<<_ressources_list[ind].ParserOS_version);
231 for (unsigned int i = 0; i < _ressources_list[ind].Parserprocs.size(); i++)
233 MESSAGE("Proc number :" << _ressources_list[ind].Parserprocs[i].Parsernumber);
234 MESSAGE("Model name :" << _ressources_list[ind].Parserprocs[i].Parsermodel_name);
235 MESSAGE("CPU(MHz) :" << _ressources_list[ind].Parserprocs[i].Parsercpu_mhz);
236 MESSAGE("Cache :" << _ressources_list[ind].Parserprocs[i].Parsercache_size);
238 for (unsigned int j = 0; j < _ressources_list[ind].Parsercontainertype.size(); j++)
239 MESSAGE("Container Type :" << _ressources_list[ind].Parsercontainertype[j]);
245 //----------------------------------------------------------------------
246 //Function : errorProtocol
247 //Purpose: overload handler function
248 //----------------------------------------------------------------------
249 QString SALOME_RessourcesCatalog_Handler::errorProtocol()
254 //----------------------------------------------------------------------
255 //Function : fatalError
256 //Purpose: overload handler function
257 //----------------------------------------------------------------------
259 SALOME_RessourcesCatalog_Handler::fatalError(const QXmlParseException& exception)
261 errorProt += QString( "fatal parsing error: %1 in line %2, column %3\n" )
262 .arg( exception.message() )
263 .arg( exception.lineNumber() )
264 .arg( exception.columnNumber() );
266 return QXmlDefaultHandler::fatalError( exception );