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 #include "Utils_ExceptHandlers.hxx"
33 UNEXPECT_CATCH(MC_NotFound, SALOME_ModuleCatalog::NotFound);
35 //----------------------------------------------------------------------
36 // Function : SALOME_ModuleCatalog_AcomponentImpl
37 // Purpose : Constructor
38 // Affect the component name, type,icone, a bool to define
39 // if it's multistudy or not.
40 // Affect too the constraint and the interfaces of the component
41 // and the pathes prefixes for all computers
42 //----------------------------------------------------------------------
43 SALOME_ModuleCatalog_AcomponentImpl::SALOME_ModuleCatalog_AcomponentImpl
44 (SALOME_ModuleCatalog::Component &C) : _Component(C)
46 BEGIN_OF("SALOME_ModuleCatalog_AcomponentImpl");
48 END_OF("SALOME_ModuleCatalog_AcomponentImpl");
51 //----------------------------------------------------------------------
52 // Function : ~SALOME_ModuleCatalog_AcomponentImpl
53 // Purpose : Destructor
54 //----------------------------------------------------------------------
55 SALOME_ModuleCatalog_AcomponentImpl::~SALOME_ModuleCatalog_AcomponentImpl()
57 BEGIN_OF("~SALOME_ModuleCatalog_AcomponentImpl");
60 END_OF("~SALOME_ModuleCatalog_AcomponentImpl");
63 //----------------------------------------------------------------------
64 // Function : GetInterfaceList
65 // Purpose : get a list of the interfaces name of a component
66 //----------------------------------------------------------------------
67 SALOME_ModuleCatalog::ListOfInterfaces*
68 SALOME_ModuleCatalog_AcomponentImpl::GetInterfaceList()
70 BEGIN_OF("GetInterfaceList");
72 SALOME_ModuleCatalog::ListOfInterfaces_var _list
73 = new SALOME_ModuleCatalog::ListOfInterfaces;
75 // All the interfaces are defined in _list_interfaces affected at the
77 unsigned int _length_interfaces = _Component.interfaces.length();
79 _list->length(_length_interfaces);
81 // Parse all the interfaces to get their name
82 for (unsigned int ind = 0; ind < _length_interfaces; ind++)
84 _list[ind] = CORBA::string_dup(_Component.interfaces[ind].interfacename);
85 MESSAGE("The component " << _Component.name
86 << " contains " << _list[ind] << " as interface");
89 END_OF("GetInterfaceList");
93 //----------------------------------------------------------------------
94 // Function : GetInterface
95 // Purpose : get one interface of a component
96 //----------------------------------------------------------------------
97 SALOME_ModuleCatalog::DefinitionInterface*
98 SALOME_ModuleCatalog_AcomponentImpl::GetInterface(const char* interfacename)
99 throw(SALOME_ModuleCatalog::NotFound)
101 BEGIN_OF("GetInterface");
102 SCRUTE(interfacename);
104 SALOME_ModuleCatalog::DefinitionInterface *_interface =
105 new SALOME_ModuleCatalog::DefinitionInterface;
109 // looking for the specified interface
110 for (unsigned int ind = 0; ind < _Component.interfaces.length(); ind++)
112 SALOME_ModuleCatalog::DefinitionInterface &I
113 = _Component.interfaces[ind];
115 if (strcmp(interfacename, I.interfacename) == 0)
119 duplicate(*_interface, I);
126 // The interface was not found, the exception should be thrown
127 string message = "The interface";
128 message += interfacename;
129 message += " of the component ";
130 message += _Component.name;
131 message += " was not found";
133 throw SALOME_ModuleCatalog::NotFound(message.c_str());
136 END_OF("GetInterface");
143 //----------------------------------------------------------------------
144 // Function : GetServiceList
145 // Purpose : get a list of the services name of an interface
147 //----------------------------------------------------------------------
148 SALOME_ModuleCatalog::ListOfServices*
149 SALOME_ModuleCatalog_AcomponentImpl::GetServiceList(const char* interfacename)
150 throw(SALOME_ModuleCatalog::NotFound)
152 BEGIN_OF("GetServiceList");
153 SCRUTE(interfacename);
155 SALOME_ModuleCatalog::ListOfServices_var _list
156 = new SALOME_ModuleCatalog::ListOfServices;
158 // Variables initialisation
161 // looking for the specified interface
162 for (unsigned int ind = 0; ind < _Component.interfaces.length(); ind++)
164 SALOME_ModuleCatalog::DefinitionInterface & I = _Component.interfaces[ind];
166 if (strcmp(interfacename, I.interfacename) == 0)
170 // Get the list of services name for this interface
171 unsigned int _length_services = I.interfaceservicelist.length();
172 _list->length(_length_services);
173 for (unsigned int ind1 = 0; ind1 < _length_services ; ind1++)
175 _list[ind1] = CORBA::string_dup(I.interfaceservicelist[ind1].ServiceName);
176 MESSAGE("The interface " << interfacename << " of the component "
177 << _Component.name << " contains " << _list[ind1] << " as a service")
184 // The interface was not found, the exception should be thrown
185 string message = "The interface";
186 message += interfacename;
187 message += " of the component ";
188 message += _Component.name;
189 message += " was not found";
191 throw SALOME_ModuleCatalog::NotFound(message.c_str());
194 END_OF("GetServiceList");
195 return _list._retn();
199 //----------------------------------------------------------------------
200 // Function : GetService
201 // Purpose : get one service of an interface of a component
202 //----------------------------------------------------------------------
203 SALOME_ModuleCatalog::Service*
204 SALOME_ModuleCatalog_AcomponentImpl::GetService(const char* interfacename,
205 const char* servicename)
206 throw(SALOME_ModuleCatalog::NotFound)
208 BEGIN_OF("GetService");
209 SCRUTE(interfacename);
212 Unexpect aCatch( MC_NotFound );
213 SALOME_ModuleCatalog::Service *service = new SALOME_ModuleCatalog::Service;
215 // Variables initialization
219 // looking for the specified interface
220 for (unsigned int ind = 0; ind < _Component.interfaces.length(); ind++)
223 SCRUTE(_Component.interfaces[ind].interfacename);
225 SALOME_ModuleCatalog::DefinitionInterface &I = _Component.interfaces[ind];
226 if (strcmp(interfacename, I.interfacename) == 0)
229 // looking for the specified service
230 for (unsigned int ind1 = 0; ind1 < I.interfaceservicelist.length() ; ind1++)
232 SALOME_ModuleCatalog::Service &S = I.interfaceservicelist[ind1];
234 SCRUTE(S.ServiceName);
236 if (strcmp(servicename, S.ServiceName) == 0)
239 // Affect the service to be returned
241 duplicate(*service, S);
251 // The interface was not found, the exception should be thrown
252 string message = "The service";
253 message += servicename;
254 message += " of the interface ";
255 message += interfacename;
256 message += " of the component ";
257 message += _Component.name;
258 message += " was not found";
260 throw SALOME_ModuleCatalog::NotFound(message.c_str());
263 END_OF("GetService");
267 //----------------------------------------------------------------------
268 // Function : GetDefaultService
269 // Purpose : get the default service of the interface
270 //----------------------------------------------------------------------
271 SALOME_ModuleCatalog::Service*
272 SALOME_ModuleCatalog_AcomponentImpl::GetDefaultService(const char* interfacename)
273 throw(SALOME_ModuleCatalog::NotFound)
275 BEGIN_OF("GetDefaultService");
276 SCRUTE(interfacename);
278 Unexpect aCatch( MC_NotFound );
279 SALOME_ModuleCatalog::Service *_service = new SALOME_ModuleCatalog::Service;
281 // Variables initialisation
284 // looking for the specified interface
285 for (unsigned int ind = 0; ind < _Component.interfaces.length(); ind++)
287 if (strcmp(interfacename, _Component.interfaces[ind].interfacename) == 0)
290 // looking for the defautl service of the wanted interface
291 for (unsigned int ind1 = 0; ind1 < _Component.interfaces[ind].interfaceservicelist.length() ; ind1++)
293 if (_Component.interfaces[ind].interfaceservicelist[ind1].Servicebydefault)
296 // affect the service to be returned
298 duplicate(*_service, _Component.interfaces[ind].interfaceservicelist[ind1]);
307 // The service was not found, the exception should be thrown
308 string message = "The default service of the interface ";
309 message += interfacename;
310 message += " of the component ";
311 message += _Component.name;
312 message += " was not found";
314 throw SALOME_ModuleCatalog::NotFound(message.c_str());
317 END_OF("GetDefaultService");
321 //----------------------------------------------------------------------
322 // Function : GetPathPrefix
323 // Purpose : get the PathPrefix of a computer
324 //----------------------------------------------------------------------
326 SALOME_ModuleCatalog_AcomponentImpl::GetPathPrefix(const char* machinename)
327 throw(SALOME_ModuleCatalog::NotFound)
329 BEGIN_OF("GetPathPrefix");
331 Unexpect aCatch( MC_NotFound );
333 // Variables initialisation
337 // Parse all the path prefixes
338 // looking for the wanted computer
339 for (unsigned int ind = 0 ; ind < _Component.paths.length() ; ind++)
341 if (strcmp(machinename, _Component.paths[ind].machine) == 0)
345 // affect the path to be returned
346 const char* _temp = _Component.paths[ind].path ;
347 _path = new char[strlen(_temp)+1];
355 // The computer was not found, the exception should be thrown
356 string message = "The computer ";
357 message += machinename;
358 message += " was not found in the catalog associated to the component ";
359 message += _Component.name;
361 throw SALOME_ModuleCatalog::NotFound(message.c_str());
364 END_OF("GetPathPrefix");
368 //----------------------------------------------------------------------
369 // Function : constraint
370 // Purpose : obtain the constraint affected to a component
371 //----------------------------------------------------------------------
372 char* SALOME_ModuleCatalog_AcomponentImpl::constraint()
374 return CORBA::string_dup(_Component.constraint);
377 //----------------------------------------------------------------------
378 // Function : componentname
379 // Purpose : obtain the componentname
380 //----------------------------------------------------------------------
381 char* SALOME_ModuleCatalog_AcomponentImpl::componentname()
383 return CORBA::string_dup(_Component.name);
386 //----------------------------------------------------------------------
387 // Function : componentusername
388 // Purpose : obtain the componentusername
389 //----------------------------------------------------------------------
390 char* SALOME_ModuleCatalog_AcomponentImpl::componentusername()
392 return CORBA::string_dup(_Component.username);
395 //----------------------------------------------------------------------
396 // Function : multistudy
397 // Purpose : define if a component can be multistudy or not
398 //----------------------------------------------------------------------
399 CORBA::Boolean SALOME_ModuleCatalog_AcomponentImpl::multistudy()
401 return _Component.multistudy ;
405 //----------------------------------------------------------------------
406 // Function : implementation type
407 // Purpose : define if a component is implemented in C++ or Python
408 //----------------------------------------------------------------------
409 CORBA::Boolean SALOME_ModuleCatalog_AcomponentImpl::implementation_type()
411 return _Component.implementationType ;
414 //----------------------------------------------------------------------
415 // Function : component_type
416 // Purpose : define the type of the component
417 //----------------------------------------------------------------------
418 SALOME_ModuleCatalog::ComponentType
419 SALOME_ModuleCatalog_AcomponentImpl::component_type()
421 return _Component.type;
424 //----------------------------------------------------------------------
426 // Purpose : obtain the icone affected to a component (for IAPP)
427 //----------------------------------------------------------------------
428 char* SALOME_ModuleCatalog_AcomponentImpl::component_icone()
430 return CORBA::string_dup(_Component.icon);
434 void SALOME_ModuleCatalog_AcomponentImpl::duplicate
435 (SALOME_ModuleCatalog::ServicesParameter & P_out,
436 const SALOME_ModuleCatalog::ServicesParameter &P_in)
438 // duplicate parameter name
439 P_out.Parametername = CORBA::string_dup(P_in.Parametername);
441 // duplicate parameter type
442 P_out.Parametertype = CORBA::string_dup(P_in.Parametertype);
446 void SALOME_ModuleCatalog_AcomponentImpl::duplicate
447 (SALOME_ModuleCatalog::ServicesDataStreamParameter & P_out,
448 const SALOME_ModuleCatalog::ServicesDataStreamParameter &P_in)
450 // duplicate parameter name
451 P_out.Parametername = CORBA::string_dup(P_in.Parametername);
453 // duplicate parameter type
454 P_out.Parametertype = P_in.Parametertype;
456 // duplicate parameter dependency
457 P_out.Parameterdependency = P_in.Parameterdependency;
461 void SALOME_ModuleCatalog_AcomponentImpl::duplicate
462 (SALOME_ModuleCatalog::Service & S_out,
463 const SALOME_ModuleCatalog::Service &S_in)
466 S_out.TypeOfNode = S_in.TypeOfNode;
468 // duplicate service name
469 S_out.ServiceName = CORBA::string_dup(S_in.ServiceName);
471 // duplicate service by default
472 S_out.Servicebydefault = S_in.Servicebydefault;
474 unsigned int _length;
476 // duplicate in Parameters
477 _length = S_in.ServiceinParameter.length();
478 S_out.ServiceinParameter.length(_length);
480 for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
481 duplicate(S_out.ServiceinParameter[ind2],
482 S_in.ServiceinParameter[ind2]);
484 // duplicate out Parameters
485 _length = S_in.ServiceoutParameter.length();
486 S_out.ServiceoutParameter.length(_length);
488 for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
489 duplicate(S_out.ServiceoutParameter[ind2],
490 S_in.ServiceoutParameter[ind2]);
492 // duplicate in DataStreamParameters
493 _length = S_in.ServiceinDataStreamParameter.length();
494 S_out.ServiceinDataStreamParameter.length(_length);
496 for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
497 duplicate(S_out.ServiceinDataStreamParameter[ind2],
498 S_in.ServiceinDataStreamParameter[ind2]);
500 // duplicate out DataStreamParameters
501 _length = S_in.ServiceoutDataStreamParameter.length();
503 S_out.ServiceoutDataStreamParameter.length(_length);
505 for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
506 duplicate(S_out.ServiceoutDataStreamParameter[ind2],
507 S_in.ServiceoutDataStreamParameter[ind2]);
511 void SALOME_ModuleCatalog_AcomponentImpl::duplicate
512 (SALOME_ModuleCatalog::DefinitionInterface & I_out,
513 const SALOME_ModuleCatalog::DefinitionInterface & I_in)
515 //duplicate interface name
516 I_out.interfacename = CORBA::string_dup(I_in.interfacename);
518 // duplicate service list
519 unsigned int _length = I_in.interfaceservicelist.length();
521 I_out.interfaceservicelist.length(_length);
523 for (unsigned int ind1 = 0; ind1 < _length ; ind1 ++)
524 duplicate(I_out.interfaceservicelist[ind1],
525 I_in.interfaceservicelist[ind1]);