Salome HOME
PR: mergefrom_PRAS_br3_06Nov04
[modules/kernel.git] / src / RessourcesCatalog / SALOME_RessourcesCatalog_Handler.cxx
1 //  SALOME RessourcesCatalog : implementation of catalog resources parsing (SALOME_ModuleCatalog.idl)
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SALOME_RessourcesCatalog_Handler.cxx
25 //  Author : Estelle Deville
26 //  Module : SALOME
27 //$Header$
28
29 #include "SALOME_RessourcesCatalog_Handler.hxx"
30
31 #include "utilities.h"
32
33 #include "SALOME_RessourcesCatalog_Handler.hxx"
34
35 #include "utilities.h"
36
37 using namespace std;
38
39 ListOfParserressources _ressources_list;
40
41 //----------------------------------------------------------------------
42 //Function : SALOME_RessourcesCatalog_Handler
43 //Purpose: Constructor
44 //----------------------------------------------------------------------
45 SALOME_RessourcesCatalog_Handler::SALOME_RessourcesCatalog_Handler()
46 {
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";
53   test_proc = "proc";
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" ;
61 }
62
63 //----------------------------------------------------------------------
64 //Function : ~SALOME_RessourcesCatalog_Handler
65 //Purpose: Destructor
66 //----------------------------------------------------------------------
67 SALOME_RessourcesCatalog_Handler::~SALOME_RessourcesCatalog_Handler()
68 {
69   MESSAGE("SALOME_RessourcesCatalog_Handler destruction");
70 }
71
72 //----------------------------------------------------------------------
73 //Function : startDocument
74 //Purpose: overload handler function 
75 //----------------------------------------------------------------------
76 bool 
77 SALOME_RessourcesCatalog_Handler::startDocument()
78 {
79   MESSAGE("Begin parse document");
80   // Empty private elements
81   _procs_list.resize(0);
82   _ressources_list.resize(0);
83   _container_list.resize(0);
84   return true;
85 }
86
87 //----------------------------------------------------------------------
88 //Function : startElement
89 //Purpose: overload handler function 
90 //----------------------------------------------------------------------
91 bool 
92 SALOME_RessourcesCatalog_Handler::startElement(const QString&, 
93                                                const QString&,
94                                                const QString& qName, 
95                                                const QXmlAttributes& atts)
96 {
97   return true;
98 }
99
100 //----------------------------------------------------------------------
101 //Function : endElement
102 //Purpose: overload handler function 
103 //----------------------------------------------------------------------
104 bool 
105 SALOME_RessourcesCatalog_Handler::endElement(const QString&, const QString&,
106                                              const QString& qName)
107 {
108   // Ressources
109
110   // tag test_computer_name
111   if((qName.compare(QString(test_computer_name))==0))
112     _a_ressource.Parsername = content;
113
114   // tag test_computer_OS
115   if((qName.compare(QString(test_computer_OS))==0))
116     _a_ressource.ParserOS = content;
117
118  // tag test_computer_OS_version
119   if((qName.compare(QString(test_computer_OS_version))==0))
120     _a_ressource.ParserOS_version = content;
121
122   //tag test_proc_number
123  if((qName.compare(QString(test_proc_number))==0))
124     _a_proc.Parsernumber = atol(content.c_str());
125
126   //tag test_proc_model
127  if((qName.compare(QString(test_proc_model))==0))
128     _a_proc.Parsermodel_name = content;
129
130   //tag test_proc_cpu
131  if((qName.compare(QString(test_proc_cpu))==0))
132     _a_proc.Parsercpu_mhz = atof(content.c_str());
133
134   //tag test_proc_cache
135  if((qName.compare(QString(test_proc_cache))==0))
136     _a_proc.Parsercache_size = atof(content.c_str());
137
138   //tag test_proc
139  if((qName.compare(QString(test_proc))==0))
140    {
141      _procs_list.push_back(_a_proc);
142
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;
148    }
149
150  //tag test_proc_list
151  if((qName.compare(QString(test_proc_list))==0))
152    {
153      _a_ressource.Parserprocs = _procs_list;
154
155      // Empty temporary structures
156      _procs_list.resize(0);
157    }
158
159   //tag test_container_type
160  if((qName.compare(QString(test_container_type))==0))
161    {
162      // We just have to compare the first character of content
163      // If C => Cpp
164      // If p => python
165      // If N => NP
166      switch(content[0]) {
167      case 'C':
168        _container_list.push_back(Cpp) ;
169        break;
170      case 'p':
171         _container_list.push_back(python) ;
172        break;
173      case 'N':
174         _container_list.push_back(NP) ;
175        break;
176        
177      default:
178        // If it'not in all theses cases, the type is affected to Cpp
179        _container_list.push_back(Cpp) ;
180        break;
181        }
182    }
183
184  //tag test container_type_list
185  if((qName.compare(QString(test_container_type_list))==0))
186    {
187      _a_ressource.Parsercontainertype = _container_list;
188
189      // Empty temporary structures
190      _container_list.resize(0);
191    }
192
193  // tag test_computer
194   if((qName.compare(QString(test_computer))==0))
195    {
196      _ressources_list.push_back(_a_ressource);
197
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);
204    }
205
206   return true;
207 }
208
209 //----------------------------------------------------------------------
210 //Function : characters
211 //Purpose: overload handler function
212 //----------------------------------------------------------------------
213 bool SALOME_RessourcesCatalog_Handler::characters(const QString& chars)
214 {
215   content = (const char *)chars ;
216   return true;
217 }
218
219 //----------------------------------------------------------------------
220 //Function : endDocument
221 //Purpose: overload handler function 
222 //----------------------------------------------------------------------
223 bool SALOME_RessourcesCatalog_Handler::endDocument()
224 {
225   //_ressources_list
226   for (unsigned int ind = 0; ind < _ressources_list.size(); ind++)
227     {
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++)
232         {
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);
237         }
238       for (unsigned int j = 0; j < _ressources_list[ind].Parsercontainertype.size(); j++)
239         MESSAGE("Container Type :" << _ressources_list[ind].Parsercontainertype[j]);
240     }
241
242  return true;
243 }
244
245 //----------------------------------------------------------------------
246 //Function : errorProtocol
247 //Purpose: overload handler function
248 //----------------------------------------------------------------------
249 QString SALOME_RessourcesCatalog_Handler::errorProtocol()
250 {
251   return errorProt;
252 }
253
254 //----------------------------------------------------------------------
255 //Function : fatalError
256 //Purpose: overload handler function
257 //----------------------------------------------------------------------
258 bool 
259 SALOME_RessourcesCatalog_Handler::fatalError(const QXmlParseException& exception)
260 {
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() );
265
266   return QXmlDefaultHandler::fatalError( exception );
267 }
268