2 // File: SALOME_ModuleCatalog_impl.cxx
3 // Created: Tue June 28 2001
4 // Author: Estelle Deville
6 // Copyright : CEA/DEN/DMSS/LGLS
9 #include "SALOME_ModuleCatalog_impl.hxx"
10 #include "SALOME_ModuleCatalog_Acomponent_impl.hxx"
13 #include <qstringlist.h>
14 #include <qfileinfo.h>
16 static const char* SEPARATOR = ":";
18 //----------------------------------------------------------------------
19 // Function : SALOME_ModuleCatalogImpl
20 // Purpose : Constructor
21 //----------------------------------------------------------------------
22 SALOME_ModuleCatalogImpl::SALOME_ModuleCatalogImpl(int argc, char** argv)
24 MESSAGE("Catalog creation");
26 // Empty used variables
27 _general_module_list.resize(0);
28 _general_path_list.resize(0);
30 _personal_module_list.resize(0);
31 _personal_path_list.resize(0);
33 // Parse the arguments given at server run
34 if (!_parseArguments(argc, argv,&_general_path,&_personal_path))
35 MESSAGE( "Error while argument parsing" )
37 // Test existency of files
38 if (_general_path == NULL)
39 MESSAGE( "Error the general catalog should be indicated" )
42 //MESSAGE("Parse general catalog");
43 // Affect the variables _general_module_list and _general_path_list
44 // with the common catalog
46 QStringList dirList = QStringList::split( SEPARATOR, _general_path, false ); // skip empty entries
47 for ( int i = 0; i < dirList.count(); i++ ) {
48 QFileInfo fileInfo( dirList[ i ] );
49 if ( fileInfo.isFile() && fileInfo.exists() ) {
50 _parse_xml_file(fileInfo.filePath(),_general_module_list, _general_path_list);
54 // Verification of _general_path_list content
55 if(!_verify_path_prefix(_general_path_list))
56 MESSAGE( "Error while parsing the general path list, differents pathes are associated to one computer, the first will be choosen" )
57 else MESSAGE("General path list OK");
59 if(_personal_path != NULL)
61 //MESSAGE("Parse personal catalog");
62 // Affect the variables _personal_module_list and _personal_path_list
63 // with the personal catalog
64 _parse_xml_file(_personal_path,_personal_module_list, _personal_path_list);
66 // Verification of _general_path_list content
67 if(!_verify_path_prefix(_personal_path_list))
68 MESSAGE("Error while parsing the personal path list, differents pathes are associated to one computer, the first will be choosen" )
69 else MESSAGE("Personal path list OK");
71 else MESSAGE("No personal catalog indicated or error while opening the personal catalog");
75 //----------------------------------------------------------------------
76 // Function : ~SALOME_ModuleCatalogImpl
77 // Purpose : Destructor
78 //----------------------------------------------------------------------
79 SALOME_ModuleCatalogImpl::~SALOME_ModuleCatalogImpl()
81 MESSAGE("Catalog Destruction");
85 //----------------------------------------------------------------------
86 // Function : GetComputerList
87 // Purpose : get a computer list
88 //----------------------------------------------------------------------
89 SALOME_ModuleCatalog::ListOfComputers*
90 SALOME_ModuleCatalogImpl::GetComputerList()
92 SALOME_ModuleCatalog::ListOfComputers_var _list_computers =
93 new SALOME_ModuleCatalog::ListOfComputers;
94 return _list_computers._retn();
97 //----------------------------------------------------------------------
98 // Function : GetPathPrefix
99 // Purpose : get the PathPrefix of a computer
100 //----------------------------------------------------------------------
102 SALOME_ModuleCatalogImpl::GetPathPrefix(const char* machinename) {
103 MESSAGE("Begin of GetPathPrefix")
104 // Variables initialisation
108 // Parse all the path prefixes
109 // looking for the wanted computer
110 for (unsigned int ind = 0 ; ind < _personal_path_list.size() ; ind++)
112 for (unsigned int ind1 = 0 ; ind1 < _personal_path_list[ind].ListOfComputer.size() ; ind1++)
114 if (strcmp(machinename, _personal_path_list[ind].ListOfComputer[ind1].c_str()) == 0)
118 // affect the path to be returned
119 const char* _temp = _personal_path_list[ind].path.c_str() ;
120 _path = new char[strlen(_temp)+1];
128 for (unsigned int ind = 0 ; ind < _general_path_list.size() ; ind++)
130 for (unsigned int ind1 = 0 ; ind1 < _general_path_list[ind].ListOfComputer.size() ; ind1++)
132 if (strcmp(machinename, _general_path_list[ind].ListOfComputer[ind1].c_str()) == 0)
136 // affect the path to be returned
137 const char* _temp = _general_path_list[ind].path.c_str() ;
138 _path = new char[strlen(_temp)+1];
148 //----------------------------------------------------------------------
149 // Function : GetComponentList
150 // Purpose : get a component list
151 // If a component is defined in the personal catalog and
152 // in the general catalog (same name), the component defined
153 // in the personal catalog is used
154 //----------------------------------------------------------------------
155 SALOME_ModuleCatalog::ListOfComponents*
156 SALOME_ModuleCatalogImpl::GetComponentList()
158 MESSAGE("Begin of GetComponentList");
159 SALOME_ModuleCatalog::ListOfComponents_var _list_components =
160 new SALOME_ModuleCatalog::ListOfComponents;
162 _list_components->length(_personal_module_list.size());
164 // All the components defined in the personal catalog are taken
165 for (unsigned int ind=0; ind < _personal_module_list.size();ind++)
167 _list_components[ind]=(_personal_module_list[ind].Parsercomponentname).c_str();
168 //SCRUTE(_list_components[ind]) ;
171 int indice = _personal_module_list.size() ;
174 // The components in the general catalog are taken only if they're
175 // not defined in the personal catalog
176 for (unsigned int ind=0; ind < _general_module_list.size();ind++)
179 for (unsigned int ind1=0; ind1 < _personal_module_list.size();ind1++)
181 // searching if the component is already defined in
182 // the personal catalog
183 if ((_general_module_list[ind].Parsercomponentname.compare(_personal_module_list[ind1].Parsercomponentname)) == 0)
188 //MESSAGE("A new component " << _general_module_list[ind].Parsercomponentname << " has to be to added in the list");
189 _list_components->length(indice+1);
190 // The component is not already defined => has to be taken
191 _list_components[indice]=(_general_module_list[ind].Parsercomponentname).c_str();
192 //SCRUTE(_list_components[indice]) ;
197 //MESSAGE("The component " <<_general_module_list[ind].Parsercomponentname << " was already defined in the personal catalog") ;
200 return _list_components._retn();
204 //----------------------------------------------------------------------
205 // Function : GetComponentIconeList
206 // Purpose : get a component list of component name and component icone
207 // If a component is defined in the personal catalog and
208 // in the general catalog (same name), the component defined
209 // in the personal catalog is used
210 //----------------------------------------------------------------------
211 SALOME_ModuleCatalog::ListOfIAPP_Affich*
212 SALOME_ModuleCatalogImpl::GetComponentIconeList()
214 MESSAGE("Begin of GetComponentIconeList");
216 SALOME_ModuleCatalog::ListOfIAPP_Affich_var _list_components_icone =
217 new SALOME_ModuleCatalog::ListOfIAPP_Affich;
219 _list_components_icone->length(_personal_module_list.size());
221 // All the components defined in the personal catalog are taken
222 for (unsigned int ind=0; ind < _personal_module_list.size();ind++)
224 _list_components_icone[ind].modulename=(_personal_module_list[ind].Parsercomponentname).c_str();
225 _list_components_icone[ind].moduleicone=(_personal_module_list[ind].Parsercomponenticone).c_str();
226 //SCRUTE(_list_components_icone[ind].modulename);
227 //SCRUTE(_list_components_icone[ind].moduleicone);
230 int indice = _personal_module_list.size() ;
233 // The components in the general catalog are taken only if they're
234 // not defined in the personal catalog
235 for (unsigned int ind=0; ind < _general_module_list.size();ind++)
238 for (unsigned int ind1=0; ind1 < _personal_module_list.size();ind1++)
240 // searching if the component is aleready defined in
241 // the personal catalog
242 if ((_general_module_list[ind].Parsercomponentname.compare(_personal_module_list[ind1].Parsercomponentname)) == 0)
247 // MESSAGE("A new component " << _general_module_list[ind].Parsercomponentname << " has to be to added in the list");
248 _list_components_icone->length(indice+1);
249 // The component is not already defined => has to be taken
250 _list_components_icone[indice].modulename=(_general_module_list[ind].Parsercomponentname).c_str();
251 _list_components_icone[indice].moduleicone=(_general_module_list[ind].Parsercomponenticone).c_str();
252 //SCRUTE(_list_components_icone[indice].modulename) ;
253 //SCRUTE(_list_components_icone[indice].moduleicone);
258 //MESSAGE("The component " <<_general_module_list[ind].Parsercomponentname << " was already defined in the personal catalog");
261 return _list_components_icone._retn() ;
264 //----------------------------------------------------------------------
265 // Function : GetTypedComponentList
266 // Purpose : get a component list of a wanted type
267 // If a component is defined in the personal catalog and
268 // in the general catalog (same name), the component defined
269 // in the personal catalog is used
270 //----------------------------------------------------------------------
271 SALOME_ModuleCatalog::ListOfComponents*
272 SALOME_ModuleCatalogImpl::GetTypedComponentList(SALOME_ModuleCatalog::ComponentType component_type)
274 MESSAGE("Begin of GetTypedComponentList");
275 SALOME_ModuleCatalog::ListOfComponents_var _list_typed_component =
276 new SALOME_ModuleCatalog::ListOfComponents;
279 _list_typed_component->length(0);
280 // Transform SALOME_ModuleCatalog::ComponentType in ParserComponentType
281 ParserComponentType _temp_component_type;
282 switch(component_type){
283 case SALOME_ModuleCatalog::GEOM:
284 _temp_component_type = GEOM ;
286 case SALOME_ModuleCatalog::MESH:
287 _temp_component_type = MESH;
289 case SALOME_ModuleCatalog::Med:
290 _temp_component_type = Med;
292 case SALOME_ModuleCatalog::SOLVER:
293 _temp_component_type = SOLVER;
295 case SALOME_ModuleCatalog::DATA:
296 _temp_component_type = DATA;
298 case SALOME_ModuleCatalog::VISU:
299 _temp_component_type = VISU;
301 case SALOME_ModuleCatalog::SUPERV:
302 _temp_component_type = SUPERV;
304 case SALOME_ModuleCatalog::OTHER:
305 _temp_component_type = OTHER;
309 // All the components in the personal catalog are taken
310 for (unsigned int ind=0; ind < _personal_module_list.size();ind++)
312 if (_personal_module_list[ind].Parsercomponenttype == _temp_component_type)
314 _list_typed_component->length(_j + 1);
315 _list_typed_component[_j] = (_modulelist[ind].Parsercomponentname).c_str();
316 //SCRUTE(_list_typed_component[_j])
321 int indice = _list_typed_component->length() ;
324 // The components in the general catalog are taken only if they're
325 // not defined in the personal catalog
326 for (unsigned int ind=0; ind < _general_module_list.size();ind++)
330 if(_general_module_list[ind].Parsercomponenttype == _temp_component_type)
332 for (unsigned int ind1=0; ind1 < _personal_module_list.size();ind1++)
334 // searching if the component is aleready defined in
335 // the personal catalog
336 if ((_general_module_list[ind].Parsercomponentname.compare(_personal_module_list[ind1].Parsercomponentname)) == 0)
341 //MESSAGE("A new component " << _general_module_list[ind].Parsercomponentname << " has to be to added in the list");
342 _list_typed_component->length(indice+1);
343 // The component is not already defined => has to be taken
344 _list_typed_component[indice]=(_general_module_list[ind].Parsercomponentname).c_str();
345 //SCRUTE(_list_typed_component[indice]) ;
350 //MESSAGE("The component " <<_general_module_list[ind].Parsercomponentname << " was already defined in the personal catalog") ;
355 return _list_typed_component._retn();
358 //----------------------------------------------------------------------
359 // Function : GetComponent
360 // Purpose : get a component
361 // If a component is defined in the personal catalog and
362 // in the general catalog (same name), the component defined
363 // in the personal catalog is used
364 //----------------------------------------------------------------------
365 SALOME_ModuleCatalog::Acomponent_ptr
366 SALOME_ModuleCatalogImpl::GetComponent(const char* componentname)
368 SALOME_ModuleCatalog::Acomponent_ptr compo;
369 SALOME_ModuleCatalog::ListOfDefInterface _list_interfaces;
370 _list_interfaces.length(0);
371 char* _constraint = NULL;
373 SALOME_ModuleCatalog::ComponentType _componenttype = SALOME_ModuleCatalog::OTHER; // default initialisation
374 CORBA::Boolean _componentmultistudy = false ; // default initialisation
375 ListOfPathPrefix _pathes ;
381 // Looking for component named "componentname" in the personal catalog
382 // If found, get name, interfaces and constraint
383 // If not found, looking for component named "componentname" in
384 // the general catalog
385 // If found, get name, interfaces and constraint
386 // If not found, NULL pointer is returned
388 for (unsigned int ind=0; ind < _personal_module_list.size();ind++)
390 if (strcmp((_personal_module_list[ind].Parsercomponentname).c_str(),componentname) == 0)
392 //MESSAGE("Component named " << componentname << " found in the personal catalog");
396 _constraint = new char[strlen(_personal_module_list[ind].Parserconstraint.c_str()) + 1];
397 _constraint = CORBA::string_dup(_personal_module_list[ind].Parserconstraint.c_str());
399 // get component type
400 switch(_personal_module_list[ind].Parsercomponenttype){
402 _componenttype = SALOME_ModuleCatalog::GEOM;
405 _componenttype = SALOME_ModuleCatalog::MESH;
408 _componenttype = SALOME_ModuleCatalog::Med;
411 _componenttype = SALOME_ModuleCatalog::SOLVER;
414 _componenttype = SALOME_ModuleCatalog::DATA;
417 _componenttype = SALOME_ModuleCatalog::VISU;
420 _componenttype = SALOME_ModuleCatalog::SUPERV;
423 _componenttype = SALOME_ModuleCatalog::OTHER;
427 // get component multistudy
428 _componentmultistudy = _personal_module_list[ind].Parsercomponentmultistudy ;
430 // get component icone
431 _icone = CORBA::string_dup(_personal_module_list[ind].Parsercomponenticone.c_str());
433 // get component interfaces
434 _list_interfaces = duplicate_interfaces(_personal_module_list[ind].ParserListInterface);
437 _pathes = duplicate_pathes(_personal_path_list);
444 SALOME_ModuleCatalog_AcomponentImpl* aComponentImpl =
445 new SALOME_ModuleCatalog_AcomponentImpl(componentname,
448 _componentmultistudy,
453 compo = aComponentImpl->_this();
456 // Not found in the personal catalog => searching in the general catalog
458 for (unsigned int ind=0; ind < _general_module_list.size();ind++)
460 if (strcmp((_general_module_list[ind].Parsercomponentname).c_str(),componentname) == 0)
462 //MESSAGE("Component named " << componentname << " found in the general catalog");
466 _constraint = new char[strlen(_general_module_list[ind].Parserconstraint.c_str()) + 1];
467 _constraint = CORBA::string_dup(_general_module_list[ind].Parserconstraint.c_str());
470 // get component type
471 switch(_general_module_list[ind].Parsercomponenttype){
473 _componenttype = SALOME_ModuleCatalog::GEOM;
476 _componenttype = SALOME_ModuleCatalog::MESH;
479 _componenttype = SALOME_ModuleCatalog::Med;
482 _componenttype = SALOME_ModuleCatalog::SOLVER;
485 _componenttype = SALOME_ModuleCatalog::DATA;
488 _componenttype = SALOME_ModuleCatalog::VISU;
491 _componenttype = SALOME_ModuleCatalog::SUPERV;
494 _componenttype = SALOME_ModuleCatalog::OTHER;
499 // get component multistudy
500 _componentmultistudy = _general_module_list[ind].Parsercomponentmultistudy ;
502 // get component icone
503 _icone = CORBA::string_dup(_general_module_list[ind].Parsercomponenticone.c_str());
505 // get component interfaces
506 _list_interfaces = duplicate_interfaces(_general_module_list[ind].ParserListInterface);
509 _pathes = duplicate_pathes(_general_path_list);
515 SALOME_ModuleCatalog_AcomponentImpl* aComponentImpl =
516 new SALOME_ModuleCatalog_AcomponentImpl(componentname,
519 _componentmultistudy,
524 compo = aComponentImpl->_this();
527 // Not found in the personal catalog and in the general catalog
528 // return NULL object
530 MESSAGE("Component with name " << componentname << " not found in catalog");
537 //----------------------------------------------------------------------
538 // Function : _parse_xml_file
539 // Purpose : parse one module catalog
540 //----------------------------------------------------------------------
542 SALOME_ModuleCatalogImpl::_parse_xml_file(const char* file,
543 ListOfParserComponent& modulelist,
544 ListOfParserPathPrefix& pathlist)
546 SALOME_ModuleCatalog_Handler* handler = new SALOME_ModuleCatalog_Handler();
549 QXmlInputSource source(xmlFile);
551 QXmlSimpleReader reader;
552 reader.setContentHandler( handler );
553 reader.setErrorHandler( handler );
554 reader.parse( source );
557 for ( ind = 0; ind < _modulelist.size(); ind++)
558 modulelist.push_back(_modulelist[ind]) ;
559 for ( ind = 0; ind < _pathlist.size(); ind++)
560 pathlist.push_back(_pathlist[ind]) ;
563 //----------------------------------------------------------------------
564 // Function : duplicate_interfaces
565 // Purpose : create a list of interfaces from the parsing of the catalog
566 //----------------------------------------------------------------------
567 SALOME_ModuleCatalog::ListOfDefInterface
568 SALOME_ModuleCatalogImpl::duplicate_interfaces(ListOfDefinitionInterface list_interface)
570 SALOME_ModuleCatalog::ListOfDefInterface _list_interfaces;
571 unsigned int _length_interfaces = list_interface.size();
572 _list_interfaces.length(_length_interfaces);
574 for (unsigned int ind = 0; ind < _length_interfaces; ind++)
576 //duplicate interface name
577 _list_interfaces[ind].interfacename = CORBA::string_dup(list_interface[ind].Parserinterfacename.c_str());
579 // duplicate service list
580 unsigned int _length_services = list_interface[ind].Parserinterfaceservicelist.size();
581 _list_interfaces[ind].interfaceservicelist.length(_length_services);
583 for (unsigned int ind1 = 0; ind1 < _length_services ; ind1 ++)
585 // duplicate service name
586 _list_interfaces[ind].interfaceservicelist[ind1].ServiceName =
587 CORBA::string_dup(list_interface[ind].Parserinterfaceservicelist[ind1].ParserServiceName.c_str());
589 // duplicate service by default
590 _list_interfaces[ind].interfaceservicelist[ind1].Servicebydefault =
591 list_interface[ind].Parserinterfaceservicelist[ind1].ParserServicebydefault;
593 // duplicate in Parameters
594 unsigned int _length_in_param = list_interface[ind].Parserinterfaceservicelist[ind1].ParserServiceinParameter.size();
595 _list_interfaces[ind].interfaceservicelist[ind1].ServiceinParameter.length(_length_in_param);
596 for (unsigned int ind2 = 0; ind2 < _length_in_param ; ind2 ++)
598 // duplicate parameter type
599 _list_interfaces[ind].interfaceservicelist[ind1].ServiceinParameter[ind2].Parametertype = CORBA::string_dup(list_interface[ind].Parserinterfaceservicelist[ind1].ParserServiceinParameter[ind2].ParserParamtype.c_str());
601 // duplicate parameter name
602 _list_interfaces[ind].interfaceservicelist[ind1].ServiceinParameter[ind2].Parametername = CORBA::string_dup(list_interface[ind].Parserinterfaceservicelist[ind1].ParserServiceinParameter[ind2].ParserParamname.c_str());
605 // duplicate out Parameters
606 unsigned int _length_out_param = list_interface[ind].Parserinterfaceservicelist[ind1].ParserServiceoutParameter.size();
607 _list_interfaces[ind].interfaceservicelist[ind1].ServiceoutParameter.length(_length_out_param);
608 for (unsigned int ind2 = 0; ind2 < _length_out_param ; ind2 ++)
610 // duplicate parameter type
611 _list_interfaces[ind].interfaceservicelist[ind1].ServiceoutParameter[ind2].Parametertype = CORBA::string_dup(list_interface[ind].Parserinterfaceservicelist[ind1].ParserServiceoutParameter[ind2].ParserParamtype.c_str());
613 // duplicate parameter name
614 _list_interfaces[ind].interfaceservicelist[ind1].ServiceoutParameter[ind2].Parametername = CORBA::string_dup(list_interface[ind].Parserinterfaceservicelist[ind1].ParserServiceoutParameter[ind2].ParserParamname.c_str());
619 return _list_interfaces;
623 //----------------------------------------------------------------------
624 // Function : duplicate_pathes
625 // Purpose : create the path prefix structures from the catalog parsing
626 //----------------------------------------------------------------------
628 SALOME_ModuleCatalogImpl::duplicate_pathes(ListOfParserPathPrefix pathes)
630 ListOfPathPrefix _pathes ;
632 unsigned int _length = pathes.size() ;
633 _pathes.resize(_length);
634 unsigned int _length_comput = 0;
636 for (unsigned int ind = 0; ind < _length ; ind++)
639 _pathes[ind].path = CORBA::string_dup(pathes[ind].path.c_str()) ;
640 //MESSAGE("Prefix : " << _pathes[ind].path);
642 _length_comput = pathes[ind].ListOfComputer.size() ;
643 _pathes[ind].ListOfComputer.resize(_length_comput);
644 for (unsigned int ind1 = 0; ind1 <_length_comput ; ind1++)
646 // duplicate computer name
647 _pathes[ind].ListOfComputer[ind1] = CORBA::string_dup(pathes[ind].ListOfComputer[ind1].c_str());
648 //MESSAGE("Computer associated to the prefix : " <<_pathes[ind].ListOfComputer[ind1]);
655 //----------------------------------------------------------------------
656 // Function : _verify_path_prefix
657 // Purpose : verify the path prefix structures from the catalog parsing
658 // Verify that there only one path prefix associated to a
659 // particular computer
660 //----------------------------------------------------------------------
662 SALOME_ModuleCatalogImpl::_verify_path_prefix(ListOfParserPathPrefix pathlist)
664 bool _return_value = true;
665 vector<string> _machine_list;
666 _machine_list.resize(0);
668 // Fill a list of all computers indicated in the path list
669 for (unsigned int ind = 0; ind < pathlist.size(); ind++)
671 for (unsigned int ind1 = 0 ; ind1 < pathlist[ind].ListOfComputer.size(); ind1++)
673 _machine_list.push_back(pathlist[ind].ListOfComputer[ind1]);
677 // Parse if a computer name is twice in the list of computers
678 for (unsigned int ind = 0; ind < _machine_list.size(); ind++)
680 for (unsigned int ind1 = ind+1 ; ind1 < _machine_list.size(); ind1++)
682 if(_machine_list[ind].compare(_machine_list[ind1]) == 0)
684 MESSAGE( "The computer " << _machine_list[ind] << " is indicated more than once in the path list")
685 _return_value = false;
689 return _return_value;
693 //----------------------------------------------------------------------
694 // Function : _parseArguments
695 // Purpose : parse arguments to get general and personal catalog files
696 //----------------------------------------------------------------------
698 SALOME_ModuleCatalogImpl::_parseArguments(int argc, char **argv,
702 bool _return_value = true;
705 for (int ind = 0; ind < argc ; ind++)
708 if (strcmp(argv[ind],"-help") == 0)
710 INFOS( "Usage: " << argv[0] << " -common 'path to general catalog' -personal 'path to personal catalog' -ORBInitRef NameService=corbaname::localhost");
711 _return_value = false ;
713 if (strcmp(argv[ind],"-common") == 0)
717 // General catalog file
718 *_general = argv[ind + 1] ;
719 /* ifstream _general_file(*_general);
722 MESSAGE( "Sorry the file " << *_general << " can't be open" )
724 _return_value = false;
729 else if (strcmp(argv[ind],"-personal") == 0)
733 // Personal catalog file
734 *_personal = argv[ind + 1] ;
735 /* ifstream _personal_file(*_personal);
738 MESSAGE("Sorry the file " << *_personal << " can't be open" )
740 _return_value = false;
746 return _return_value;