1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SALOME ModuleCatalog : implementation of ModuleCatalog server which parsers xml description of modules
24 // File : SALOME_ModuleCatalog_impl.cxx
25 // Author : Estelle Deville
29 #include "SALOME_ModuleCatalog_impl.hxx"
30 #include "SALOME_ModuleCatalog_Acomponent_impl.hxx"
31 #include <libxml/parser.h>
34 #include "utilities.h"
43 static int MYDEBUG = 0;
45 static int MYDEBUG = 0;
48 static const char* SEPARATOR = "::";
49 static const char* OLD_SEPARATOR = ":";
52 std::list<std::string> splitStringToList(const std::string& theString, const std::string& theSeparator)
54 std::list<std::string> aList;
56 int sepLen = theSeparator.length();
57 int startPos = 0, sepPos = theString.find(theSeparator, startPos);
62 if(sepPos != std::string::npos)
63 anItem = theString.substr(startPos, sepPos - startPos);
65 anItem = theString.substr(startPos);
66 if (anItem.length() > 0)
67 aList.push_back(anItem);
68 if(sepPos == std::string::npos)
70 startPos = sepPos + sepLen;
71 sepPos = theString.find(theSeparator, startPos);
77 //----------------------------------------------------------------------
78 // Function : SALOME_ModuleCatalogImpl
79 // Purpose : Constructor
80 //----------------------------------------------------------------------
81 SALOME_ModuleCatalogImpl::SALOME_ModuleCatalogImpl(int argc, char** argv, CORBA::ORB_ptr orb) : _orb(orb)
83 if(MYDEBUG) MESSAGE("Catalog creation");
87 // Conversion rules for component types
88 ComponentTypeConvert[GEOM]
89 = SALOME_ModuleCatalog::GEOM;
90 ComponentTypeConvert[MESH]
91 = SALOME_ModuleCatalog::MESH;
92 ComponentTypeConvert[Med]
93 = SALOME_ModuleCatalog::Med;
94 ComponentTypeConvert[SOLVER]
95 = SALOME_ModuleCatalog::SOLVER;
96 ComponentTypeConvert[DATA]
97 = SALOME_ModuleCatalog::DATA;
98 ComponentTypeConvert[VISU]
99 = SALOME_ModuleCatalog::VISU;
100 ComponentTypeConvert[SUPERV]
101 = SALOME_ModuleCatalog::SUPERV;
102 ComponentTypeConvert[OTHER]
103 = SALOME_ModuleCatalog::OTHER;
105 // Conversion rules for datastream parameters dependency
106 DataStreamDepConvert["UNDEFINED"]
107 = SALOME_ModuleCatalog::DATASTREAM_UNDEFINED;
108 DataStreamDepConvert["T"]
109 = SALOME_ModuleCatalog::DATASTREAM_TEMPORAL;
110 DataStreamDepConvert["I"]
111 = SALOME_ModuleCatalog::DATASTREAM_ITERATIVE;
113 // Empty used variables
114 _general_module_list.resize(0);
115 _general_path_list.resize(0);
117 _personal_module_list.resize(0);
118 _personal_path_list.resize(0);
120 // Parse the arguments given at server run
121 if (!_parseArguments(argc, argv,&_general_path,&_personal_path))
122 if(MYDEBUG) MESSAGE( "Error while argument parsing" );
124 // Test existency of files
125 if (_general_path == NULL)
127 if(MYDEBUG) MESSAGE( "Error the general catalog should be indicated" );
131 // Affect the _general_module_list and _general_path_list members
132 // with the common catalog
134 std::list<std::string> dirList;
137 dirList = splitStringToList(_general_path, SEPARATOR);
139 //check for new format
140 bool isNew = (std::string( _general_path ).find(SEPARATOR) != std::string::npos);
143 dirList = splitStringToList(_general_path, SEPARATOR);
146 dirList = splitStringToList(_general_path, OLD_SEPARATOR);
150 for (std::list<std::string>::iterator iter = dirList.begin(); iter != dirList.end(); iter++)
152 std::string aPath = (*iter);
153 //remove inverted commas from filename
154 while (aPath.find('\"') != std::string::npos)
155 aPath.erase(aPath.find('\"'), 1);
157 _parse_xml_file(aPath.c_str(),
158 _general_module_list,
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");
170 if(MYDEBUG) MESSAGE("General path list OK");
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,
182 // Verification of _general_path_list content
183 if(!_verify_path_prefix(_personal_path_list)){
184 if(MYDEBUG) MESSAGE("Error while parsing the personal path list, "
185 "differents paths are associated to the same computer, "
186 "the first one will be choosen" );
188 if(MYDEBUG) MESSAGE("Personal path list OK");
191 if(MYDEBUG) MESSAGE("No personal catalog indicated or error while "
192 "opening the personal catalog");
196 //----------------------------------------------------------------------
197 // Function : ~SALOME_ModuleCatalogImpl
198 // Purpose : Destructor
199 //----------------------------------------------------------------------
200 SALOME_ModuleCatalogImpl::~SALOME_ModuleCatalogImpl()
202 if(MYDEBUG) MESSAGE("Catalog Destruction");
206 //! Get the list of all types of the catalog
208 * \return the list of types
210 SALOME_ModuleCatalog::ListOfTypeDefinition* SALOME_ModuleCatalogImpl::GetTypes()
212 SALOME_ModuleCatalog::ListOfTypeDefinition_var type_list = new SALOME_ModuleCatalog::ListOfTypeDefinition();
213 type_list->length(_typeList.size());
215 for (unsigned int ind = 0 ; ind < _typeList.size() ; ind++)
217 //no real need to call string_dup, omniorb calls it on operator= (const char *) but it is safer
218 type_list[ind].name=CORBA::string_dup(_typeList[ind].name.c_str());
219 type_list[ind].kind=SALOME_ModuleCatalog::NONE;
220 if(_typeList[ind].kind=="double")
221 type_list[ind].kind=SALOME_ModuleCatalog::Dble;
222 else if(_typeList[ind].kind=="int")
223 type_list[ind].kind=SALOME_ModuleCatalog::Int;
224 else if(_typeList[ind].kind=="bool")
225 type_list[ind].kind=SALOME_ModuleCatalog::Bool;
226 else if(_typeList[ind].kind=="string")
227 type_list[ind].kind=SALOME_ModuleCatalog::Str;
228 else if(_typeList[ind].kind=="objref")
230 type_list[ind].kind=SALOME_ModuleCatalog::Objref;
231 type_list[ind].id=CORBA::string_dup(_typeList[ind].id.c_str());
233 type_list[ind].bases.length(_typeList[ind].bases.size());
234 std::vector<std::string>::const_iterator miter;
235 miter=_typeList[ind].bases.begin();
237 while(miter != _typeList[ind].bases.end())
239 type_list[ind].bases[n_memb]=CORBA::string_dup(miter->c_str());
244 else if(_typeList[ind].kind=="sequence")
246 type_list[ind].kind=SALOME_ModuleCatalog::Seq;
247 type_list[ind].content=CORBA::string_dup(_typeList[ind].content.c_str());
249 else if(_typeList[ind].kind=="array")
251 type_list[ind].kind=SALOME_ModuleCatalog::Array;
252 type_list[ind].content=CORBA::string_dup(_typeList[ind].content.c_str());
254 else if(_typeList[ind].kind=="struct")
256 type_list[ind].kind=SALOME_ModuleCatalog::Struc;
258 type_list[ind].members.length(_typeList[ind].members.size());
260 std::vector< std::pair<std::string,std::string> >::const_iterator miter;
261 miter=_typeList[ind].members.begin();
263 while(miter != _typeList[ind].members.end())
265 type_list[ind].members[n_memb].name=CORBA::string_dup(miter->first.c_str());
266 type_list[ind].members[n_memb].type=CORBA::string_dup(miter->second.c_str());
272 return type_list._retn();
275 //----------------------------------------------------------------------
276 // Function : GetComputerList
277 // Purpose : get a computer list
278 //----------------------------------------------------------------------
279 SALOME_ModuleCatalog::ListOfComputers*
280 SALOME_ModuleCatalogImpl::GetComputerList()
282 SALOME_ModuleCatalog::ListOfComputers_var _list_computers =
283 new SALOME_ModuleCatalog::ListOfComputers;
284 return _list_computers._retn();
287 //----------------------------------------------------------------------
288 // Function : GetPathPrefix
289 // Purpose : get the PathPrefix of a computer
290 //----------------------------------------------------------------------
292 SALOME_ModuleCatalogImpl::GetPathPrefix(const char* machinename) {
293 if(MYDEBUG) MESSAGE("Begin of GetPathPrefix");
294 // Variables initialisation
298 // Parse all the path prefixes
299 // looking for the wanted computer
300 for (unsigned int ind = 0 ; ind < _personal_path_list.size() ; ind++)
302 for (unsigned int ind1 = 0 ; ind1 < _personal_path_list[ind].listOfComputer.size() ; ind1++)
304 if (strcmp(machinename, _personal_path_list[ind].listOfComputer[ind1].c_str()) == 0)
308 // affect the path to be returned
309 const char* _temp = _personal_path_list[ind].path.c_str() ;
310 _path = new char[strlen(_temp)+1];
318 for (unsigned int ind = 0 ; ind < _general_path_list.size() ; ind++)
320 for (unsigned int ind1 = 0 ; ind1 < _general_path_list[ind].listOfComputer.size() ; ind1++)
322 if (strcmp(machinename, _general_path_list[ind].listOfComputer[ind1].c_str()) == 0)
326 // affect the path to be returned
327 const char* _temp = _general_path_list[ind].path.c_str() ;
328 _path = new char[strlen(_temp)+1];
338 //----------------------------------------------------------------------
339 // Function : GetComponentList
340 // Purpose : get a component list
341 // If a component is defined in the personal catalog and
342 // in the general catalog (same name), the component defined
343 // in the personal catalog is used
344 //----------------------------------------------------------------------
345 SALOME_ModuleCatalog::ListOfComponents*
346 SALOME_ModuleCatalogImpl::GetComponentList()
348 if(MYDEBUG) MESSAGE("Begin of GetComponentList");
349 SALOME_ModuleCatalog::ListOfComponents_var _list_components =
350 new SALOME_ModuleCatalog::ListOfComponents;
352 _list_components->length(_personal_module_list.size());
354 // All the components defined in the personal catalog are taken
355 for(unsigned int ind=0; ind < _personal_module_list.size();ind++){
356 _list_components[ind]=(_personal_module_list[ind].name).c_str();
357 if(MYDEBUG) SCRUTE(_list_components[ind]) ;
360 int indice = _personal_module_list.size() ;
363 // The components in the general catalog are taken only if they're
364 // not defined in the personal catalog
365 for(unsigned int ind=0; ind < _general_module_list.size();ind++){
367 for(unsigned int ind1=0; ind1 < _personal_module_list.size();ind1++){
368 // searching if the component is already defined in
369 // the personal catalog
370 if ((_general_module_list[ind].name.compare(_personal_module_list[ind1].name)) == 0)
374 if(MYDEBUG) MESSAGE("A new component " << _general_module_list[ind].name
375 << " has to be to added in the list");
376 _list_components->length(indice+1);
377 // The component is not already defined => has to be taken
378 _list_components[indice]=(_general_module_list[ind].name).c_str();
379 if(MYDEBUG) SCRUTE(_list_components[indice]) ;
383 if(MYDEBUG) MESSAGE("The component " <<_general_module_list[ind].name
384 << " was already defined in the personal catalog") ;
388 if(MYDEBUG) MESSAGE ( "End of GetComponentList" );
389 return _list_components._retn();
393 //----------------------------------------------------------------------
394 // Function : GetComponentIconeList
395 // Purpose : get a component list of component name and component icone
396 // If a component is defined in the personal catalog and
397 // in the general catalog (same name), the component defined
398 // in the personal catalog is used
399 //----------------------------------------------------------------------
400 SALOME_ModuleCatalog::ListOfIAPP_Affich*
401 SALOME_ModuleCatalogImpl::GetComponentIconeList()
403 if(MYDEBUG) MESSAGE("Begin of GetComponentIconeList");
405 SALOME_ModuleCatalog::ListOfIAPP_Affich_var _list_components_icone =
406 new SALOME_ModuleCatalog::ListOfIAPP_Affich;
408 _list_components_icone->length(_personal_module_list.size());
410 // All the components defined in the personal catalog are taken
411 for(unsigned int ind=0; ind < _personal_module_list.size();ind++){
412 _list_components_icone[ind].modulename=(_personal_module_list[ind].name).c_str();
413 _list_components_icone[ind].moduleusername=(_personal_module_list[ind].username).c_str();
414 _list_components_icone[ind].moduleicone=(_personal_module_list[ind].icon).c_str();
415 _list_components_icone[ind].moduleversion=(_personal_module_list[ind].version).c_str();
416 _list_components_icone[ind].modulecomment=(_personal_module_list[ind].comment).c_str();
417 //if(MYDEBUG) SCRUTE(_list_components_icone[ind].modulename);
418 //if(MYDEBUG) SCRUTE(_list_components_icone[ind].moduleicone);
421 int indice = _personal_module_list.size() ;
424 // The components in the general catalog are taken only if they're
425 // not defined in the personal catalog
426 for(unsigned int ind=0; ind < _general_module_list.size();ind++){
428 for(unsigned int ind1=0; ind1 < _personal_module_list.size();ind1++){
429 // searching if the component is aleready defined in
430 // the personal catalog
431 if((_general_module_list[ind].name.compare(_personal_module_list[ind1].name)) == 0)
435 // if(MYDEBUG) MESSAGE("A new component " << _general_module_list[ind].name << " has to be to added in the list");
436 _list_components_icone->length(indice+1);
437 // The component is not already defined => has to be taken
438 _list_components_icone[indice].modulename=_general_module_list[ind].name.c_str();
439 _list_components_icone[indice].moduleusername=_general_module_list[ind].username.c_str();
440 _list_components_icone[indice].moduleicone=_general_module_list[ind].icon.c_str();
441 _list_components_icone[indice].moduleversion=_general_module_list[ind].version.c_str();
442 _list_components_icone[indice].modulecomment=_general_module_list[ind].comment.c_str();
443 //if(MYDEBUG) SCRUTE(_list_components_icone[indice].modulename) ;
444 //if(MYDEBUG) SCRUTE(_list_components_icone[indice].moduleicone);
449 //if(MYDEBUG) MESSAGE("The component " <<_general_module_list[ind].name << " was already defined in the personal catalog");
452 return _list_components_icone._retn() ;
455 //----------------------------------------------------------------------
456 // Function : GetTypedComponentList
457 // Purpose : get a component list of a wanted type
458 // If a component is defined in the personal catalog and
459 // in the general catalog (same name), the component defined
460 // in the personal catalog is used
461 //----------------------------------------------------------------------
462 SALOME_ModuleCatalog::ListOfComponents*
463 SALOME_ModuleCatalogImpl::GetTypedComponentList(SALOME_ModuleCatalog::ComponentType component_type)
465 if(MYDEBUG) MESSAGE("Begin of GetTypedComponentList");
466 SALOME_ModuleCatalog::ListOfComponents_var _list_typed_component =
467 new SALOME_ModuleCatalog::ListOfComponents;
470 _list_typed_component->length(0);
471 // Transform SALOME_ModuleCatalog::ComponentType in ParserComponentType
472 ParserComponentType _temp_component_type;
473 switch(component_type){
474 case SALOME_ModuleCatalog::GEOM:
475 _temp_component_type = GEOM ;
477 case SALOME_ModuleCatalog::MESH:
478 _temp_component_type = MESH;
480 case SALOME_ModuleCatalog::Med:
481 _temp_component_type = Med;
483 case SALOME_ModuleCatalog::SOLVER:
484 _temp_component_type = SOLVER;
486 case SALOME_ModuleCatalog::DATA:
487 _temp_component_type = DATA;
489 case SALOME_ModuleCatalog::VISU:
490 _temp_component_type = VISU;
492 case SALOME_ModuleCatalog::SUPERV:
493 _temp_component_type = SUPERV;
495 case SALOME_ModuleCatalog::OTHER:
496 _temp_component_type = OTHER;
500 // All the components in the personal catalog are taken
501 for (unsigned int ind=0; ind < _personal_module_list.size();ind++)
503 if (_personal_module_list[ind].type == _temp_component_type)
505 _list_typed_component->length(_j + 1);
506 _list_typed_component[_j] = _personal_module_list[ind].name.c_str();
507 //if(MYDEBUG) SCRUTE(_list_typed_component[_j]);
512 int indice = _list_typed_component->length() ;
515 // The components in the general catalog are taken only if they're
516 // not defined in the personal catalog
517 for (unsigned int ind=0; ind < _general_module_list.size();ind++)
521 if(_general_module_list[ind].type == _temp_component_type)
523 for (unsigned int ind1=0; ind1 < _personal_module_list.size();ind1++)
525 // searching if the component is aleready defined in
526 // the personal catalog
527 if ((_general_module_list[ind].name.compare(_personal_module_list[ind1].name)) == 0)
532 //if(MYDEBUG) MESSAGE("A new component " << _general_module_list[ind].name << " has to be to added in the list");
533 _list_typed_component->length(indice+1);
534 // The component is not already defined => has to be taken
535 _list_typed_component[indice]=(_general_module_list[ind].name).c_str();
536 //if(MYDEBUG) SCRUTE(_list_typed_component[indice]) ;
541 //if(MYDEBUG) MESSAGE("The component " <<_general_module_list[ind].name << " was already defined in the personal catalog") ;
546 return _list_typed_component._retn();
549 //----------------------------------------------------------------------
550 // Function : GetComponent
551 // Purpose : get a component
552 // If a component is defined in the personal catalog and
553 // in the general catalog (same name), the component defined
554 // in the personal catalog is used
555 //----------------------------------------------------------------------
556 SALOME_ModuleCatalog::Acomponent_ptr
557 SALOME_ModuleCatalogImpl::GetComponent(const char* name)
559 // Looking for component named "componentname" in the personal catalog
560 // If found, get name, interfaces and constraint
561 // If not found, looking for component named "componentname" in
562 // the general catalog
563 // If found, get name, interfaces and constraint
564 // If not found, NULL pointer is returned
567 ParserComponent *C_parser = NULL;
568 //ParserPathPrefixes *pp = NULL;
570 SALOME_ModuleCatalog::Acomponent_ptr compo
571 = SALOME_ModuleCatalog::Acomponent::_nil();
572 C_parser = findComponent(s);
575 // DebugParserComponent(*C_parser);
577 SALOME_ModuleCatalog::ComponentDef C_corba;
578 duplicate(C_corba, *C_parser);
581 SALOME_ModuleCatalog_AcomponentImpl * aComponentImpl =
582 new SALOME_ModuleCatalog_AcomponentImpl(C_corba);
584 compo = aComponentImpl->_this();
587 // Not found in the personal catalog and in the general catalog
588 // return NULL object
589 if(MYDEBUG) MESSAGE("Component with name " << name
590 << " not found in catalog");
596 SALOME_ModuleCatalog::ComponentDef *
597 SALOME_ModuleCatalogImpl::GetComponentInfo(const char *name)
601 ParserComponent * C_parser = findComponent(s);
605 SALOME_ModuleCatalog::ComponentDef * C_corba
606 = new SALOME_ModuleCatalog::ComponentDef;
607 duplicate(*C_corba, *C_parser);
614 CORBA::Long SALOME_ModuleCatalogImpl::getPID()
618 (CORBA::Long)getpid();
620 (CORBA::Long)_getpid();
624 void SALOME_ModuleCatalogImpl::ShutdownWithExit()
626 exit( EXIT_SUCCESS );
630 SALOME_ModuleCatalogImpl::findComponent(const std::string & name)
632 ParserComponent * C_parser = NULL;
635 for (unsigned int ind=0; ind < _personal_module_list.size();ind++)
637 if (name.compare(_personal_module_list[ind].name) == 0)
639 if(MYDEBUG) MESSAGE("Component named " << name
640 << " found in the personal catalog");
641 C_parser = &(_personal_module_list[ind]);
647 for (unsigned int ind=0; ind < _general_module_list.size();ind++)
649 if (name.compare(_general_module_list[ind].name) == 0)
651 // if(MYDEBUG) MESSAGE("Component named " << name
652 // << " found in the general catalog");
653 C_parser = &(_general_module_list[ind]);
661 //----------------------------------------------------------------------
662 // Function : _parse_xml_file
663 // Purpose : parse one module catalog
664 //----------------------------------------------------------------------
666 SALOME_ModuleCatalogImpl::_parse_xml_file(const char* file,
667 ParserComponents& modulelist,
668 ParserPathPrefixes& pathList,
669 ParserTypes& typeMap,
672 if(MYDEBUG) BEGIN_OF("_parse_xml_file");
673 if(MYDEBUG) SCRUTE(file);
675 //Local path and module list for the file to parse
676 ParserPathPrefixes _pathList;
677 ParserComponents _moduleList;
679 SALOME_ModuleCatalog_Handler* handler = new SALOME_ModuleCatalog_Handler(_pathList,_moduleList,typeMap,typeList);
681 FILE* aFile = fopen(file, "r");
685 xmlDocPtr aDoc = xmlReadFile(file, NULL, 0);
688 handler->ProcessXmlDocument(aDoc);
690 MESSAGE("ModuleCatalog: could not parse file "<<file);
696 MESSAGE("ModuleCatalog: file "<<file<<" is not readable.");
702 for ( i = 0; i < _moduleList.size(); i++) {
703 for (j=0; j<modulelist.size(); j++) {
704 if (modulelist[j].name == _moduleList[i].name)
707 if (j < modulelist.size())
708 modulelist[j] = _moduleList[i];
710 modulelist.push_back(_moduleList[i]);
713 for ( i=0; i < _pathList.size(); i++)
714 pathList.push_back(_pathList[i]) ;
716 for (j=0; j<modulelist.size(); j++)
717 modulelist[j].prefixes = pathList;
721 SALOME_ModuleCatalogImpl::ImportXmlCatalogFile(const char* file)
723 _parse_xml_file(file, _personal_module_list, _personal_path_list,_typeMap,_typeList);
728 // Duplicate functions create a Corba structure (component,
729 // interface, service, parameter) from the corresponding C++
733 //----------------------------------------------------------------------
734 // Function : duplicate
735 // Purpose : create a component from the catalog parsing
736 //----------------------------------------------------------------------
737 void SALOME_ModuleCatalogImpl::duplicate
738 (SALOME_ModuleCatalog::ComponentDef & C_corba,
739 const ParserComponent & C_parser)
741 C_corba.name = CORBA::string_dup(C_parser.name.c_str());
742 C_corba.username = CORBA::string_dup(C_parser.username.c_str());
743 C_corba.multistudy = C_parser.multistudy;
744 C_corba.icon = CORBA::string_dup(C_parser.icon.c_str());
745 C_corba.type = ComponentTypeConvert[C_parser.type];
746 if(C_parser.implementationType == "EXE")
747 C_corba.implementationType=SALOME_ModuleCatalog::EXE;
748 else if(C_parser.implementationType == "CEXE")
749 C_corba.implementationType=SALOME_ModuleCatalog::CEXE;
750 else if(C_parser.implementationType == "PY")
751 C_corba.implementationType=SALOME_ModuleCatalog::PY;
753 C_corba.implementationType=SALOME_ModuleCatalog::SO;
754 C_corba.implname = CORBA::string_dup(C_parser.implementationName.c_str());
756 unsigned int _length = C_parser.interfaces.size();
757 C_corba.interfaces.length(_length);
759 for (unsigned int ind = 0; ind < _length; ind++)
760 duplicate(C_corba.interfaces[ind], C_parser.interfaces[ind]);
764 //----------------------------------------------------------------------
765 // Function : duplicate
766 // Purpose : create an interface from the catalog parsing
767 //----------------------------------------------------------------------
768 void SALOME_ModuleCatalogImpl::duplicate
769 (SALOME_ModuleCatalog::DefinitionInterface & I_corba,
770 const ParserInterface & I_parser)
772 //duplicate interface name
773 I_corba.interfacename = CORBA::string_dup(I_parser.name.c_str());
775 // duplicate service list
776 unsigned int _length = I_parser.services.size();
777 // if(MYDEBUG) SCRUTE(_length);
778 // I_corba.interfaceservicelist
779 // = new SALOME_ModuleCatalog::ListOfInterfaceService;
780 I_corba.interfaceservicelist.length(_length);
782 for (unsigned int ind1 = 0; ind1 < _length ; ind1 ++)
783 duplicate(I_corba.interfaceservicelist[ind1],
784 I_parser.services[ind1]);
787 //----------------------------------------------------------------------
788 // Function : duplicate
789 // Purpose : create a service from the catalog parsing
790 //----------------------------------------------------------------------
791 void SALOME_ModuleCatalogImpl::duplicate
792 (SALOME_ModuleCatalog::Service & S_corba,
793 const ParserService & S_parser)
795 // duplicate service name
796 S_corba.ServiceName = CORBA::string_dup(S_parser.name.c_str());
798 // duplicate service by default
799 S_corba.Servicebydefault = S_parser.byDefault;
801 S_corba.TypeOfNode = S_parser.typeOfNode;
803 unsigned int _length;
805 // duplicate in Parameters
806 _length = S_parser.inParameters.size();
807 S_corba.ServiceinParameter.length(_length);
809 for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
810 duplicate(S_corba.ServiceinParameter[ind2],
811 S_parser.inParameters[ind2]);
813 // duplicate out Parameters
814 _length = S_parser.outParameters.size();
815 S_corba.ServiceoutParameter.length(_length);
817 for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
818 duplicate(S_corba.ServiceoutParameter[ind2],
819 S_parser.outParameters[ind2]);
821 // duplicate in DataStreamParameters
822 _length = S_parser.inDataStreamParameters.size();
823 S_corba.ServiceinDataStreamParameter.length(_length);
825 for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
826 duplicate(S_corba.ServiceinDataStreamParameter[ind2],
827 S_parser.inDataStreamParameters[ind2]);
829 // duplicate out DataStreamParameters
830 _length = S_parser.outDataStreamParameters.size();
831 // if(MYDEBUG) SCRUTE(_length);
832 S_corba.ServiceoutDataStreamParameter.length(_length);
834 for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
835 duplicate(S_corba.ServiceoutDataStreamParameter[ind2],
836 S_parser.outDataStreamParameters[ind2]);
839 //----------------------------------------------------------------------
840 // Function : duplicate
841 // Purpose : create a service parameter from the catalog parsing
842 //----------------------------------------------------------------------
843 void SALOME_ModuleCatalogImpl::duplicate
844 (SALOME_ModuleCatalog::ServicesParameter & P_corba,
845 const ParserParameter & P_parser)
847 // duplicate parameter name
848 P_corba.Parametername = CORBA::string_dup(P_parser.name.c_str());
850 // duplicate parameter type
851 P_corba.Parametertype = CORBA::string_dup(P_parser.type.c_str());
855 //----------------------------------------------------------------------
856 // Function : duplicate
857 // Purpose : create a service datastream parameter from the catalog parsing
858 //----------------------------------------------------------------------
859 void SALOME_ModuleCatalogImpl::duplicate
860 (SALOME_ModuleCatalog::ServicesDataStreamParameter & P_corba,
861 const ParserDataStreamParameter & P_parser)
863 std::map < std::string,
864 SALOME_ModuleCatalog::DataStreamDependency >::const_iterator it_dep;
866 // duplicate parameter name
867 P_corba.Parametername = CORBA::string_dup(P_parser.name.c_str());
869 // duplicate parameter type
872 // it_type = DataStreamTypeConvert.find(P_parser.type);
873 // P_corba.Parametertype
874 // = (it_type == DataStreamTypeConvert.end())
875 // ? it_type->second : SALOME_ModuleCatalog::DATASTREAM_UNKNOWN;
877 P_corba.Parametertype = CORBA::string_dup(P_parser.type.c_str());
879 // duplicate parameter dependency
881 if(MYDEBUG) SCRUTE(P_parser.dependency);
882 P_corba.Parameterdependency = SALOME_ModuleCatalog::DATASTREAM_UNDEFINED;
883 for (it_dep = DataStreamDepConvert.begin();
884 it_dep != DataStreamDepConvert.end();
886 if (P_parser.dependency.compare(it_dep->first) == 0) {
887 P_corba.Parameterdependency = it_dep->second;
891 if(MYDEBUG) SCRUTE(P_corba.Parameterdependency);
894 //----------------------------------------------------------------------
895 // Function : duplicate
896 // Purpose : create the path prefix structures from the catalog parsing
897 //----------------------------------------------------------------------
899 SALOME_ModuleCatalogImpl::duplicate(ParserPathPrefixes &L_out,
900 const ParserPathPrefixes &L_in)
906 //----------------------------------------------------------------------
907 // Function : _verify_path_prefix
908 // Purpose : verify the path prefix structures from the catalog parsing
909 // Verify that there only one path prefix associated to a
910 // particular computer
911 //----------------------------------------------------------------------
913 SALOME_ModuleCatalogImpl::_verify_path_prefix(ParserPathPrefixes & pathList)
915 bool _return_value = true;
916 std::vector<std::string> _machine_list;
918 // Fill a list of all computers indicated in the path list
919 for (unsigned int ind = 0; ind < pathList.size(); ind++)
921 for (unsigned int ind1 = 0 ; ind1 < pathList[ind].listOfComputer.size(); ind1++)
923 _machine_list.push_back(pathList[ind].listOfComputer[ind1]);
927 // Parse if a computer name is twice in the list of computers
928 for (unsigned int ind = 0; ind < _machine_list.size(); ind++)
930 for (unsigned int ind1 = ind+1 ; ind1 < _machine_list.size(); ind1++)
932 if(_machine_list[ind].compare(_machine_list[ind1]) == 0)
934 if(MYDEBUG) MESSAGE( "The computer " << _machine_list[ind] << " is indicated more than once in the path list");
935 _return_value = false;
939 return _return_value;
943 //----------------------------------------------------------------------
944 // Function : _parseArguments
945 // Purpose : parse arguments to get general and personal catalog files
946 //----------------------------------------------------------------------
948 SALOME_ModuleCatalogImpl::_parseArguments(int argc, char **argv,
952 bool _return_value = true;
955 for (int ind = 0; ind < argc ; ind++)
958 if (strcmp(argv[ind],"-help") == 0)
960 INFOS( "Usage: " << argv[0]
961 << " -common 'path to general catalog' "
962 " -personal 'path to personal catalog' "
963 " -ORBInitRef NameService=corbaname::localhost");
964 _return_value = false ;
967 if (strcmp(argv[ind],"-common") == 0)
971 // General catalog file
972 *_general = argv[ind + 1] ;
975 else if (strcmp(argv[ind],"-personal") == 0)
979 // Personal catalog file
980 *_personal = argv[ind + 1] ;
984 return _return_value;