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