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
30 #define WRITE_RESSOURCES_TYPE
31 #include "SALOME_RessourcesCatalog_Handler.hxx"
33 //----------------------------------------------------------------------
34 //Function : SALOME_RessourcesCatalog_Handler
35 //Purpose: Constructor
36 //----------------------------------------------------------------------
37 SALOME_RessourcesCatalog_Handler::SALOME_RessourcesCatalog_Handler()
39 MESSAGE("SALOME_RessourcesCatalog_Handler creation");
40 //XML tags initialisation
41 test_computer = "computer";
42 test_computer_name="name";
43 test_computer_OS="OS";
44 test_computer_OS_version = "OS-version";
46 test_proc_number ="number" ;
47 test_proc_model= "model" ;
48 test_proc_cpu= "CPU-MHz" ;
49 test_proc_cache = "cache" ;
50 test_proc_list = "proc-list" ;
51 test_container_type = "containertype" ;
52 test_container_type_list = "containertype-list" ;
55 //----------------------------------------------------------------------
56 //Function : ~SALOME_RessourcesCatalog_Handler
58 //----------------------------------------------------------------------
59 SALOME_RessourcesCatalog_Handler::~SALOME_RessourcesCatalog_Handler()
61 MESSAGE("SALOME_RessourcesCatalog_Handler destruction");
64 //----------------------------------------------------------------------
65 //Function : startDocument
66 //Purpose: overload handler function
67 //----------------------------------------------------------------------
69 SALOME_RessourcesCatalog_Handler::startDocument()
71 MESSAGE("Begin parse document");
72 // Empty private elements
73 _procs_list.resize(0);
74 _ressources_list.resize(0);
75 _container_list.resize(0);
79 //----------------------------------------------------------------------
80 //Function : startElement
81 //Purpose: overload handler function
82 //----------------------------------------------------------------------
84 SALOME_RessourcesCatalog_Handler::startElement(const QString&,
87 const QXmlAttributes& atts)
92 //----------------------------------------------------------------------
93 //Function : endElement
94 //Purpose: overload handler function
95 //----------------------------------------------------------------------
97 SALOME_RessourcesCatalog_Handler::endElement(const QString&, const QString&,
102 // tag test_computer_name
103 if((qName.compare(QString(test_computer_name))==0))
104 _a_ressource.Parsername = content;
106 // tag test_computer_OS
107 if((qName.compare(QString(test_computer_OS))==0))
108 _a_ressource.ParserOS = content;
110 // tag test_computer_OS_version
111 if((qName.compare(QString(test_computer_OS_version))==0))
112 _a_ressource.ParserOS_version = content;
114 //tag test_proc_number
115 if((qName.compare(QString(test_proc_number))==0))
116 _a_proc.Parsernumber = atol(content.c_str());
118 //tag test_proc_model
119 if((qName.compare(QString(test_proc_model))==0))
120 _a_proc.Parsermodel_name = content;
123 if((qName.compare(QString(test_proc_cpu))==0))
124 _a_proc.Parsercpu_mhz = atof(content.c_str());
126 //tag test_proc_cache
127 if((qName.compare(QString(test_proc_cache))==0))
128 _a_proc.Parsercache_size = atof(content.c_str());
131 if((qName.compare(QString(test_proc))==0))
133 _procs_list.push_back(_a_proc);
135 // Empty temporary structures
136 _a_proc.Parsernumber = 0;
137 _a_proc.Parsermodel_name = "";
138 _a_proc.Parsercpu_mhz = 0;
139 _a_proc.Parsercache_size = 0;
143 if((qName.compare(QString(test_proc_list))==0))
145 _a_ressource.Parserprocs = _procs_list;
147 // Empty temporary structures
148 _procs_list.resize(0);
151 //tag test_container_type
152 if((qName.compare(QString(test_container_type))==0))
154 // We just have to compare the first character of content
160 _container_list.push_back(Cpp) ;
163 _container_list.push_back(python) ;
166 _container_list.push_back(NP) ;
170 // If it'not in all theses cases, the type is affected to Cpp
171 _container_list.push_back(Cpp) ;
176 //tag test container_type_list
177 if((qName.compare(QString(test_container_type_list))==0))
179 _a_ressource.Parsercontainertype = _container_list;
181 // Empty temporary structures
182 _container_list.resize(0);
186 if((qName.compare(QString(test_computer))==0))
188 _ressources_list.push_back(_a_ressource);
190 // Empty temporary structures
191 _a_ressource.Parsername = "";
192 _a_ressource.ParserOS="";
193 _a_ressource.ParserOS_version="";
194 _a_ressource.Parserprocs.resize(0);
195 _a_ressource.Parsercontainertype.resize(0);
201 //----------------------------------------------------------------------
202 //Function : characters
203 //Purpose: overload handler function
204 //----------------------------------------------------------------------
205 bool SALOME_RessourcesCatalog_Handler::characters(const QString& chars)
207 content = (const char *)chars ;
211 //----------------------------------------------------------------------
212 //Function : endDocument
213 //Purpose: overload handler function
214 //----------------------------------------------------------------------
215 bool SALOME_RessourcesCatalog_Handler::endDocument()
218 for (unsigned int ind = 0; ind < _ressources_list.size(); ind++)
220 MESSAGE("Ressources name :"<<_ressources_list[ind].Parsername);
221 MESSAGE("OS :"<<_ressources_list[ind].ParserOS);
222 MESSAGE("OS version :"<<_ressources_list[ind].ParserOS_version);
223 for (unsigned int i = 0; i < _ressources_list[ind].Parserprocs.size(); i++)
225 MESSAGE("Proc number :" << _ressources_list[ind].Parserprocs[i].Parsernumber);
226 MESSAGE("Model name :" << _ressources_list[ind].Parserprocs[i].Parsermodel_name);
227 MESSAGE("CPU(MHz) :" << _ressources_list[ind].Parserprocs[i].Parsercpu_mhz);
228 MESSAGE("Cache :" << _ressources_list[ind].Parserprocs[i].Parsercache_size);
230 for (unsigned int j = 0; j < _ressources_list[ind].Parsercontainertype.size(); j++)
231 MESSAGE("Container Type :" << _ressources_list[ind].Parsercontainertype[j]);
237 //----------------------------------------------------------------------
238 //Function : errorProtocol
239 //Purpose: overload handler function
240 //----------------------------------------------------------------------
241 QString SALOME_RessourcesCatalog_Handler::errorProtocol()
246 //----------------------------------------------------------------------
247 //Function : fatalError
248 //Purpose: overload handler function
249 //----------------------------------------------------------------------
251 SALOME_RessourcesCatalog_Handler::fatalError(const QXmlParseException& exception)
253 errorProt += QString( "fatal parsing error: %1 in line %2, column %3\n" )
254 .arg( exception.message() )
255 .arg( exception.lineNumber() )
256 .arg( exception.columnNumber() );
258 return QXmlDefaultHandler::fatalError( exception );