1 // Copyright (C) 2007-2020 CEA/DEN, EDF R&D, 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 static int MYDEBUG = 0;
39 static int MYDEBUG = 0;
42 //----------------------------------------------------------------------
43 // Function : SALOME_ModuleCatalog_AcomponentImpl
44 // Purpose : Constructor
45 // Affect the component name, type,icon
46 // Affect too the constraint and the interfaces of the component
47 // and the path prefixes for all computers
48 //----------------------------------------------------------------------
49 SALOME_ModuleCatalog_AcomponentImpl::SALOME_ModuleCatalog_AcomponentImpl
50 (SALOME_ModuleCatalog::ComponentDef &C) : _Component(C)
52 if(MYDEBUG) BEGIN_OF("SALOME_ModuleCatalog_AcomponentImpl");
54 if(MYDEBUG) END_OF("SALOME_ModuleCatalog_AcomponentImpl");
57 //----------------------------------------------------------------------
58 // Function : ~SALOME_ModuleCatalog_AcomponentImpl
59 // Purpose : Destructor
60 //----------------------------------------------------------------------
61 SALOME_ModuleCatalog_AcomponentImpl::~SALOME_ModuleCatalog_AcomponentImpl()
63 if(MYDEBUG) BEGIN_OF("~SALOME_ModuleCatalog_AcomponentImpl");
66 if(MYDEBUG) END_OF("~SALOME_ModuleCatalog_AcomponentImpl");
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 if(MYDEBUG) BEGIN_OF("GetInterfaceList");
78 SALOME_ModuleCatalog::ListOfInterfaces_var _list
79 = new SALOME_ModuleCatalog::ListOfInterfaces;
81 // All the interfaces are defined in _list_interfaces affected at the
83 unsigned int _length_interfaces = _Component.interfaces.length();
85 _list->length(_length_interfaces);
87 // Parse all the interfaces to get their name
88 for (unsigned int ind = 0; ind < _length_interfaces; ind++)
90 _list[ind] = CORBA::string_dup(_Component.interfaces[ind].interfacename);
91 if(MYDEBUG) MESSAGE("The component " << _Component.name
92 << " contains " << _list[ind] << " as interface");
95 if(MYDEBUG) END_OF("GetInterfaceList");
99 //----------------------------------------------------------------------
100 // Function : GetInterface
101 // Purpose : get one interface of a component
102 //----------------------------------------------------------------------
103 SALOME_ModuleCatalog::DefinitionInterface*
104 SALOME_ModuleCatalog_AcomponentImpl::GetInterface(const char* interfacename)
106 if(MYDEBUG) BEGIN_OF("GetInterface");
107 if(MYDEBUG) SCRUTE(interfacename);
109 SALOME_ModuleCatalog::DefinitionInterface *_interface =
110 new SALOME_ModuleCatalog::DefinitionInterface;
114 // looking for the specified interface
115 for (unsigned int ind = 0; ind < _Component.interfaces.length(); ind++)
117 SALOME_ModuleCatalog::DefinitionInterface &I
118 = _Component.interfaces[ind];
120 if (strcmp(interfacename, I.interfacename) == 0)
124 duplicate(*_interface, I);
128 if(MYDEBUG) SCRUTE(_find);
131 // The interface was not found, the exception should be thrown
132 std::string message = "The interface";
133 message += interfacename;
134 message += " of the component ";
135 message += _Component.name;
136 message += " was not found";
137 if(MYDEBUG) MESSAGE(message);
138 throw SALOME_ModuleCatalog::NotFound(message.c_str());
141 if(MYDEBUG) END_OF("GetInterface");
148 //----------------------------------------------------------------------
149 // Function : GetServiceList
150 // Purpose : get a list of the services name of an interface
152 //----------------------------------------------------------------------
153 SALOME_ModuleCatalog::ListOfServices*
154 SALOME_ModuleCatalog_AcomponentImpl::GetServiceList(const char* interfacename)
156 if(MYDEBUG) BEGIN_OF("GetServiceList");
157 if(MYDEBUG) SCRUTE(interfacename);
159 SALOME_ModuleCatalog::ListOfServices_var _list
160 = new SALOME_ModuleCatalog::ListOfServices;
162 // Variables initialisation
165 // looking for the specified interface
166 for (unsigned int ind = 0; ind < _Component.interfaces.length(); ind++)
168 SALOME_ModuleCatalog::DefinitionInterface & I = _Component.interfaces[ind];
170 if (strcmp(interfacename, I.interfacename) == 0)
174 // Get the list of services name for this interface
175 unsigned int _length_services = I.interfaceservicelist.length();
176 _list->length(_length_services);
177 for (unsigned int ind1 = 0; ind1 < _length_services ; ind1++)
179 _list[ind1] = CORBA::string_dup(I.interfaceservicelist[ind1].ServiceName);
180 if(MYDEBUG) MESSAGE("The interface " << interfacename << " of the component "
181 << _Component.name << " contains " << _list[ind1] << " as a service")
188 // The interface was not found, the exception should be thrown
189 std::string message = "The interface";
190 message += interfacename;
191 message += " of the component ";
192 message += _Component.name;
193 message += " was not found";
194 if(MYDEBUG) MESSAGE(message);
195 throw SALOME_ModuleCatalog::NotFound(message.c_str());
198 if(MYDEBUG) END_OF("GetServiceList");
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)
211 if(MYDEBUG) BEGIN_OF("GetService");
212 if(MYDEBUG) SCRUTE(interfacename);
213 if(MYDEBUG) SCRUTE(servicename);
215 Unexpect aCatch( MC_NotFound );
216 SALOME_ModuleCatalog::Service *service = new SALOME_ModuleCatalog::Service;
218 // Variables initialization
222 // looking for the specified interface
223 for (unsigned int ind = 0; ind < _Component.interfaces.length(); ind++)
225 if(MYDEBUG) SCRUTE(ind);
226 if(MYDEBUG) SCRUTE(_Component.interfaces[ind].interfacename);
228 SALOME_ModuleCatalog::DefinitionInterface &I = _Component.interfaces[ind];
229 if (strcmp(interfacename, I.interfacename) == 0)
232 // looking for the specified service
233 for (unsigned int ind1 = 0; ind1 < I.interfaceservicelist.length() ; ind1++)
235 SALOME_ModuleCatalog::Service &S = I.interfaceservicelist[ind1];
236 if(MYDEBUG) SCRUTE(ind1);
237 if(MYDEBUG) SCRUTE(S.ServiceName);
239 if (strcmp(servicename, S.ServiceName) == 0)
242 // Affect the service to be returned
244 duplicate(*service, S);
251 if(MYDEBUG) SCRUTE(_find);
254 // The interface was not found, the exception should be thrown
255 std::string message = "The service";
256 message += servicename;
257 message += " of the interface ";
258 message += interfacename;
259 message += " of the component ";
260 message += _Component.name;
261 message += " was not found";
262 if(MYDEBUG) MESSAGE(message);
263 throw SALOME_ModuleCatalog::NotFound(message.c_str());
266 if(MYDEBUG) END_OF("GetService");
270 //----------------------------------------------------------------------
271 // Function : GetDefaultService
272 // Purpose : get the default service of the interface
273 //----------------------------------------------------------------------
274 SALOME_ModuleCatalog::Service*
275 SALOME_ModuleCatalog_AcomponentImpl::GetDefaultService(const char* interfacename)
277 if(MYDEBUG) BEGIN_OF("GetDefaultService");
278 if(MYDEBUG) SCRUTE(interfacename);
280 Unexpect aCatch( MC_NotFound );
281 SALOME_ModuleCatalog::Service *_service = new SALOME_ModuleCatalog::Service;
283 // Variables initialisation
286 // looking for the specified interface
287 for (unsigned int ind = 0; ind < _Component.interfaces.length(); ind++)
289 if (strcmp(interfacename, _Component.interfaces[ind].interfacename) == 0)
292 // looking for the default service of the wanted interface
293 for (unsigned int ind1 = 0; ind1 < _Component.interfaces[ind].interfaceservicelist.length() ; ind1++)
295 if (_Component.interfaces[ind].interfaceservicelist[ind1].Servicebydefault)
298 // affect the service to be returned
300 duplicate(*_service, _Component.interfaces[ind].interfaceservicelist[ind1]);
309 // The service was not found, the exception should be thrown
310 std::string message = "The default service of the interface ";
311 message += interfacename;
312 message += " of the component ";
313 message += _Component.name;
314 message += " was not found";
315 if(MYDEBUG) MESSAGE(message);
316 throw SALOME_ModuleCatalog::NotFound(message.c_str());
319 if(MYDEBUG) END_OF("GetDefaultService");
323 //----------------------------------------------------------------------
324 // Function : GetPathPrefix
325 // Purpose : get the PathPrefix of a computer
326 //----------------------------------------------------------------------
328 SALOME_ModuleCatalog_AcomponentImpl::GetPathPrefix(const char* machinename)
330 if(MYDEBUG) BEGIN_OF("GetPathPrefix");
331 if(MYDEBUG) SCRUTE(machinename);
332 Unexpect aCatch( MC_NotFound );
334 // Variables initialisation
338 // Parse all the path prefixes
339 // looking for the wanted computer
340 for (unsigned int ind = 0 ; ind < _Component.paths.length() ; ind++)
342 if (strcmp(machinename, _Component.paths[ind].machine) == 0)
346 // affect the path to be returned
347 const char* _temp = _Component.paths[ind].path ;
348 _path = new char[strlen(_temp)+1];
353 if(MYDEBUG) SCRUTE(_find);
356 // The computer was not found, the exception should be thrown
357 std::string message = "The computer ";
358 message += machinename;
359 message += " was not found in the catalog associated to the component ";
360 message += _Component.name;
361 if(MYDEBUG) MESSAGE(message);
362 throw SALOME_ModuleCatalog::NotFound(message.c_str());
365 if(MYDEBUG) END_OF("GetPathPrefix");
369 //----------------------------------------------------------------------
370 // Function : constraint
371 // Purpose : obtain the constraint affected to a component
372 //----------------------------------------------------------------------
373 char* SALOME_ModuleCatalog_AcomponentImpl::constraint()
375 return CORBA::string_dup(_Component.constraint);
378 //----------------------------------------------------------------------
379 // Function : componentname
380 // Purpose : obtain the componentname
381 //----------------------------------------------------------------------
382 char* SALOME_ModuleCatalog_AcomponentImpl::componentname()
384 return CORBA::string_dup(_Component.name);
387 //----------------------------------------------------------------------
388 // Function : componentusername
389 // Purpose : obtain the componentusername
390 //----------------------------------------------------------------------
391 char* SALOME_ModuleCatalog_AcomponentImpl::componentusername()
393 return CORBA::string_dup(_Component.username);
396 //----------------------------------------------------------------------
397 // Function : implementation type
398 // Purpose : return the implementation type : C++ (dyn lib), Python (module) or executable
399 //----------------------------------------------------------------------
400 SALOME_ModuleCatalog::ImplType SALOME_ModuleCatalog_AcomponentImpl::implementation_type()
402 return _Component.implementationType ;
405 //----------------------------------------------------------------------
406 // Function : implementation name
407 // Purpose : return the implementation name to exec if the default one is not convenient
408 //----------------------------------------------------------------------
409 char* SALOME_ModuleCatalog_AcomponentImpl::implementation_name()
411 return _Component.implname ;
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();
502 if(MYDEBUG) SCRUTE(_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();
520 if(MYDEBUG) SCRUTE(_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]);