Salome HOME
PR: mergefrom_PAL_OCC_21Oct04
[modules/yacs.git] / src / ModuleCatalog / SALOME_ModuleCatalog_impl.cxx
1 //  SALOME ModuleCatalog : implementation of ModuleCatalog server which parsers xml description of modules
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SALOME_ModuleCatalog_impl.cxx
25 //  Author : Estelle Deville
26 //  Module : SALOME
27 //  $Header$
28 //
29 #include "SALOME_ModuleCatalog_impl.hxx"
30 #include "SALOME_ModuleCatalog_Acomponent_impl.hxx"
31 #include <fstream>
32 #include <map>
33
34 #include <qstringlist.h>
35 #include <qfileinfo.h>
36 using namespace std;
37
38 #ifdef _DEBUG_
39 static int MYDEBUG = 0;
40 #else
41 static int MYDEBUG = 0;
42 #endif
43
44 static const char* SEPARATOR    = ":";
45
46 //----------------------------------------------------------------------
47 // Function : SALOME_ModuleCatalogImpl
48 // Purpose  : Constructor 
49 //----------------------------------------------------------------------
50 SALOME_ModuleCatalogImpl::SALOME_ModuleCatalogImpl(int argc, char** argv, CORBA::ORB_ptr orb) : _orb(orb)
51 {
52   if(MYDEBUG) MESSAGE("Catalog creation");
53
54   // Conversion rules for component types
55   ComponentTypeConvert[GEOM]
56     = SALOME_ModuleCatalog::GEOM;
57   ComponentTypeConvert[MESH]
58     = SALOME_ModuleCatalog::MESH;
59   ComponentTypeConvert[Med]
60     = SALOME_ModuleCatalog::Med;
61   ComponentTypeConvert[SOLVER]
62     = SALOME_ModuleCatalog::SOLVER;
63   ComponentTypeConvert[DATA]
64     = SALOME_ModuleCatalog::DATA;
65   ComponentTypeConvert[VISU]
66     = SALOME_ModuleCatalog::VISU;
67   ComponentTypeConvert[SUPERV]
68     = SALOME_ModuleCatalog::SUPERV;
69   ComponentTypeConvert[OTHER]
70     = SALOME_ModuleCatalog::OTHER;
71
72   // Conversion rules for datastream parameters type and dependency
73   DataStreamTypeConvert["UNKNOWN"] 
74     = SALOME_ModuleCatalog::DATASTREAM_UNKNOWN;
75   DataStreamTypeConvert["INTEGER"] 
76     = SALOME_ModuleCatalog::DATASTREAM_INTEGER;
77   DataStreamTypeConvert["FLOAT"]   
78     = SALOME_ModuleCatalog::DATASTREAM_FLOAT;
79   DataStreamTypeConvert["DOUBLE"]  
80     = SALOME_ModuleCatalog::DATASTREAM_DOUBLE;
81   DataStreamTypeConvert["STRING"]  
82     = SALOME_ModuleCatalog::DATASTREAM_STRING;
83   DataStreamTypeConvert["BOOLEAN"] 
84     = SALOME_ModuleCatalog::DATASTREAM_BOOLEAN;
85
86   DataStreamDepConvert["UNDEFINED"] 
87     = SALOME_ModuleCatalog::DATASTREAM_UNDEFINED;
88   DataStreamDepConvert["T"]
89     = SALOME_ModuleCatalog::DATASTREAM_TEMPORAL;
90   DataStreamDepConvert["I"] 
91     = SALOME_ModuleCatalog::DATASTREAM_ITERATIVE;
92
93   // Empty used variables
94   _general_module_list.resize(0);
95   _general_path_list.resize(0);
96
97   _personal_module_list.resize(0);
98   _personal_path_list.resize(0);
99
100   // Parse the arguments given at server run
101   if (!_parseArguments(argc, argv,&_general_path,&_personal_path))
102     if(MYDEBUG) MESSAGE( "Error while argument parsing" );
103
104   // Test existency of files
105   if (_general_path == NULL){
106     if(MYDEBUG) MESSAGE( "Error the general catalog should be indicated" );
107   }else{
108     // Affect the _general_module_list and _general_path_list members
109     // with the common catalog
110     
111     QStringList dirList 
112       = QStringList::split( SEPARATOR, _general_path, 
113                             false ); // skip empty entries
114     
115     for ( int i = 0; i < dirList.count(); i++ ) {
116       QFileInfo fileInfo( dirList[ i ] );
117       if ( fileInfo.isFile() && fileInfo.exists() ) {
118         _parse_xml_file(fileInfo.filePath(), 
119                         _general_module_list, 
120                         _general_path_list);
121       }
122     }
123     
124     // Verification of _general_path_list content
125     if(!_verify_path_prefix(_general_path_list)){
126       if(MYDEBUG) MESSAGE( "Error while parsing the general path list, "
127                            "differents paths are associated to the same computer," 
128                            "the first one will be choosen");
129     }else{
130       if(MYDEBUG) MESSAGE("General path list OK");
131     }
132     
133     if(_personal_path != NULL){
134       // Initialize the _personal_module_list and 
135       // _personal_path_list members with the personal catalog files
136       _parse_xml_file(_personal_path,
137                       _personal_module_list, 
138                       _personal_path_list);
139       
140       // Verification of _general_path_list content
141       if(!_verify_path_prefix(_personal_path_list)){
142         if(MYDEBUG) MESSAGE("Error while parsing the personal path list, "
143                             "differents paths are associated to the same computer, "
144                             "the first one will be choosen" );
145       }else {
146         if(MYDEBUG) MESSAGE("Personal path list OK");
147       }
148     }else 
149       if(MYDEBUG) MESSAGE("No personal catalog indicated or error while "
150                           "opening the personal catalog");
151   }
152 }
153
154 //----------------------------------------------------------------------
155 // Function : ~SALOME_ModuleCatalogImpl
156 // Purpose  : Destructor 
157 //----------------------------------------------------------------------
158 SALOME_ModuleCatalogImpl::~SALOME_ModuleCatalogImpl()
159 {
160   if(MYDEBUG) MESSAGE("Catalog Destruction");
161 }
162
163
164 //----------------------------------------------------------------------
165 // Function : GetComputerList
166 // Purpose  : get a computer list
167 //----------------------------------------------------------------------
168 SALOME_ModuleCatalog::ListOfComputers* 
169 SALOME_ModuleCatalogImpl::GetComputerList()
170 {
171   SALOME_ModuleCatalog::ListOfComputers_var _list_computers = 
172     new SALOME_ModuleCatalog::ListOfComputers;
173   return _list_computers._retn();
174 }
175
176 //----------------------------------------------------------------------
177 // Function : GetPathPrefix
178 // Purpose  : get the PathPrefix of a computer
179 //----------------------------------------------------------------------
180 char * 
181 SALOME_ModuleCatalogImpl::GetPathPrefix(const char* machinename) {
182   if(MYDEBUG) MESSAGE("Begin of GetPathPrefix");
183   // Variables initialisation
184   char* _path = NULL;
185   bool _find = false ;
186
187   // Parse all the path prefixes
188   // looking for the wanted computer
189   for (unsigned int ind = 0 ; ind < _personal_path_list.size() ; ind++)
190     {
191       for (unsigned int ind1 = 0 ; ind1 < _personal_path_list[ind].listOfComputer.size() ; ind1++)    
192         {
193           if (strcmp(machinename, _personal_path_list[ind].listOfComputer[ind1].c_str()) == 0)
194             {
195               _find = true ;
196               // Wanted computer
197               // affect the path to be returned
198                 const char* _temp = _personal_path_list[ind].path.c_str() ;
199                   _path = new char[strlen(_temp)+1];
200               strcpy(_path,_temp);
201             }
202         }
203     }
204
205   if (!_find)
206     {
207     for (unsigned int ind = 0 ; ind < _general_path_list.size() ; ind++)
208       {
209         for (unsigned int ind1 = 0 ; ind1 < _general_path_list[ind].listOfComputer.size() ; ind1++)    
210           {
211             if (strcmp(machinename, _general_path_list[ind].listOfComputer[ind1].c_str()) == 0)
212               {
213                 _find = true ;
214                 // Wanted computer
215                 // affect the path to be returned
216                   const char* _temp = _general_path_list[ind].path.c_str() ;
217                     _path = new char[strlen(_temp)+1];
218                 strcpy(_path,_temp);
219               }
220           }
221       }
222     }
223
224   return _path;
225 }
226
227 //----------------------------------------------------------------------
228 // Function : GetComponentList
229 // Purpose  : get a component list
230 //            If a component is defined in the personal catalog and 
231 //            in the general catalog (same name), the component defined
232 //            in the personal catalog is used
233 //----------------------------------------------------------------------
234 SALOME_ModuleCatalog::ListOfComponents* 
235 SALOME_ModuleCatalogImpl::GetComponentList()
236 {
237   if(MYDEBUG) MESSAGE("Begin of GetComponentList");
238   SALOME_ModuleCatalog::ListOfComponents_var _list_components = 
239     new SALOME_ModuleCatalog::ListOfComponents;
240
241   _list_components->length(_personal_module_list.size());
242
243   // All the components defined in the personal catalog are taken
244   for(unsigned int ind=0; ind < _personal_module_list.size();ind++){
245     _list_components[ind]=(_personal_module_list[ind].name).c_str();
246     if(MYDEBUG) SCRUTE(_list_components[ind]) ;
247   }
248
249   int indice = _personal_module_list.size() ;
250   bool _find = false;
251   
252   // The components in the general catalog are taken only if they're
253   // not defined in the personal catalog
254   for(unsigned int ind=0; ind < _general_module_list.size();ind++){
255     _find = false;
256     for(unsigned int ind1=0; ind1 < _personal_module_list.size();ind1++){
257       // searching if the component is already defined in 
258       // the personal catalog
259       if ((_general_module_list[ind].name.compare(_personal_module_list[ind1].name)) == 0)
260         _find = true;
261     }
262     if(!_find){
263       if(MYDEBUG) MESSAGE("A new component " << _general_module_list[ind].name 
264                           << " has to be to added in the list");
265       _list_components->length(indice+1);
266       // The component is not already defined => has to be taken
267       _list_components[indice]=(_general_module_list[ind].name).c_str();   
268       if(MYDEBUG) SCRUTE(_list_components[indice]) ;
269       
270       indice++;
271     }else{
272       if(MYDEBUG) MESSAGE("The component " <<_general_module_list[ind].name 
273                           << " was already defined in the personal catalog") ;
274     }
275   }
276   
277   if(MYDEBUG) MESSAGE ( "End of GetComponentList" );
278   return _list_components._retn();
279 }
280
281
282 //----------------------------------------------------------------------
283 // Function : GetComponentIconeList
284 // Purpose  : get a component list of component name and component icone
285 //            If a component is defined in the personal catalog and 
286 //            in the general catalog (same name), the component defined
287 //            in the personal catalog is used
288 //----------------------------------------------------------------------
289 SALOME_ModuleCatalog::ListOfIAPP_Affich* 
290 SALOME_ModuleCatalogImpl::GetComponentIconeList()
291 {
292   if(MYDEBUG) MESSAGE("Begin of GetComponentIconeList");
293
294   SALOME_ModuleCatalog::ListOfIAPP_Affich_var _list_components_icone = 
295     new SALOME_ModuleCatalog::ListOfIAPP_Affich;
296
297   _list_components_icone->length(_personal_module_list.size());
298
299   // All the components defined in the personal catalog are taken
300   for(unsigned int ind=0; ind < _personal_module_list.size();ind++){
301     _list_components_icone[ind].modulename=(_personal_module_list[ind].name).c_str();
302     _list_components_icone[ind].moduleusername=(_personal_module_list[ind].username).c_str();
303     _list_components_icone[ind].moduleicone=(_personal_module_list[ind].icon).c_str();
304     //if(MYDEBUG) SCRUTE(_list_components_icone[ind].modulename); 
305     //if(MYDEBUG) SCRUTE(_list_components_icone[ind].moduleicone);
306   }
307   
308   int indice = _personal_module_list.size() ;
309   bool _find = false;
310   
311   // The components in the general catalog are taken only if they're
312   // not defined in the personal catalog
313   for(unsigned int ind=0; ind < _general_module_list.size();ind++){
314     _find = false;
315     for(unsigned int ind1=0; ind1 < _personal_module_list.size();ind1++){
316       // searching if the component is aleready defined in 
317       // the personal catalog
318       if((_general_module_list[ind].name.compare(_personal_module_list[ind1].name)) == 0)
319         _find = true;
320     }
321     if(!_find){
322       //          if(MYDEBUG) MESSAGE("A new component " << _general_module_list[ind].name << " has to be to added in the list");
323       _list_components_icone->length(indice+1);
324       // The component is not already defined => has to be taken
325       _list_components_icone[indice].modulename=_general_module_list[ind].name.c_str();  
326       _list_components_icone[indice].moduleusername=_general_module_list[ind].username.c_str();  
327       _list_components_icone[indice].moduleicone=_general_module_list[ind].icon.c_str(); 
328       //if(MYDEBUG) SCRUTE(_list_components_icone[indice].modulename) ;
329       //if(MYDEBUG) SCRUTE(_list_components_icone[indice].moduleicone);
330       
331       indice++;
332     }
333     // else 
334     //if(MYDEBUG) MESSAGE("The component " <<_general_module_list[ind].name << " was already defined in the personal catalog"); 
335   }
336   
337   return _list_components_icone._retn() ;
338 }
339
340 //----------------------------------------------------------------------
341 // Function : GetTypedComponentList
342 // Purpose  : get a component list of a wanted type
343 //            If a component is defined in the personal catalog and 
344 //            in the general catalog (same name), the component defined
345 //            in the personal catalog is used
346 //----------------------------------------------------------------------
347 SALOME_ModuleCatalog::ListOfComponents* 
348 SALOME_ModuleCatalogImpl::GetTypedComponentList(SALOME_ModuleCatalog::ComponentType component_type)
349 {
350   if(MYDEBUG) MESSAGE("Begin of GetTypedComponentList");
351   SALOME_ModuleCatalog::ListOfComponents_var _list_typed_component = 
352     new SALOME_ModuleCatalog::ListOfComponents;
353   int _j = 0;
354
355   _list_typed_component->length(0);
356   // Transform SALOME_ModuleCatalog::ComponentType in ParserComponentType
357   ParserComponentType _temp_component_type;
358   switch(component_type){
359   case SALOME_ModuleCatalog::GEOM:
360     _temp_component_type = GEOM ;
361     break;
362   case SALOME_ModuleCatalog::MESH:
363     _temp_component_type = MESH;
364     break;   
365   case SALOME_ModuleCatalog::Med:
366     _temp_component_type = Med;
367     break;    
368   case SALOME_ModuleCatalog::SOLVER:   
369     _temp_component_type = SOLVER;
370     break;
371   case SALOME_ModuleCatalog::DATA:
372     _temp_component_type = DATA;
373     break;
374   case SALOME_ModuleCatalog::VISU:
375     _temp_component_type = VISU;
376     break;  
377   case SALOME_ModuleCatalog::SUPERV:
378     _temp_component_type = SUPERV;
379     break;
380   case SALOME_ModuleCatalog::OTHER:
381     _temp_component_type = OTHER;
382     break;
383   }
384
385   // All the components in the personal catalog are taken
386   for (unsigned int ind=0; ind < _personal_module_list.size();ind++)
387     {
388       if  (_personal_module_list[ind].type == _temp_component_type)
389         {
390           _list_typed_component->length(_j + 1); 
391           _list_typed_component[_j] = (_moduleList[ind].name).c_str();
392           //if(MYDEBUG) SCRUTE(_list_typed_component[_j]);
393           _j++;
394         }
395     }
396
397   int indice = _list_typed_component->length() ;
398   bool _find = false;
399   
400   // The components in the general catalog are taken only if they're
401   // not defined in the personal catalog
402   for (unsigned int ind=0; ind < _general_module_list.size();ind++)
403     {
404       _find = false;
405
406       if(_general_module_list[ind].type == _temp_component_type)
407         {
408           for (unsigned int ind1=0; ind1 < _personal_module_list.size();ind1++)
409             {
410               // searching if the component is aleready defined in 
411               // the personal catalog
412               if ((_general_module_list[ind].name.compare(_personal_module_list[ind1].name)) == 0)
413                 _find = true;
414             }
415           if (!_find)
416             {
417               //if(MYDEBUG) MESSAGE("A new component " << _general_module_list[ind].name << " has to be to added in the list");
418               _list_typed_component->length(indice+1);
419               // The component is not already defined => has to be taken
420               _list_typed_component[indice]=(_general_module_list[ind].name).c_str();   
421               //if(MYDEBUG) SCRUTE(_list_typed_component[indice]) ;
422
423               indice++;
424             }
425           //else 
426             //if(MYDEBUG) MESSAGE("The component " <<_general_module_list[ind].name << " was already defined in the personal catalog") ;
427         }
428     }
429
430
431   return _list_typed_component._retn();
432 }
433
434 //----------------------------------------------------------------------
435 // Function : GetComponent
436 // Purpose  : get a component 
437 //            If a component is defined in the personal catalog and 
438 //            in the general catalog (same name), the component defined
439 //            in the personal catalog is used
440 //----------------------------------------------------------------------
441 SALOME_ModuleCatalog::Acomponent_ptr 
442 SALOME_ModuleCatalogImpl::GetComponent(const char* name)
443 {
444   // Looking for component named "componentname" in the personal catalog
445   // If found, get name, interfaces and constraint
446   // If not found, looking for component named "componentname" in
447   // the general catalog
448   // If found, get name, interfaces and constraint
449   // If not found, NULL pointer is returned
450
451   std::string s(name);
452   ParserComponent *C_parser = NULL;
453   ParserPathPrefixes *pp = NULL;
454
455   SALOME_ModuleCatalog::Acomponent_ptr compo = NULL;
456   
457   C_parser = findComponent(s);
458   if (C_parser) {
459     
460 //    DebugParserComponent(*C_parser);
461
462     SALOME_ModuleCatalog::Component C_corba;
463     duplicate(C_corba, *C_parser);
464
465     
466     SALOME_ModuleCatalog_AcomponentImpl * aComponentImpl = 
467       new SALOME_ModuleCatalog_AcomponentImpl(C_corba);
468     
469     compo = aComponentImpl->_this();
470   }
471   else {
472     // Not found in the personal catalog and in the general catalog
473     // return NULL object
474     if(MYDEBUG) MESSAGE("Component with name  " << name 
475                         << " not found in catalog");
476     compo = NULL;
477   }
478   
479   return compo;
480 }
481
482 SALOME_ModuleCatalog::Component *
483 SALOME_ModuleCatalogImpl::GetComponentInfo(const char *name)
484 {
485   std::string s(name);
486
487   ParserComponent * C_parser = findComponent(s);
488   
489   if (C_parser) {
490     
491     SALOME_ModuleCatalog::Component * C_corba 
492       = new SALOME_ModuleCatalog::Component; 
493     duplicate(*C_corba, *C_parser);
494     return C_corba;
495   }
496
497   return NULL;
498 }
499
500 ParserComponent *
501 SALOME_ModuleCatalogImpl::findComponent(const string & name)
502 {
503   ParserComponent * C_parser = NULL;
504
505   if (!C_parser)
506     for (unsigned int ind=0; ind < _personal_module_list.size();ind++)
507       if (name.compare(_personal_module_list[ind].name) == 0)
508         {
509           if(MYDEBUG) MESSAGE("Component named " << name 
510                               << " found in the personal catalog");
511           C_parser = &(_personal_module_list[ind]);
512           break;
513         }
514
515   if (!C_parser)
516     for (unsigned int ind=0; ind < _general_module_list.size();ind++)
517       {
518         if (name.compare(_general_module_list[ind].name) == 0)
519           {
520             if(MYDEBUG) MESSAGE("Component named " << name 
521                                 << " found in the general catalog");
522             C_parser = &(_general_module_list[ind]);
523             break;
524           }
525       }
526
527   return C_parser;
528 }
529
530 //----------------------------------------------------------------------
531 // Function : _parse_xml_file
532 // Purpose  : parse one module catalog 
533 //----------------------------------------------------------------------
534 void 
535 SALOME_ModuleCatalogImpl::_parse_xml_file(const char* file, 
536                                           ParserComponents& modulelist, 
537                                           ParserPathPrefixes& pathList)
538 {
539   if(MYDEBUG) BEGIN_OF("_parse_xml_file");
540   if(MYDEBUG) SCRUTE(file);
541
542   SALOME_ModuleCatalog_Handler* handler = new SALOME_ModuleCatalog_Handler();
543   QFile xmlFile(file);
544
545   QXmlInputSource source(xmlFile);
546
547   QXmlSimpleReader reader;
548   reader.setContentHandler( handler );
549   reader.setErrorHandler( handler );
550   reader.parse( source );
551   xmlFile.close();
552
553   unsigned int i, j;
554
555   for ( i = 0; i < _moduleList.size(); i++) {
556     for (j=0; j<modulelist.size(); j++) {
557       if (modulelist[j].name == _moduleList[i].name)
558         break;
559     }
560     if (j < modulelist.size())
561       modulelist[j] = _moduleList[i];
562     else
563       modulelist.push_back(_moduleList[i]);
564   }
565
566   for ( i=0; i < _pathList.size(); i++)
567     pathList.push_back(_pathList[i]) ;
568
569   for (j=0; j<modulelist.size(); j++)
570     modulelist[j].prefixes = pathList;
571 }
572
573 void 
574 SALOME_ModuleCatalogImpl::ImportXmlCatalogFile(const char* file)
575 {
576   _parse_xml_file(file, _personal_module_list, _personal_path_list);
577 }
578
579
580 //
581 //  Duplicate functions create a Corba structure (component,
582 //  interface, service, parameter) from the corresponding C++ 
583 //  parser structure
584 //
585
586 //----------------------------------------------------------------------
587 // Function : duplicate
588 // Purpose  : create a component from the catalog parsing
589 //----------------------------------------------------------------------
590 void SALOME_ModuleCatalogImpl::duplicate
591 (SALOME_ModuleCatalog::Component & C_corba, 
592  const ParserComponent & C_parser)
593 {
594   C_corba.name = CORBA::string_dup(C_parser.name.c_str());
595   C_corba.username = CORBA::string_dup(C_parser.username.c_str());
596   C_corba.multistudy = C_parser.multistudy;
597   C_corba.icon = CORBA::string_dup(C_parser.icon.c_str());
598   C_corba.type = ComponentTypeConvert[C_parser.type];
599   C_corba.implementationType = C_parser.implementationType;
600
601   unsigned int _length = C_parser.interfaces.size();
602   C_corba.interfaces.length(_length);
603   
604   for (unsigned int ind = 0; ind < _length; ind++)
605     duplicate(C_corba.interfaces[ind], C_parser.interfaces[ind]);
606 }
607
608
609 //----------------------------------------------------------------------
610 // Function : duplicate
611 // Purpose  : create an interface from the catalog parsing
612 //----------------------------------------------------------------------
613 void SALOME_ModuleCatalogImpl::duplicate
614 (SALOME_ModuleCatalog::DefinitionInterface & I_corba,
615  const ParserInterface & I_parser)
616 {
617   //duplicate interface name
618   I_corba.interfacename = CORBA::string_dup(I_parser.name.c_str());
619   
620   // duplicate service list
621   unsigned int _length = I_parser.services.size();
622   if(MYDEBUG) SCRUTE(_length);
623   //  I_corba.interfaceservicelist 
624   //  = new SALOME_ModuleCatalog::ListOfInterfaceService;
625   I_corba.interfaceservicelist.length(_length);
626   
627   for (unsigned int ind1 = 0; ind1 < _length ; ind1 ++)
628     duplicate(I_corba.interfaceservicelist[ind1],
629               I_parser.services[ind1]);
630 }
631
632 //----------------------------------------------------------------------
633 // Function : duplicate
634 // Purpose  : create a service from the catalog parsing
635 //----------------------------------------------------------------------
636 void SALOME_ModuleCatalogImpl::duplicate
637 (SALOME_ModuleCatalog::Service & S_corba,
638  const ParserService & S_parser)
639 {
640   // duplicate service name
641   S_corba.ServiceName = CORBA::string_dup(S_parser.name.c_str());
642   
643   // duplicate service by default
644   S_corba.Servicebydefault = S_parser.byDefault;
645
646   S_corba.TypeOfNode = S_parser.typeOfNode;
647
648   unsigned int _length;
649
650   // duplicate in Parameters
651   _length = S_parser.inParameters.size();
652   S_corba.ServiceinParameter.length(_length);
653
654   for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
655     duplicate(S_corba.ServiceinParameter[ind2],
656               S_parser.inParameters[ind2]);
657   
658   // duplicate out Parameters
659   _length = S_parser.outParameters.size();
660   S_corba.ServiceoutParameter.length(_length);
661   
662   for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
663     duplicate(S_corba.ServiceoutParameter[ind2],
664               S_parser.outParameters[ind2]);
665   
666   // duplicate in DataStreamParameters
667   _length = S_parser.inDataStreamParameters.size();
668   S_corba.ServiceinDataStreamParameter.length(_length);
669   
670   for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
671     duplicate(S_corba.ServiceinDataStreamParameter[ind2],
672               S_parser.inDataStreamParameters[ind2]);
673   
674   // duplicate out DataStreamParameters
675   _length = S_parser.outDataStreamParameters.size();
676   if(MYDEBUG) SCRUTE(_length);
677   S_corba.ServiceoutDataStreamParameter.length(_length);
678   
679   for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
680     duplicate(S_corba.ServiceoutDataStreamParameter[ind2],
681               S_parser.outDataStreamParameters[ind2]);
682 }
683
684 //----------------------------------------------------------------------
685 // Function : duplicate
686 // Purpose  : create a service parameter from the catalog parsing
687 //----------------------------------------------------------------------
688 void SALOME_ModuleCatalogImpl::duplicate
689 (SALOME_ModuleCatalog::ServicesParameter & P_corba,
690  const ParserParameter & P_parser)
691 {
692   // duplicate parameter name
693   P_corba.Parametername = CORBA::string_dup(P_parser.name.c_str());
694   
695   // duplicate parameter type
696   P_corba.Parametertype = CORBA::string_dup(P_parser.type.c_str());
697 }
698
699
700 //----------------------------------------------------------------------
701 // Function : duplicate
702 // Purpose  : create a service datastream parameter from the catalog parsing
703 //----------------------------------------------------------------------
704 void SALOME_ModuleCatalogImpl::duplicate
705 (SALOME_ModuleCatalog::ServicesDataStreamParameter & P_corba,
706  const ParserDataStreamParameter & P_parser)
707 {
708   std::map < std::string, 
709     SALOME_ModuleCatalog::DataStreamType >::const_iterator it_type;
710
711   std::map < std::string, 
712     SALOME_ModuleCatalog::DataStreamDependency >::const_iterator it_dep;
713
714   // duplicate parameter name
715   P_corba.Parametername = CORBA::string_dup(P_parser.name.c_str());
716   
717   // doesn't work ??? 
718   //   it_type = DataStreamTypeConvert.find(P_parser.type);
719   //   P_corba.Parametertype
720   //     = (it_type == DataStreamTypeConvert.end()) 
721   //     ? it_type->second : SALOME_ModuleCatalog::DATASTREAM_UNKNOWN;
722
723   if(MYDEBUG) SCRUTE(P_parser.type);
724   P_corba.Parametertype = SALOME_ModuleCatalog::DATASTREAM_UNKNOWN;
725   for (it_type = DataStreamTypeConvert.begin(); 
726        it_type != DataStreamTypeConvert.end(); 
727        it_type++)
728     if (P_parser.type.compare(it_type->first) == 0) {
729       P_corba.Parametertype = it_type->second;
730       break;
731     }
732   if(MYDEBUG) SCRUTE(P_corba.Parametertype);
733
734   // duplicate parameter type
735
736   // doesn't work ??? 
737   //   it_type = DataStreamTypeConvert.find(P_parser.type);
738   //   P_corba.Parametertype
739   //     = (it_type == DataStreamTypeConvert.end()) 
740   //     ? it_type->second : SALOME_ModuleCatalog::DATASTREAM_UNKNOWN;
741   
742   if(MYDEBUG) SCRUTE(P_parser.dependency);
743   P_corba.Parameterdependency = SALOME_ModuleCatalog::DATASTREAM_UNDEFINED;
744   for (it_dep = DataStreamDepConvert.begin(); 
745        it_dep != DataStreamDepConvert.end(); 
746        it_dep++)
747     if (P_parser.dependency.compare(it_dep->first) == 0) {
748       P_corba.Parameterdependency = it_dep->second;
749       break;
750     }
751
752   if(MYDEBUG) SCRUTE(P_corba.Parameterdependency);
753 }
754
755 //----------------------------------------------------------------------
756 // Function : duplicate
757 // Purpose  : create the path prefix structures from the catalog parsing
758 //----------------------------------------------------------------------
759 void
760 SALOME_ModuleCatalogImpl::duplicate(ParserPathPrefixes &L_out, 
761                                     const ParserPathPrefixes &L_in)
762 {
763   L_out = L_in;
764 }
765
766
767 //----------------------------------------------------------------------
768 // Function : _verify_path_prefix
769 // Purpose  : verify the path prefix structures from the catalog parsing
770 //            Verify that there only one path prefix associated to a 
771 //            particular computer
772 //----------------------------------------------------------------------
773 bool
774 SALOME_ModuleCatalogImpl::_verify_path_prefix(ParserPathPrefixes & pathList)
775 {
776   bool _return_value = true;
777   vector<string> _machine_list;
778
779   // Fill a list of all computers indicated in the path list
780   for (unsigned int ind = 0; ind < pathList.size(); ind++)
781     { 
782       for (unsigned int ind1 = 0 ; ind1 < pathList[ind].listOfComputer.size(); ind1++)
783         {
784           _machine_list.push_back(pathList[ind].listOfComputer[ind1]);
785         }
786     }
787
788   // Parse if a computer name is twice in the list of computers
789   for (unsigned int ind = 0; ind < _machine_list.size(); ind++)
790     {
791      for (unsigned int ind1 = ind+1 ; ind1 < _machine_list.size(); ind1++)
792        {
793          if(_machine_list[ind].compare(_machine_list[ind1]) == 0)
794            {
795              if(MYDEBUG) MESSAGE( "The computer " << _machine_list[ind] << " is indicated more than once in the path list");
796              _return_value = false; 
797            }
798        }
799     }
800   return _return_value;
801 }
802
803
804 //----------------------------------------------------------------------
805 // Function : _parseArguments
806 // Purpose  : parse arguments to get general and personal catalog files
807 //----------------------------------------------------------------------
808 bool
809 SALOME_ModuleCatalogImpl::_parseArguments(int argc, char **argv, 
810                                           char **_general, 
811                                           char** _personal)
812 {
813   bool _return_value = true;
814   *_general = NULL;
815   *_personal = NULL ;
816   for (int ind = 0; ind < argc ; ind++)
817     {
818
819       if (strcmp(argv[ind],"-help") == 0)
820         {
821           INFOS( "Usage: " << argv[0] 
822                  << " -common 'path to general catalog' "
823                  " -personal 'path to personal catalog' "
824                  " -ORBInitRef NameService=corbaname::localhost");
825             _return_value = false ;
826         }
827
828       if (strcmp(argv[ind],"-common") == 0)
829         {
830           if (ind + 1 < argc)
831             {
832               // General catalog file
833               *_general = argv[ind + 1] ;
834             }
835         }
836       else if (strcmp(argv[ind],"-personal") == 0)
837         {
838           if (ind + 1 < argc)
839             {
840               // Personal catalog file
841               *_personal = argv[ind + 1] ;
842             }
843         }
844     }
845   return _return_value;
846 }
847
848