Salome HOME
PR: corrections residuelles des anomalies du merge cvs
[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 using namespace std;
34
35 ListOfParserressources _ressources_list;
36
37 //----------------------------------------------------------------------
38 //Function : SALOME_RessourcesCatalog_Handler
39 //Purpose: Constructor
40 //----------------------------------------------------------------------
41 SALOME_RessourcesCatalog_Handler::SALOME_RessourcesCatalog_Handler()
42 {
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";
49   test_proc = "proc";
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" ;
57 }
58
59 //----------------------------------------------------------------------
60 //Function : ~SALOME_RessourcesCatalog_Handler
61 //Purpose: Destructor
62 //----------------------------------------------------------------------
63 SALOME_RessourcesCatalog_Handler::~SALOME_RessourcesCatalog_Handler()
64 {
65   MESSAGE("SALOME_RessourcesCatalog_Handler destruction");
66 }
67
68 //----------------------------------------------------------------------
69 //Function : startDocument
70 //Purpose: overload handler function 
71 //----------------------------------------------------------------------
72 bool 
73 SALOME_RessourcesCatalog_Handler::startDocument()
74 {
75   MESSAGE("Begin parse document");
76   // Empty private elements
77   _procs_list.resize(0);
78   _ressources_list.resize(0);
79   _container_list.resize(0);
80   return true;
81 }
82
83 //----------------------------------------------------------------------
84 //Function : startElement
85 //Purpose: overload handler function 
86 //----------------------------------------------------------------------
87 bool 
88 SALOME_RessourcesCatalog_Handler::startElement(const QString&, 
89                                                const QString&,
90                                                const QString& qName, 
91                                                const QXmlAttributes& atts)
92 {
93   return true;
94 }
95
96 //----------------------------------------------------------------------
97 //Function : endElement
98 //Purpose: overload handler function 
99 //----------------------------------------------------------------------
100 bool 
101 SALOME_RessourcesCatalog_Handler::endElement(const QString&, const QString&,
102                                              const QString& qName)
103 {
104   // Ressources
105
106   // tag test_computer_name
107   if((qName.compare(QString(test_computer_name))==0))
108     _a_ressource.Parsername = content;
109
110   // tag test_computer_OS
111   if((qName.compare(QString(test_computer_OS))==0))
112     _a_ressource.ParserOS = content;
113
114  // tag test_computer_OS_version
115   if((qName.compare(QString(test_computer_OS_version))==0))
116     _a_ressource.ParserOS_version = content;
117
118   //tag test_proc_number
119  if((qName.compare(QString(test_proc_number))==0))
120     _a_proc.Parsernumber = atol(content.c_str());
121
122   //tag test_proc_model
123  if((qName.compare(QString(test_proc_model))==0))
124     _a_proc.Parsermodel_name = content;
125
126   //tag test_proc_cpu
127  if((qName.compare(QString(test_proc_cpu))==0))
128     _a_proc.Parsercpu_mhz = atof(content.c_str());
129
130   //tag test_proc_cache
131  if((qName.compare(QString(test_proc_cache))==0))
132     _a_proc.Parsercache_size = atof(content.c_str());
133
134   //tag test_proc
135  if((qName.compare(QString(test_proc))==0))
136    {
137      _procs_list.push_back(_a_proc);
138
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;
144    }
145
146  //tag test_proc_list
147  if((qName.compare(QString(test_proc_list))==0))
148    {
149      _a_ressource.Parserprocs = _procs_list;
150
151      // Empty temporary structures
152      _procs_list.resize(0);
153    }
154
155   //tag test_container_type
156  if((qName.compare(QString(test_container_type))==0))
157    {
158      // We just have to compare the first character of content
159      // If C => Cpp
160      // If p => python
161      // If N => NP
162      switch(content[0]) {
163      case 'C':
164        _container_list.push_back(Cpp) ;
165        break;
166      case 'p':
167         _container_list.push_back(python) ;
168        break;
169      case 'N':
170         _container_list.push_back(NP) ;
171        break;
172        
173      default:
174        // If it'not in all theses cases, the type is affected to Cpp
175        _container_list.push_back(Cpp) ;
176        break;
177        }
178    }
179
180  //tag test container_type_list
181  if((qName.compare(QString(test_container_type_list))==0))
182    {
183      _a_ressource.Parsercontainertype = _container_list;
184
185      // Empty temporary structures
186      _container_list.resize(0);
187    }
188
189  // tag test_computer
190   if((qName.compare(QString(test_computer))==0))
191    {
192      _ressources_list.push_back(_a_ressource);
193
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);
200    }
201
202   return true;
203 }
204
205 //----------------------------------------------------------------------
206 //Function : characters
207 //Purpose: overload handler function
208 //----------------------------------------------------------------------
209 bool SALOME_RessourcesCatalog_Handler::characters(const QString& chars)
210 {
211   content = (const char *)chars ;
212   return true;
213 }
214
215 //----------------------------------------------------------------------
216 //Function : endDocument
217 //Purpose: overload handler function 
218 //----------------------------------------------------------------------
219 bool SALOME_RessourcesCatalog_Handler::endDocument()
220 {
221   //_ressources_list
222   for (unsigned int ind = 0; ind < _ressources_list.size(); ind++)
223     {
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++)
228         {
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);
233         }
234       for (unsigned int j = 0; j < _ressources_list[ind].Parsercontainertype.size(); j++)
235         MESSAGE("Container Type :" << _ressources_list[ind].Parsercontainertype[j]);
236     }
237
238  return true;
239 }
240
241 //----------------------------------------------------------------------
242 //Function : errorProtocol
243 //Purpose: overload handler function
244 //----------------------------------------------------------------------
245 QString SALOME_RessourcesCatalog_Handler::errorProtocol()
246 {
247   return errorProt;
248 }
249
250 //----------------------------------------------------------------------
251 //Function : fatalError
252 //Purpose: overload handler function
253 //----------------------------------------------------------------------
254 bool 
255 SALOME_RessourcesCatalog_Handler::fatalError(const QXmlParseException& exception)
256 {
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() );
261
262   return QXmlDefaultHandler::fatalError( exception );
263 }
264