1 // Copyright (C) 2007-2016 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)
105 throw(SALOME_ModuleCatalog::NotFound)
107 if(MYDEBUG) BEGIN_OF("GetInterface");
108 if(MYDEBUG) SCRUTE(interfacename);
110 SALOME_ModuleCatalog::DefinitionInterface *_interface =
111 new SALOME_ModuleCatalog::DefinitionInterface;
115 // looking for the specified interface
116 for (unsigned int ind = 0; ind < _Component.interfaces.length(); ind++)
118 SALOME_ModuleCatalog::DefinitionInterface &I
119 = _Component.interfaces[ind];
121 if (strcmp(interfacename, I.interfacename) == 0)
125 duplicate(*_interface, I);
129 if(MYDEBUG) SCRUTE(_find);
132 // The interface was not found, the exception should be thrown
133 std::string message = "The interface";
134 message += interfacename;
135 message += " of the component ";
136 message += _Component.name;
137 message += " was not found";
138 if(MYDEBUG) MESSAGE(message);
139 throw SALOME_ModuleCatalog::NotFound(message.c_str());
142 if(MYDEBUG) END_OF("GetInterface");
149 //----------------------------------------------------------------------
150 // Function : GetServiceList
151 // Purpose : get a list of the services name of an interface
153 //----------------------------------------------------------------------
154 SALOME_ModuleCatalog::ListOfServices*
155 SALOME_ModuleCatalog_AcomponentImpl::GetServiceList(const char* interfacename)
156 throw(SALOME_ModuleCatalog::NotFound)
158 if(MYDEBUG) BEGIN_OF("GetServiceList");
159 if(MYDEBUG) SCRUTE(interfacename);
161 SALOME_ModuleCatalog::ListOfServices_var _list
162 = new SALOME_ModuleCatalog::ListOfServices;
164 // Variables initialisation
167 // looking for the specified interface
168 for (unsigned int ind = 0; ind < _Component.interfaces.length(); ind++)
170 SALOME_ModuleCatalog::DefinitionInterface & I = _Component.interfaces[ind];
172 if (strcmp(interfacename, I.interfacename) == 0)
176 // Get the list of services name for this interface
177 unsigned int _length_services = I.interfaceservicelist.length();
178 _list->length(_length_services);
179 for (unsigned int ind1 = 0; ind1 < _length_services ; ind1++)
181 _list[ind1] = CORBA::string_dup(I.interfaceservicelist[ind1].ServiceName);
182 if(MYDEBUG) MESSAGE("The interface " << interfacename << " of the component "
183 << _Component.name << " contains " << _list[ind1] << " as a service")
190 // The interface was not found, the exception should be thrown
191 std::string message = "The interface";
192 message += interfacename;
193 message += " of the component ";
194 message += _Component.name;
195 message += " was not found";
196 if(MYDEBUG) MESSAGE(message);
197 throw SALOME_ModuleCatalog::NotFound(message.c_str());
200 if(MYDEBUG) END_OF("GetServiceList");
201 return _list._retn();
205 //----------------------------------------------------------------------
206 // Function : GetService
207 // Purpose : get one service of an interface of a component
208 //----------------------------------------------------------------------
209 SALOME_ModuleCatalog::Service*
210 SALOME_ModuleCatalog_AcomponentImpl::GetService(const char* interfacename,
211 const char* servicename)
212 throw(SALOME_ModuleCatalog::NotFound)
214 if(MYDEBUG) BEGIN_OF("GetService");
215 if(MYDEBUG) SCRUTE(interfacename);
216 if(MYDEBUG) SCRUTE(servicename);
218 Unexpect aCatch( MC_NotFound );
219 SALOME_ModuleCatalog::Service *service = new SALOME_ModuleCatalog::Service;
221 // Variables initialization
225 // looking for the specified interface
226 for (unsigned int ind = 0; ind < _Component.interfaces.length(); ind++)
228 if(MYDEBUG) SCRUTE(ind);
229 if(MYDEBUG) SCRUTE(_Component.interfaces[ind].interfacename);
231 SALOME_ModuleCatalog::DefinitionInterface &I = _Component.interfaces[ind];
232 if (strcmp(interfacename, I.interfacename) == 0)
235 // looking for the specified service
236 for (unsigned int ind1 = 0; ind1 < I.interfaceservicelist.length() ; ind1++)
238 SALOME_ModuleCatalog::Service &S = I.interfaceservicelist[ind1];
239 if(MYDEBUG) SCRUTE(ind1);
240 if(MYDEBUG) SCRUTE(S.ServiceName);
242 if (strcmp(servicename, S.ServiceName) == 0)
245 // Affect the service to be returned
247 duplicate(*service, S);
254 if(MYDEBUG) SCRUTE(_find);
257 // The interface was not found, the exception should be thrown
258 std::string message = "The service";
259 message += servicename;
260 message += " of the interface ";
261 message += interfacename;
262 message += " of the component ";
263 message += _Component.name;
264 message += " was not found";
265 if(MYDEBUG) MESSAGE(message);
266 throw SALOME_ModuleCatalog::NotFound(message.c_str());
269 if(MYDEBUG) END_OF("GetService");
273 //----------------------------------------------------------------------
274 // Function : GetDefaultService
275 // Purpose : get the default service of the interface
276 //----------------------------------------------------------------------
277 SALOME_ModuleCatalog::Service*
278 SALOME_ModuleCatalog_AcomponentImpl::GetDefaultService(const char* interfacename)
279 throw(SALOME_ModuleCatalog::NotFound)
281 if(MYDEBUG) BEGIN_OF("GetDefaultService");
282 if(MYDEBUG) SCRUTE(interfacename);
284 Unexpect aCatch( MC_NotFound );
285 SALOME_ModuleCatalog::Service *_service = new SALOME_ModuleCatalog::Service;
287 // Variables initialisation
290 // looking for the specified interface
291 for (unsigned int ind = 0; ind < _Component.interfaces.length(); ind++)
293 if (strcmp(interfacename, _Component.interfaces[ind].interfacename) == 0)
296 // looking for the default service of the wanted interface
297 for (unsigned int ind1 = 0; ind1 < _Component.interfaces[ind].interfaceservicelist.length() ; ind1++)
299 if (_Component.interfaces[ind].interfaceservicelist[ind1].Servicebydefault)
302 // affect the service to be returned
304 duplicate(*_service, _Component.interfaces[ind].interfaceservicelist[ind1]);
313 // The service was not found, the exception should be thrown
314 std::string message = "The default service of the interface ";
315 message += interfacename;
316 message += " of the component ";
317 message += _Component.name;
318 message += " was not found";
319 if(MYDEBUG) MESSAGE(message);
320 throw SALOME_ModuleCatalog::NotFound(message.c_str());
323 if(MYDEBUG) END_OF("GetDefaultService");
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 if(MYDEBUG) BEGIN_OF("GetPathPrefix");
336 if(MYDEBUG) SCRUTE(machinename);
337 Unexpect aCatch( MC_NotFound );
339 // Variables initialisation
343 // Parse all the path prefixes
344 // looking for the wanted computer
345 for (unsigned int ind = 0 ; ind < _Component.paths.length() ; ind++)
347 if (strcmp(machinename, _Component.paths[ind].machine) == 0)
351 // affect the path to be returned
352 const char* _temp = _Component.paths[ind].path ;
353 _path = new char[strlen(_temp)+1];
358 if(MYDEBUG) SCRUTE(_find);
361 // The computer was not found, the exception should be thrown
362 std::string message = "The computer ";
363 message += machinename;
364 message += " was not found in the catalog associated to the component ";
365 message += _Component.name;
366 if(MYDEBUG) MESSAGE(message);
367 throw SALOME_ModuleCatalog::NotFound(message.c_str());
370 if(MYDEBUG) END_OF("GetPathPrefix");
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(_Component.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 : componentusername
394 // Purpose : obtain the componentusername
395 //----------------------------------------------------------------------
396 char* SALOME_ModuleCatalog_AcomponentImpl::componentusername()
398 return CORBA::string_dup(_Component.username);
401 //----------------------------------------------------------------------
402 // Function : implementation type
403 // Purpose : return the implementation type : C++ (dyn lib), Python (module) or executable
404 //----------------------------------------------------------------------
405 SALOME_ModuleCatalog::ImplType SALOME_ModuleCatalog_AcomponentImpl::implementation_type()
407 return _Component.implementationType ;
410 //----------------------------------------------------------------------
411 // Function : implementation name
412 // Purpose : return the implementation name to exec if the default one is not convenient
413 //----------------------------------------------------------------------
414 char* SALOME_ModuleCatalog_AcomponentImpl::implementation_name()
416 return _Component.implname ;
419 //----------------------------------------------------------------------
420 // Function : component_type
421 // Purpose : define the type of the component
422 //----------------------------------------------------------------------
423 SALOME_ModuleCatalog::ComponentType
424 SALOME_ModuleCatalog_AcomponentImpl::component_type()
426 return _Component.type;
429 //----------------------------------------------------------------------
431 // Purpose : obtain the icone affected to a component (for IAPP)
432 //----------------------------------------------------------------------
433 char* SALOME_ModuleCatalog_AcomponentImpl::component_icone()
435 return CORBA::string_dup(_Component.icon);
439 void SALOME_ModuleCatalog_AcomponentImpl::duplicate
440 (SALOME_ModuleCatalog::ServicesParameter & P_out,
441 const SALOME_ModuleCatalog::ServicesParameter &P_in)
443 // duplicate parameter name
444 P_out.Parametername = CORBA::string_dup(P_in.Parametername);
446 // duplicate parameter type
447 P_out.Parametertype = CORBA::string_dup(P_in.Parametertype);
451 void SALOME_ModuleCatalog_AcomponentImpl::duplicate
452 (SALOME_ModuleCatalog::ServicesDataStreamParameter & P_out,
453 const SALOME_ModuleCatalog::ServicesDataStreamParameter &P_in)
455 // duplicate parameter name
456 P_out.Parametername = CORBA::string_dup(P_in.Parametername);
458 // duplicate parameter type
459 P_out.Parametertype = P_in.Parametertype;
461 // duplicate parameter dependency
462 P_out.Parameterdependency = P_in.Parameterdependency;
466 void SALOME_ModuleCatalog_AcomponentImpl::duplicate
467 (SALOME_ModuleCatalog::Service & S_out,
468 const SALOME_ModuleCatalog::Service &S_in)
471 S_out.TypeOfNode = S_in.TypeOfNode;
473 // duplicate service name
474 S_out.ServiceName = CORBA::string_dup(S_in.ServiceName);
476 // duplicate service by default
477 S_out.Servicebydefault = S_in.Servicebydefault;
479 unsigned int _length;
481 // duplicate in Parameters
482 _length = S_in.ServiceinParameter.length();
483 S_out.ServiceinParameter.length(_length);
485 for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
486 duplicate(S_out.ServiceinParameter[ind2],
487 S_in.ServiceinParameter[ind2]);
489 // duplicate out Parameters
490 _length = S_in.ServiceoutParameter.length();
491 S_out.ServiceoutParameter.length(_length);
493 for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
494 duplicate(S_out.ServiceoutParameter[ind2],
495 S_in.ServiceoutParameter[ind2]);
497 // duplicate in DataStreamParameters
498 _length = S_in.ServiceinDataStreamParameter.length();
499 S_out.ServiceinDataStreamParameter.length(_length);
501 for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
502 duplicate(S_out.ServiceinDataStreamParameter[ind2],
503 S_in.ServiceinDataStreamParameter[ind2]);
505 // duplicate out DataStreamParameters
506 _length = S_in.ServiceoutDataStreamParameter.length();
507 if(MYDEBUG) SCRUTE(_length);
508 S_out.ServiceoutDataStreamParameter.length(_length);
510 for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
511 duplicate(S_out.ServiceoutDataStreamParameter[ind2],
512 S_in.ServiceoutDataStreamParameter[ind2]);
516 void SALOME_ModuleCatalog_AcomponentImpl::duplicate
517 (SALOME_ModuleCatalog::DefinitionInterface & I_out,
518 const SALOME_ModuleCatalog::DefinitionInterface & I_in)
520 //duplicate interface name
521 I_out.interfacename = CORBA::string_dup(I_in.interfacename);
523 // duplicate service list
524 unsigned int _length = I_in.interfaceservicelist.length();
525 if(MYDEBUG) SCRUTE(_length);
526 I_out.interfaceservicelist.length(_length);
528 for (unsigned int ind1 = 0; ind1 < _length ; ind1 ++)
529 duplicate(I_out.interfaceservicelist[ind1],
530 I_in.interfaceservicelist[ind1]);