1 // Copyright (C) 2007-2022 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, or (at your option) any later version.
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 "SALOME_ModuleCatalog_Handler.hxx"
32 #include "SALOME_Fake_NamingService.hxx"
34 #include <libxml/parser.h>
37 #include "utilities.h"
39 #include <Basics_Utils.hxx>
45 #include <sys/types.h>
57 static int MYDEBUG = 0;
59 static int MYDEBUG = 0;
62 static const char* SEPARATOR = "::";
63 static const char* OLD_SEPARATOR = ":";
65 const char SALOME_ModuleCatalogImpl::ENTRY_IN_NS[] = "/Kernel/ModulCatalog";
67 SALOME_ModuleCatalog::ModuleCatalog_ptr KERNEL::getModuleComponentServantSA(const char *listOfCatalogs)
69 static SALOME_ModuleCatalog::ModuleCatalog_var moduleCata;
70 if(CORBA::is_nil(moduleCata))
72 CORBA::ORB_ptr orb = KERNEL::getORB();
73 constexpr int NB_OF_ELT_IN_CMD = 3;
74 char *argv[NB_OF_ELT_IN_CMD] = {"SALOME_ModuleCatalog_Server","-common",nullptr};
76 argv[2] = const_cast<char*>(listOfCatalogs);
77 SALOME_ModuleCatalogImpl *servant = new SALOME_ModuleCatalogImpl(NB_OF_ELT_IN_CMD,argv,orb);
78 moduleCata = servant->_this();
79 SALOME_Fake_NamingService NS;
80 NS.Register(moduleCata,SALOME_ModuleCatalogImpl::ENTRY_IN_NS);
82 return SALOME_ModuleCatalog::ModuleCatalog::_duplicate(moduleCata);
85 std::list<std::string> splitStringToList(const std::string& theString, const std::string& theSeparator)
87 std::list<std::string> aList;
89 size_t sepLen = theSeparator.length();
90 size_t startPos = 0, sepPos = theString.find(theSeparator, startPos);
95 if(sepPos != std::string::npos)
96 anItem = theString.substr(startPos, sepPos - startPos);
98 anItem = theString.substr(startPos);
99 if (anItem.length() > 0)
100 aList.push_back(anItem);
101 if(sepPos == std::string::npos)
103 startPos = sepPos + sepLen;
104 sepPos = theString.find(theSeparator, startPos);
110 class SALOME_ModuleCatalogImpl::Private
112 friend class SALOME_ModuleCatalogImpl;
114 //! method to parse one module catalog
116 \param file const char* arguments
117 \param modulelist ParserComponents arguments
118 \param pathlist ParserPathPrefixes arguments
119 \param typeMap ParserTypes arguments
121 void _parse_xml_file(const char* file,
122 ParserComponents & modulelist,
123 ParserPathPrefixes & pathlist,
124 ParserTypes& typeMap,
127 //! method to find component in the parser list
129 \param name string argument
130 \return pointer on a component, NULL if not found
132 ParserComponent *findComponent(const std::string & name);
134 //! method to create a CORBA component description from parser
136 \param C_corba Component argument
137 \param C_parser const ParserComponent argument
139 void duplicate(SALOME_ModuleCatalog::ComponentDef & C_corba,
140 const ParserComponent & C_parser);
142 //! method to create a CORBA interface description from parser
144 \param I_corba DefinitionInterface argument
145 \param I_parser const ParserInterface argument
147 void duplicate(SALOME_ModuleCatalog::DefinitionInterface & I_corba,
148 const ParserInterface & I_parser);
150 //! method to create a CORBA service description from parser
152 \param S_corba Service argument
153 \param S_parser const ParserService argument
155 void duplicate(SALOME_ModuleCatalog::Service & S_corba,
156 const ParserService & service);
158 //! method to create a CORBA parameter description from parser
160 \param P_corba ServicesParameter argument
161 \param P_parser const ParserParameter argument
163 void duplicate(SALOME_ModuleCatalog::ServicesParameter & P_corba,
164 const ParserParameter & P_parser);
166 //! method to create a CORBA datastream parameter description from parser
168 \param P_corba ServicesDataStreamParameter argument
169 \param P_parser const ParserDataStreamParameter argument
171 void duplicate(SALOME_ModuleCatalog::ServicesDataStreamParameter & P_corba,
172 const ParserDataStreamParameter & P_parser);
174 //! method to create the path prefix structures from the catalog parsing
176 \param paths ParserPathPrefixes arguments
179 void duplicate(ParserPathPrefixes & p_out, const ParserPathPrefixes & P_in);
181 //! method to verify path prefix content
183 \param pathlist ListOfParserPathPrefix arguments
184 \return true if verification is OK
186 bool _verify_path_prefix(ParserPathPrefixes & pathlist);
188 // Theses variables will contain the path to the general and personal catalogs
190 char* _personal_path;
192 // These variables will contain the information on the general common catalog
193 ParserComponents _general_module_list ;
194 ParserPathPrefixes _general_path_list ;
195 ParserTypes _typeMap;
198 // These variables will contain the information on the personal catalog
199 ParserComponents _personal_module_list ;
200 ParserPathPrefixes _personal_path_list ;
202 std::map <std::string, SALOME_ModuleCatalog::DataStreamDependency>
203 DataStreamDepConvert;
205 std::map <ParserComponentType, SALOME_ModuleCatalog::ComponentType>
206 ComponentTypeConvert;
209 //----------------------------------------------------------------------
210 // Function : SALOME_ModuleCatalogImpl
211 // Purpose : Constructor
212 //----------------------------------------------------------------------
213 SALOME_ModuleCatalogImpl::SALOME_ModuleCatalogImpl(int argc, char** argv, CORBA::ORB_ptr orb) : _orb(orb)
215 myPrivate = new Private;
216 if(MYDEBUG) MESSAGE("Catalog creation");
220 // Conversion rules for component types
221 myPrivate->ComponentTypeConvert[GEOM]
222 = SALOME_ModuleCatalog::GEOM;
223 myPrivate->ComponentTypeConvert[MESH]
224 = SALOME_ModuleCatalog::MESH;
225 myPrivate->ComponentTypeConvert[Med]
226 = SALOME_ModuleCatalog::Med;
227 myPrivate->ComponentTypeConvert[SOLVER]
228 = SALOME_ModuleCatalog::SOLVER;
229 myPrivate->ComponentTypeConvert[DATA]
230 = SALOME_ModuleCatalog::DATA;
231 myPrivate->ComponentTypeConvert[VISU]
232 = SALOME_ModuleCatalog::VISU;
233 myPrivate->ComponentTypeConvert[SUPERV]
234 = SALOME_ModuleCatalog::SUPERV;
235 myPrivate->ComponentTypeConvert[OTHER]
236 = SALOME_ModuleCatalog::OTHER;
238 // Conversion rules for datastream parameters dependency
239 myPrivate->DataStreamDepConvert["UNDEFINED"]
240 = SALOME_ModuleCatalog::DATASTREAM_UNDEFINED;
241 myPrivate->DataStreamDepConvert["T"]
242 = SALOME_ModuleCatalog::DATASTREAM_TEMPORAL;
243 myPrivate->DataStreamDepConvert["I"]
244 = SALOME_ModuleCatalog::DATASTREAM_ITERATIVE;
246 // Empty used variables
247 myPrivate->_general_module_list.resize(0);
248 myPrivate->_general_path_list.resize(0);
250 myPrivate->_personal_module_list.resize(0);
251 myPrivate->_personal_path_list.resize(0);
253 // Parse the arguments given at server run
254 if (!_parseArguments(argc, argv,&myPrivate->_general_path,&myPrivate->_personal_path))
255 if(MYDEBUG) MESSAGE( "Error while argument parsing" );
257 // Test existency of files
258 if (myPrivate->_general_path == NULL)
260 if(MYDEBUG) MESSAGE( "Error the general catalog should be indicated" );
264 // Affect the _general_module_list and _general_path_list members
265 // with the common catalog
267 std::list<std::string> dirList;
270 dirList = splitStringToList(myPrivate->_general_path, SEPARATOR);
272 //check for new format
273 bool isNew = (std::string( myPrivate->_general_path ).find(SEPARATOR) != std::string::npos);
276 dirList = splitStringToList(myPrivate->_general_path, SEPARATOR);
279 dirList = splitStringToList(myPrivate->_general_path, OLD_SEPARATOR);
283 for (std::list<std::string>::iterator iter = dirList.begin(); iter != dirList.end(); iter++)
285 std::string aPath = (*iter);
286 //remove inverted commas from filename
287 while (aPath.find('\"') != std::string::npos)
288 aPath.erase(aPath.find('\"'), 1);
290 myPrivate->_parse_xml_file(aPath.c_str(),
291 myPrivate->_general_module_list,
292 myPrivate->_general_path_list,
294 myPrivate->_typeList);
297 // Verification of _general_path_list content
298 if (!myPrivate->_verify_path_prefix(myPrivate->_general_path_list)) {
299 if(MYDEBUG) MESSAGE( "Error while parsing the general path list, "
300 "different paths are associated to the same computer,"
301 "the first one will be chosen");
303 if(MYDEBUG) MESSAGE("General path list OK");
306 if (myPrivate->_personal_path != NULL) {
307 // Initialize the _personal_module_list and
308 // _personal_path_list members with the personal catalog files
309 myPrivate->_parse_xml_file(myPrivate->_personal_path,
310 myPrivate->_personal_module_list,
311 myPrivate->_personal_path_list,
313 myPrivate->_typeList);
315 // Verification of _general_path_list content
316 if(!myPrivate->_verify_path_prefix(myPrivate->_personal_path_list)){
317 if(MYDEBUG) MESSAGE("Error while parsing the personal path list, "
318 "different paths are associated to the same computer, "
319 "the first one will be chosen" );
321 if(MYDEBUG) MESSAGE("Personal path list OK");
324 if(MYDEBUG) MESSAGE("No personal catalog indicated or error while "
325 "opening the personal catalog");
329 //----------------------------------------------------------------------
330 // Function : ~SALOME_ModuleCatalogImpl
331 // Purpose : Destructor
332 //----------------------------------------------------------------------
333 SALOME_ModuleCatalogImpl::~SALOME_ModuleCatalogImpl()
335 if(MYDEBUG) MESSAGE("Catalog Destruction");
340 //! Get the list of all types of the catalog
342 * \return the list of types
344 SALOME_ModuleCatalog::ListOfTypeDefinition* SALOME_ModuleCatalogImpl::GetTypes()
346 SALOME_ModuleCatalog::ListOfTypeDefinition_var type_list = new SALOME_ModuleCatalog::ListOfTypeDefinition();
347 type_list->length((CORBA::ULong)myPrivate->_typeList.size());
349 for (unsigned int ind = 0 ; ind < myPrivate->_typeList.size() ; ind++)
351 //no real need to call string_dup, omniorb calls it on operator= (const char *) but it is safer
352 type_list[ind].name=CORBA::string_dup(myPrivate->_typeList[ind].name.c_str());
353 type_list[ind].kind=SALOME_ModuleCatalog::NONE;
354 if(myPrivate->_typeList[ind].kind=="double")
355 type_list[ind].kind=SALOME_ModuleCatalog::Dble;
356 else if(myPrivate->_typeList[ind].kind=="int")
357 type_list[ind].kind=SALOME_ModuleCatalog::Int;
358 else if(myPrivate->_typeList[ind].kind=="bool")
359 type_list[ind].kind=SALOME_ModuleCatalog::Bool;
360 else if(myPrivate->_typeList[ind].kind=="string")
361 type_list[ind].kind=SALOME_ModuleCatalog::Str;
362 else if(myPrivate->_typeList[ind].kind=="objref")
364 type_list[ind].kind=SALOME_ModuleCatalog::Objref;
365 type_list[ind].id=CORBA::string_dup(myPrivate->_typeList[ind].id.c_str());
367 type_list[ind].bases.length((CORBA::ULong)myPrivate->_typeList[ind].bases.size());
368 std::vector<std::string>::const_iterator miter;
369 miter=myPrivate->_typeList[ind].bases.begin();
371 while(miter != myPrivate->_typeList[ind].bases.end())
373 type_list[ind].bases[n_memb]=CORBA::string_dup(miter->c_str());
378 else if(myPrivate->_typeList[ind].kind=="sequence")
380 type_list[ind].kind=SALOME_ModuleCatalog::Seq;
381 type_list[ind].content=CORBA::string_dup(myPrivate->_typeList[ind].content.c_str());
383 else if(myPrivate->_typeList[ind].kind=="array")
385 type_list[ind].kind=SALOME_ModuleCatalog::Array;
386 type_list[ind].content=CORBA::string_dup(myPrivate->_typeList[ind].content.c_str());
388 else if(myPrivate->_typeList[ind].kind=="struct")
390 type_list[ind].kind=SALOME_ModuleCatalog::Struc;
392 type_list[ind].members.length((CORBA::ULong)myPrivate->_typeList[ind].members.size());
394 std::vector< std::pair<std::string,std::string> >::const_iterator miter;
395 miter=myPrivate->_typeList[ind].members.begin();
397 while(miter != myPrivate->_typeList[ind].members.end())
399 type_list[ind].members[n_memb].name=CORBA::string_dup(miter->first.c_str());
400 type_list[ind].members[n_memb].type=CORBA::string_dup(miter->second.c_str());
406 return type_list._retn();
409 //----------------------------------------------------------------------
410 // Function : GetComputerList
411 // Purpose : get a computer list
412 //----------------------------------------------------------------------
413 SALOME_ModuleCatalog::ListOfComputers*
414 SALOME_ModuleCatalogImpl::GetComputerList()
416 SALOME_ModuleCatalog::ListOfComputers_var _list_computers =
417 new SALOME_ModuleCatalog::ListOfComputers;
418 return _list_computers._retn();
421 //----------------------------------------------------------------------
422 // Function : GetPathPrefix
423 // Purpose : get the PathPrefix of a computer
424 //----------------------------------------------------------------------
426 SALOME_ModuleCatalogImpl::GetPathPrefix(const char* machinename) {
427 if(MYDEBUG) MESSAGE("Begin of GetPathPrefix");
428 // Variables initialisation
432 // Parse all the path prefixes
433 // looking for the wanted computer
434 for (unsigned int ind = 0; ind < myPrivate->_personal_path_list.size() && !_find; ind++)
436 for (unsigned int ind1 = 0; ind1 < myPrivate->_personal_path_list[ind].listOfComputer.size() && !_find; ind1++)
438 if ( myPrivate->_personal_path_list[ind].listOfComputer[ind1] == machinename )
442 // affect the path to be returned
443 _path = myPrivate->_personal_path_list[ind].path;
448 for (unsigned int ind = 0; ind < myPrivate->_general_path_list.size() && !_find; ind++)
450 for (unsigned int ind1 = 0; ind1 < myPrivate->_general_path_list[ind].listOfComputer.size() && !_find; ind1++)
452 if (myPrivate->_general_path_list[ind].listOfComputer[ind1] == machinename)
456 // affect the path to be returned
457 _path = myPrivate->_general_path_list[ind].path;
461 return CORBA::string_dup(_path.c_str()) ;
464 //----------------------------------------------------------------------
465 // Function : GetComponentList
466 // Purpose : get a component list
467 // If a component is defined in the personal catalog and
468 // in the general catalog (same name), the component defined
469 // in the personal catalog is used
470 //----------------------------------------------------------------------
471 SALOME_ModuleCatalog::ListOfComponents*
472 SALOME_ModuleCatalogImpl::GetComponentList()
474 if(MYDEBUG) MESSAGE("Begin of GetComponentList");
475 SALOME_ModuleCatalog::ListOfComponents_var _list_components =
476 new SALOME_ModuleCatalog::ListOfComponents;
478 _list_components->length((CORBA::ULong)myPrivate->_personal_module_list.size());
480 // All the components defined in the personal catalog are taken
481 for(unsigned int ind=0; ind < myPrivate->_personal_module_list.size();ind++){
482 _list_components[ind]=(myPrivate->_personal_module_list[ind].name).c_str();
483 if(MYDEBUG) SCRUTE(_list_components[ind]) ;
486 size_t indice = myPrivate->_personal_module_list.size();
489 // The components in the general catalog are taken only if they're
490 // not defined in the personal catalog
491 for(unsigned int ind=0; ind < myPrivate->_general_module_list.size();ind++){
493 for(unsigned int ind1=0; ind1 < myPrivate->_personal_module_list.size();ind1++){
494 // searching if the component is already defined in
495 // the personal catalog
496 if ((myPrivate->_general_module_list[ind].name.compare(myPrivate->_personal_module_list[ind1].name)) == 0)
500 if(MYDEBUG) MESSAGE("A new component " << myPrivate->_general_module_list[ind].name
501 << " has to be to added in the list");
502 _list_components->length((CORBA::ULong)indice+1);
503 // The component is not already defined => has to be taken
504 _list_components[(CORBA::ULong)indice]=(myPrivate->_general_module_list[ind].name).c_str();
505 if(MYDEBUG) SCRUTE(_list_components[(CORBA::ULong)indice]) ;
509 if(MYDEBUG) MESSAGE("The component " <<myPrivate->_general_module_list[ind].name
510 << " was already defined in the personal catalog") ;
514 if(MYDEBUG) MESSAGE ( "End of GetComponentList" );
515 return _list_components._retn();
519 //----------------------------------------------------------------------
520 // Function : GetComponentIconeList
521 // Purpose : get a component list of component name and component icone
522 // If a component is defined in the personal catalog and
523 // in the general catalog (same name), the component defined
524 // in the personal catalog is used
525 //----------------------------------------------------------------------
526 SALOME_ModuleCatalog::ListOfIAPP_Affich*
527 SALOME_ModuleCatalogImpl::GetComponentIconeList()
529 if(MYDEBUG) MESSAGE("Begin of GetComponentIconeList");
531 SALOME_ModuleCatalog::ListOfIAPP_Affich_var _list_components_icone =
532 new SALOME_ModuleCatalog::ListOfIAPP_Affich;
534 _list_components_icone->length((CORBA::ULong)myPrivate->_personal_module_list.size());
536 // All the components defined in the personal catalog are taken
537 for(unsigned int ind=0; ind < myPrivate->_personal_module_list.size();ind++){
538 _list_components_icone[ind].modulename=(myPrivate->_personal_module_list[ind].name).c_str();
539 _list_components_icone[ind].moduleusername=(myPrivate->_personal_module_list[ind].username).c_str();
540 _list_components_icone[ind].moduleicone=(myPrivate->_personal_module_list[ind].icon).c_str();
541 _list_components_icone[ind].moduleversion=(myPrivate->_personal_module_list[ind].version).c_str();
542 _list_components_icone[ind].modulecomment=(myPrivate->_personal_module_list[ind].comment).c_str();
543 //if(MYDEBUG) SCRUTE(_list_components_icone[ind].modulename);
544 //if(MYDEBUG) SCRUTE(_list_components_icone[ind].moduleicone);
547 size_t indice = myPrivate->_personal_module_list.size();
550 // The components in the general catalog are taken only if they're
551 // not defined in the personal catalog
552 for(unsigned int ind=0; ind < myPrivate->_general_module_list.size();ind++){
554 for(unsigned int ind1=0; ind1 < myPrivate->_personal_module_list.size();ind1++){
555 // searching if the component is aleready defined in
556 // the personal catalog
557 if((myPrivate->_general_module_list[ind].name.compare(myPrivate->_personal_module_list[ind1].name)) == 0)
561 // if(MYDEBUG) MESSAGE("A new component " << _general_module_list[ind].name << " has to be to added in the list");
562 _list_components_icone->length((CORBA::ULong)indice+1);
563 // The component is not already defined => has to be taken
564 _list_components_icone[(CORBA::ULong)indice].modulename=myPrivate->_general_module_list[ind].name.c_str();
565 _list_components_icone[(CORBA::ULong)indice].moduleusername=myPrivate->_general_module_list[ind].username.c_str();
566 _list_components_icone[(CORBA::ULong)indice].moduleicone=myPrivate->_general_module_list[ind].icon.c_str();
567 _list_components_icone[(CORBA::ULong)indice].moduleversion=myPrivate->_general_module_list[ind].version.c_str();
568 _list_components_icone[(CORBA::ULong)indice].modulecomment=myPrivate->_general_module_list[ind].comment.c_str();
569 //if(MYDEBUG) SCRUTE(_list_components_icone[(CORBA::ULong)indice].modulename) ;
570 //if(MYDEBUG) SCRUTE(_list_components_icone[(CORBA::ULong)indice].moduleicone);
575 //if(MYDEBUG) MESSAGE("The component " <<_general_module_list[ind].name << " was already defined in the personal catalog");
578 return _list_components_icone._retn() ;
581 //----------------------------------------------------------------------
582 // Function : GetTypedComponentList
583 // Purpose : get a component list of a wanted type
584 // If a component is defined in the personal catalog and
585 // in the general catalog (same name), the component defined
586 // in the personal catalog is used
587 //----------------------------------------------------------------------
588 SALOME_ModuleCatalog::ListOfComponents*
589 SALOME_ModuleCatalogImpl::GetTypedComponentList(SALOME_ModuleCatalog::ComponentType component_type)
591 if(MYDEBUG) MESSAGE("Begin of GetTypedComponentList");
592 SALOME_ModuleCatalog::ListOfComponents_var _list_typed_component =
593 new SALOME_ModuleCatalog::ListOfComponents;
596 _list_typed_component->length(0);
597 // Transform SALOME_ModuleCatalog::ComponentType in ParserComponentType
598 ParserComponentType _temp_component_type = OTHER;
599 switch(component_type){
600 case SALOME_ModuleCatalog::GEOM:
601 _temp_component_type = GEOM ;
603 case SALOME_ModuleCatalog::MESH:
604 _temp_component_type = MESH;
606 case SALOME_ModuleCatalog::Med:
607 _temp_component_type = Med;
609 case SALOME_ModuleCatalog::SOLVER:
610 _temp_component_type = SOLVER;
612 case SALOME_ModuleCatalog::DATA:
613 _temp_component_type = DATA;
615 case SALOME_ModuleCatalog::VISU:
616 _temp_component_type = VISU;
618 case SALOME_ModuleCatalog::SUPERV:
619 _temp_component_type = SUPERV;
621 case SALOME_ModuleCatalog::OTHER:
622 _temp_component_type = OTHER;
626 // All the components in the personal catalog are taken
627 for (unsigned int ind=0; ind < myPrivate->_personal_module_list.size();ind++)
629 if (myPrivate->_personal_module_list[ind].type == _temp_component_type)
631 _list_typed_component->length(_j + 1);
632 _list_typed_component[_j] = myPrivate->_personal_module_list[ind].name.c_str();
633 //if(MYDEBUG) SCRUTE(_list_typed_component[_j]);
638 int indice = _list_typed_component->length() ;
641 // The components in the general catalog are taken only if they're
642 // not defined in the personal catalog
643 for (unsigned int ind=0; ind < myPrivate->_general_module_list.size();ind++)
647 if(myPrivate->_general_module_list[ind].type == _temp_component_type)
649 for (unsigned int ind1=0; ind1 < myPrivate->_personal_module_list.size();ind1++)
651 // searching if the component is aleready defined in
652 // the personal catalog
653 if ((myPrivate->_general_module_list[ind].name.compare(myPrivate->_personal_module_list[ind1].name)) == 0)
658 //if(MYDEBUG) MESSAGE("A new component " << _general_module_list[ind].name << " has to be to added in the list");
659 _list_typed_component->length(indice+1);
660 // The component is not already defined => has to be taken
661 _list_typed_component[indice]=(myPrivate->_general_module_list[ind].name).c_str();
662 //if(MYDEBUG) SCRUTE(_list_typed_component[indice]) ;
667 //if(MYDEBUG) MESSAGE("The component " <<_general_module_list[ind].name << " was already defined in the personal catalog") ;
672 return _list_typed_component._retn();
675 //----------------------------------------------------------------------
676 // Function : GetComponent
677 // Purpose : get a component
678 // If a component is defined in the personal catalog and
679 // in the general catalog (same name), the component defined
680 // in the personal catalog is used
681 //----------------------------------------------------------------------
682 SALOME_ModuleCatalog::Acomponent_ptr
683 SALOME_ModuleCatalogImpl::GetComponent(const char* name)
685 // Looking for component named "componentname" in the personal catalog
686 // If found, get name, interfaces and constraint
687 // If not found, looking for component named "componentname" in
688 // the general catalog
689 // If found, get name, interfaces and constraint
690 // If not found, NULL pointer is returned
693 ParserComponent *C_parser = NULL;
694 //ParserPathPrefixes *pp = NULL;
696 SALOME_ModuleCatalog::Acomponent_ptr compo
697 = SALOME_ModuleCatalog::Acomponent::_nil();
698 C_parser = myPrivate->findComponent(s);
701 // DebugParserComponent(*C_parser);
703 SALOME_ModuleCatalog::ComponentDef C_corba;
704 myPrivate->duplicate(C_corba, *C_parser);
707 SALOME_ModuleCatalog_AcomponentImpl * aComponentImpl =
708 new SALOME_ModuleCatalog_AcomponentImpl(C_corba);
710 compo = aComponentImpl->_this();
713 // Not found in the personal catalog and in the general catalog
714 // return NULL object
715 if(MYDEBUG) MESSAGE("Component with name " << name
716 << " not found in catalog");
722 SALOME_ModuleCatalog::ComponentDef *
723 SALOME_ModuleCatalogImpl::GetComponentInfo(const char *name)
727 ParserComponent * C_parser = myPrivate->findComponent(s);
731 SALOME_ModuleCatalog::ComponentDef * C_corba
732 = new SALOME_ModuleCatalog::ComponentDef;
733 myPrivate->duplicate(*C_corba, *C_parser);
740 void SALOME_ModuleCatalogImpl::ping()
744 CORBA::Long SALOME_ModuleCatalogImpl::getPID()
748 (CORBA::Long)getpid();
750 (CORBA::Long)_getpid();
754 void SALOME_ModuleCatalogImpl::ShutdownWithExit()
756 exit( EXIT_SUCCESS );
759 void SALOME_ModuleCatalogImpl::shutdown()
761 if (!CORBA::is_nil(_orb)) _orb->shutdown(0);
766 //----------------------------------------------------------------------
767 // Function : _parseArguments
768 // Purpose : parse arguments to get general and personal catalog files
769 //----------------------------------------------------------------------
771 SALOME_ModuleCatalogImpl::_parseArguments(int argc, char **argv,
775 bool _return_value = true;
778 for (int ind = 0; ind < argc ; ind++)
781 if (strcmp(argv[ind],"-help") == 0)
783 INFOS( "Usage: " << argv[0]
784 << " -common 'path to general catalog' "
785 " -personal 'path to personal catalog' "
786 " -ORBInitRef NameService=corbaname::localhost");
787 _return_value = false ;
790 if (strcmp(argv[ind],"-common") == 0)
794 // General catalog file
795 *_general = argv[ind + 1] ;
798 else if (strcmp(argv[ind],"-personal") == 0)
802 // Personal catalog file
803 *_personal = argv[ind + 1] ;
807 return _return_value;
811 SALOME_ModuleCatalogImpl::Private::findComponent(const std::string & name)
813 ParserComponent * C_parser = NULL;
816 for (unsigned int ind=0; ind < _personal_module_list.size();ind++)
818 if (name.compare(_personal_module_list[ind].name) == 0)
820 if(MYDEBUG) MESSAGE("Component named " << name
821 << " found in the personal catalog");
822 C_parser = &(_personal_module_list[ind]);
828 for (unsigned int ind=0; ind < _general_module_list.size();ind++)
830 if (name.compare(_general_module_list[ind].name) == 0)
832 // if(MYDEBUG) MESSAGE("Component named " << name
833 // << " found in the general catalog");
834 C_parser = &(_general_module_list[ind]);
842 //----------------------------------------------------------------------
843 // Function : _parse_xml_file
844 // Purpose : parse one module catalog
845 //----------------------------------------------------------------------
847 SALOME_ModuleCatalogImpl::Private::_parse_xml_file(const char* file,
848 ParserComponents& modulelist,
849 ParserPathPrefixes& pathList,
850 ParserTypes& typeMap,
853 if(MYDEBUG) BEGIN_OF("_parse_xml_file");
854 if(MYDEBUG) SCRUTE(file);
856 //Local path and module list for the file to parse
857 ParserPathPrefixes _pathList;
858 ParserComponents _moduleList;
860 SALOME_ModuleCatalog_Handler* handler = new SALOME_ModuleCatalog_Handler(_pathList,_moduleList,typeMap,typeList);
862 const wchar_t* w_file = Kernel_Utils::utf8_decode(file);
863 FILE* aFile = _wfopen(w_file, L"r");
865 FILE* aFile = fopen(file, "r");
870 xmlDocPtr aDoc = xmlReadFile(file, NULL, 0);
873 handler->ProcessXmlDocument(aDoc);
875 MESSAGE("ModuleCatalog: could not parse file "<<file);
881 MESSAGE("ModuleCatalog: file "<<file<<" is not readable.");
887 for ( i = 0; i < _moduleList.size(); i++) {
888 for (j=0; j<modulelist.size(); j++) {
889 if (modulelist[j].name == _moduleList[i].name)
892 if (j < modulelist.size())
893 modulelist[j] = _moduleList[i];
895 modulelist.push_back(_moduleList[i]);
898 for ( i=0; i < _pathList.size(); i++)
899 pathList.push_back(_pathList[i]) ;
901 for (j=0; j<modulelist.size(); j++)
902 modulelist[j].prefixes = pathList;
906 SALOME_ModuleCatalogImpl::ImportXmlCatalogFile(const char* file)
908 myPrivate->_parse_xml_file(file, myPrivate->_personal_module_list, myPrivate->_personal_path_list,myPrivate->_typeMap,myPrivate->_typeList);
913 // Duplicate functions create a Corba structure (component,
914 // interface, service, parameter) from the corresponding C++
918 //----------------------------------------------------------------------
919 // Function : duplicate
920 // Purpose : create a component from the catalog parsing
921 //----------------------------------------------------------------------
922 void SALOME_ModuleCatalogImpl::Private::duplicate
923 (SALOME_ModuleCatalog::ComponentDef & C_corba,
924 const ParserComponent & C_parser)
926 C_corba.name = CORBA::string_dup(C_parser.name.c_str());
927 C_corba.username = CORBA::string_dup(C_parser.username.c_str());
928 C_corba.icon = CORBA::string_dup(C_parser.icon.c_str());
929 C_corba.type = ComponentTypeConvert[C_parser.type];
930 if(C_parser.implementationType == "EXE")
931 C_corba.implementationType=SALOME_ModuleCatalog::EXE;
932 else if(C_parser.implementationType == "CEXE")
933 C_corba.implementationType=SALOME_ModuleCatalog::CEXE;
934 else if(C_parser.implementationType == "PY")
935 C_corba.implementationType=SALOME_ModuleCatalog::PY;
937 C_corba.implementationType=SALOME_ModuleCatalog::SO;
938 C_corba.implname = CORBA::string_dup(C_parser.implementationName.c_str());
940 size_t _length = C_parser.interfaces.size();
941 C_corba.interfaces.length((CORBA::ULong)_length);
943 for (unsigned int ind = 0; ind < _length; ind++)
944 duplicate(C_corba.interfaces[ind], C_parser.interfaces[ind]);
948 //----------------------------------------------------------------------
949 // Function : duplicate
950 // Purpose : create an interface from the catalog parsing
951 //----------------------------------------------------------------------
952 void SALOME_ModuleCatalogImpl::Private::duplicate
953 (SALOME_ModuleCatalog::DefinitionInterface & I_corba,
954 const ParserInterface & I_parser)
956 //duplicate interface name
957 I_corba.interfacename = CORBA::string_dup(I_parser.name.c_str());
959 // duplicate service list
960 size_t _length = I_parser.services.size();
961 // if(MYDEBUG) SCRUTE(_length);
962 // I_corba.interfaceservicelist
963 // = new SALOME_ModuleCatalog::ListOfInterfaceService;
964 I_corba.interfaceservicelist.length((CORBA::ULong)_length);
966 for (unsigned int ind1 = 0; ind1 < _length ; ind1 ++)
967 duplicate(I_corba.interfaceservicelist[ind1],
968 I_parser.services[ind1]);
971 //----------------------------------------------------------------------
972 // Function : duplicate
973 // Purpose : create a service from the catalog parsing
974 //----------------------------------------------------------------------
975 void SALOME_ModuleCatalogImpl::Private::duplicate
976 (SALOME_ModuleCatalog::Service & S_corba,
977 const ParserService & S_parser)
979 // duplicate service name
980 S_corba.ServiceName = CORBA::string_dup(S_parser.name.c_str());
982 // duplicate service by default
983 S_corba.Servicebydefault = S_parser.byDefault;
985 S_corba.TypeOfNode = S_parser.typeOfNode;
989 // duplicate in Parameters
990 _length = S_parser.inParameters.size();
991 S_corba.ServiceinParameter.length((CORBA::ULong)_length);
993 for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
994 duplicate(S_corba.ServiceinParameter[ind2],
995 S_parser.inParameters[ind2]);
997 // duplicate out Parameters
998 _length = S_parser.outParameters.size();
999 S_corba.ServiceoutParameter.length((CORBA::ULong)_length);
1001 for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
1002 duplicate(S_corba.ServiceoutParameter[ind2],
1003 S_parser.outParameters[ind2]);
1005 // duplicate in DataStreamParameters
1006 _length = S_parser.inDataStreamParameters.size();
1007 S_corba.ServiceinDataStreamParameter.length((CORBA::ULong)_length);
1009 for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
1010 duplicate(S_corba.ServiceinDataStreamParameter[ind2],
1011 S_parser.inDataStreamParameters[ind2]);
1013 // duplicate out DataStreamParameters
1014 _length = S_parser.outDataStreamParameters.size();
1015 // if(MYDEBUG) SCRUTE(_length);
1016 S_corba.ServiceoutDataStreamParameter.length((CORBA::ULong)_length);
1018 for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
1019 duplicate(S_corba.ServiceoutDataStreamParameter[ind2],
1020 S_parser.outDataStreamParameters[ind2]);
1023 //----------------------------------------------------------------------
1024 // Function : duplicate
1025 // Purpose : create a service parameter from the catalog parsing
1026 //----------------------------------------------------------------------
1027 void SALOME_ModuleCatalogImpl::Private::duplicate
1028 (SALOME_ModuleCatalog::ServicesParameter & P_corba,
1029 const ParserParameter & P_parser)
1031 // duplicate parameter name
1032 P_corba.Parametername = CORBA::string_dup(P_parser.name.c_str());
1034 // duplicate parameter type
1035 P_corba.Parametertype = CORBA::string_dup(P_parser.type.c_str());
1039 //----------------------------------------------------------------------
1040 // Function : duplicate
1041 // Purpose : create a service datastream parameter from the catalog parsing
1042 //----------------------------------------------------------------------
1043 void SALOME_ModuleCatalogImpl::Private::duplicate
1044 (SALOME_ModuleCatalog::ServicesDataStreamParameter & P_corba,
1045 const ParserDataStreamParameter & P_parser)
1047 std::map < std::string,
1048 SALOME_ModuleCatalog::DataStreamDependency >::const_iterator it_dep;
1050 // duplicate parameter name
1051 P_corba.Parametername = CORBA::string_dup(P_parser.name.c_str());
1053 // duplicate parameter type
1056 // it_type = DataStreamTypeConvert.find(P_parser.type);
1057 // P_corba.Parametertype
1058 // = (it_type == DataStreamTypeConvert.end())
1059 // ? it_type->second : SALOME_ModuleCatalog::DATASTREAM_UNKNOWN;
1061 P_corba.Parametertype = CORBA::string_dup(P_parser.type.c_str());
1063 // duplicate parameter dependency
1065 if(MYDEBUG) SCRUTE(P_parser.dependency);
1066 P_corba.Parameterdependency = SALOME_ModuleCatalog::DATASTREAM_UNDEFINED;
1067 for (it_dep = DataStreamDepConvert.begin();
1068 it_dep != DataStreamDepConvert.end();
1070 if (P_parser.dependency.compare(it_dep->first) == 0) {
1071 P_corba.Parameterdependency = it_dep->second;
1075 if(MYDEBUG) SCRUTE(P_corba.Parameterdependency);
1078 //----------------------------------------------------------------------
1079 // Function : duplicate
1080 // Purpose : create the path prefix structures from the catalog parsing
1081 //----------------------------------------------------------------------
1083 SALOME_ModuleCatalogImpl::Private::duplicate(ParserPathPrefixes &L_out,
1084 const ParserPathPrefixes &L_in)
1090 //----------------------------------------------------------------------
1091 // Function : _verify_path_prefix
1092 // Purpose : verify the path prefix structures from the catalog parsing
1093 // Verify that there only one path prefix associated to a
1094 // particular computer
1095 //----------------------------------------------------------------------
1097 SALOME_ModuleCatalogImpl::Private::_verify_path_prefix(ParserPathPrefixes & pathList)
1099 bool _return_value = true;
1100 std::vector<std::string> _machine_list;
1102 // Fill a list of all computers indicated in the path list
1103 for (unsigned int ind = 0; ind < pathList.size(); ind++)
1105 for (unsigned int ind1 = 0 ; ind1 < pathList[ind].listOfComputer.size(); ind1++)
1107 _machine_list.push_back(pathList[ind].listOfComputer[ind1]);
1111 // Parse if a computer name is twice in the list of computers
1112 for (unsigned int ind = 0; ind < _machine_list.size(); ind++)
1114 for (unsigned int ind1 = ind+1 ; ind1 < _machine_list.size(); ind1++)
1116 if(_machine_list[ind].compare(_machine_list[ind1]) == 0)
1118 if(MYDEBUG) MESSAGE( "The computer " << _machine_list[ind] << " is indicated more than once in the path list");
1119 _return_value = false;
1123 return _return_value;