1 // SALOME RessourcesCatalog : 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_RessourcesCatalog_impl.cxx
25 // Author : Estelle Deville
29 #include "SALOME_RessourcesCatalog_impl.hxx"
32 //----------------------------------------------------------------------
33 // Function : SALOME_RessourcesCatalogImpl
34 // Purpose : Constructor
35 //----------------------------------------------------------------------
36 SALOME_RessourcesCatalogImpl::SALOME_RessourcesCatalogImpl(int argc, char** argv)
38 MESSAGE("Ressources Catalog creation");
40 // Empty used variables
41 _ressourceslist.resize(0);
43 // Parse the arguments given at server run
44 if (!_parseArguments(argc, argv,&_path_ressources))
45 MESSAGE( "Error while argument parsing" )
47 // Test existency of files
48 if (_path_ressources == NULL)
49 MESSAGE( "Error the ressources catalog should be indicated" )
52 MESSAGE("Parse ressources catalog");
53 // Affect the variable _ressourceslist
54 _parse_xml_file(_path_ressources,_ressourceslist);
56 // Verification of _datatype_list content
57 if(!_verify_ressources(_ressourceslist))
58 MESSAGE( "Error while parsing the ressources catalog" )
59 else MESSAGE("Ressources Catalog OK");
63 //----------------------------------------------------------------------
64 // Function : ~SALOME_RessourcesCatalogImpl
65 // Purpose : Destructor
66 //----------------------------------------------------------------------
67 SALOME_RessourcesCatalogImpl::~SALOME_RessourcesCatalogImpl()
69 MESSAGE("Ressources Catalog Destruction");
72 //----------------------------------------------------------------------
73 // Function : GetComputerList
74 // Purpose : get ressources list
75 //----------------------------------------------------------------------
76 SALOME_RessourcesCatalog::ListOfComputer*
77 SALOME_RessourcesCatalogImpl::GetComputerList()
79 MESSAGE("Begin of GetComputerList");
80 SALOME_RessourcesCatalog::ListOfComputer_var _list = new SALOME_RessourcesCatalog::ListOfComputer;
81 _list->length(_ressourceslist.size());
82 for (unsigned int ind=0; ind < _ressourceslist.size();ind++)
84 _list[ind]=CORBA::string_dup(_ressourceslist[ind].Parsername.c_str());
90 //----------------------------------------------------------------------
91 // Function : GetRessourcesList
92 // Purpose : get a data type name list
93 //----------------------------------------------------------------------
94 SALOME_RessourcesCatalog::ListOfContainerType*
95 SALOME_RessourcesCatalogImpl::GetContainerTypeList(const char* computer)
96 throw(SALOME_RessourcesCatalog::NotFound)
98 MESSAGE("Begin of GetContainerTypeList");
99 SALOME_RessourcesCatalog::ListOfContainerType_var _list =
100 new SALOME_RessourcesCatalog::ListOfContainerType;
104 // Looking for ressources named "computer"
105 // If found, get container type list
106 // If not found, exception is thrown
108 for (unsigned int ind=0; ind < _ressourceslist.size();ind++)
110 if (strcmp((_ressourceslist[ind].Parsername).c_str(),computer) == 0)
112 MESSAGE("Ressources named " << computer << " found in the ressources catalog");
115 _list->length(_ressourceslist[ind].Parsercontainertype.size());
116 for (unsigned int ind1=0; ind1 < _ressourceslist[ind].Parsercontainertype.size();ind1++)
118 // get container type list
119 switch(_ressourceslist[ind].Parsercontainertype[ind1]){
121 _list[ind1] = SALOME_RessourcesCatalog::Cpp;
124 _list[ind1] = SALOME_RessourcesCatalog::python;
127 _list[ind1] = SALOME_RessourcesCatalog::NP;
136 // The ressources was not found, the exception should be thrown
137 MESSAGE( "The ressource " << computer << " was not found in the ressources catalog" )
138 throw SALOME_RessourcesCatalog::NotFound() ;
140 return _list._retn();
143 //----------------------------------------------------------------------
144 // Function : GetComputerInfo
145 // Purpose : get ressources information
146 //----------------------------------------------------------------------
147 SALOME_RessourcesCatalog::computer_info*
148 SALOME_RessourcesCatalogImpl::GetComputerInfo(const char* computer)
149 throw(SALOME_RessourcesCatalog::NotFound)
151 MESSAGE("Begin of GetComputerInfo");
152 SALOME_RessourcesCatalog::computer_info_var _computer_info =
153 new SALOME_RessourcesCatalog::computer_info;
157 // Looking for ressources named "computer"
158 // If found, get computer info
159 // If not found, exception is thrown
160 for (unsigned int ind=0; ind < _ressourceslist.size();ind++)
162 if (strcmp((_ressourceslist[ind].Parsername).c_str(),computer) == 0)
164 MESSAGE("Ressources named " << computer << " found in the ressources catalog");
167 _computer_info->name = CORBA::string_dup(_ressourceslist[ind].Parsername.c_str());
168 _computer_info->OS = CORBA::string_dup(_ressourceslist[ind].ParserOS.c_str());
169 _computer_info->OS_version = CORBA::string_dup(_ressourceslist[ind].ParserOS_version.c_str());
170 _computer_info->procs = _duplicate_procs(_ressourceslist[ind].Parserprocs);
176 // The ressources was not found, the exception should be thrown
177 MESSAGE( "The ressource " << computer << " was not found in the ressources catalog" )
178 throw SALOME_RessourcesCatalog::NotFound() ;
180 return _computer_info._retn();
185 //----------------------------------------------------------------------
186 // Function : _parse_xml_file
187 // Purpose : parse one module catalog
188 //----------------------------------------------------------------------
190 SALOME_RessourcesCatalogImpl::_parse_xml_file(const char* file,
191 ListOfParserressources& ressourceslist)
193 SALOME_RessourcesCatalog_Handler* handler = new SALOME_RessourcesCatalog_Handler();
196 QXmlInputSource source(xmlFile);
198 QXmlSimpleReader reader;
199 reader.setContentHandler( handler );
200 reader.setErrorHandler( handler );
201 reader.parse( source );
203 ressourceslist = _ressources_list;
207 //----------------------------------------------------------------------
208 // Function : _verify_ressources
209 // Purpose : verify ressources from the catalog parsing
210 // Verify that a computer is'nt defined twice in the catalog
211 //----------------------------------------------------------------------
213 SALOME_RessourcesCatalogImpl::_verify_ressources(ListOfParserressources ressourceslist)
215 bool _return_value = true;
217 vector<string> _machine_list;
218 _machine_list.resize(0);
220 // Fill a list of all computers indicated in the ressources list
221 for (unsigned int ind = 0; ind < ressourceslist.size(); ind++)
222 _machine_list.push_back(ressourceslist[ind].Parsername);
224 // Parse if a computer name is twice in the list of computers
225 for (unsigned int ind = 0; ind < _machine_list.size(); ind++)
227 for (unsigned int ind1 = ind+1 ; ind1 < _machine_list.size(); ind1++)
229 if(_machine_list[ind].compare(_machine_list[ind1]) == 0)
231 MESSAGE("The computer " << _machine_list[ind] << " is indicated more than once in the ressources list")
232 _return_value = false;
237 return _return_value;
241 //----------------------------------------------------------------------
242 // Function : _parseArguments
243 // Purpose : parse arguments to get general and personal catalog files
244 //----------------------------------------------------------------------
246 SALOME_RessourcesCatalogImpl::_parseArguments(int argc, char **argv,
249 bool _return_value = true;
251 for (int ind = 0; ind < argc ; ind++)
254 if (strcmp(argv[ind],"-help") == 0)
256 INFOS( "Usage: " << argv[0] << " -common 'path to ressources catalog' -ORBInitRef NameService=corbaname::localhost");
257 _return_value = false ;
259 if (strcmp(argv[ind],"-common") == 0)
263 // General catalog file
264 *_path= argv[ind + 1] ;
265 ifstream _path_file(*_path);
268 MESSAGE( "Sorry the file " << *_path << " can't be open" )
270 _return_value = false;
276 return _return_value;
279 //----------------------------------------------------------------------
280 // Function : _duplicate_procs
281 // Purpose : create a list of processors information from the catalog parsing
282 //----------------------------------------------------------------------
283 SALOME_RessourcesCatalog::ListOfProc
284 SALOME_RessourcesCatalogImpl::_duplicate_procs(ListOfParserProc list_procs)
286 SALOME_RessourcesCatalog::ListOfProc _list_procs;
287 unsigned int _length = list_procs.size();
288 _list_procs.length(_length);
290 for (unsigned int ind = 0; ind < _length; ind++)
292 //duplicate processor number
293 _list_procs[ind].number = list_procs[ind].Parsernumber;
295 //duplicate model name
296 _list_procs[ind].model_name = CORBA::string_dup(list_procs[ind].Parsermodel_name.c_str());
299 _list_procs[ind].cpu_mhz = list_procs[ind].Parsercpu_mhz;
301 // duplicate cache size
302 _list_procs[ind].cache_size = list_procs[ind].Parsercache_size;