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)
49 //----------------------------------------------------------------------
50 // Function : ~SALOME_ModuleCatalog_AcomponentImpl
51 // Purpose : Destructor
52 //----------------------------------------------------------------------
53 SALOME_ModuleCatalog_AcomponentImpl::~SALOME_ModuleCatalog_AcomponentImpl()
57 //----------------------------------------------------------------------
58 // Function : GetInterfaceList
59 // Purpose : get a list of the interfaces name of a component
60 //----------------------------------------------------------------------
61 SALOME_ModuleCatalog::ListOfInterfaces*
62 SALOME_ModuleCatalog_AcomponentImpl::GetInterfaceList()
64 SALOME_ModuleCatalog::ListOfInterfaces_var _list
65 = new SALOME_ModuleCatalog::ListOfInterfaces;
67 // All the interfaces are defined in _list_interfaces affected at the
69 unsigned int _length_interfaces = _Component.interfaces.length();
71 _list->length(_length_interfaces);
73 // Parse all the interfaces to get their name
74 for (unsigned int ind = 0; ind < _length_interfaces; ind++)
76 _list[ind] = CORBA::string_dup(_Component.interfaces[ind].interfacename);
81 //----------------------------------------------------------------------
82 // Function : GetInterface
83 // Purpose : get one interface of a component
84 //----------------------------------------------------------------------
85 SALOME_ModuleCatalog::DefinitionInterface*
86 SALOME_ModuleCatalog_AcomponentImpl::GetInterface(const char* interfacename)
88 SALOME_ModuleCatalog::DefinitionInterface *_interface =
89 new SALOME_ModuleCatalog::DefinitionInterface;
93 // looking for the specified interface
94 for (unsigned int ind = 0; ind < _Component.interfaces.length(); ind++)
96 SALOME_ModuleCatalog::DefinitionInterface &I
97 = _Component.interfaces[ind];
99 if (strcmp(interfacename, I.interfacename) == 0)
103 duplicate(*_interface, I);
108 // The interface was not found, the exception should be thrown
109 std::string message = "The interface";
110 message += interfacename;
111 message += " of the component ";
112 message += _Component.name;
113 message += " was not found";
115 throw SALOME_ModuleCatalog::NotFound(message.c_str());
122 //----------------------------------------------------------------------
123 // Function : GetServiceList
124 // Purpose : get a list of the services name of an interface
126 //----------------------------------------------------------------------
127 SALOME_ModuleCatalog::ListOfServices*
128 SALOME_ModuleCatalog_AcomponentImpl::GetServiceList(const char* interfacename)
130 SALOME_ModuleCatalog::ListOfServices_var _list
131 = new SALOME_ModuleCatalog::ListOfServices;
133 // Variables initialisation
136 // looking for the specified interface
137 for (unsigned int ind = 0; ind < _Component.interfaces.length(); ind++)
139 SALOME_ModuleCatalog::DefinitionInterface & I = _Component.interfaces[ind];
141 if (strcmp(interfacename, I.interfacename) == 0)
145 // Get the list of services name for this interface
146 unsigned int _length_services = I.interfaceservicelist.length();
147 _list->length(_length_services);
148 for (unsigned int ind1 = 0; ind1 < _length_services ; ind1++)
150 _list[ind1] = CORBA::string_dup(I.interfaceservicelist[ind1].ServiceName);
151 MESSAGE("The interface " << interfacename << " of the component "
152 << _Component.name << " contains " << _list[ind1] << " as a service");
159 // The interface was not found, the exception should be thrown
160 std::string message = "The interface";
161 message += interfacename;
162 message += " of the component ";
163 message += _Component.name;
164 message += " was not found";
166 throw SALOME_ModuleCatalog::NotFound(message.c_str());
168 return _list._retn();
172 //----------------------------------------------------------------------
173 // Function : GetService
174 // Purpose : get one service of an interface of a component
175 //----------------------------------------------------------------------
176 SALOME_ModuleCatalog::Service*
177 SALOME_ModuleCatalog_AcomponentImpl::GetService(const char* interfacename,
178 const char* servicename)
180 Unexpect aCatch( MC_NotFound );
181 SALOME_ModuleCatalog::Service *service = new SALOME_ModuleCatalog::Service;
183 // Variables initialization
187 // looking for the specified interface
188 for (unsigned int ind = 0; ind < _Component.interfaces.length(); ind++)
191 SCRUTE(_Component.interfaces[ind].interfacename);
193 SALOME_ModuleCatalog::DefinitionInterface &I = _Component.interfaces[ind];
194 if (strcmp(interfacename, I.interfacename) == 0)
197 // looking for the specified service
198 for (unsigned int ind1 = 0; ind1 < I.interfaceservicelist.length() ; ind1++)
200 SALOME_ModuleCatalog::Service &S = I.interfaceservicelist[ind1];
202 SCRUTE(S.ServiceName);
204 if (strcmp(servicename, S.ServiceName) == 0)
207 // Affect the service to be returned
209 duplicate(*service, S);
217 // The interface was not found, the exception should be thrown
218 std::string message = "The service";
219 message += servicename;
220 message += " of the interface ";
221 message += interfacename;
222 message += " of the component ";
223 message += _Component.name;
224 message += " was not found";
226 throw SALOME_ModuleCatalog::NotFound(message.c_str());
231 //----------------------------------------------------------------------
232 // Function : GetDefaultService
233 // Purpose : get the default service of the interface
234 //----------------------------------------------------------------------
235 SALOME_ModuleCatalog::Service*
236 SALOME_ModuleCatalog_AcomponentImpl::GetDefaultService(const char* interfacename)
238 Unexpect aCatch( MC_NotFound );
239 SALOME_ModuleCatalog::Service *_service = new SALOME_ModuleCatalog::Service;
241 // Variables initialisation
244 // looking for the specified interface
245 for (unsigned int ind = 0; ind < _Component.interfaces.length(); ind++)
247 if (strcmp(interfacename, _Component.interfaces[ind].interfacename) == 0)
250 // looking for the default service of the wanted interface
251 for (unsigned int ind1 = 0; ind1 < _Component.interfaces[ind].interfaceservicelist.length() ; ind1++)
253 if (_Component.interfaces[ind].interfaceservicelist[ind1].Servicebydefault)
256 // affect the service to be returned
258 duplicate(*_service, _Component.interfaces[ind].interfaceservicelist[ind1]);
267 // The service was not found, the exception should be thrown
268 std::string message = "The default service of the interface ";
269 message += interfacename;
270 message += " of the component ";
271 message += _Component.name;
272 message += " was not found";
274 throw SALOME_ModuleCatalog::NotFound(message.c_str());
279 //----------------------------------------------------------------------
280 // Function : GetPathPrefix
281 // Purpose : get the PathPrefix of a computer
282 //----------------------------------------------------------------------
284 SALOME_ModuleCatalog_AcomponentImpl::GetPathPrefix(const char* machinename)
286 BEGIN_OF("GetPathPrefix");
288 Unexpect aCatch( MC_NotFound );
290 // Variables initialisation
294 // Parse all the path prefixes
295 // looking for the wanted computer
296 for (unsigned int ind = 0 ; ind < _Component.paths.length() ; ind++)
298 if (strcmp(machinename, _Component.paths[ind].machine) == 0)
302 // affect the path to be returned
303 const char* _temp = _Component.paths[ind].path ;
304 _path = new char[strlen(_temp)+1];
312 // The computer was not found, the exception should be thrown
313 std::string message = "The computer ";
314 message += machinename;
315 message += " was not found in the catalog associated to the component ";
316 message += _Component.name;
318 throw SALOME_ModuleCatalog::NotFound(message.c_str());
321 END_OF("GetPathPrefix");
325 //----------------------------------------------------------------------
326 // Function : constraint
327 // Purpose : obtain the constraint affected to a component
328 //----------------------------------------------------------------------
329 char* SALOME_ModuleCatalog_AcomponentImpl::constraint()
331 return CORBA::string_dup(_Component.constraint);
334 //----------------------------------------------------------------------
335 // Function : componentname
336 // Purpose : obtain the componentname
337 //----------------------------------------------------------------------
338 char* SALOME_ModuleCatalog_AcomponentImpl::componentname()
340 return CORBA::string_dup(_Component.name);
343 //----------------------------------------------------------------------
344 // Function : componentusername
345 // Purpose : obtain the componentusername
346 //----------------------------------------------------------------------
347 char* SALOME_ModuleCatalog_AcomponentImpl::componentusername()
349 return CORBA::string_dup(_Component.username);
352 //----------------------------------------------------------------------
353 // Function : implementation type
354 // Purpose : return the implementation type : C++ (dyn lib), Python (module) or executable
355 //----------------------------------------------------------------------
356 SALOME_ModuleCatalog::ImplType SALOME_ModuleCatalog_AcomponentImpl::implementation_type()
358 return _Component.implementationType ;
361 //----------------------------------------------------------------------
362 // Function : implementation name
363 // Purpose : return the implementation name to exec if the default one is not convenient
364 //----------------------------------------------------------------------
365 char* SALOME_ModuleCatalog_AcomponentImpl::implementation_name()
367 return _Component.implname ;
370 //----------------------------------------------------------------------
371 // Function : component_type
372 // Purpose : define the type of the component
373 //----------------------------------------------------------------------
374 SALOME_ModuleCatalog::ComponentType
375 SALOME_ModuleCatalog_AcomponentImpl::component_type()
377 return _Component.type;
380 //----------------------------------------------------------------------
382 // Purpose : obtain the icone affected to a component (for IAPP)
383 //----------------------------------------------------------------------
384 char* SALOME_ModuleCatalog_AcomponentImpl::component_icone()
386 return CORBA::string_dup(_Component.icon);
390 void SALOME_ModuleCatalog_AcomponentImpl::duplicate
391 (SALOME_ModuleCatalog::ServicesParameter & P_out,
392 const SALOME_ModuleCatalog::ServicesParameter &P_in)
394 // duplicate parameter name
395 P_out.Parametername = CORBA::string_dup(P_in.Parametername);
397 // duplicate parameter type
398 P_out.Parametertype = CORBA::string_dup(P_in.Parametertype);
402 void SALOME_ModuleCatalog_AcomponentImpl::duplicate
403 (SALOME_ModuleCatalog::ServicesDataStreamParameter & P_out,
404 const SALOME_ModuleCatalog::ServicesDataStreamParameter &P_in)
406 // duplicate parameter name
407 P_out.Parametername = CORBA::string_dup(P_in.Parametername);
409 // duplicate parameter type
410 P_out.Parametertype = P_in.Parametertype;
412 // duplicate parameter dependency
413 P_out.Parameterdependency = P_in.Parameterdependency;
417 void SALOME_ModuleCatalog_AcomponentImpl::duplicate
418 (SALOME_ModuleCatalog::Service & S_out,
419 const SALOME_ModuleCatalog::Service &S_in)
422 S_out.TypeOfNode = S_in.TypeOfNode;
424 // duplicate service name
425 S_out.ServiceName = CORBA::string_dup(S_in.ServiceName);
427 // duplicate service by default
428 S_out.Servicebydefault = S_in.Servicebydefault;
430 unsigned int _length;
432 // duplicate in Parameters
433 _length = S_in.ServiceinParameter.length();
434 S_out.ServiceinParameter.length(_length);
436 for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
437 duplicate(S_out.ServiceinParameter[ind2],
438 S_in.ServiceinParameter[ind2]);
440 // duplicate out Parameters
441 _length = S_in.ServiceoutParameter.length();
442 S_out.ServiceoutParameter.length(_length);
444 for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
445 duplicate(S_out.ServiceoutParameter[ind2],
446 S_in.ServiceoutParameter[ind2]);
448 // duplicate in DataStreamParameters
449 _length = S_in.ServiceinDataStreamParameter.length();
450 S_out.ServiceinDataStreamParameter.length(_length);
452 for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
453 duplicate(S_out.ServiceinDataStreamParameter[ind2],
454 S_in.ServiceinDataStreamParameter[ind2]);
456 // duplicate out DataStreamParameters
457 _length = S_in.ServiceoutDataStreamParameter.length();
458 S_out.ServiceoutDataStreamParameter.length(_length);
460 for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
461 duplicate(S_out.ServiceoutDataStreamParameter[ind2],
462 S_in.ServiceoutDataStreamParameter[ind2]);
466 void SALOME_ModuleCatalog_AcomponentImpl::duplicate
467 (SALOME_ModuleCatalog::DefinitionInterface & I_out,
468 const SALOME_ModuleCatalog::DefinitionInterface & I_in)
470 //duplicate interface name
471 I_out.interfacename = CORBA::string_dup(I_in.interfacename);
473 // duplicate service list
474 unsigned int _length = I_in.interfaceservicelist.length();
475 I_out.interfaceservicelist.length(_length);
477 for (unsigned int ind1 = 0; ind1 < _length ; ind1 ++)
478 duplicate(I_out.interfaceservicelist[ind1],
479 I_in.interfaceservicelist[ind1]);