Salome HOME
Initialisation de la base KERNEL avec la version operationnelle de KERNEL_SRC issue...
[modules/yacs.git] / src / ModuleCatalog / SALOME_ModuleCatalog_impl.cxx
1 using namespace std;
2 // File: SALOME_ModuleCatalog_impl.cxx
3 // Created: Tue June 28 2001
4 // Author: Estelle Deville
5 // Project: SALOME
6 // Copyright : CEA/DEN/DMSS/LGLS
7 // $Header$
8
9 #include "SALOME_ModuleCatalog_impl.hxx"
10 #include "SALOME_ModuleCatalog_Acomponent_impl.hxx"
11 #include <fstream>
12
13 #include <qstringlist.h>
14 #include <qfileinfo.h>
15
16 static const char* SEPARATOR    = ":";
17
18 //----------------------------------------------------------------------
19 // Function : SALOME_ModuleCatalogImpl
20 // Purpose  : Constructor 
21 //----------------------------------------------------------------------
22 SALOME_ModuleCatalogImpl::SALOME_ModuleCatalogImpl(int argc, char** argv)
23 {
24   MESSAGE("Catalog creation");
25
26   // Empty used variables
27   _general_module_list.resize(0);
28   _general_path_list.resize(0);
29
30   _personal_module_list.resize(0);
31   _personal_path_list.resize(0);
32
33   // Parse the arguments given at server run
34   if (!_parseArguments(argc, argv,&_general_path,&_personal_path))
35     MESSAGE( "Error while argument parsing" )
36
37   // Test existency of files
38   if (_general_path == NULL)
39     MESSAGE( "Error the general catalog should be indicated" )
40   else
41     {
42       //MESSAGE("Parse general catalog");
43       // Affect the variables _general_module_list and _general_path_list 
44       // with the common catalog
45       
46       QStringList dirList = QStringList::split( SEPARATOR, _general_path, false ); // skip empty entries
47       for ( int i = 0; i < dirList.count(); i++ ) {
48         QFileInfo fileInfo( dirList[ i ] );
49         if ( fileInfo.isFile() && fileInfo.exists() ) {
50           _parse_xml_file(fileInfo.filePath(),_general_module_list, _general_path_list);
51         }
52       }
53
54       // Verification of _general_path_list content
55       if(!_verify_path_prefix(_general_path_list))
56         MESSAGE( "Error while parsing the general path list, differents pathes are associated to one computer, the first will be choosen" )
57       else MESSAGE("General path list OK");
58     
59       if(_personal_path != NULL)
60         {
61           //MESSAGE("Parse personal catalog");
62           // Affect the variables _personal_module_list and _personal_path_list 
63           // with the personal catalog
64           _parse_xml_file(_personal_path,_personal_module_list, _personal_path_list);
65           
66           // Verification of _general_path_list content
67           if(!_verify_path_prefix(_personal_path_list))
68             MESSAGE("Error while parsing the personal path list, differents pathes are associated to one computer, the first will be choosen" )
69           else MESSAGE("Personal path list OK");
70         }
71       else MESSAGE("No personal catalog indicated or error while opening the personal catalog");
72     }
73 }
74
75 //----------------------------------------------------------------------
76 // Function : ~SALOME_ModuleCatalogImpl
77 // Purpose  : Destructor 
78 //----------------------------------------------------------------------
79 SALOME_ModuleCatalogImpl::~SALOME_ModuleCatalogImpl()
80 {
81   MESSAGE("Catalog Destruction");
82 }
83
84
85 //----------------------------------------------------------------------
86 // Function : GetComputerList
87 // Purpose  : get a computer list
88 //----------------------------------------------------------------------
89 SALOME_ModuleCatalog::ListOfComputers* 
90 SALOME_ModuleCatalogImpl::GetComputerList()
91 {
92   SALOME_ModuleCatalog::ListOfComputers_var _list_computers = 
93     new SALOME_ModuleCatalog::ListOfComputers;
94   return _list_computers._retn();
95 }
96
97 //----------------------------------------------------------------------
98 // Function : GetPathPrefix
99 // Purpose  : get the PathPrefix of a computer
100 //----------------------------------------------------------------------
101 char* 
102 SALOME_ModuleCatalogImpl::GetPathPrefix(const char* machinename) {
103   MESSAGE("Begin of GetPathPrefix")
104   // Variables initialisation
105   char* _path = NULL;
106   bool _find = false ;
107
108   // Parse all the path prefixes
109   // looking for the wanted computer
110   for (unsigned int ind = 0 ; ind < _personal_path_list.size() ; ind++)
111     {
112       for (unsigned int ind1 = 0 ; ind1 < _personal_path_list[ind].ListOfComputer.size() ; ind1++)    
113         {
114           if (strcmp(machinename, _personal_path_list[ind].ListOfComputer[ind1].c_str()) == 0)
115             {
116               _find = true ;
117               // Wanted computer
118               // affect the path to be returned
119                 const char* _temp = _personal_path_list[ind].path.c_str() ;
120                   _path = new char[strlen(_temp)+1];
121               strcpy(_path,_temp);
122             }
123         }
124     }
125
126   if (!_find)
127     {
128     for (unsigned int ind = 0 ; ind < _general_path_list.size() ; ind++)
129       {
130         for (unsigned int ind1 = 0 ; ind1 < _general_path_list[ind].ListOfComputer.size() ; ind1++)    
131           {
132             if (strcmp(machinename, _general_path_list[ind].ListOfComputer[ind1].c_str()) == 0)
133               {
134                 _find = true ;
135                 // Wanted computer
136                 // affect the path to be returned
137                   const char* _temp = _general_path_list[ind].path.c_str() ;
138                     _path = new char[strlen(_temp)+1];
139                 strcpy(_path,_temp);
140               }
141           }
142       }
143     }
144
145   return _path;
146 }
147
148 //----------------------------------------------------------------------
149 // Function : GetComponentList
150 // Purpose  : get a component list
151 //            If a component is defined in the personal catalog and 
152 //            in the general catalog (same name), the component defined
153 //            in the personal catalog is used
154 //----------------------------------------------------------------------
155 SALOME_ModuleCatalog::ListOfComponents* 
156 SALOME_ModuleCatalogImpl::GetComponentList()
157 {
158   MESSAGE("Begin of GetComponentList");
159   SALOME_ModuleCatalog::ListOfComponents_var _list_components = 
160     new SALOME_ModuleCatalog::ListOfComponents;
161
162   _list_components->length(_personal_module_list.size());
163
164   // All the components defined in the personal catalog are taken
165   for (unsigned int ind=0; ind < _personal_module_list.size();ind++)
166     {
167        _list_components[ind]=(_personal_module_list[ind].Parsercomponentname).c_str();
168        //SCRUTE(_list_components[ind]) ;
169     }
170
171   int indice = _personal_module_list.size() ;
172   bool _find = false;
173   
174   // The components in the general catalog are taken only if they're
175   // not defined in the personal catalog
176   for (unsigned int ind=0; ind < _general_module_list.size();ind++)
177     {
178       _find = false;
179       for (unsigned int ind1=0; ind1 < _personal_module_list.size();ind1++)
180         {
181           // searching if the component is already defined in 
182           // the personal catalog
183           if ((_general_module_list[ind].Parsercomponentname.compare(_personal_module_list[ind1].Parsercomponentname)) == 0)
184             _find = true;
185         }
186       if (!_find)
187         {
188           //MESSAGE("A new component " << _general_module_list[ind].Parsercomponentname << " has to be to added in the list");
189           _list_components->length(indice+1);
190           // The component is not already defined => has to be taken
191           _list_components[indice]=(_general_module_list[ind].Parsercomponentname).c_str();   
192           //SCRUTE(_list_components[indice]) ;
193
194           indice++;
195         }
196       // else 
197         //MESSAGE("The component " <<_general_module_list[ind].Parsercomponentname << " was already defined in the personal catalog") ;
198      }
199
200   return _list_components._retn();
201 }
202
203
204 //----------------------------------------------------------------------
205 // Function : GetComponentIconeList
206 // Purpose  : get a component list of component name and component icone
207 //            If a component is defined in the personal catalog and 
208 //            in the general catalog (same name), the component defined
209 //            in the personal catalog is used
210 //----------------------------------------------------------------------
211 SALOME_ModuleCatalog::ListOfIAPP_Affich* 
212 SALOME_ModuleCatalogImpl::GetComponentIconeList()
213 {
214   MESSAGE("Begin of GetComponentIconeList");
215
216   SALOME_ModuleCatalog::ListOfIAPP_Affich_var _list_components_icone = 
217     new SALOME_ModuleCatalog::ListOfIAPP_Affich;
218
219   _list_components_icone->length(_personal_module_list.size());
220
221   // All the components defined in the personal catalog are taken
222   for (unsigned int ind=0; ind < _personal_module_list.size();ind++)
223     {
224        _list_components_icone[ind].modulename=(_personal_module_list[ind].Parsercomponentname).c_str();
225        _list_components_icone[ind].moduleicone=(_personal_module_list[ind].Parsercomponenticone).c_str();
226        //SCRUTE(_list_components_icone[ind].modulename); 
227        //SCRUTE(_list_components_icone[ind].moduleicone);
228     }
229
230   int indice = _personal_module_list.size() ;
231   bool _find = false;
232   
233   // The components in the general catalog are taken only if they're
234   // not defined in the personal catalog
235   for (unsigned int ind=0; ind < _general_module_list.size();ind++)
236     {
237       _find = false;
238       for (unsigned int ind1=0; ind1 < _personal_module_list.size();ind1++)
239         {
240           // searching if the component is aleready defined in 
241           // the personal catalog
242           if ((_general_module_list[ind].Parsercomponentname.compare(_personal_module_list[ind1].Parsercomponentname)) == 0)
243             _find = true;
244         }
245       if (!_find)
246         {
247           //      MESSAGE("A new component " << _general_module_list[ind].Parsercomponentname << " has to be to added in the list");
248           _list_components_icone->length(indice+1);
249           // The component is not already defined => has to be taken
250           _list_components_icone[indice].modulename=(_general_module_list[ind].Parsercomponentname).c_str();  
251           _list_components_icone[indice].moduleicone=(_general_module_list[ind].Parsercomponenticone).c_str(); 
252           //SCRUTE(_list_components_icone[indice].modulename) ;
253           //SCRUTE(_list_components_icone[indice].moduleicone);
254
255           indice++;
256         }
257       // else 
258         //MESSAGE("The component " <<_general_module_list[ind].Parsercomponentname << " was already defined in the personal catalog"); 
259      }
260
261   return _list_components_icone._retn() ;
262 }
263
264 //----------------------------------------------------------------------
265 // Function : GetTypedComponentList
266 // Purpose  : get a component list of a wanted type
267 //            If a component is defined in the personal catalog and 
268 //            in the general catalog (same name), the component defined
269 //            in the personal catalog is used
270 //----------------------------------------------------------------------
271 SALOME_ModuleCatalog::ListOfComponents* 
272 SALOME_ModuleCatalogImpl::GetTypedComponentList(SALOME_ModuleCatalog::ComponentType component_type)
273 {
274   MESSAGE("Begin of GetTypedComponentList");
275   SALOME_ModuleCatalog::ListOfComponents_var _list_typed_component = 
276     new SALOME_ModuleCatalog::ListOfComponents;
277   int _j = 0;
278
279   _list_typed_component->length(0);
280   // Transform SALOME_ModuleCatalog::ComponentType in ParserComponentType
281   ParserComponentType _temp_component_type;
282   switch(component_type){
283   case SALOME_ModuleCatalog::GEOM:
284     _temp_component_type = GEOM ;
285     break;
286   case SALOME_ModuleCatalog::MESH:
287     _temp_component_type = MESH;
288     break;   
289   case SALOME_ModuleCatalog::Med:
290     _temp_component_type = Med;
291     break;    
292   case SALOME_ModuleCatalog::SOLVER:   
293     _temp_component_type = SOLVER;
294     break;
295   case SALOME_ModuleCatalog::DATA:
296     _temp_component_type = DATA;
297     break;
298   case SALOME_ModuleCatalog::VISU:
299     _temp_component_type = VISU;
300     break;  
301   case SALOME_ModuleCatalog::SUPERV:
302     _temp_component_type = SUPERV;
303     break;
304   case SALOME_ModuleCatalog::OTHER:
305     _temp_component_type = OTHER;
306     break;
307   }
308
309   // All the components in the personal catalog are taken
310   for (unsigned int ind=0; ind < _personal_module_list.size();ind++)
311     {
312       if  (_personal_module_list[ind].Parsercomponenttype == _temp_component_type)
313         {
314           _list_typed_component->length(_j + 1); 
315           _list_typed_component[_j] = (_modulelist[ind].Parsercomponentname).c_str();
316           //SCRUTE(_list_typed_component[_j])
317           _j++;
318         }
319     }
320
321   int indice = _list_typed_component->length() ;
322   bool _find = false;
323   
324   // The components in the general catalog are taken only if they're
325   // not defined in the personal catalog
326   for (unsigned int ind=0; ind < _general_module_list.size();ind++)
327     {
328       _find = false;
329
330       if(_general_module_list[ind].Parsercomponenttype == _temp_component_type)
331         {
332           for (unsigned int ind1=0; ind1 < _personal_module_list.size();ind1++)
333             {
334               // searching if the component is aleready defined in 
335               // the personal catalog
336               if ((_general_module_list[ind].Parsercomponentname.compare(_personal_module_list[ind1].Parsercomponentname)) == 0)
337                 _find = true;
338             }
339           if (!_find)
340             {
341               //MESSAGE("A new component " << _general_module_list[ind].Parsercomponentname << " has to be to added in the list");
342               _list_typed_component->length(indice+1);
343               // The component is not already defined => has to be taken
344               _list_typed_component[indice]=(_general_module_list[ind].Parsercomponentname).c_str();   
345               //SCRUTE(_list_typed_component[indice]) ;
346
347               indice++;
348             }
349           //else 
350             //MESSAGE("The component " <<_general_module_list[ind].Parsercomponentname << " was already defined in the personal catalog") ;
351         }
352     }
353
354
355   return _list_typed_component._retn();
356 }
357
358 //----------------------------------------------------------------------
359 // Function : GetComponent
360 // Purpose  : get a component 
361 //            If a component is defined in the personal catalog and 
362 //            in the general catalog (same name), the component defined
363 //            in the personal catalog is used
364 //----------------------------------------------------------------------
365 SALOME_ModuleCatalog::Acomponent_ptr 
366 SALOME_ModuleCatalogImpl::GetComponent(const char* componentname)
367 {
368   SALOME_ModuleCatalog::Acomponent_ptr compo;
369   SALOME_ModuleCatalog::ListOfDefInterface _list_interfaces;
370   _list_interfaces.length(0);
371   char* _constraint = NULL;
372   char* _icone = NULL;
373   SALOME_ModuleCatalog::ComponentType _componenttype = SALOME_ModuleCatalog::OTHER; // default initialisation
374   CORBA::Boolean _componentmultistudy = false ; // default initialisation
375   ListOfPathPrefix _pathes ;
376   _pathes.resize(0);
377   
378
379   bool find = false ;
380
381   // Looking for component named "componentname" in the personal catalog
382   // If found, get name, interfaces and constraint
383   // If not found, looking for component named "componentname" in
384   // the general catalog
385   // If found, get name, interfaces and constraint
386   // If not found, NULL pointer is returned
387
388   for (unsigned int ind=0; ind < _personal_module_list.size();ind++)
389     {
390      if (strcmp((_personal_module_list[ind].Parsercomponentname).c_str(),componentname) == 0)
391         {
392           //MESSAGE("Component named " << componentname << " found in the personal catalog");
393             find = true;
394
395           // get constraint
396           _constraint = new char[strlen(_personal_module_list[ind].Parserconstraint.c_str()) + 1];
397           _constraint = CORBA::string_dup(_personal_module_list[ind].Parserconstraint.c_str());
398
399           // get component type
400           switch(_personal_module_list[ind].Parsercomponenttype){
401           case GEOM:
402             _componenttype = SALOME_ModuleCatalog::GEOM;
403             break;
404           case MESH:
405             _componenttype = SALOME_ModuleCatalog::MESH;
406             break;
407           case Med:
408             _componenttype = SALOME_ModuleCatalog::Med;
409             break;
410           case SOLVER:
411             _componenttype = SALOME_ModuleCatalog::SOLVER;
412             break;
413           case DATA:
414             _componenttype = SALOME_ModuleCatalog::DATA;
415             break;
416           case VISU:
417             _componenttype = SALOME_ModuleCatalog::VISU;
418             break;
419           case SUPERV:
420             _componenttype = SALOME_ModuleCatalog::SUPERV;
421             break;
422           case OTHER:
423             _componenttype = SALOME_ModuleCatalog::OTHER;
424             break;
425           }
426           
427           // get component multistudy
428           _componentmultistudy = _personal_module_list[ind].Parsercomponentmultistudy ;
429
430           // get component icone
431           _icone = CORBA::string_dup(_personal_module_list[ind].Parsercomponenticone.c_str());
432
433           // get component interfaces
434           _list_interfaces = duplicate_interfaces(_personal_module_list[ind].ParserListInterface);
435
436           // get pathes prefix
437           _pathes = duplicate_pathes(_personal_path_list);
438
439         }
440     }
441   
442   if (find)
443     {
444       SALOME_ModuleCatalog_AcomponentImpl* aComponentImpl = 
445         new SALOME_ModuleCatalog_AcomponentImpl(componentname,
446                                                 _constraint,
447                                                 _componenttype,
448                                                 _componentmultistudy,
449                                                 _icone,
450                                                 _list_interfaces,
451                                                 _pathes);
452       
453       compo = aComponentImpl->_this();
454     }
455   else
456     // Not found in the personal catalog => searching in the general catalog
457     {
458       for (unsigned int ind=0; ind < _general_module_list.size();ind++)
459         {
460           if (strcmp((_general_module_list[ind].Parsercomponentname).c_str(),componentname) == 0)
461             {
462               //MESSAGE("Component named " << componentname << " found in the general catalog");
463               find = true;
464
465               // get constraint
466               _constraint = new char[strlen(_general_module_list[ind].Parserconstraint.c_str()) + 1];
467               _constraint = CORBA::string_dup(_general_module_list[ind].Parserconstraint.c_str());
468
469
470               // get component type
471               switch(_general_module_list[ind].Parsercomponenttype){
472               case GEOM:
473                 _componenttype = SALOME_ModuleCatalog::GEOM;
474                 break;
475               case MESH:
476                 _componenttype = SALOME_ModuleCatalog::MESH;
477                 break;
478               case Med:
479                 _componenttype = SALOME_ModuleCatalog::Med;
480                 break;
481               case SOLVER:
482                 _componenttype = SALOME_ModuleCatalog::SOLVER;
483                 break;
484               case DATA:
485                 _componenttype = SALOME_ModuleCatalog::DATA;
486                 break;
487               case VISU:
488                 _componenttype = SALOME_ModuleCatalog::VISU;
489                 break;
490               case SUPERV:
491                 _componenttype = SALOME_ModuleCatalog::SUPERV;
492                 break;
493               case OTHER:
494                 _componenttype = SALOME_ModuleCatalog::OTHER;
495                 break;
496               }
497
498
499               // get component multistudy
500               _componentmultistudy = _general_module_list[ind].Parsercomponentmultistudy ;
501
502               // get component icone
503               _icone = CORBA::string_dup(_general_module_list[ind].Parsercomponenticone.c_str());
504
505               // get component interfaces
506               _list_interfaces = duplicate_interfaces(_general_module_list[ind].ParserListInterface);
507
508               // get pathes prefix
509               _pathes = duplicate_pathes(_general_path_list);
510             }
511         }
512   
513       if (find)
514         {
515           SALOME_ModuleCatalog_AcomponentImpl* aComponentImpl = 
516             new SALOME_ModuleCatalog_AcomponentImpl(componentname,
517                                                     _constraint,
518                                                     _componenttype,
519                                                     _componentmultistudy,
520                                                     _icone,
521                                                     _list_interfaces,
522                                                     _pathes);
523       
524           compo = aComponentImpl->_this();
525         }
526       else
527         // Not found in the personal catalog and in the general catalog
528         // return NULL object
529         {
530           MESSAGE("Component with name  " << componentname << " not found in catalog");
531           compo = NULL;
532         }
533     }
534   return compo;
535 }
536
537 //----------------------------------------------------------------------
538 // Function : _parse_xml_file
539 // Purpose  : parse one module catalog 
540 //----------------------------------------------------------------------
541 void 
542 SALOME_ModuleCatalogImpl::_parse_xml_file(const char* file, 
543                                           ListOfParserComponent& modulelist, 
544                                           ListOfParserPathPrefix& pathlist)
545 {
546   SALOME_ModuleCatalog_Handler* handler = new SALOME_ModuleCatalog_Handler();
547   QFile xmlFile(file);
548
549   QXmlInputSource source(xmlFile);
550
551   QXmlSimpleReader reader;
552   reader.setContentHandler( handler );
553   reader.setErrorHandler( handler );
554   reader.parse( source );
555   xmlFile.close();
556   unsigned int ind;
557   for ( ind = 0; ind < _modulelist.size(); ind++)
558     modulelist.push_back(_modulelist[ind]) ;
559   for ( ind = 0; ind < _pathlist.size(); ind++)
560     pathlist.push_back(_pathlist[ind]) ;
561 }
562
563 //----------------------------------------------------------------------
564 // Function : duplicate_interfaces
565 // Purpose  : create a list of interfaces from the parsing of the catalog
566 //----------------------------------------------------------------------
567 SALOME_ModuleCatalog::ListOfDefInterface
568 SALOME_ModuleCatalogImpl::duplicate_interfaces(ListOfDefinitionInterface list_interface)
569 {
570   SALOME_ModuleCatalog::ListOfDefInterface _list_interfaces;
571   unsigned int _length_interfaces = list_interface.size();
572   _list_interfaces.length(_length_interfaces);
573   
574   for (unsigned int ind = 0; ind < _length_interfaces; ind++)
575     {
576       //duplicate interface name
577       _list_interfaces[ind].interfacename = CORBA::string_dup(list_interface[ind].Parserinterfacename.c_str());
578
579       // duplicate service list
580       unsigned int _length_services = list_interface[ind].Parserinterfaceservicelist.size();
581       _list_interfaces[ind].interfaceservicelist.length(_length_services);
582
583       for (unsigned int ind1 = 0; ind1 < _length_services ; ind1 ++)
584         {
585           // duplicate service name
586           _list_interfaces[ind].interfaceservicelist[ind1].ServiceName =
587             CORBA::string_dup(list_interface[ind].Parserinterfaceservicelist[ind1].ParserServiceName.c_str());
588
589           // duplicate service by default
590           _list_interfaces[ind].interfaceservicelist[ind1].Servicebydefault =
591             list_interface[ind].Parserinterfaceservicelist[ind1].ParserServicebydefault;
592
593           // duplicate in Parameters
594           unsigned int _length_in_param = list_interface[ind].Parserinterfaceservicelist[ind1].ParserServiceinParameter.size();
595           _list_interfaces[ind].interfaceservicelist[ind1].ServiceinParameter.length(_length_in_param);
596           for (unsigned int ind2 = 0; ind2 < _length_in_param ; ind2 ++)
597             {
598               // duplicate parameter type
599               _list_interfaces[ind].interfaceservicelist[ind1].ServiceinParameter[ind2].Parametertype = CORBA::string_dup(list_interface[ind].Parserinterfaceservicelist[ind1].ParserServiceinParameter[ind2].ParserParamtype.c_str());
600               
601               // duplicate parameter name
602               _list_interfaces[ind].interfaceservicelist[ind1].ServiceinParameter[ind2].Parametername = CORBA::string_dup(list_interface[ind].Parserinterfaceservicelist[ind1].ParserServiceinParameter[ind2].ParserParamname.c_str());
603             }
604
605           // duplicate out Parameters
606           unsigned int _length_out_param = list_interface[ind].Parserinterfaceservicelist[ind1].ParserServiceoutParameter.size();
607           _list_interfaces[ind].interfaceservicelist[ind1].ServiceoutParameter.length(_length_out_param);
608           for (unsigned int ind2 = 0; ind2 < _length_out_param ; ind2 ++)
609             {
610               // duplicate parameter type
611               _list_interfaces[ind].interfaceservicelist[ind1].ServiceoutParameter[ind2].Parametertype = CORBA::string_dup(list_interface[ind].Parserinterfaceservicelist[ind1].ParserServiceoutParameter[ind2].ParserParamtype.c_str());
612               
613               // duplicate parameter name
614               _list_interfaces[ind].interfaceservicelist[ind1].ServiceoutParameter[ind2].Parametername = CORBA::string_dup(list_interface[ind].Parserinterfaceservicelist[ind1].ParserServiceoutParameter[ind2].ParserParamname.c_str());
615             }
616       
617         }
618     }
619   return _list_interfaces;
620 }
621
622
623 //----------------------------------------------------------------------
624 // Function : duplicate_pathes
625 // Purpose  : create the path prefix structures from the catalog parsing
626 //----------------------------------------------------------------------
627 ListOfPathPrefix 
628 SALOME_ModuleCatalogImpl::duplicate_pathes(ListOfParserPathPrefix pathes)
629 {
630   ListOfPathPrefix _pathes ;
631
632   unsigned int _length = pathes.size() ;
633   _pathes.resize(_length);
634   unsigned int _length_comput = 0;
635   
636   for (unsigned int ind = 0; ind < _length ; ind++)
637     {
638       // duplicate path
639       _pathes[ind].path = CORBA::string_dup(pathes[ind].path.c_str()) ;
640       //MESSAGE("Prefix : " << _pathes[ind].path);
641
642       _length_comput = pathes[ind].ListOfComputer.size() ;
643       _pathes[ind].ListOfComputer.resize(_length_comput);
644       for (unsigned int ind1 = 0; ind1 <_length_comput  ; ind1++)
645         {
646           // duplicate computer name
647           _pathes[ind].ListOfComputer[ind1] = CORBA::string_dup(pathes[ind].ListOfComputer[ind1].c_str());
648           //MESSAGE("Computer associated to the prefix : " <<_pathes[ind].ListOfComputer[ind1]);  
649         }
650     } 
651   return _pathes ;
652 }
653
654
655 //----------------------------------------------------------------------
656 // Function : _verify_path_prefix
657 // Purpose  : verify the path prefix structures from the catalog parsing
658 //            Verify that there only one path prefix associated to a 
659 //            particular computer
660 //----------------------------------------------------------------------
661 bool
662 SALOME_ModuleCatalogImpl::_verify_path_prefix(ListOfParserPathPrefix pathlist)
663 {
664   bool _return_value = true;
665   vector<string> _machine_list;
666   _machine_list.resize(0);
667
668   // Fill a list of all computers indicated in the path list
669   for (unsigned int ind = 0; ind < pathlist.size(); ind++)
670     { 
671       for (unsigned int ind1 = 0 ; ind1 < pathlist[ind].ListOfComputer.size(); ind1++)
672         {
673           _machine_list.push_back(pathlist[ind].ListOfComputer[ind1]);
674         }
675     }
676
677   // Parse if a computer name is twice in the list of computers
678   for (unsigned int ind = 0; ind < _machine_list.size(); ind++)
679     {
680      for (unsigned int ind1 = ind+1 ; ind1 < _machine_list.size(); ind1++)
681        {
682          if(_machine_list[ind].compare(_machine_list[ind1]) == 0)
683            {
684              MESSAGE( "The computer " << _machine_list[ind] << " is indicated more than once in the path list")
685              _return_value = false; 
686            }
687        }
688     }
689   return _return_value;
690 }
691
692
693 //----------------------------------------------------------------------
694 // Function : _parseArguments
695 // Purpose  : parse arguments to get general and personal catalog files
696 //----------------------------------------------------------------------
697 bool
698 SALOME_ModuleCatalogImpl::_parseArguments(int argc, char **argv, 
699                                           char **_general, 
700                                           char** _personal)
701 {
702   bool _return_value = true;
703   *_general = NULL;
704   *_personal = NULL ;
705   for (int ind = 0; ind < argc ; ind++)
706     {
707
708       if (strcmp(argv[ind],"-help") == 0)
709         {
710           INFOS( "Usage: " << argv[0] << " -common 'path to general catalog' -personal 'path to personal catalog' -ORBInitRef NameService=corbaname::localhost");
711             _return_value = false ;
712         }
713       if (strcmp(argv[ind],"-common") == 0)
714         {
715           if (ind + 1 < argc)
716             {
717               // General catalog file
718               *_general = argv[ind + 1] ;
719 /*            ifstream _general_file(*_general);
720               if (!_general_file)
721                 {
722                   MESSAGE( "Sorry the file " << *_general << " can't be open" )
723                   *_general = NULL;
724                   _return_value = false;
725                 }
726 */
727             }
728         }
729       else if (strcmp(argv[ind],"-personal") == 0)
730         {
731           if (ind + 1 < argc)
732             {
733               // Personal catalog file
734               *_personal = argv[ind + 1] ;
735 /*            ifstream _personal_file(*_personal);
736               if (!_personal_file)
737                 {
738                   MESSAGE("Sorry the file " << *_personal << " can't be open" )
739                   *_personal = NULL;
740                   _return_value = false;
741                 }
742 */
743             }
744         }
745     }
746   return _return_value;
747 }
748
749