1 // SALOME ModuleCatalog : implementation of ModuleCatalog server which parsers xml description of modules
3 // Copyright (C) 2003 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.
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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SALOME_ModuleCatalog_Acomponent_impl.cxx
25 // Author : Estelle Deville
30 #include "SALOME_ModuleCatalog_Acomponent_impl.hxx"
32 //----------------------------------------------------------------------
33 // Function : SALOME_ModuleCatalog_AcomponentImpl
34 // Purpose : Constructor
35 // Affect the component name, type,icone, a bool to define
36 // if it's multistudy or not.
37 // Affect too the constraint and the interfaces of the component
38 // and the pathes prefixes for all computers
39 //----------------------------------------------------------------------
40 SALOME_ModuleCatalog_AcomponentImpl::SALOME_ModuleCatalog_AcomponentImpl(
42 const char* constraint,
43 SALOME_ModuleCatalog::ComponentType componenttype,
44 CORBA::Boolean componentmultistudy,
46 SALOME_ModuleCatalog::ListOfDefInterface list_interfaces,
47 ListOfPathPrefix pathes)
49 MESSAGE("Component creation")
50 // Affect component name
51 _component_name = new char[strlen(name)+1];
52 strcpy(_component_name, name);
55 _constraint =new char[strlen(constraint)+1];
56 strcpy(_constraint, constraint);
58 // Affect component type
59 _componenttype = componenttype;
61 // Affect component multistudy
62 _componentmultistudy = componentmultistudy;
65 _icone =new char[strlen(icone)+1];
66 strcpy(_icone, icone);
69 _list_interfaces.length(list_interfaces.length());
70 _list_interfaces = list_interfaces;
72 // affect path prefixes
73 _pathes.resize(pathes.size());
77 //----------------------------------------------------------------------
78 // Function : ~SALOME_ModuleCatalog_AcomponentImpl
79 // Purpose : Destructor
80 //----------------------------------------------------------------------
81 SALOME_ModuleCatalog_AcomponentImpl::~SALOME_ModuleCatalog_AcomponentImpl()
83 MESSAGE("Component destruction")
85 delete [] _component_name;
86 delete [] _constraint;
89 //----------------------------------------------------------------------
90 // Function : GetInterfaceList
91 // Purpose : get a list of the interfaces name of a component
92 //----------------------------------------------------------------------
93 SALOME_ModuleCatalog::ListOfInterfaces*
94 SALOME_ModuleCatalog_AcomponentImpl::GetInterfaceList()
96 SALOME_ModuleCatalog::ListOfInterfaces_var _list = new SALOME_ModuleCatalog::ListOfInterfaces;
98 // All the interfaces are defined in _list_interfaces affected at the
100 unsigned int _length_interfaces =_list_interfaces.length();
102 _list->length(_length_interfaces);
104 // Parse all the interfaces to get their name
105 for (unsigned int ind = 0; ind < _length_interfaces; ind++)
107 _list[ind] = CORBA::string_dup(_list_interfaces[ind].interfacename);
108 MESSAGE("The component " << _component_name << " contains " << _list[ind] << " as interface")
111 return _list._retn();
114 //----------------------------------------------------------------------
115 // Function : GetInterface
116 // Purpose : get one interface of a component
117 //----------------------------------------------------------------------
118 SALOME_ModuleCatalog::DefinitionInterface*
119 SALOME_ModuleCatalog_AcomponentImpl::GetInterface(const char* interfacename)
120 throw(SALOME_ModuleCatalog::NotFound)
122 SALOME_ModuleCatalog::DefinitionInterface_var _interface = new SALOME_ModuleCatalog::DefinitionInterface;
123 SALOME_ModuleCatalog::Service_var _service = new SALOME_ModuleCatalog::Service;
124 // Variables initialisation
125 _interface->interfaceservicelist.length(0);
129 // looking for the specified interface
130 for (unsigned int ind = 0; ind < _list_interfaces.length(); ind++)
132 if (strcmp(interfacename, _list_interfaces[ind].interfacename) == 0)
137 // Affect the name of the interface
138 _interface->interfacename = interfacename;
140 // Affect each service of the wanted interface
141 for (unsigned int ind1 = 0; ind1 < _list_interfaces[ind].interfaceservicelist.length() ; ind1++)
143 _interface->interfaceservicelist.length(_length+1);
144 _service = _duplicate_service(_list_interfaces[ind].interfaceservicelist[ind1]);
145 _interface->interfaceservicelist[_length] = _service;
155 // The interface was not found, the exception should be thrown
156 char * message = new char[100];
157 strcpy(message, "The interface ");
158 strcat(message,interfacename);
159 strcat(message, " of the component ");
160 strcat(message,_component_name);
161 strcat(message, " was not found") ;
162 MESSAGE("The interface " << interfacename << " of the component " << _component_name << " was not found")
163 throw SALOME_ModuleCatalog::NotFound(message);
167 return _interface._retn();
172 //----------------------------------------------------------------------
173 // Function : GetServiceList
174 // Purpose : get a list of the services name of an interface
176 //----------------------------------------------------------------------
177 SALOME_ModuleCatalog::ListOfServices*
178 SALOME_ModuleCatalog_AcomponentImpl::GetServiceList(const char* interfacename)
179 throw(SALOME_ModuleCatalog::NotFound)
181 SALOME_ModuleCatalog::ListOfServices_var _list = new SALOME_ModuleCatalog::ListOfServices;
183 // Variables initialisation
187 // looking for the specified interface
188 for (unsigned int ind = 0; ind < _list_interfaces.length(); ind++)
190 if (strcmp(interfacename, _list_interfaces[ind].interfacename) == 0)
194 // Get the list of services name for this interface
195 unsigned int _length_services = _list_interfaces[ind].interfaceservicelist.length();
196 _list->length(_length_services);
197 for (unsigned int ind1 = 0; ind1 < _length_services ; ind1++)
199 _list[ind1] = CORBA::string_dup(_list_interfaces[ind].interfaceservicelist[ind1].ServiceName);
200 MESSAGE("The interface " << interfacename << " of the component " << _component_name << " contains " << _list[ind1] << " as a service")
207 // The interface was not found, the exception should be thrown
208 char * message = new char[100];
209 strcpy(message, "The interface ");
210 strcat(message,interfacename);
211 strcat(message, " of the component ");
212 strcat(message,_component_name);
213 strcat(message, " was not found") ;
214 MESSAGE("The interface " << interfacename << " of the component " << _component_name << " was not found")
215 throw SALOME_ModuleCatalog::NotFound(message);
219 return _list._retn();
223 //----------------------------------------------------------------------
224 // Function : GetService
225 // Purpose : get one service of an interface of a component
226 //----------------------------------------------------------------------
227 SALOME_ModuleCatalog::Service*
228 SALOME_ModuleCatalog_AcomponentImpl::GetService(const char* interfacename,
229 const char* servicename)
230 throw(SALOME_ModuleCatalog::NotFound)
232 SALOME_ModuleCatalog::Service_var _service = new SALOME_ModuleCatalog::Service;
233 // Varaibles initialisation
236 // looking for the specified interface
237 for (unsigned int ind = 0; ind < _list_interfaces.length(); ind++)
239 if (strcmp(interfacename, _list_interfaces[ind].interfacename) == 0)
242 // looking for the specified service
243 for (unsigned int ind1 = 0; ind1 < _list_interfaces[ind].interfaceservicelist.length() ; ind1++)
245 if (strcmp(servicename, _list_interfaces[ind].interfaceservicelist[ind1].ServiceName) == 0)
248 // Affect the service to be returned
250 _service = _duplicate_service(_list_interfaces[ind].interfaceservicelist[ind1]);
259 // The service was not found, the exception should be thrown
260 char * message = new char[100];
261 strcpy(message, "The service ");
262 strcat(message, servicename);
263 strcat(message," of the interface ");
264 strcat(message,interfacename);
265 strcat(message, " of the component ");
266 strcat(message,_component_name);
267 strcat(message, " was not found") ;
268 MESSAGE("The service " << servicename << " of the interface " << interfacename << " of the component " << _component_name << " was not found")
269 throw SALOME_ModuleCatalog::NotFound(message);
273 return _service._retn();
276 //----------------------------------------------------------------------
277 // Function : GetDefaultService
278 // Purpose : get the default service of the interface
279 //----------------------------------------------------------------------
280 SALOME_ModuleCatalog::Service*
281 SALOME_ModuleCatalog_AcomponentImpl::GetDefaultService(const char* interfacename)
282 throw(SALOME_ModuleCatalog::NotFound)
284 SALOME_ModuleCatalog::Service_var _service = new SALOME_ModuleCatalog::Service;
286 // Variables initialisation
289 // looking for the specified interface
290 for (unsigned int ind = 0; ind < _list_interfaces.length(); ind++)
292 if (strcmp(interfacename, _list_interfaces[ind].interfacename) == 0)
295 // looking for the defautl service of the wanted interface
296 for (unsigned int ind1 = 0; ind1 < _list_interfaces[ind].interfaceservicelist.length() ; ind1++)
298 if (_list_interfaces[ind].interfaceservicelist[ind1].Servicebydefault)
301 // affect the service to be returned
303 _service = _duplicate_service(_list_interfaces[ind].interfaceservicelist[ind1]);
312 // The service was not found, the exception should be thrown
313 char * message = new char[100];
314 strcpy(message, "The default service of the interface ");
315 strcat(message,interfacename);
316 strcat(message, " of the component ");
317 strcat(message,_component_name);
318 strcat(message, " was not found") ;
319 MESSAGE("The default service of the interface " << interfacename << " of the component " << _component_name << " was not found")
320 throw SALOME_ModuleCatalog::NotFound(message);
324 return _service._retn();
327 //----------------------------------------------------------------------
328 // Function : GetPathPrefix
329 // Purpose : get the PathPrefix of a computer
330 //----------------------------------------------------------------------
332 SALOME_ModuleCatalog_AcomponentImpl::GetPathPrefix(const char* machinename)
333 throw(SALOME_ModuleCatalog::NotFound)
335 MESSAGE("Begin of GetPathPrefix")
336 // Variables initialisation
340 // Parse all the path prefixes
341 // looking for the wanted computer
342 for (unsigned int ind = 0 ; ind < _pathes.size() ; ind++)
344 for (unsigned int ind1 = 0 ; ind1 < _pathes[ind].ListOfComputer.size() ; ind1++)
346 if (strcmp(machinename, _pathes[ind].ListOfComputer[ind1].c_str()) == 0)
350 // affect the path to be returned
351 const char* _temp = _pathes[ind].path.c_str() ;
352 _path = new char[strlen(_temp)+1];
360 // The computer was not found, the exception should be thrown
361 char * message = new char[100];
362 strcpy(message, "The computer ");
363 strcat(message,machinename);
364 strcat(message, " was not found in the catalog associated to the component ") ;
365 strcat(message,_component_name);
366 MESSAGE("The computer " << machinename << " was not found in the catalog associated to the component " << _component_name)
367 throw SALOME_ModuleCatalog::NotFound(message);
374 //----------------------------------------------------------------------
375 // Function : constraint
376 // Purpose : obtain the constraint affected to a component
377 //----------------------------------------------------------------------
378 char* SALOME_ModuleCatalog_AcomponentImpl::constraint()
380 return CORBA::string_dup(_constraint);
383 //----------------------------------------------------------------------
384 // Function : componentname
385 // Purpose : obtain the componentname
386 //----------------------------------------------------------------------
387 char* SALOME_ModuleCatalog_AcomponentImpl::componentname()
389 return CORBA::string_dup(_component_name);
392 //----------------------------------------------------------------------
393 // Function : multistudy
394 // Purpose : define if a component can be multistudy or not
395 //----------------------------------------------------------------------
396 CORBA::Boolean SALOME_ModuleCatalog_AcomponentImpl::multistudy()
398 return _componentmultistudy ;
401 //----------------------------------------------------------------------
402 // Function : component_type
403 // Purpose : define the type of the component
404 //----------------------------------------------------------------------
405 SALOME_ModuleCatalog::ComponentType
406 SALOME_ModuleCatalog_AcomponentImpl::component_type()
408 return _componenttype;
411 //----------------------------------------------------------------------
413 // Purpose : obtain the icone affected to a component (for IAPP)
414 //----------------------------------------------------------------------
415 char* SALOME_ModuleCatalog_AcomponentImpl::component_icone()
417 return CORBA::string_dup(_icone);
420 //----------------------------------------------------------------------
421 // Function : _duplicate_service
422 // Purpose : duplicate a service
423 //----------------------------------------------------------------------
424 SALOME_ModuleCatalog::Service_var
425 SALOME_ModuleCatalog_AcomponentImpl::_duplicate_service(SALOME_ModuleCatalog::Service service)
427 SALOME_ModuleCatalog::Service_var _service = new SALOME_ModuleCatalog::Service;
430 _service->ServiceName = CORBA::string_dup(service.ServiceName);
431 // service by default
432 _service->Servicebydefault = service.Servicebydefault;
434 // in Parameters service
435 unsigned int _length_in_param = service.ServiceinParameter.length();
436 for(unsigned int ind = 0; ind < _length_in_param; ind++)
438 _service->ServiceinParameter.length(_length_in_param);
440 _service->ServiceinParameter[ind].Parametertype = CORBA::string_dup(service.ServiceinParameter[ind].Parametertype);
442 _service->ServiceinParameter[ind].Parametername = CORBA::string_dup(service.ServiceinParameter[ind].Parametername);
445 // out Parameters service
446 unsigned int _length_out_param = service.ServiceoutParameter.length();
447 for(unsigned int ind = 0; ind < _length_out_param; ind++)
449 _service->ServiceoutParameter.length(_length_out_param);
450 // out Parameter type
451 _service->ServiceoutParameter[ind].Parametertype = CORBA::string_dup(service.ServiceoutParameter[ind].Parametertype);
452 // out Parameter name
453 _service->ServiceoutParameter[ind].Parametername = CORBA::string_dup(service.ServiceoutParameter[ind].Parametername);