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