1 // Copyright (C) 2007-2024 CEA, EDF, OPEN CASCADE
3 // Copyright (C) 2003-2007 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, or (at your option) any later version.
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.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SALOME ModuleCatalog : implementation of ModuleCatalog server which parsers xml description of modules
24 // File : SALOME_ModuleCatalog_Acomponent_impl.cxx
25 // Author : Estelle Deville
29 #include "SALOME_ModuleCatalog_Acomponent_impl.hxx"
31 #include "Utils_ExceptHandlers.hxx"
32 UNEXPECT_CATCH(MC_NotFound, SALOME_ModuleCatalog::NotFound)
34 #include "utilities.h"
37 //----------------------------------------------------------------------
38 // Function : SALOME_ModuleCatalog_AcomponentImpl
39 // Purpose : Constructor
40 // Affect the component name, type,icon
41 // Affect too the constraint and the interfaces of the component
42 // and the path prefixes for all computers
43 //----------------------------------------------------------------------
44 SALOME_ModuleCatalog_AcomponentImpl::SALOME_ModuleCatalog_AcomponentImpl
45 (SALOME_ModuleCatalog::ComponentDef &C) : _Component(C)
47 BEGIN_OF("SALOME_ModuleCatalog_AcomponentImpl");
49 END_OF("SALOME_ModuleCatalog_AcomponentImpl");
52 //----------------------------------------------------------------------
53 // Function : ~SALOME_ModuleCatalog_AcomponentImpl
54 // Purpose : Destructor
55 //----------------------------------------------------------------------
56 SALOME_ModuleCatalog_AcomponentImpl::~SALOME_ModuleCatalog_AcomponentImpl()
58 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)
100 BEGIN_OF("GetInterface");
101 SCRUTE(interfacename);
103 SALOME_ModuleCatalog::DefinitionInterface *_interface =
104 new SALOME_ModuleCatalog::DefinitionInterface;
108 // looking for the specified interface
109 for (unsigned int ind = 0; ind < _Component.interfaces.length(); ind++)
111 SALOME_ModuleCatalog::DefinitionInterface &I
112 = _Component.interfaces[ind];
114 if (strcmp(interfacename, I.interfacename) == 0)
118 duplicate(*_interface, I);
125 // The interface was not found, the exception should be thrown
126 std::string message = "The interface";
127 message += interfacename;
128 message += " of the component ";
129 message += _Component.name;
130 message += " was not found";
132 throw SALOME_ModuleCatalog::NotFound(message.c_str());
135 END_OF("GetInterface");
142 //----------------------------------------------------------------------
143 // Function : GetServiceList
144 // Purpose : get a list of the services name of an interface
146 //----------------------------------------------------------------------
147 SALOME_ModuleCatalog::ListOfServices*
148 SALOME_ModuleCatalog_AcomponentImpl::GetServiceList(const char* interfacename)
150 BEGIN_OF("GetServiceList");
151 SCRUTE(interfacename);
153 SALOME_ModuleCatalog::ListOfServices_var _list
154 = new SALOME_ModuleCatalog::ListOfServices;
156 // Variables initialisation
159 // looking for the specified interface
160 for (unsigned int ind = 0; ind < _Component.interfaces.length(); ind++)
162 SALOME_ModuleCatalog::DefinitionInterface & I = _Component.interfaces[ind];
164 if (strcmp(interfacename, I.interfacename) == 0)
168 // Get the list of services name for this interface
169 unsigned int _length_services = I.interfaceservicelist.length();
170 _list->length(_length_services);
171 for (unsigned int ind1 = 0; ind1 < _length_services ; ind1++)
173 _list[ind1] = CORBA::string_dup(I.interfaceservicelist[ind1].ServiceName);
174 MESSAGE("The interface " << interfacename << " of the component "
175 << _Component.name << " contains " << _list[ind1] << " as a service");
182 // The interface was not found, the exception should be thrown
183 std::string message = "The interface";
184 message += interfacename;
185 message += " of the component ";
186 message += _Component.name;
187 message += " was not found";
189 throw SALOME_ModuleCatalog::NotFound(message.c_str());
192 END_OF("GetServiceList");
193 return _list._retn();
197 //----------------------------------------------------------------------
198 // Function : GetService
199 // Purpose : get one service of an interface of a component
200 //----------------------------------------------------------------------
201 SALOME_ModuleCatalog::Service*
202 SALOME_ModuleCatalog_AcomponentImpl::GetService(const char* interfacename,
203 const char* servicename)
205 BEGIN_OF("GetService");
206 SCRUTE(interfacename);
209 Unexpect aCatch( MC_NotFound );
210 SALOME_ModuleCatalog::Service *service = new SALOME_ModuleCatalog::Service;
212 // Variables initialization
216 // looking for the specified interface
217 for (unsigned int ind = 0; ind < _Component.interfaces.length(); ind++)
220 SCRUTE(_Component.interfaces[ind].interfacename);
222 SALOME_ModuleCatalog::DefinitionInterface &I = _Component.interfaces[ind];
223 if (strcmp(interfacename, I.interfacename) == 0)
226 // looking for the specified service
227 for (unsigned int ind1 = 0; ind1 < I.interfaceservicelist.length() ; ind1++)
229 SALOME_ModuleCatalog::Service &S = I.interfaceservicelist[ind1];
231 SCRUTE(S.ServiceName);
233 if (strcmp(servicename, S.ServiceName) == 0)
236 // Affect the service to be returned
238 duplicate(*service, S);
248 // The interface was not found, the exception should be thrown
249 std::string message = "The service";
250 message += servicename;
251 message += " of the interface ";
252 message += interfacename;
253 message += " of the component ";
254 message += _Component.name;
255 message += " was not found";
257 throw SALOME_ModuleCatalog::NotFound(message.c_str());
260 END_OF("GetService");
264 //----------------------------------------------------------------------
265 // Function : GetDefaultService
266 // Purpose : get the default service of the interface
267 //----------------------------------------------------------------------
268 SALOME_ModuleCatalog::Service*
269 SALOME_ModuleCatalog_AcomponentImpl::GetDefaultService(const char* interfacename)
271 BEGIN_OF("GetDefaultService");
272 SCRUTE(interfacename);
274 Unexpect aCatch( MC_NotFound );
275 SALOME_ModuleCatalog::Service *_service = new SALOME_ModuleCatalog::Service;
277 // Variables initialisation
280 // looking for the specified interface
281 for (unsigned int ind = 0; ind < _Component.interfaces.length(); ind++)
283 if (strcmp(interfacename, _Component.interfaces[ind].interfacename) == 0)
286 // looking for the default service of the wanted interface
287 for (unsigned int ind1 = 0; ind1 < _Component.interfaces[ind].interfaceservicelist.length() ; ind1++)
289 if (_Component.interfaces[ind].interfaceservicelist[ind1].Servicebydefault)
292 // affect the service to be returned
294 duplicate(*_service, _Component.interfaces[ind].interfaceservicelist[ind1]);
303 // The service was not found, the exception should be thrown
304 std::string message = "The default service of the interface ";
305 message += interfacename;
306 message += " of the component ";
307 message += _Component.name;
308 message += " was not found";
310 throw SALOME_ModuleCatalog::NotFound(message.c_str());
313 END_OF("GetDefaultService");
317 //----------------------------------------------------------------------
318 // Function : GetPathPrefix
319 // Purpose : get the PathPrefix of a computer
320 //----------------------------------------------------------------------
322 SALOME_ModuleCatalog_AcomponentImpl::GetPathPrefix(const char* machinename)
324 BEGIN_OF("GetPathPrefix");
326 Unexpect aCatch( MC_NotFound );
328 // Variables initialisation
332 // Parse all the path prefixes
333 // looking for the wanted computer
334 for (unsigned int ind = 0 ; ind < _Component.paths.length() ; ind++)
336 if (strcmp(machinename, _Component.paths[ind].machine) == 0)
340 // affect the path to be returned
341 const char* _temp = _Component.paths[ind].path ;
342 _path = new char[strlen(_temp)+1];
350 // The computer was not found, the exception should be thrown
351 std::string message = "The computer ";
352 message += machinename;
353 message += " was not found in the catalog associated to the component ";
354 message += _Component.name;
356 throw SALOME_ModuleCatalog::NotFound(message.c_str());
359 END_OF("GetPathPrefix");
363 //----------------------------------------------------------------------
364 // Function : constraint
365 // Purpose : obtain the constraint affected to a component
366 //----------------------------------------------------------------------
367 char* SALOME_ModuleCatalog_AcomponentImpl::constraint()
369 return CORBA::string_dup(_Component.constraint);
372 //----------------------------------------------------------------------
373 // Function : componentname
374 // Purpose : obtain the componentname
375 //----------------------------------------------------------------------
376 char* SALOME_ModuleCatalog_AcomponentImpl::componentname()
378 return CORBA::string_dup(_Component.name);
381 //----------------------------------------------------------------------
382 // Function : componentusername
383 // Purpose : obtain the componentusername
384 //----------------------------------------------------------------------
385 char* SALOME_ModuleCatalog_AcomponentImpl::componentusername()
387 return CORBA::string_dup(_Component.username);
390 //----------------------------------------------------------------------
391 // Function : implementation type
392 // Purpose : return the implementation type : C++ (dyn lib), Python (module) or executable
393 //----------------------------------------------------------------------
394 SALOME_ModuleCatalog::ImplType SALOME_ModuleCatalog_AcomponentImpl::implementation_type()
396 return _Component.implementationType ;
399 //----------------------------------------------------------------------
400 // Function : implementation name
401 // Purpose : return the implementation name to exec if the default one is not convenient
402 //----------------------------------------------------------------------
403 char* SALOME_ModuleCatalog_AcomponentImpl::implementation_name()
405 return _Component.implname ;
408 //----------------------------------------------------------------------
409 // Function : component_type
410 // Purpose : define the type of the component
411 //----------------------------------------------------------------------
412 SALOME_ModuleCatalog::ComponentType
413 SALOME_ModuleCatalog_AcomponentImpl::component_type()
415 return _Component.type;
418 //----------------------------------------------------------------------
420 // Purpose : obtain the icone affected to a component (for IAPP)
421 //----------------------------------------------------------------------
422 char* SALOME_ModuleCatalog_AcomponentImpl::component_icone()
424 return CORBA::string_dup(_Component.icon);
428 void SALOME_ModuleCatalog_AcomponentImpl::duplicate
429 (SALOME_ModuleCatalog::ServicesParameter & P_out,
430 const SALOME_ModuleCatalog::ServicesParameter &P_in)
432 // duplicate parameter name
433 P_out.Parametername = CORBA::string_dup(P_in.Parametername);
435 // duplicate parameter type
436 P_out.Parametertype = CORBA::string_dup(P_in.Parametertype);
440 void SALOME_ModuleCatalog_AcomponentImpl::duplicate
441 (SALOME_ModuleCatalog::ServicesDataStreamParameter & P_out,
442 const SALOME_ModuleCatalog::ServicesDataStreamParameter &P_in)
444 // duplicate parameter name
445 P_out.Parametername = CORBA::string_dup(P_in.Parametername);
447 // duplicate parameter type
448 P_out.Parametertype = P_in.Parametertype;
450 // duplicate parameter dependency
451 P_out.Parameterdependency = P_in.Parameterdependency;
455 void SALOME_ModuleCatalog_AcomponentImpl::duplicate
456 (SALOME_ModuleCatalog::Service & S_out,
457 const SALOME_ModuleCatalog::Service &S_in)
460 S_out.TypeOfNode = S_in.TypeOfNode;
462 // duplicate service name
463 S_out.ServiceName = CORBA::string_dup(S_in.ServiceName);
465 // duplicate service by default
466 S_out.Servicebydefault = S_in.Servicebydefault;
468 unsigned int _length;
470 // duplicate in Parameters
471 _length = S_in.ServiceinParameter.length();
472 S_out.ServiceinParameter.length(_length);
474 for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
475 duplicate(S_out.ServiceinParameter[ind2],
476 S_in.ServiceinParameter[ind2]);
478 // duplicate out Parameters
479 _length = S_in.ServiceoutParameter.length();
480 S_out.ServiceoutParameter.length(_length);
482 for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
483 duplicate(S_out.ServiceoutParameter[ind2],
484 S_in.ServiceoutParameter[ind2]);
486 // duplicate in DataStreamParameters
487 _length = S_in.ServiceinDataStreamParameter.length();
488 S_out.ServiceinDataStreamParameter.length(_length);
490 for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
491 duplicate(S_out.ServiceinDataStreamParameter[ind2],
492 S_in.ServiceinDataStreamParameter[ind2]);
494 // duplicate out DataStreamParameters
495 _length = S_in.ServiceoutDataStreamParameter.length();
497 S_out.ServiceoutDataStreamParameter.length(_length);
499 for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
500 duplicate(S_out.ServiceoutDataStreamParameter[ind2],
501 S_in.ServiceoutDataStreamParameter[ind2]);
505 void SALOME_ModuleCatalog_AcomponentImpl::duplicate
506 (SALOME_ModuleCatalog::DefinitionInterface & I_out,
507 const SALOME_ModuleCatalog::DefinitionInterface & I_in)
509 //duplicate interface name
510 I_out.interfacename = CORBA::string_dup(I_in.interfacename);
512 // duplicate service list
513 unsigned int _length = I_in.interfaceservicelist.length();
515 I_out.interfaceservicelist.length(_length);
517 for (unsigned int ind1 = 0; ind1 < _length ; ind1 ++)
518 duplicate(I_out.interfaceservicelist[ind1],
519 I_in.interfaceservicelist[ind1]);