2 // File: SALOME_RessourcesCatalog_impl.cxx
3 // Created: Mon Sep 10 2001
4 // Author: Estelle Deville
6 // Copyright : CEA/DEN/DMSS/LGLS
9 #include "SALOME_RessourcesCatalog_impl.hxx"
12 //----------------------------------------------------------------------
13 // Function : SALOME_RessourcesCatalogImpl
14 // Purpose : Constructor
15 //----------------------------------------------------------------------
16 SALOME_RessourcesCatalogImpl::SALOME_RessourcesCatalogImpl(int argc, char** argv)
18 MESSAGE("Ressources Catalog creation");
20 // Empty used variables
21 _ressourceslist.resize(0);
23 // Parse the arguments given at server run
24 if (!_parseArguments(argc, argv,&_path_ressources))
25 MESSAGE( "Error while argument parsing" )
27 // Test existency of files
28 if (_path_ressources == NULL)
29 MESSAGE( "Error the ressources catalog should be indicated" )
32 MESSAGE("Parse ressources catalog");
33 // Affect the variable _ressourceslist
34 _parse_xml_file(_path_ressources,_ressourceslist);
36 // Verification of _datatype_list content
37 if(!_verify_ressources(_ressourceslist))
38 MESSAGE( "Error while parsing the ressources catalog" )
39 else MESSAGE("Ressources Catalog OK");
43 //----------------------------------------------------------------------
44 // Function : ~SALOME_RessourcesCatalogImpl
45 // Purpose : Destructor
46 //----------------------------------------------------------------------
47 SALOME_RessourcesCatalogImpl::~SALOME_RessourcesCatalogImpl()
49 MESSAGE("Ressources Catalog Destruction");
52 //----------------------------------------------------------------------
53 // Function : GetComputerList
54 // Purpose : get ressources list
55 //----------------------------------------------------------------------
56 SALOME_RessourcesCatalog::ListOfComputer*
57 SALOME_RessourcesCatalogImpl::GetComputerList()
59 MESSAGE("Begin of GetComputerList");
60 SALOME_RessourcesCatalog::ListOfComputer_var _list = new SALOME_RessourcesCatalog::ListOfComputer;
61 _list->length(_ressourceslist.size());
62 for (unsigned int ind=0; ind < _ressourceslist.size();ind++)
64 _list[ind]=CORBA::string_dup(_ressourceslist[ind].Parsername.c_str());
70 //----------------------------------------------------------------------
71 // Function : GetRessourcesList
72 // Purpose : get a data type name list
73 //----------------------------------------------------------------------
74 SALOME_RessourcesCatalog::ListOfContainerType*
75 SALOME_RessourcesCatalogImpl::GetContainerTypeList(const char* computer)
76 throw(SALOME_RessourcesCatalog::NotFound)
78 MESSAGE("Begin of GetContainerTypeList");
79 SALOME_RessourcesCatalog::ListOfContainerType_var _list =
80 new SALOME_RessourcesCatalog::ListOfContainerType;
84 // Looking for ressources named "computer"
85 // If found, get container type list
86 // If not found, exception is thrown
88 for (unsigned int ind=0; ind < _ressourceslist.size();ind++)
90 if (strcmp((_ressourceslist[ind].Parsername).c_str(),computer) == 0)
92 MESSAGE("Ressources named " << computer << " found in the ressources catalog");
95 _list->length(_ressourceslist[ind].Parsercontainertype.size());
96 for (unsigned int ind1=0; ind1 < _ressourceslist[ind].Parsercontainertype.size();ind1++)
98 // get container type list
99 switch(_ressourceslist[ind].Parsercontainertype[ind1]){
101 _list[ind1] = SALOME_RessourcesCatalog::Cpp;
104 _list[ind1] = SALOME_RessourcesCatalog::python;
107 _list[ind1] = SALOME_RessourcesCatalog::NP;
116 // The ressources was not found, the exception should be thrown
117 MESSAGE( "The ressource " << computer << " was not found in the ressources catalog" )
118 throw SALOME_RessourcesCatalog::NotFound() ;
120 return _list._retn();
123 //----------------------------------------------------------------------
124 // Function : GetComputerInfo
125 // Purpose : get ressources information
126 //----------------------------------------------------------------------
127 SALOME_RessourcesCatalog::computer_info*
128 SALOME_RessourcesCatalogImpl::GetComputerInfo(const char* computer)
129 throw(SALOME_RessourcesCatalog::NotFound)
131 MESSAGE("Begin of GetComputerInfo");
132 SALOME_RessourcesCatalog::computer_info_var _computer_info =
133 new SALOME_RessourcesCatalog::computer_info;
137 // Looking for ressources named "computer"
138 // If found, get computer info
139 // If not found, exception is thrown
140 for (unsigned int ind=0; ind < _ressourceslist.size();ind++)
142 if (strcmp((_ressourceslist[ind].Parsername).c_str(),computer) == 0)
144 MESSAGE("Ressources named " << computer << " found in the ressources catalog");
147 _computer_info->name = CORBA::string_dup(_ressourceslist[ind].Parsername.c_str());
148 _computer_info->OS = CORBA::string_dup(_ressourceslist[ind].ParserOS.c_str());
149 _computer_info->OS_version = CORBA::string_dup(_ressourceslist[ind].ParserOS_version.c_str());
150 _computer_info->procs = _duplicate_procs(_ressourceslist[ind].Parserprocs);
156 // The ressources was not found, the exception should be thrown
157 MESSAGE( "The ressource " << computer << " was not found in the ressources catalog" )
158 throw SALOME_RessourcesCatalog::NotFound() ;
160 return _computer_info._retn();
165 //----------------------------------------------------------------------
166 // Function : _parse_xml_file
167 // Purpose : parse one module catalog
168 //----------------------------------------------------------------------
170 SALOME_RessourcesCatalogImpl::_parse_xml_file(const char* file,
171 ListOfParserressources& ressourceslist)
173 SALOME_RessourcesCatalog_Handler* handler = new SALOME_RessourcesCatalog_Handler();
176 QXmlInputSource source(xmlFile);
178 QXmlSimpleReader reader;
179 reader.setContentHandler( handler );
180 reader.setErrorHandler( handler );
181 reader.parse( source );
183 ressourceslist = _ressources_list;
187 //----------------------------------------------------------------------
188 // Function : _verify_ressources
189 // Purpose : verify ressources from the catalog parsing
190 // Verify that a computer is'nt defined twice in the catalog
191 //----------------------------------------------------------------------
193 SALOME_RessourcesCatalogImpl::_verify_ressources(ListOfParserressources ressourceslist)
195 bool _return_value = true;
197 vector<string> _machine_list;
198 _machine_list.resize(0);
200 // Fill a list of all computers indicated in the ressources list
201 for (unsigned int ind = 0; ind < ressourceslist.size(); ind++)
202 _machine_list.push_back(ressourceslist[ind].Parsername);
204 // Parse if a computer name is twice in the list of computers
205 for (unsigned int ind = 0; ind < _machine_list.size(); ind++)
207 for (unsigned int ind1 = ind+1 ; ind1 < _machine_list.size(); ind1++)
209 if(_machine_list[ind].compare(_machine_list[ind1]) == 0)
211 MESSAGE("The computer " << _machine_list[ind] << " is indicated more than once in the ressources list")
212 _return_value = false;
217 return _return_value;
221 //----------------------------------------------------------------------
222 // Function : _parseArguments
223 // Purpose : parse arguments to get general and personal catalog files
224 //----------------------------------------------------------------------
226 SALOME_RessourcesCatalogImpl::_parseArguments(int argc, char **argv,
229 bool _return_value = true;
231 for (int ind = 0; ind < argc ; ind++)
234 if (strcmp(argv[ind],"-help") == 0)
236 INFOS( "Usage: " << argv[0] << " -common 'path to ressources catalog' -ORBInitRef NameService=corbaname::localhost");
237 _return_value = false ;
239 if (strcmp(argv[ind],"-common") == 0)
243 // General catalog file
244 *_path= argv[ind + 1] ;
245 ifstream _path_file(*_path);
248 MESSAGE( "Sorry the file " << *_path << " can't be open" )
250 _return_value = false;
256 return _return_value;
259 //----------------------------------------------------------------------
260 // Function : _duplicate_procs
261 // Purpose : create a list of processors information from the catalog parsing
262 //----------------------------------------------------------------------
263 SALOME_RessourcesCatalog::ListOfProc
264 SALOME_RessourcesCatalogImpl::_duplicate_procs(ListOfParserProc list_procs)
266 SALOME_RessourcesCatalog::ListOfProc _list_procs;
267 unsigned int _length = list_procs.size();
268 _list_procs.length(_length);
270 for (unsigned int ind = 0; ind < _length; ind++)
272 //duplicate processor number
273 _list_procs[ind].number = list_procs[ind].Parsernumber;
275 //duplicate model name
276 _list_procs[ind].model_name = CORBA::string_dup(list_procs[ind].Parsermodel_name.c_str());
279 _list_procs[ind].cpu_mhz = list_procs[ind].Parsercpu_mhz;
281 // duplicate cache size
282 _list_procs[ind].cache_size = list_procs[ind].Parsercache_size;