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(
22 const char* constraint,
23 SALOME_ModuleCatalog::ComponentType componenttype,
24 CORBA::Boolean componentmultistudy,
26 SALOME_ModuleCatalog::ListOfDefInterface list_interfaces,
27 ListOfPathPrefix pathes)
29 MESSAGE("Component creation")
30 // Affect component name
31 _component_name = new char[strlen(name)+1];
32 strcpy(_component_name, name);
35 _constraint =new char[strlen(constraint)+1];
36 strcpy(_constraint, constraint);
38 // Affect component type
39 _componenttype = componenttype;
41 // Affect component multistudy
42 _componentmultistudy = componentmultistudy;
45 _icone =new char[strlen(icone)+1];
46 strcpy(_icone, icone);
49 _list_interfaces.length(list_interfaces.length());
50 _list_interfaces = list_interfaces;
52 // affect path prefixes
53 _pathes.resize(pathes.size());
57 //----------------------------------------------------------------------
58 // Function : ~SALOME_ModuleCatalog_AcomponentImpl
59 // Purpose : Destructor
60 //----------------------------------------------------------------------
61 SALOME_ModuleCatalog_AcomponentImpl::~SALOME_ModuleCatalog_AcomponentImpl()
63 MESSAGE("Component destruction")
65 delete [] _component_name;
66 delete [] _constraint;
69 //----------------------------------------------------------------------
70 // Function : GetInterfaceList
71 // Purpose : get a list of the interfaces name of a component
72 //----------------------------------------------------------------------
73 SALOME_ModuleCatalog::ListOfInterfaces*
74 SALOME_ModuleCatalog_AcomponentImpl::GetInterfaceList()
76 SALOME_ModuleCatalog::ListOfInterfaces_var _list = new SALOME_ModuleCatalog::ListOfInterfaces;
78 // All the interfaces are defined in _list_interfaces affected at the
80 unsigned int _length_interfaces =_list_interfaces.length();
82 _list->length(_length_interfaces);
84 // Parse all the interfaces to get their name
85 for (unsigned int ind = 0; ind < _length_interfaces; ind++)
87 _list[ind] = CORBA::string_dup(_list_interfaces[ind].interfacename);
88 MESSAGE("The component " << _component_name << " contains " << _list[ind] << " as interface")
94 //----------------------------------------------------------------------
95 // Function : GetInterface
96 // Purpose : get one interface of a component
97 //----------------------------------------------------------------------
98 SALOME_ModuleCatalog::DefinitionInterface*
99 SALOME_ModuleCatalog_AcomponentImpl::GetInterface(const char* interfacename)
100 throw(SALOME_ModuleCatalog::NotFound)
102 SALOME_ModuleCatalog::DefinitionInterface_var _interface = new SALOME_ModuleCatalog::DefinitionInterface;
103 SALOME_ModuleCatalog::Service_var _service = new SALOME_ModuleCatalog::Service;
104 // Variables initialisation
105 _interface->interfaceservicelist.length(0);
109 // looking for the specified interface
110 for (unsigned int ind = 0; ind < _list_interfaces.length(); ind++)
112 if (strcmp(interfacename, _list_interfaces[ind].interfacename) == 0)
117 // Affect the name of the interface
118 _interface->interfacename = interfacename;
120 // Affect each service of the wanted interface
121 for (unsigned int ind1 = 0; ind1 < _list_interfaces[ind].interfaceservicelist.length() ; ind1++)
123 _interface->interfaceservicelist.length(_length+1);
124 _service = _duplicate_service(_list_interfaces[ind].interfaceservicelist[ind1]);
125 _interface->interfaceservicelist[_length] = _service;
135 // The interface was not found, the exception should be thrown
136 char * message = new char[100];
137 strcpy(message, "The interface ");
138 strcat(message,interfacename);
139 strcat(message, " of the component ");
140 strcat(message,_component_name);
141 strcat(message, " was not found") ;
142 MESSAGE("The interface " << interfacename << " of the component " << _component_name << " was not found")
143 throw SALOME_ModuleCatalog::NotFound(message);
147 return _interface._retn();
152 //----------------------------------------------------------------------
153 // Function : GetServiceList
154 // Purpose : get a list of the services name of an interface
156 //----------------------------------------------------------------------
157 SALOME_ModuleCatalog::ListOfServices*
158 SALOME_ModuleCatalog_AcomponentImpl::GetServiceList(const char* interfacename)
159 throw(SALOME_ModuleCatalog::NotFound)
161 SALOME_ModuleCatalog::ListOfServices_var _list = new SALOME_ModuleCatalog::ListOfServices;
163 // Variables initialisation
167 // looking for the specified interface
168 for (unsigned int ind = 0; ind < _list_interfaces.length(); ind++)
170 if (strcmp(interfacename, _list_interfaces[ind].interfacename) == 0)
174 // Get the list of services name for this interface
175 unsigned int _length_services = _list_interfaces[ind].interfaceservicelist.length();
176 _list->length(_length_services);
177 for (unsigned int ind1 = 0; ind1 < _length_services ; ind1++)
179 _list[ind1] = CORBA::string_dup(_list_interfaces[ind].interfaceservicelist[ind1].ServiceName);
180 MESSAGE("The interface " << interfacename << " of the component " << _component_name << " contains " << _list[ind1] << " as a service")
187 // The interface was not found, the exception should be thrown
188 char * message = new char[100];
189 strcpy(message, "The interface ");
190 strcat(message,interfacename);
191 strcat(message, " of the component ");
192 strcat(message,_component_name);
193 strcat(message, " was not found") ;
194 MESSAGE("The interface " << interfacename << " of the component " << _component_name << " was not found")
195 throw SALOME_ModuleCatalog::NotFound(message);
199 return _list._retn();
203 //----------------------------------------------------------------------
204 // Function : GetService
205 // Purpose : get one service of an interface of a component
206 //----------------------------------------------------------------------
207 SALOME_ModuleCatalog::Service*
208 SALOME_ModuleCatalog_AcomponentImpl::GetService(const char* interfacename,
209 const char* servicename)
210 throw(SALOME_ModuleCatalog::NotFound)
212 SALOME_ModuleCatalog::Service_var _service = new SALOME_ModuleCatalog::Service;
213 // Varaibles initialisation
216 // looking for the specified interface
217 for (unsigned int ind = 0; ind < _list_interfaces.length(); ind++)
219 if (strcmp(interfacename, _list_interfaces[ind].interfacename) == 0)
222 // looking for the specified service
223 for (unsigned int ind1 = 0; ind1 < _list_interfaces[ind].interfaceservicelist.length() ; ind1++)
225 if (strcmp(servicename, _list_interfaces[ind].interfaceservicelist[ind1].ServiceName) == 0)
228 // Affect the service to be returned
230 _service = _duplicate_service(_list_interfaces[ind].interfaceservicelist[ind1]);
239 // The service was not found, the exception should be thrown
240 char * message = new char[100];
241 strcpy(message, "The service ");
242 strcat(message, servicename);
243 strcat(message," of the interface ");
244 strcat(message,interfacename);
245 strcat(message, " of the component ");
246 strcat(message,_component_name);
247 strcat(message, " was not found") ;
248 MESSAGE("The service " << servicename << " of the interface " << interfacename << " of the component " << _component_name << " was not found")
249 throw SALOME_ModuleCatalog::NotFound(message);
253 return _service._retn();
256 //----------------------------------------------------------------------
257 // Function : GetDefaultService
258 // Purpose : get the default service of the interface
259 //----------------------------------------------------------------------
260 SALOME_ModuleCatalog::Service*
261 SALOME_ModuleCatalog_AcomponentImpl::GetDefaultService(const char* interfacename)
262 throw(SALOME_ModuleCatalog::NotFound)
264 SALOME_ModuleCatalog::Service_var _service = new SALOME_ModuleCatalog::Service;
266 // Variables initialisation
269 // looking for the specified interface
270 for (unsigned int ind = 0; ind < _list_interfaces.length(); ind++)
272 if (strcmp(interfacename, _list_interfaces[ind].interfacename) == 0)
275 // looking for the defautl service of the wanted interface
276 for (unsigned int ind1 = 0; ind1 < _list_interfaces[ind].interfaceservicelist.length() ; ind1++)
278 if (_list_interfaces[ind].interfaceservicelist[ind1].Servicebydefault)
281 // affect the service to be returned
283 _service = _duplicate_service(_list_interfaces[ind].interfaceservicelist[ind1]);
292 // The service was not found, the exception should be thrown
293 char * message = new char[100];
294 strcpy(message, "The default service of the interface ");
295 strcat(message,interfacename);
296 strcat(message, " of the component ");
297 strcat(message,_component_name);
298 strcat(message, " was not found") ;
299 MESSAGE("The default service of the interface " << interfacename << " of the component " << _component_name << " was not found")
300 throw SALOME_ModuleCatalog::NotFound(message);
304 return _service._retn();
307 //----------------------------------------------------------------------
308 // Function : GetPathPrefix
309 // Purpose : get the PathPrefix of a computer
310 //----------------------------------------------------------------------
312 SALOME_ModuleCatalog_AcomponentImpl::GetPathPrefix(const char* machinename)
313 throw(SALOME_ModuleCatalog::NotFound)
315 MESSAGE("Begin of GetPathPrefix")
316 // Variables initialisation
320 // Parse all the path prefixes
321 // looking for the wanted computer
322 for (unsigned int ind = 0 ; ind < _pathes.size() ; ind++)
324 for (unsigned int ind1 = 0 ; ind1 < _pathes[ind].ListOfComputer.size() ; ind1++)
326 if (strcmp(machinename, _pathes[ind].ListOfComputer[ind1].c_str()) == 0)
330 // affect the path to be returned
331 const char* _temp = _pathes[ind].path.c_str() ;
332 _path = new char[strlen(_temp)+1];
340 // The computer was not found, the exception should be thrown
341 char * message = new char[100];
342 strcpy(message, "The computer ");
343 strcat(message,machinename);
344 strcat(message, " was not found in the catalog associated to the component ") ;
345 strcat(message,_component_name);
346 MESSAGE("The computer " << machinename << " was not found in the catalog associated to the component " << _component_name)
347 throw SALOME_ModuleCatalog::NotFound(message);
354 //----------------------------------------------------------------------
355 // Function : constraint
356 // Purpose : obtain the constraint affected to a component
357 //----------------------------------------------------------------------
358 char* SALOME_ModuleCatalog_AcomponentImpl::constraint()
360 return CORBA::string_dup(_constraint);
363 //----------------------------------------------------------------------
364 // Function : componentname
365 // Purpose : obtain the componentname
366 //----------------------------------------------------------------------
367 char* SALOME_ModuleCatalog_AcomponentImpl::componentname()
369 return CORBA::string_dup(_component_name);
372 //----------------------------------------------------------------------
373 // Function : multistudy
374 // Purpose : define if a component can be multistudy or not
375 //----------------------------------------------------------------------
376 CORBA::Boolean SALOME_ModuleCatalog_AcomponentImpl::multistudy()
378 return _componentmultistudy ;
381 //----------------------------------------------------------------------
382 // Function : component_type
383 // Purpose : define the type of the component
384 //----------------------------------------------------------------------
385 SALOME_ModuleCatalog::ComponentType
386 SALOME_ModuleCatalog_AcomponentImpl::component_type()
388 return _componenttype;
391 //----------------------------------------------------------------------
393 // Purpose : obtain the icone affected to a component (for IAPP)
394 //----------------------------------------------------------------------
395 char* SALOME_ModuleCatalog_AcomponentImpl::component_icone()
397 return CORBA::string_dup(_icone);
400 //----------------------------------------------------------------------
401 // Function : _duplicate_service
402 // Purpose : duplicate a service
403 //----------------------------------------------------------------------
404 SALOME_ModuleCatalog::Service_var
405 SALOME_ModuleCatalog_AcomponentImpl::_duplicate_service(SALOME_ModuleCatalog::Service service)
407 SALOME_ModuleCatalog::Service_var _service = new SALOME_ModuleCatalog::Service;
410 _service->ServiceName = CORBA::string_dup(service.ServiceName);
411 // service by default
412 _service->Servicebydefault = service.Servicebydefault;
414 // in Parameters service
415 unsigned int _length_in_param = service.ServiceinParameter.length();
416 for(unsigned int ind = 0; ind < _length_in_param; ind++)
418 _service->ServiceinParameter.length(_length_in_param);
420 _service->ServiceinParameter[ind].Parametertype = CORBA::string_dup(service.ServiceinParameter[ind].Parametertype);
422 _service->ServiceinParameter[ind].Parametername = CORBA::string_dup(service.ServiceinParameter[ind].Parametername);
425 // out Parameters service
426 unsigned int _length_out_param = service.ServiceoutParameter.length();
427 for(unsigned int ind = 0; ind < _length_out_param; ind++)
429 _service->ServiceoutParameter.length(_length_out_param);
430 // out Parameter type
431 _service->ServiceoutParameter[ind].Parametertype = CORBA::string_dup(service.ServiceoutParameter[ind].Parametertype);
432 // out Parameter name
433 _service->ServiceoutParameter[ind].Parametername = CORBA::string_dup(service.ServiceoutParameter[ind].Parametername);