1 // SALOME ResourcesCatalog : 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_ResourcesCatalog_Handler.cxx
25 // Author : Estelle Deville
29 #include "SALOME_ResourcesCatalog_Handler.hxx"
33 #include "utilities.h"
37 //----------------------------------------------------------------------
38 //Function : SALOME_ResourcesCatalog_Handler
39 //Purpose: Constructor
40 //----------------------------------------------------------------------
41 SALOME_ResourcesCatalog_Handler::SALOME_ResourcesCatalog_Handler(MapOfParserResourcesType& listOfResources):_resources_list(listOfResources)
43 MESSAGE("SALOME_ResourcesCatalog_Handler creation");
44 //XML tags initialisation
45 test_machine="machine";
46 test_resources="resources";
48 test_hostname="hostname";
50 test_protocol="protocol";
52 test_user_name="userName";
53 test_modules="modules";
54 test_module_name="moduleName";
55 test_module_path="modulePath";
56 test_pre_req_file_path="preReqFilePath";
58 test_mem_in_mb="memInMB";
59 test_cpu_freq_mhz="CPUFreqMHz";
60 test_nb_of_nodes="nbOfNodes";
61 test_nb_of_proc_per_node="nbOfProcPerNode";
64 //----------------------------------------------------------------------
65 //Function : ~SALOME_ResourcesCatalog_Handler
67 //----------------------------------------------------------------------
68 SALOME_ResourcesCatalog_Handler::~SALOME_ResourcesCatalog_Handler()
70 MESSAGE("SALOME_ResourcesCatalog_Handler destruction");
73 //----------------------------------------------------------------------
74 //Function : GetResourcesAfterParsing
75 //Purpose: Retrieves DS after the file parse.
76 //----------------------------------------------------------------------
77 const MapOfParserResourcesType& SALOME_ResourcesCatalog_Handler::GetResourcesAfterParsing() const
79 return _resources_list;
82 //----------------------------------------------------------------------
83 //Function : startDocument
84 //Purpose: overload handler function
85 //----------------------------------------------------------------------
86 bool SALOME_ResourcesCatalog_Handler::startDocument()
88 MESSAGE("Begin parse document");
89 // Empty private elements
90 _resources_list.clear();
94 //----------------------------------------------------------------------
95 //Function : startElement
96 //Purpose: overload handler function
97 //----------------------------------------------------------------------
98 bool SALOME_ResourcesCatalog_Handler::startElement(const QString&,
101 const QXmlAttributes& attrs)
103 for(int i=0;i<attrs.count();i++)
105 QString qName(attrs.localName(i));
106 std::string content(attrs.value(i).latin1());
107 if((qName.compare(QString(test_hostname))==0))
108 _resource.DataForSort._hostName = content;
109 if((qName.compare(QString(test_alias))==0))
110 _resource.Alias = content;
111 if((qName.compare(QString(test_protocol))==0)){
114 _resource.Protocol = rsh;
117 _resource.Protocol = ssh;
120 // If it'not in all theses cases, the protocol is affected to rsh
121 _resource.Protocol = rsh;
125 if((qName.compare(QString(test_mode))==0))
129 _resource.Mode = interactive;
132 _resource.Mode = batch;
135 // If it'not in all theses cases, the mode is affected to interactive
136 _resource.Mode = interactive;
140 if((qName.compare(QString(test_user_name))==0))
141 _resource.UserName = content;
142 if((qName.compare(QString(test_module_name))==0))
143 previous_module_name = content;
144 if((qName.compare(QString(test_module_path))==0))
145 previous_module_path = content;
146 if((qName.compare(QString(test_pre_req_file_path))==0))
147 _resource.PreReqFilePath = content;
148 if((qName.compare(QString(test_os))==0))
149 _resource.OS = content;
150 if((qName.compare(QString(test_mem_in_mb))==0))
151 _resource.DataForSort._memInMB = atoi(content.c_str());
152 if((qName.compare(QString(test_cpu_freq_mhz))==0))
153 _resource.DataForSort._CPUFreqMHz = atoi(content.c_str());
154 if((qName.compare(QString(test_nb_of_nodes))==0))
155 _resource.DataForSort._nbOfNodes = atoi(content.c_str());
156 if((qName.compare(QString(test_nb_of_proc_per_node))==0))
157 _resource.DataForSort._nbOfProcPerNode = atoi(content.c_str());
162 //----------------------------------------------------------------------
163 //Function : endElement
164 //Purpose: overload handler function
165 //----------------------------------------------------------------------
166 bool SALOME_ResourcesCatalog_Handler::endElement(const QString&, const QString&,
167 const QString& qName)
169 if((qName.compare(QString(test_modules))==0))
170 _resource.ModulesPath[previous_module_name] = previous_module_path;
171 if((qName.compare(QString(test_machine))==0))
172 _resources_list[_resource.DataForSort._hostName]=_resource;
176 //----------------------------------------------------------------------
177 //Function : characters
178 //Purpose: overload handler function
179 //----------------------------------------------------------------------
180 bool SALOME_ResourcesCatalog_Handler::characters(const QString& chars)
182 content = (const char *)chars ;
186 //----------------------------------------------------------------------
187 //Function : endDocument
188 //Purpose: overload handler function
189 //----------------------------------------------------------------------
190 bool SALOME_ResourcesCatalog_Handler::endDocument()
193 // for (unsigned int ind = 0; ind < _resources_list.size(); ind++)
195 // MESSAGE("Resources name :"<<_resources_list[ind].Parsername);
196 // MESSAGE("OS :"<<_resources_list[ind].ParserOS);
197 // MESSAGE("OS version :"<<_resources_list[ind].ParserOS_version);
198 // for (unsigned int i = 0; i < _resources_list[ind].Parserprocs.size(); i++)
200 // MESSAGE("Proc number :" << _resources_list[ind].Parserprocs[i].Parsernumber);
201 // MESSAGE("Model name :" << _resources_list[ind].Parserprocs[i].Parsermodel_name);
202 // MESSAGE("CPU(MHz) :" << _resources_list[ind].Parserprocs[i].Parsercpu_mhz);
203 // MESSAGE("Cache :" << _resources_list[ind].Parserprocs[i].Parsercache_size);
205 // for (unsigned int j = 0; j < _resources_list[ind].Parsercontainertype.size(); j++)
206 // MESSAGE("Container Type :" << _resources_list[ind].Parsercontainertype[j]);
208 cout << "This is the end of document" << endl;
212 //----------------------------------------------------------------------
213 //Function : errorProtocol
214 //Purpose: overload handler function
215 //----------------------------------------------------------------------
216 QString SALOME_ResourcesCatalog_Handler::errorProtocol()
218 cout << "error prot !!!!!!!!!!!!!!!!!" << endl;
222 //----------------------------------------------------------------------
223 //Function : fatalError
224 //Purpose: overload handler function
225 //----------------------------------------------------------------------
227 SALOME_ResourcesCatalog_Handler::fatalError(const QXmlParseException& exception)
229 cout << "fatal error !!!!!!!!!!!!!!!!!" << endl;
230 errorProt += QString( "fatal parsing error: %1 in line %2, column %3\n" )
231 .arg( exception.message() )
232 .arg( exception.lineNumber() )
233 .arg( exception.columnNumber() );
235 return QXmlDefaultHandler::fatalError( exception );
238 //----------------------------------------------------------------------
239 //Function : FillDocument
240 //Purpose: Fill the document tree in xml file, used to write in xml file.
241 //----------------------------------------------------------------------
242 void SALOME_ResourcesCatalog_Handler::PrepareDocToXmlFile(QDomDocument& doc)
244 QDomElement root = doc.createElement("resources");
245 doc.appendChild(root);
246 for(map<string, ParserResourcesType>::iterator iter=_resources_list.begin();iter!=_resources_list.end();iter++)
248 QDomElement eltRoot = doc.createElement(test_machine);
249 root.appendChild( eltRoot );
250 eltRoot.setAttribute((char *)test_hostname,(*iter).first.c_str());
251 eltRoot.setAttribute((char *)test_alias,(*iter).second.Alias.c_str());
252 switch((*iter).second.Protocol)
255 eltRoot.setAttribute((char *)test_protocol,"rsh");
258 eltRoot.setAttribute((char *)test_protocol,"ssh");
261 eltRoot.setAttribute((char *)test_protocol,"rsh");
263 switch((*iter).second.Mode)
266 eltRoot.setAttribute((char *)test_mode,"interactive");
269 eltRoot.setAttribute((char *)test_mode,"batch");
272 eltRoot.setAttribute((char *)test_mode,"interactive");
274 eltRoot.setAttribute((char *)test_user_name,(*iter).second.UserName.c_str());
275 for(map<string, string>::const_iterator iter2=(*iter).second.ModulesPath.begin();iter2!=(*iter).second.ModulesPath.end();iter2++)
277 QDomElement rootForModulesPaths=doc.createElement(test_modules);
278 rootForModulesPaths.setAttribute(test_module_name,(*iter2).first.c_str());
279 rootForModulesPaths.setAttribute(test_module_path,(*iter2).second.c_str());
280 eltRoot.appendChild(rootForModulesPaths);
282 eltRoot.setAttribute(test_pre_req_file_path,(*iter).second.PreReqFilePath.c_str());
283 eltRoot.setAttribute(test_os,(*iter).second.OS.c_str());
284 eltRoot.setAttribute(test_mem_in_mb,(*iter).second.DataForSort._memInMB);
285 eltRoot.setAttribute(test_cpu_freq_mhz,(*iter).second.DataForSort._CPUFreqMHz);
286 eltRoot.setAttribute(test_nb_of_nodes,(*iter).second.DataForSort._nbOfNodes);
287 eltRoot.setAttribute(test_nb_of_proc_per_node,(*iter).second.DataForSort._nbOfProcPerNode);