Salome HOME
NRI : Remove OCC_LIBS.
[modules/kernel.git] / src / RessourcesCatalog / SALOME_RessourcesCatalog_Handler.cxx
1 using namespace std;
2 //File SALOME_RessourcesCatalog_Handler.cxx
3 //Created: Fri Sept 07 2001
4 //Author: Estelle Deville
5 //Project: SALOME
6 //Copyright: CEA/DEN/DM2S/LGLS
7 //$Header$
8
9 #define WRITE_RESSOURCES_TYPE
10 #include "SALOME_RessourcesCatalog_Handler.hxx"
11
12 //----------------------------------------------------------------------
13 //Function : SALOME_RessourcesCatalog_Handler
14 //Purpose: Constructor
15 //----------------------------------------------------------------------
16 SALOME_RessourcesCatalog_Handler::SALOME_RessourcesCatalog_Handler()
17 {
18   MESSAGE("SALOME_RessourcesCatalog_Handler creation");
19   //XML tags initialisation
20   test_computer = "computer";
21   test_computer_name="name";
22   test_computer_OS="OS";
23   test_computer_OS_version = "OS-version";
24   test_proc = "proc";
25   test_proc_number ="number" ;
26   test_proc_model= "model" ;
27   test_proc_cpu= "CPU-MHz" ;
28   test_proc_cache = "cache" ;
29   test_proc_list = "proc-list" ;
30   test_container_type = "containertype" ;
31   test_container_type_list = "containertype-list" ;
32 }
33
34 //----------------------------------------------------------------------
35 //Function : ~SALOME_RessourcesCatalog_Handler
36 //Purpose: Destructor
37 //----------------------------------------------------------------------
38 SALOME_RessourcesCatalog_Handler::~SALOME_RessourcesCatalog_Handler()
39 {
40   MESSAGE("SALOME_RessourcesCatalog_Handler destruction");
41 }
42
43 //----------------------------------------------------------------------
44 //Function : startDocument
45 //Purpose: overload handler function 
46 //----------------------------------------------------------------------
47 bool 
48 SALOME_RessourcesCatalog_Handler::startDocument()
49 {
50   MESSAGE("Begin parse document");
51   // Empty private elements
52   _procs_list.resize(0);
53   _ressources_list.resize(0);
54   _container_list.resize(0);
55   return true;
56 }
57
58 //----------------------------------------------------------------------
59 //Function : startElement
60 //Purpose: overload handler function 
61 //----------------------------------------------------------------------
62 bool 
63 SALOME_RessourcesCatalog_Handler::startElement(const QString&, 
64                                                const QString&,
65                                                const QString& qName, 
66                                                const QXmlAttributes& atts)
67 {
68   return true;
69 }
70
71 //----------------------------------------------------------------------
72 //Function : endElement
73 //Purpose: overload handler function 
74 //----------------------------------------------------------------------
75 bool 
76 SALOME_RessourcesCatalog_Handler::endElement(const QString&, const QString&,
77                                              const QString& qName)
78 {
79   // Ressources
80
81   // tag test_computer_name
82   if((qName.compare(QString(test_computer_name))==0))
83     _a_ressource.Parsername = content;
84
85   // tag test_computer_OS
86   if((qName.compare(QString(test_computer_OS))==0))
87     _a_ressource.ParserOS = content;
88
89  // tag test_computer_OS_version
90   if((qName.compare(QString(test_computer_OS_version))==0))
91     _a_ressource.ParserOS_version = content;
92
93   //tag test_proc_number
94  if((qName.compare(QString(test_proc_number))==0))
95     _a_proc.Parsernumber = atol(content.c_str());
96
97   //tag test_proc_model
98  if((qName.compare(QString(test_proc_model))==0))
99     _a_proc.Parsermodel_name = content;
100
101   //tag test_proc_cpu
102  if((qName.compare(QString(test_proc_cpu))==0))
103     _a_proc.Parsercpu_mhz = atof(content.c_str());
104
105   //tag test_proc_cache
106  if((qName.compare(QString(test_proc_cache))==0))
107     _a_proc.Parsercache_size = atof(content.c_str());
108
109   //tag test_proc
110  if((qName.compare(QString(test_proc))==0))
111    {
112      _procs_list.push_back(_a_proc);
113
114      // Empty temporary structures
115      _a_proc.Parsernumber = 0;
116      _a_proc.Parsermodel_name = "";
117      _a_proc.Parsercpu_mhz = 0;
118      _a_proc.Parsercache_size = 0;
119    }
120
121  //tag test_proc_list
122  if((qName.compare(QString(test_proc_list))==0))
123    {
124      _a_ressource.Parserprocs = _procs_list;
125
126      // Empty temporary structures
127      _procs_list.resize(0);
128    }
129
130   //tag test_container_type
131  if((qName.compare(QString(test_container_type))==0))
132    {
133      // We just have to compare the first character of content
134      // If C => Cpp
135      // If p => python
136      // If N => NP
137      switch(content[0]) {
138      case 'C':
139        _container_list.push_back(Cpp) ;
140        break;
141      case 'p':
142         _container_list.push_back(python) ;
143        break;
144      case 'N':
145         _container_list.push_back(NP) ;
146        break;
147        
148      default:
149        // If it'not in all theses cases, the type is affected to Cpp
150        _container_list.push_back(Cpp) ;
151        break;
152        }
153    }
154
155  //tag test container_type_list
156  if((qName.compare(QString(test_container_type_list))==0))
157    {
158      _a_ressource.Parsercontainertype = _container_list;
159
160      // Empty temporary structures
161      _container_list.resize(0);
162    }
163
164  // tag test_computer
165   if((qName.compare(QString(test_computer))==0))
166    {
167      _ressources_list.push_back(_a_ressource);
168
169      // Empty temporary structures
170      _a_ressource.Parsername = "";
171      _a_ressource.ParserOS="";
172      _a_ressource.ParserOS_version="";
173      _a_ressource.Parserprocs.resize(0);
174      _a_ressource.Parsercontainertype.resize(0);
175    }
176
177   return true;
178 }
179
180 //----------------------------------------------------------------------
181 //Function : characters
182 //Purpose: overload handler function
183 //----------------------------------------------------------------------
184 bool SALOME_RessourcesCatalog_Handler::characters(const QString& chars)
185 {
186   content = chars ;
187   return true;
188 }
189
190 //----------------------------------------------------------------------
191 //Function : endDocument
192 //Purpose: overload handler function 
193 //----------------------------------------------------------------------
194 bool SALOME_RessourcesCatalog_Handler::endDocument()
195 {
196   //_ressources_list
197   for (unsigned int ind = 0; ind < _ressources_list.size(); ind++)
198     {
199       MESSAGE("Ressources name :"<<_ressources_list[ind].Parsername);
200       MESSAGE("OS :"<<_ressources_list[ind].ParserOS); 
201       MESSAGE("OS version :"<<_ressources_list[ind].ParserOS_version);
202       for (unsigned int i = 0; i < _ressources_list[ind].Parserprocs.size(); i++)
203         {
204           MESSAGE("Proc number :" << _ressources_list[ind].Parserprocs[i].Parsernumber);
205           MESSAGE("Model name :" << _ressources_list[ind].Parserprocs[i].Parsermodel_name);
206           MESSAGE("CPU(MHz) :" << _ressources_list[ind].Parserprocs[i].Parsercpu_mhz);
207           MESSAGE("Cache :" << _ressources_list[ind].Parserprocs[i].Parsercache_size);
208         }
209       for (unsigned int j = 0; j < _ressources_list[ind].Parsercontainertype.size(); j++)
210         MESSAGE("Container Type :" << _ressources_list[ind].Parsercontainertype[j]);
211     }
212
213  return true;
214 }
215
216 //----------------------------------------------------------------------
217 //Function : errorProtocol
218 //Purpose: overload handler function
219 //----------------------------------------------------------------------
220 QString SALOME_RessourcesCatalog_Handler::errorProtocol()
221 {
222   return errorProt;
223 }
224
225 //----------------------------------------------------------------------
226 //Function : fatalError
227 //Purpose: overload handler function
228 //----------------------------------------------------------------------
229 bool 
230 SALOME_RessourcesCatalog_Handler::fatalError(const QXmlParseException& exception)
231 {
232     errorProt += QString( "fatal parsing error: %1 in line %2, column %3\n" )
233     .arg( exception.message() )
234     .arg( exception.lineNumber() )
235     .arg( exception.columnNumber() );
236
237   return QXmlDefaultHandler::fatalError( exception );
238 }
239