1 // Copyright (C) 2007-2024 CEA, EDF, 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 const char* SEPARATOR = "::";
58 static const char* OLD_SEPARATOR = ":";
60 const char SALOME_ModuleCatalogImpl::ENTRY_IN_NS[] = "/Kernel/ModulCatalog";
62 SALOME_ModuleCatalog::ModuleCatalog_ptr KERNEL::getModuleComponentServantSA(const char *listOfCatalogs)
64 static SALOME_ModuleCatalog::ModuleCatalog_var moduleCata;
65 if(CORBA::is_nil(moduleCata))
67 CORBA::ORB_ptr orb = KERNEL::getORB();
68 constexpr int NB_OF_ELT_IN_CMD = 3;
69 char *argv[NB_OF_ELT_IN_CMD] = {"SALOME_ModuleCatalog_Server","-common",nullptr};
71 argv[2] = const_cast<char*>(listOfCatalogs);
72 SALOME_ModuleCatalogImpl *servant = new SALOME_ModuleCatalogImpl(NB_OF_ELT_IN_CMD,argv,orb);
73 moduleCata = servant->_this();
74 SALOME_Fake_NamingService NS;
75 NS.Register(moduleCata,SALOME_ModuleCatalogImpl::ENTRY_IN_NS);
77 return SALOME_ModuleCatalog::ModuleCatalog::_duplicate(moduleCata);
80 std::list<std::string> splitStringToList(const std::string& theString, const std::string& theSeparator)
82 std::list<std::string> aList;
84 size_t sepLen = theSeparator.length();
85 size_t startPos = 0, sepPos = theString.find(theSeparator, startPos);
90 if(sepPos != std::string::npos)
91 anItem = theString.substr(startPos, sepPos - startPos);
93 anItem = theString.substr(startPos);
94 if (anItem.length() > 0)
95 aList.push_back(anItem);
96 if(sepPos == std::string::npos)
98 startPos = sepPos + sepLen;
99 sepPos = theString.find(theSeparator, startPos);
105 class SALOME_ModuleCatalogImpl::Private
107 friend class SALOME_ModuleCatalogImpl;
109 //! method to parse one module catalog
111 \param file const char* arguments
112 \param modulelist ParserComponents arguments
113 \param pathlist ParserPathPrefixes arguments
114 \param typeMap ParserTypes arguments
116 void _parse_xml_file(const char* file,
117 ParserComponents & modulelist,
118 ParserPathPrefixes & pathlist,
119 ParserTypes& typeMap,
122 //! method to find component in the parser list
124 \param name string argument
125 \return pointer on a component, NULL if not found
127 ParserComponent *findComponent(const std::string & name);
129 //! method to create a CORBA component description from parser
131 \param C_corba Component argument
132 \param C_parser const ParserComponent argument
134 void duplicate(SALOME_ModuleCatalog::ComponentDef & C_corba,
135 const ParserComponent & C_parser);
137 //! method to create a CORBA interface description from parser
139 \param I_corba DefinitionInterface argument
140 \param I_parser const ParserInterface argument
142 void duplicate(SALOME_ModuleCatalog::DefinitionInterface & I_corba,
143 const ParserInterface & I_parser);
145 //! method to create a CORBA service description from parser
147 \param S_corba Service argument
148 \param S_parser const ParserService argument
150 void duplicate(SALOME_ModuleCatalog::Service & S_corba,
151 const ParserService & service);
153 //! method to create a CORBA parameter description from parser
155 \param P_corba ServicesParameter argument
156 \param P_parser const ParserParameter argument
158 void duplicate(SALOME_ModuleCatalog::ServicesParameter & P_corba,
159 const ParserParameter & P_parser);
161 //! method to create a CORBA datastream parameter description from parser
163 \param P_corba ServicesDataStreamParameter argument
164 \param P_parser const ParserDataStreamParameter argument
166 void duplicate(SALOME_ModuleCatalog::ServicesDataStreamParameter & P_corba,
167 const ParserDataStreamParameter & P_parser);
169 //! method to create the path prefix structures from the catalog parsing
171 \param paths ParserPathPrefixes arguments
174 void duplicate(ParserPathPrefixes & p_out, const ParserPathPrefixes & P_in);
176 //! method to verify path prefix content
178 \param pathlist ListOfParserPathPrefix arguments
179 \return true if verification is OK
181 bool _verify_path_prefix(ParserPathPrefixes & pathlist);
183 // Theses variables will contain the path to the general and personal catalogs
185 char* _personal_path;
187 // These variables will contain the information on the general common catalog
188 ParserComponents _general_module_list ;
189 ParserPathPrefixes _general_path_list ;
190 ParserTypes _typeMap;
193 // These variables will contain the information on the personal catalog
194 ParserComponents _personal_module_list ;
195 ParserPathPrefixes _personal_path_list ;
197 std::map <std::string, SALOME_ModuleCatalog::DataStreamDependency>
198 DataStreamDepConvert;
200 std::map <ParserComponentType, SALOME_ModuleCatalog::ComponentType>
201 ComponentTypeConvert;
204 //----------------------------------------------------------------------
205 // Function : SALOME_ModuleCatalogImpl
206 // Purpose : Constructor
207 //----------------------------------------------------------------------
208 SALOME_ModuleCatalogImpl::SALOME_ModuleCatalogImpl(int argc, char** argv, CORBA::ORB_ptr orb) : _orb(orb)
210 myPrivate = new Private;
211 DEBUG_MESSAGE("Catalog creation");
215 // Conversion rules for component types
216 myPrivate->ComponentTypeConvert[GEOM]
217 = SALOME_ModuleCatalog::GEOM;
218 myPrivate->ComponentTypeConvert[MESH]
219 = SALOME_ModuleCatalog::MESH;
220 myPrivate->ComponentTypeConvert[Med]
221 = SALOME_ModuleCatalog::Med;
222 myPrivate->ComponentTypeConvert[SOLVER]
223 = SALOME_ModuleCatalog::SOLVER;
224 myPrivate->ComponentTypeConvert[DATA]
225 = SALOME_ModuleCatalog::DATA;
226 myPrivate->ComponentTypeConvert[VISU]
227 = SALOME_ModuleCatalog::VISU;
228 myPrivate->ComponentTypeConvert[SUPERV]
229 = SALOME_ModuleCatalog::SUPERV;
230 myPrivate->ComponentTypeConvert[OTHER]
231 = SALOME_ModuleCatalog::OTHER;
233 // Conversion rules for datastream parameters dependency
234 myPrivate->DataStreamDepConvert["UNDEFINED"]
235 = SALOME_ModuleCatalog::DATASTREAM_UNDEFINED;
236 myPrivate->DataStreamDepConvert["T"]
237 = SALOME_ModuleCatalog::DATASTREAM_TEMPORAL;
238 myPrivate->DataStreamDepConvert["I"]
239 = SALOME_ModuleCatalog::DATASTREAM_ITERATIVE;
241 // Empty used variables
242 myPrivate->_general_module_list.resize(0);
243 myPrivate->_general_path_list.resize(0);
245 myPrivate->_personal_module_list.resize(0);
246 myPrivate->_personal_path_list.resize(0);
248 // Parse the arguments given at server run
249 if (!_parseArguments(argc, argv,&myPrivate->_general_path,&myPrivate->_personal_path))
250 MESSAGE( "Error while argument parsing" );
252 // Test existency of files
253 if (myPrivate->_general_path == NULL)
255 MESSAGE( "Error the general catalog should be indicated" );
259 // Affect the _general_module_list and _general_path_list members
260 // with the common catalog
262 std::list<std::string> dirList;
265 dirList = splitStringToList(myPrivate->_general_path, SEPARATOR);
267 //check for new format
268 bool isNew = (std::string( myPrivate->_general_path ).find(SEPARATOR) != std::string::npos);
271 dirList = splitStringToList(myPrivate->_general_path, SEPARATOR);
274 dirList = splitStringToList(myPrivate->_general_path, OLD_SEPARATOR);
278 for (std::list<std::string>::iterator iter = dirList.begin(); iter != dirList.end(); iter++)
280 std::string aPath = (*iter);
281 //remove inverted commas from filename
282 while (aPath.find('\"') != std::string::npos)
283 aPath.erase(aPath.find('\"'), 1);
285 myPrivate->_parse_xml_file(aPath.c_str(),
286 myPrivate->_general_module_list,
287 myPrivate->_general_path_list,
289 myPrivate->_typeList);
292 // Verification of _general_path_list content
293 if (!myPrivate->_verify_path_prefix(myPrivate->_general_path_list)) {
294 WARNING_MESSAGE( "Error while parsing the general path list, "
295 "different paths are associated to the same computer,"
296 "the first one will be chosen");
298 DEBUG_MESSAGE("General path list OK");
301 if (myPrivate->_personal_path != NULL) {
302 // Initialize the _personal_module_list and
303 // _personal_path_list members with the personal catalog files
304 myPrivate->_parse_xml_file(myPrivate->_personal_path,
305 myPrivate->_personal_module_list,
306 myPrivate->_personal_path_list,
308 myPrivate->_typeList);
310 // Verification of _general_path_list content
311 if(!myPrivate->_verify_path_prefix(myPrivate->_personal_path_list)){
312 MESSAGE("Error while parsing the personal path list, "
313 "different paths are associated to the same computer, "
314 "the first one will be chosen" );
316 MESSAGE("Personal path list OK");
319 INFO_MESSAGE("No personal catalog indicated or error while "
320 "opening the personal catalog");
324 //----------------------------------------------------------------------
325 // Function : ~SALOME_ModuleCatalogImpl
326 // Purpose : Destructor
327 //----------------------------------------------------------------------
328 SALOME_ModuleCatalogImpl::~SALOME_ModuleCatalogImpl()
330 MESSAGE("Catalog Destruction");
335 //! Get the list of all types of the catalog
337 * \return the list of types
339 SALOME_ModuleCatalog::ListOfTypeDefinition* SALOME_ModuleCatalogImpl::GetTypes()
341 SALOME_ModuleCatalog::ListOfTypeDefinition_var type_list = new SALOME_ModuleCatalog::ListOfTypeDefinition();
342 type_list->length((CORBA::ULong)myPrivate->_typeList.size());
344 for (unsigned int ind = 0 ; ind < myPrivate->_typeList.size() ; ind++)
346 //no real need to call string_dup, omniorb calls it on operator= (const char *) but it is safer
347 type_list[ind].name=CORBA::string_dup(myPrivate->_typeList[ind].name.c_str());
348 type_list[ind].kind=SALOME_ModuleCatalog::NONE;
349 if(myPrivate->_typeList[ind].kind=="double")
350 type_list[ind].kind=SALOME_ModuleCatalog::Dble;
351 else if(myPrivate->_typeList[ind].kind=="int")
352 type_list[ind].kind=SALOME_ModuleCatalog::Int;
353 else if(myPrivate->_typeList[ind].kind=="bool")
354 type_list[ind].kind=SALOME_ModuleCatalog::Bool;
355 else if(myPrivate->_typeList[ind].kind=="string")
356 type_list[ind].kind=SALOME_ModuleCatalog::Str;
357 else if(myPrivate->_typeList[ind].kind=="objref")
359 type_list[ind].kind=SALOME_ModuleCatalog::Objref;
360 type_list[ind].id=CORBA::string_dup(myPrivate->_typeList[ind].id.c_str());
362 type_list[ind].bases.length((CORBA::ULong)myPrivate->_typeList[ind].bases.size());
363 std::vector<std::string>::const_iterator miter;
364 miter=myPrivate->_typeList[ind].bases.begin();
366 while(miter != myPrivate->_typeList[ind].bases.end())
368 type_list[ind].bases[n_memb]=CORBA::string_dup(miter->c_str());
373 else if(myPrivate->_typeList[ind].kind=="sequence")
375 type_list[ind].kind=SALOME_ModuleCatalog::Seq;
376 type_list[ind].content=CORBA::string_dup(myPrivate->_typeList[ind].content.c_str());
378 else if(myPrivate->_typeList[ind].kind=="array")
380 type_list[ind].kind=SALOME_ModuleCatalog::Array;
381 type_list[ind].content=CORBA::string_dup(myPrivate->_typeList[ind].content.c_str());
383 else if(myPrivate->_typeList[ind].kind=="struct")
385 type_list[ind].kind=SALOME_ModuleCatalog::Struc;
387 type_list[ind].members.length((CORBA::ULong)myPrivate->_typeList[ind].members.size());
389 std::vector< std::pair<std::string,std::string> >::const_iterator miter;
390 miter=myPrivate->_typeList[ind].members.begin();
392 while(miter != myPrivate->_typeList[ind].members.end())
394 type_list[ind].members[n_memb].name=CORBA::string_dup(miter->first.c_str());
395 type_list[ind].members[n_memb].type=CORBA::string_dup(miter->second.c_str());
401 return type_list._retn();
404 //----------------------------------------------------------------------
405 // Function : GetComputerList
406 // Purpose : get a computer list
407 //----------------------------------------------------------------------
408 SALOME_ModuleCatalog::ListOfComputers*
409 SALOME_ModuleCatalogImpl::GetComputerList()
411 SALOME_ModuleCatalog::ListOfComputers_var _list_computers =
412 new SALOME_ModuleCatalog::ListOfComputers;
413 return _list_computers._retn();
416 //----------------------------------------------------------------------
417 // Function : GetPathPrefix
418 // Purpose : get the PathPrefix of a computer
419 //----------------------------------------------------------------------
421 SALOME_ModuleCatalogImpl::GetPathPrefix(const char* machinename) {
422 MESSAGE("Begin of GetPathPrefix");
423 // Variables initialisation
427 // Parse all the path prefixes
428 // looking for the wanted computer
429 for (unsigned int ind = 0; ind < myPrivate->_personal_path_list.size() && !_find; ind++)
431 for (unsigned int ind1 = 0; ind1 < myPrivate->_personal_path_list[ind].listOfComputer.size() && !_find; ind1++)
433 if ( myPrivate->_personal_path_list[ind].listOfComputer[ind1] == machinename )
437 // affect the path to be returned
438 _path = myPrivate->_personal_path_list[ind].path;
443 for (unsigned int ind = 0; ind < myPrivate->_general_path_list.size() && !_find; ind++)
445 for (unsigned int ind1 = 0; ind1 < myPrivate->_general_path_list[ind].listOfComputer.size() && !_find; ind1++)
447 if (myPrivate->_general_path_list[ind].listOfComputer[ind1] == machinename)
451 // affect the path to be returned
452 _path = myPrivate->_general_path_list[ind].path;
456 return CORBA::string_dup(_path.c_str()) ;
459 //----------------------------------------------------------------------
460 // Function : GetComponentList
461 // Purpose : get a component list
462 // If a component is defined in the personal catalog and
463 // in the general catalog (same name), the component defined
464 // in the personal catalog is used
465 //----------------------------------------------------------------------
466 SALOME_ModuleCatalog::ListOfComponents*
467 SALOME_ModuleCatalogImpl::GetComponentList()
469 MESSAGE("Begin of GetComponentList");
470 SALOME_ModuleCatalog::ListOfComponents_var _list_components =
471 new SALOME_ModuleCatalog::ListOfComponents;
473 _list_components->length((CORBA::ULong)myPrivate->_personal_module_list.size());
475 // All the components defined in the personal catalog are taken
476 for(unsigned int ind=0; ind < myPrivate->_personal_module_list.size();ind++){
477 _list_components[ind]=(myPrivate->_personal_module_list[ind].name).c_str();
478 SCRUTE(_list_components[ind]) ;
481 size_t indice = myPrivate->_personal_module_list.size();
484 // The components in the general catalog are taken only if they're
485 // not defined in the personal catalog
486 for(unsigned int ind=0; ind < myPrivate->_general_module_list.size();ind++){
488 for(unsigned int ind1=0; ind1 < myPrivate->_personal_module_list.size();ind1++){
489 // searching if the component is already defined in
490 // the personal catalog
491 if ((myPrivate->_general_module_list[ind].name.compare(myPrivate->_personal_module_list[ind1].name)) == 0)
495 _list_components->length((CORBA::ULong)indice+1);
496 // The component is not already defined => has to be taken
497 _list_components[(CORBA::ULong)indice]=(myPrivate->_general_module_list[ind].name).c_str();
501 MESSAGE("The component " <<myPrivate->_general_module_list[ind].name
502 << " was already defined in the personal catalog") ;
506 MESSAGE("End of GetComponentList");
507 return _list_components._retn();
511 //----------------------------------------------------------------------
512 // Function : GetComponentIconeList
513 // Purpose : get a component list of component name and component icone
514 // If a component is defined in the personal catalog and
515 // in the general catalog (same name), the component defined
516 // in the personal catalog is used
517 //----------------------------------------------------------------------
518 SALOME_ModuleCatalog::ListOfIAPP_Affich*
519 SALOME_ModuleCatalogImpl::GetComponentIconeList()
521 MESSAGE("Begin of GetComponentIconeList");
523 SALOME_ModuleCatalog::ListOfIAPP_Affich_var _list_components_icone =
524 new SALOME_ModuleCatalog::ListOfIAPP_Affich;
526 _list_components_icone->length((CORBA::ULong)myPrivate->_personal_module_list.size());
528 // All the components defined in the personal catalog are taken
529 for(unsigned int ind=0; ind < myPrivate->_personal_module_list.size();ind++){
530 _list_components_icone[ind].modulename=(myPrivate->_personal_module_list[ind].name).c_str();
531 _list_components_icone[ind].moduleusername=(myPrivate->_personal_module_list[ind].username).c_str();
532 _list_components_icone[ind].moduleicone=(myPrivate->_personal_module_list[ind].icon).c_str();
533 _list_components_icone[ind].moduleversion=(myPrivate->_personal_module_list[ind].version).c_str();
534 _list_components_icone[ind].modulecomment=(myPrivate->_personal_module_list[ind].comment).c_str();
535 //SCRUTE(_list_components_icone[ind].modulename);
536 //SCRUTE(_list_components_icone[ind].moduleicone);
539 size_t indice = myPrivate->_personal_module_list.size();
542 // The components in the general catalog are taken only if they're
543 // not defined in the personal catalog
544 for(unsigned int ind=0; ind < myPrivate->_general_module_list.size();ind++){
546 for(unsigned int ind1=0; ind1 < myPrivate->_personal_module_list.size();ind1++){
547 // searching if the component is aleready defined in
548 // the personal catalog
549 if((myPrivate->_general_module_list[ind].name.compare(myPrivate->_personal_module_list[ind1].name)) == 0)
553 //MESSAGE("A new component " << _general_module_list[ind].name << " has to be to added in the list");
554 _list_components_icone->length((CORBA::ULong)indice+1);
555 // The component is not already defined => has to be taken
556 _list_components_icone[(CORBA::ULong)indice].modulename=myPrivate->_general_module_list[ind].name.c_str();
557 _list_components_icone[(CORBA::ULong)indice].moduleusername=myPrivate->_general_module_list[ind].username.c_str();
558 _list_components_icone[(CORBA::ULong)indice].moduleicone=myPrivate->_general_module_list[ind].icon.c_str();
559 _list_components_icone[(CORBA::ULong)indice].moduleversion=myPrivate->_general_module_list[ind].version.c_str();
560 _list_components_icone[(CORBA::ULong)indice].modulecomment=myPrivate->_general_module_list[ind].comment.c_str();
561 //SCRUTE(_list_components_icone[(CORBA::ULong)indice].modulename) ;
562 //SCRUTE(_list_components_icone[(CORBA::ULong)indice].moduleicone);
567 //MESSAGE("The component " <<_general_module_list[ind].name << " was already defined in the personal catalog");
570 return _list_components_icone._retn() ;
573 //----------------------------------------------------------------------
574 // Function : GetTypedComponentList
575 // Purpose : get a component list of a wanted type
576 // If a component is defined in the personal catalog and
577 // in the general catalog (same name), the component defined
578 // in the personal catalog is used
579 //----------------------------------------------------------------------
580 SALOME_ModuleCatalog::ListOfComponents*
581 SALOME_ModuleCatalogImpl::GetTypedComponentList(SALOME_ModuleCatalog::ComponentType component_type)
583 MESSAGE("Begin of GetTypedComponentList");
584 SALOME_ModuleCatalog::ListOfComponents_var _list_typed_component =
585 new SALOME_ModuleCatalog::ListOfComponents;
588 _list_typed_component->length(0);
589 // Transform SALOME_ModuleCatalog::ComponentType in ParserComponentType
590 ParserComponentType _temp_component_type = OTHER;
591 switch(component_type){
592 case SALOME_ModuleCatalog::GEOM:
593 _temp_component_type = GEOM ;
595 case SALOME_ModuleCatalog::MESH:
596 _temp_component_type = MESH;
598 case SALOME_ModuleCatalog::Med:
599 _temp_component_type = Med;
601 case SALOME_ModuleCatalog::SOLVER:
602 _temp_component_type = SOLVER;
604 case SALOME_ModuleCatalog::DATA:
605 _temp_component_type = DATA;
607 case SALOME_ModuleCatalog::VISU:
608 _temp_component_type = VISU;
610 case SALOME_ModuleCatalog::SUPERV:
611 _temp_component_type = SUPERV;
613 case SALOME_ModuleCatalog::OTHER:
614 _temp_component_type = OTHER;
618 // All the components in the personal catalog are taken
619 for (unsigned int ind=0; ind < myPrivate->_personal_module_list.size();ind++)
621 if (myPrivate->_personal_module_list[ind].type == _temp_component_type)
623 _list_typed_component->length(_j + 1);
624 _list_typed_component[_j] = myPrivate->_personal_module_list[ind].name.c_str();
625 //SCRUTE(_list_typed_component[_j]);
630 int indice = _list_typed_component->length() ;
633 // The components in the general catalog are taken only if they're
634 // not defined in the personal catalog
635 for (unsigned int ind=0; ind < myPrivate->_general_module_list.size();ind++)
639 if(myPrivate->_general_module_list[ind].type == _temp_component_type)
641 for (unsigned int ind1=0; ind1 < myPrivate->_personal_module_list.size();ind1++)
643 // searching if the component is aleready defined in
644 // the personal catalog
645 if ((myPrivate->_general_module_list[ind].name.compare(myPrivate->_personal_module_list[ind1].name)) == 0)
650 //MESSAGE("A new component " << _general_module_list[ind].name << " has to be to added in the list");
651 _list_typed_component->length(indice+1);
652 // The component is not already defined => has to be taken
653 _list_typed_component[indice]=(myPrivate->_general_module_list[ind].name).c_str();
654 //SCRUTE(_list_typed_component[indice]) ;
659 //MESSAGE("The component " <<_general_module_list[ind].name << " was already defined in the personal catalog") ;
664 return _list_typed_component._retn();
667 //----------------------------------------------------------------------
668 // Function : GetComponent
669 // Purpose : get a component
670 // If a component is defined in the personal catalog and
671 // in the general catalog (same name), the component defined
672 // in the personal catalog is used
673 //----------------------------------------------------------------------
674 SALOME_ModuleCatalog::Acomponent_ptr
675 SALOME_ModuleCatalogImpl::GetComponent(const char* name)
677 // Looking for component named "componentname" in the personal catalog
678 // If found, get name, interfaces and constraint
679 // If not found, looking for component named "componentname" in
680 // the general catalog
681 // If found, get name, interfaces and constraint
682 // If not found, NULL pointer is returned
685 ParserComponent *C_parser = NULL;
686 //ParserPathPrefixes *pp = NULL;
688 SALOME_ModuleCatalog::Acomponent_ptr compo
689 = SALOME_ModuleCatalog::Acomponent::_nil();
690 C_parser = myPrivate->findComponent(s);
693 // DebugParserComponent(*C_parser);
695 SALOME_ModuleCatalog::ComponentDef C_corba;
696 myPrivate->duplicate(C_corba, *C_parser);
699 SALOME_ModuleCatalog_AcomponentImpl * aComponentImpl =
700 new SALOME_ModuleCatalog_AcomponentImpl(C_corba);
702 compo = aComponentImpl->_this();
705 // Not found in the personal catalog and in the general catalog
706 // return NULL object
707 MESSAGE("Component with name " << name
708 << " not found in catalog");
714 SALOME_ModuleCatalog::ComponentDef *
715 SALOME_ModuleCatalogImpl::GetComponentInfo(const char *name)
719 ParserComponent * C_parser = myPrivate->findComponent(s);
723 SALOME_ModuleCatalog::ComponentDef * C_corba
724 = new SALOME_ModuleCatalog::ComponentDef;
725 myPrivate->duplicate(*C_corba, *C_parser);
732 void SALOME_ModuleCatalogImpl::ping()
736 CORBA::Long SALOME_ModuleCatalogImpl::getPID()
740 (CORBA::Long)getpid();
742 (CORBA::Long)_getpid();
746 void SALOME_ModuleCatalogImpl::ShutdownWithExit()
748 exit( EXIT_SUCCESS );
751 void SALOME_ModuleCatalogImpl::shutdown()
753 if (!CORBA::is_nil(_orb)) _orb->shutdown(0);
758 //----------------------------------------------------------------------
759 // Function : _parseArguments
760 // Purpose : parse arguments to get general and personal catalog files
761 //----------------------------------------------------------------------
763 SALOME_ModuleCatalogImpl::_parseArguments(int argc, char **argv,
767 bool _return_value = true;
770 for (int ind = 0; ind < argc ; ind++)
773 if (strcmp(argv[ind],"-help") == 0)
775 INFOS( "Usage: " << argv[0]
776 << " -common 'path to general catalog' "
777 " -personal 'path to personal catalog' "
778 " -ORBInitRef NameService=corbaname::localhost");
779 _return_value = false ;
782 if (strcmp(argv[ind],"-common") == 0)
786 // General catalog file
787 *_general = argv[ind + 1] ;
790 else if (strcmp(argv[ind],"-personal") == 0)
794 // Personal catalog file
795 *_personal = argv[ind + 1] ;
799 return _return_value;
803 SALOME_ModuleCatalogImpl::Private::findComponent(const std::string & name)
805 ParserComponent * C_parser = NULL;
808 for (unsigned int ind=0; ind < _personal_module_list.size();ind++)
810 if (name.compare(_personal_module_list[ind].name) == 0)
812 MESSAGE("Component named " << name
813 << " found in the personal catalog");
814 C_parser = &(_personal_module_list[ind]);
820 for (unsigned int ind=0; ind < _general_module_list.size();ind++)
822 if (name.compare(_general_module_list[ind].name) == 0)
824 //MESSAGE("Component named " << name
825 // << " found in the general catalog");
826 C_parser = &(_general_module_list[ind]);
834 //----------------------------------------------------------------------
835 // Function : _parse_xml_file
836 // Purpose : parse one module catalog
837 //----------------------------------------------------------------------
839 SALOME_ModuleCatalogImpl::Private::_parse_xml_file(const char* file,
840 ParserComponents& modulelist,
841 ParserPathPrefixes& pathList,
842 ParserTypes& typeMap,
845 DEBUG_MESSAGE("parsing of " << file);
847 //Local path and module list for the file to parse
848 ParserPathPrefixes _pathList;
849 ParserComponents _moduleList;
851 SALOME_ModuleCatalog_Handler* handler = new SALOME_ModuleCatalog_Handler(_pathList,_moduleList,typeMap,typeList);
853 const wchar_t* w_file = Kernel_Utils::utf8_decode(file);
854 FILE* aFile = _wfopen(w_file, L"r");
856 FILE* aFile = fopen(file, "r");
861 xmlDocPtr aDoc = xmlReadFile(file, NULL, 0);
864 handler->ProcessXmlDocument(aDoc);
866 MESSAGE("ModuleCatalog: could not parse file "<<file);
872 MESSAGE("ModuleCatalog: file "<<file<<" is not readable.");
878 for ( i = 0; i < _moduleList.size(); i++) {
879 for (j=0; j<modulelist.size(); j++) {
880 if (modulelist[j].name == _moduleList[i].name)
883 if (j < modulelist.size())
884 modulelist[j] = _moduleList[i];
886 modulelist.push_back(_moduleList[i]);
889 for ( i=0; i < _pathList.size(); i++)
890 pathList.push_back(_pathList[i]) ;
892 for (j=0; j<modulelist.size(); j++)
893 modulelist[j].prefixes = pathList;
897 SALOME_ModuleCatalogImpl::ImportXmlCatalogFile(const char* file)
899 myPrivate->_parse_xml_file(file, myPrivate->_personal_module_list, myPrivate->_personal_path_list,myPrivate->_typeMap,myPrivate->_typeList);
904 // Duplicate functions create a Corba structure (component,
905 // interface, service, parameter) from the corresponding C++
909 //----------------------------------------------------------------------
910 // Function : duplicate
911 // Purpose : create a component from the catalog parsing
912 //----------------------------------------------------------------------
913 void SALOME_ModuleCatalogImpl::Private::duplicate
914 (SALOME_ModuleCatalog::ComponentDef & C_corba,
915 const ParserComponent & C_parser)
917 C_corba.name = CORBA::string_dup(C_parser.name.c_str());
918 C_corba.username = CORBA::string_dup(C_parser.username.c_str());
919 C_corba.icon = CORBA::string_dup(C_parser.icon.c_str());
920 C_corba.type = ComponentTypeConvert[C_parser.type];
921 if(C_parser.implementationType == "EXE")
922 C_corba.implementationType=SALOME_ModuleCatalog::EXE;
923 else if(C_parser.implementationType == "CEXE")
924 C_corba.implementationType=SALOME_ModuleCatalog::CEXE;
925 else if(C_parser.implementationType == "PY")
926 C_corba.implementationType=SALOME_ModuleCatalog::PY;
928 C_corba.implementationType=SALOME_ModuleCatalog::SO;
929 C_corba.implname = CORBA::string_dup(C_parser.implementationName.c_str());
931 size_t _length = C_parser.interfaces.size();
932 C_corba.interfaces.length((CORBA::ULong)_length);
934 for (unsigned int ind = 0; ind < _length; ind++)
935 duplicate(C_corba.interfaces[ind], C_parser.interfaces[ind]);
939 //----------------------------------------------------------------------
940 // Function : duplicate
941 // Purpose : create an interface from the catalog parsing
942 //----------------------------------------------------------------------
943 void SALOME_ModuleCatalogImpl::Private::duplicate
944 (SALOME_ModuleCatalog::DefinitionInterface & I_corba,
945 const ParserInterface & I_parser)
947 //duplicate interface name
948 I_corba.interfacename = CORBA::string_dup(I_parser.name.c_str());
950 // duplicate service list
951 size_t _length = I_parser.services.size();
953 // I_corba.interfaceservicelist
954 // = new SALOME_ModuleCatalog::ListOfInterfaceService;
955 I_corba.interfaceservicelist.length((CORBA::ULong)_length);
957 for (unsigned int ind1 = 0; ind1 < _length ; ind1 ++)
958 duplicate(I_corba.interfaceservicelist[ind1],
959 I_parser.services[ind1]);
962 //----------------------------------------------------------------------
963 // Function : duplicate
964 // Purpose : create a service from the catalog parsing
965 //----------------------------------------------------------------------
966 void SALOME_ModuleCatalogImpl::Private::duplicate
967 (SALOME_ModuleCatalog::Service & S_corba,
968 const ParserService & S_parser)
970 // duplicate service name
971 S_corba.ServiceName = CORBA::string_dup(S_parser.name.c_str());
973 // duplicate service by default
974 S_corba.Servicebydefault = S_parser.byDefault;
976 S_corba.TypeOfNode = S_parser.typeOfNode;
980 // duplicate in Parameters
981 _length = S_parser.inParameters.size();
982 S_corba.ServiceinParameter.length((CORBA::ULong)_length);
984 for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
985 duplicate(S_corba.ServiceinParameter[ind2],
986 S_parser.inParameters[ind2]);
988 // duplicate out Parameters
989 _length = S_parser.outParameters.size();
990 S_corba.ServiceoutParameter.length((CORBA::ULong)_length);
992 for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
993 duplicate(S_corba.ServiceoutParameter[ind2],
994 S_parser.outParameters[ind2]);
996 // duplicate in DataStreamParameters
997 _length = S_parser.inDataStreamParameters.size();
998 S_corba.ServiceinDataStreamParameter.length((CORBA::ULong)_length);
1000 for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
1001 duplicate(S_corba.ServiceinDataStreamParameter[ind2],
1002 S_parser.inDataStreamParameters[ind2]);
1004 // duplicate out DataStreamParameters
1005 _length = S_parser.outDataStreamParameters.size();
1007 S_corba.ServiceoutDataStreamParameter.length((CORBA::ULong)_length);
1009 for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
1010 duplicate(S_corba.ServiceoutDataStreamParameter[ind2],
1011 S_parser.outDataStreamParameters[ind2]);
1014 //----------------------------------------------------------------------
1015 // Function : duplicate
1016 // Purpose : create a service parameter from the catalog parsing
1017 //----------------------------------------------------------------------
1018 void SALOME_ModuleCatalogImpl::Private::duplicate
1019 (SALOME_ModuleCatalog::ServicesParameter & P_corba,
1020 const ParserParameter & P_parser)
1022 // duplicate parameter name
1023 P_corba.Parametername = CORBA::string_dup(P_parser.name.c_str());
1025 // duplicate parameter type
1026 P_corba.Parametertype = CORBA::string_dup(P_parser.type.c_str());
1030 //----------------------------------------------------------------------
1031 // Function : duplicate
1032 // Purpose : create a service datastream parameter from the catalog parsing
1033 //----------------------------------------------------------------------
1034 void SALOME_ModuleCatalogImpl::Private::duplicate
1035 (SALOME_ModuleCatalog::ServicesDataStreamParameter & P_corba,
1036 const ParserDataStreamParameter & P_parser)
1038 std::map < std::string,
1039 SALOME_ModuleCatalog::DataStreamDependency >::const_iterator it_dep;
1041 // duplicate parameter name
1042 P_corba.Parametername = CORBA::string_dup(P_parser.name.c_str());
1044 // duplicate parameter type
1047 // it_type = DataStreamTypeConvert.find(P_parser.type);
1048 // P_corba.Parametertype
1049 // = (it_type == DataStreamTypeConvert.end())
1050 // ? it_type->second : SALOME_ModuleCatalog::DATASTREAM_UNKNOWN;
1052 P_corba.Parametertype = CORBA::string_dup(P_parser.type.c_str());
1054 // duplicate parameter dependency
1056 P_corba.Parameterdependency = SALOME_ModuleCatalog::DATASTREAM_UNDEFINED;
1057 for (it_dep = DataStreamDepConvert.begin();
1058 it_dep != DataStreamDepConvert.end();
1060 if (P_parser.dependency.compare(it_dep->first) == 0) {
1061 P_corba.Parameterdependency = it_dep->second;
1066 //----------------------------------------------------------------------
1067 // Function : duplicate
1068 // Purpose : create the path prefix structures from the catalog parsing
1069 //----------------------------------------------------------------------
1071 SALOME_ModuleCatalogImpl::Private::duplicate(ParserPathPrefixes &L_out,
1072 const ParserPathPrefixes &L_in)
1078 //----------------------------------------------------------------------
1079 // Function : _verify_path_prefix
1080 // Purpose : verify the path prefix structures from the catalog parsing
1081 // Verify that there only one path prefix associated to a
1082 // particular computer
1083 //----------------------------------------------------------------------
1085 SALOME_ModuleCatalogImpl::Private::_verify_path_prefix(ParserPathPrefixes & pathList)
1087 bool _return_value = true;
1088 std::vector<std::string> _machine_list;
1090 // Fill a list of all computers indicated in the path list
1091 for (unsigned int ind = 0; ind < pathList.size(); ind++)
1093 for (unsigned int ind1 = 0 ; ind1 < pathList[ind].listOfComputer.size(); ind1++)
1095 _machine_list.push_back(pathList[ind].listOfComputer[ind1]);
1099 // Parse if a computer name is twice in the list of computers
1100 for (unsigned int ind = 0; ind < _machine_list.size(); ind++)
1102 for (unsigned int ind1 = ind+1 ; ind1 < _machine_list.size(); ind1++)
1104 if(_machine_list[ind].compare(_machine_list[ind1]) == 0)
1106 MESSAGE( "The computer " << _machine_list[ind] << " is indicated more than once in the path list");
1107 _return_value = false;
1111 return _return_value;