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