2 // File: SALOME_ModuleCatalog_Acomponent_impl.cxx
3 // Created: Tue June 28 2001
4 // Author: Estelle Deville
6 // Copyright : CEA/DEN/DMSS/LGLS
10 #include "SALOME_ModuleCatalog_Acomponent_impl.hxx"
12 //----------------------------------------------------------------------
13 // Function : SALOME_ModuleCatalog_AcomponentImpl
14 // Purpose : Constructor
15 // Affect the component name, type,icone, a bool to define
16 // if it's multistudy or not.
17 // Affect too the constraint and the interfaces of the component
18 // and the pathes prefixes for all computers
19 //----------------------------------------------------------------------
20 SALOME_ModuleCatalog_AcomponentImpl::SALOME_ModuleCatalog_AcomponentImpl(
23 const char* constraint,
24 SALOME_ModuleCatalog::ComponentType componenttype,
25 CORBA::Boolean componentmultistudy,
27 SALOME_ModuleCatalog::ListOfDefInterface list_interfaces,
28 ListOfPathPrefix pathes)
30 MESSAGE("Component creation")
31 // Affect component name
32 _component_name = new char[strlen(name)+1];
33 strcpy(_component_name, name);
35 // Affect component user name
36 _component_user_name = new char[strlen(username)+1];
37 strcpy(_component_user_name, username);
40 _constraint =new char[strlen(constraint)+1];
41 strcpy(_constraint, constraint);
43 // Affect component type
44 _componenttype = componenttype;
46 // Affect component multistudy
47 _componentmultistudy = componentmultistudy;
50 _icone =new char[strlen(icone)+1];
51 strcpy(_icone, icone);
54 _list_interfaces.length(list_interfaces.length());
55 _list_interfaces = list_interfaces;
57 // affect path prefixes
58 _pathes.resize(pathes.size());
62 //----------------------------------------------------------------------
63 // Function : ~SALOME_ModuleCatalog_AcomponentImpl
64 // Purpose : Destructor
65 //----------------------------------------------------------------------
66 SALOME_ModuleCatalog_AcomponentImpl::~SALOME_ModuleCatalog_AcomponentImpl()
68 MESSAGE("Component destruction")
70 delete [] _component_name;
71 delete [] _component_user_name;
72 delete [] _constraint;
75 //----------------------------------------------------------------------
76 // Function : GetInterfaceList
77 // Purpose : get a list of the interfaces name of a component
78 //----------------------------------------------------------------------
79 SALOME_ModuleCatalog::ListOfInterfaces*
80 SALOME_ModuleCatalog_AcomponentImpl::GetInterfaceList()
82 SALOME_ModuleCatalog::ListOfInterfaces_var _list = new SALOME_ModuleCatalog::ListOfInterfaces;
84 // All the interfaces are defined in _list_interfaces affected at the
86 unsigned int _length_interfaces =_list_interfaces.length();
88 _list->length(_length_interfaces);
90 // Parse all the interfaces to get their name
91 for (unsigned int ind = 0; ind < _length_interfaces; ind++)
93 _list[ind] = CORBA::string_dup(_list_interfaces[ind].interfacename);
94 MESSAGE("The component " << _component_name << " contains " << _list[ind] << " as interface")
100 //----------------------------------------------------------------------
101 // Function : GetInterface
102 // Purpose : get one interface of a component
103 //----------------------------------------------------------------------
104 SALOME_ModuleCatalog::DefinitionInterface*
105 SALOME_ModuleCatalog_AcomponentImpl::GetInterface(const char* interfacename)
106 throw(SALOME_ModuleCatalog::NotFound)
108 SALOME_ModuleCatalog::DefinitionInterface_var _interface = new SALOME_ModuleCatalog::DefinitionInterface;
109 SALOME_ModuleCatalog::Service_var _service = new SALOME_ModuleCatalog::Service;
110 // Variables initialisation
111 _interface->interfaceservicelist.length(0);
115 // looking for the specified interface
116 for (unsigned int ind = 0; ind < _list_interfaces.length(); ind++)
118 if (strcmp(interfacename, _list_interfaces[ind].interfacename) == 0)
123 // Affect the name of the interface
124 _interface->interfacename = interfacename;
126 // Affect each service of the wanted interface
127 for (unsigned int ind1 = 0; ind1 < _list_interfaces[ind].interfaceservicelist.length() ; ind1++)
129 _interface->interfaceservicelist.length(_length+1);
130 _service = _duplicate_service(_list_interfaces[ind].interfaceservicelist[ind1]);
131 _interface->interfaceservicelist[_length] = _service;
141 // The interface was not found, the exception should be thrown
142 char * message = new char[100];
143 strcpy(message, "The interface ");
144 strcat(message,interfacename);
145 strcat(message, " of the component ");
146 strcat(message,_component_name);
147 strcat(message, " was not found") ;
148 MESSAGE("The interface " << interfacename << " of the component " << _component_name << " was not found")
149 throw SALOME_ModuleCatalog::NotFound(message);
153 return _interface._retn();
158 //----------------------------------------------------------------------
159 // Function : GetServiceList
160 // Purpose : get a list of the services name of an interface
162 //----------------------------------------------------------------------
163 SALOME_ModuleCatalog::ListOfServices*
164 SALOME_ModuleCatalog_AcomponentImpl::GetServiceList(const char* interfacename)
165 throw(SALOME_ModuleCatalog::NotFound)
167 SALOME_ModuleCatalog::ListOfServices_var _list = new SALOME_ModuleCatalog::ListOfServices;
169 // Variables initialisation
173 // looking for the specified interface
174 for (unsigned int ind = 0; ind < _list_interfaces.length(); ind++)
176 if (strcmp(interfacename, _list_interfaces[ind].interfacename) == 0)
180 // Get the list of services name for this interface
181 unsigned int _length_services = _list_interfaces[ind].interfaceservicelist.length();
182 _list->length(_length_services);
183 for (unsigned int ind1 = 0; ind1 < _length_services ; ind1++)
185 _list[ind1] = CORBA::string_dup(_list_interfaces[ind].interfaceservicelist[ind1].ServiceName);
186 MESSAGE("The interface " << interfacename << " of the component " << _component_name << " contains " << _list[ind1] << " as a service")
193 // The interface was not found, the exception should be thrown
194 char * message = new char[100];
195 strcpy(message, "The interface ");
196 strcat(message,interfacename);
197 strcat(message, " of the component ");
198 strcat(message,_component_name);
199 strcat(message, " was not found") ;
200 MESSAGE("The interface " << interfacename << " of the component " << _component_name << " was not found")
201 throw SALOME_ModuleCatalog::NotFound(message);
205 return _list._retn();
209 //----------------------------------------------------------------------
210 // Function : GetService
211 // Purpose : get one service of an interface of a component
212 //----------------------------------------------------------------------
213 SALOME_ModuleCatalog::Service*
214 SALOME_ModuleCatalog_AcomponentImpl::GetService(const char* interfacename,
215 const char* servicename)
216 throw(SALOME_ModuleCatalog::NotFound)
218 SALOME_ModuleCatalog::Service_var _service = new SALOME_ModuleCatalog::Service;
219 // Varaibles initialisation
222 // looking for the specified interface
223 for (unsigned int ind = 0; ind < _list_interfaces.length(); ind++)
225 if (strcmp(interfacename, _list_interfaces[ind].interfacename) == 0)
228 // looking for the specified service
229 for (unsigned int ind1 = 0; ind1 < _list_interfaces[ind].interfaceservicelist.length() ; ind1++)
231 if (strcmp(servicename, _list_interfaces[ind].interfaceservicelist[ind1].ServiceName) == 0)
234 // Affect the service to be returned
236 _service = _duplicate_service(_list_interfaces[ind].interfaceservicelist[ind1]);
245 // The service was not found, the exception should be thrown
246 char * message = new char[100];
247 strcpy(message, "The service ");
248 strcat(message, servicename);
249 strcat(message," of the interface ");
250 strcat(message,interfacename);
251 strcat(message, " of the component ");
252 strcat(message,_component_name);
253 strcat(message, " was not found") ;
254 MESSAGE("The service " << servicename << " of the interface " << interfacename << " of the component " << _component_name << " was not found")
255 throw SALOME_ModuleCatalog::NotFound(message);
259 return _service._retn();
262 //----------------------------------------------------------------------
263 // Function : GetDefaultService
264 // Purpose : get the default service of the interface
265 //----------------------------------------------------------------------
266 SALOME_ModuleCatalog::Service*
267 SALOME_ModuleCatalog_AcomponentImpl::GetDefaultService(const char* interfacename)
268 throw(SALOME_ModuleCatalog::NotFound)
270 SALOME_ModuleCatalog::Service_var _service = new SALOME_ModuleCatalog::Service;
272 // Variables initialisation
275 // looking for the specified interface
276 for (unsigned int ind = 0; ind < _list_interfaces.length(); ind++)
278 if (strcmp(interfacename, _list_interfaces[ind].interfacename) == 0)
281 // looking for the defautl service of the wanted interface
282 for (unsigned int ind1 = 0; ind1 < _list_interfaces[ind].interfaceservicelist.length() ; ind1++)
284 if (_list_interfaces[ind].interfaceservicelist[ind1].Servicebydefault)
287 // affect the service to be returned
289 _service = _duplicate_service(_list_interfaces[ind].interfaceservicelist[ind1]);
298 // The service was not found, the exception should be thrown
299 char * message = new char[100];
300 strcpy(message, "The default service of the interface ");
301 strcat(message,interfacename);
302 strcat(message, " of the component ");
303 strcat(message,_component_name);
304 strcat(message, " was not found") ;
305 MESSAGE("The default service of the interface " << interfacename << " of the component " << _component_name << " was not found")
306 throw SALOME_ModuleCatalog::NotFound(message);
310 return _service._retn();
313 //----------------------------------------------------------------------
314 // Function : GetPathPrefix
315 // Purpose : get the PathPrefix of a computer
316 //----------------------------------------------------------------------
318 SALOME_ModuleCatalog_AcomponentImpl::GetPathPrefix(const char* machinename)
319 throw(SALOME_ModuleCatalog::NotFound)
321 MESSAGE("Begin of GetPathPrefix")
322 // Variables initialisation
326 // Parse all the path prefixes
327 // looking for the wanted computer
328 for (unsigned int ind = 0 ; ind < _pathes.size() ; ind++)
330 for (unsigned int ind1 = 0 ; ind1 < _pathes[ind].ListOfComputer.size() ; ind1++)
332 if (strcmp(machinename, _pathes[ind].ListOfComputer[ind1].c_str()) == 0)
336 // affect the path to be returned
337 const char* _temp = _pathes[ind].path.c_str() ;
338 _path = new char[strlen(_temp)+1];
346 // The computer was not found, the exception should be thrown
347 char * message = new char[100];
348 strcpy(message, "The computer ");
349 strcat(message,machinename);
350 strcat(message, " was not found in the catalog associated to the component ") ;
351 strcat(message,_component_name);
352 MESSAGE("The computer " << machinename << " was not found in the catalog associated to the component " << _component_name)
353 throw SALOME_ModuleCatalog::NotFound(message);
360 //----------------------------------------------------------------------
361 // Function : constraint
362 // Purpose : obtain the constraint affected to a component
363 //----------------------------------------------------------------------
364 char* SALOME_ModuleCatalog_AcomponentImpl::constraint()
366 return CORBA::string_dup(_constraint);
369 //----------------------------------------------------------------------
370 // Function : componentname
371 // Purpose : obtain the componentname
372 //----------------------------------------------------------------------
373 char* SALOME_ModuleCatalog_AcomponentImpl::componentname()
375 return CORBA::string_dup(_component_name);
378 //----------------------------------------------------------------------
379 // Function : componentusername
380 // Purpose : obtain the componentusername
381 //----------------------------------------------------------------------
382 char* SALOME_ModuleCatalog_AcomponentImpl::componentusername()
384 return CORBA::string_dup(_component_user_name);
387 //----------------------------------------------------------------------
388 // Function : multistudy
389 // Purpose : define if a component can be multistudy or not
390 //----------------------------------------------------------------------
391 CORBA::Boolean SALOME_ModuleCatalog_AcomponentImpl::multistudy()
393 return _componentmultistudy ;
396 //----------------------------------------------------------------------
397 // Function : component_type
398 // Purpose : define the type of the component
399 //----------------------------------------------------------------------
400 SALOME_ModuleCatalog::ComponentType
401 SALOME_ModuleCatalog_AcomponentImpl::component_type()
403 return _componenttype;
406 //----------------------------------------------------------------------
408 // Purpose : obtain the icone affected to a component (for IAPP)
409 //----------------------------------------------------------------------
410 char* SALOME_ModuleCatalog_AcomponentImpl::component_icone()
412 return CORBA::string_dup(_icone);
415 //----------------------------------------------------------------------
416 // Function : _duplicate_service
417 // Purpose : duplicate a service
418 //----------------------------------------------------------------------
419 SALOME_ModuleCatalog::Service_var
420 SALOME_ModuleCatalog_AcomponentImpl::_duplicate_service(SALOME_ModuleCatalog::Service service)
422 SALOME_ModuleCatalog::Service_var _service = new SALOME_ModuleCatalog::Service;
425 _service->ServiceName = CORBA::string_dup(service.ServiceName);
426 // service by default
427 _service->Servicebydefault = service.Servicebydefault;
429 // in Parameters service
430 unsigned int _length_in_param = service.ServiceinParameter.length();
431 for(unsigned int ind = 0; ind < _length_in_param; ind++)
433 _service->ServiceinParameter.length(_length_in_param);
435 _service->ServiceinParameter[ind].Parametertype = CORBA::string_dup(service.ServiceinParameter[ind].Parametertype);
437 _service->ServiceinParameter[ind].Parametername = CORBA::string_dup(service.ServiceinParameter[ind].Parametername);
440 // out Parameters service
441 unsigned int _length_out_param = service.ServiceoutParameter.length();
442 for(unsigned int ind = 0; ind < _length_out_param; ind++)
444 _service->ServiceoutParameter.length(_length_out_param);
445 // out Parameter type
446 _service->ServiceoutParameter[ind].Parametertype = CORBA::string_dup(service.ServiceoutParameter[ind].Parametertype);
447 // out Parameter name
448 _service->ServiceoutParameter[ind].Parametername = CORBA::string_dup(service.ServiceoutParameter[ind].Parametername);