1 // Copyright (C) 2007-2014 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,icone, a bool to define
46 // if it's multistudy or not.
47 // Affect too the constraint and the interfaces of the component
48 // and the pathes prefixes for all computers
49 //----------------------------------------------------------------------
50 SALOME_ModuleCatalog_AcomponentImpl::SALOME_ModuleCatalog_AcomponentImpl
51 (SALOME_ModuleCatalog::ComponentDef &C) : _Component(C)
53 if(MYDEBUG) BEGIN_OF("SALOME_ModuleCatalog_AcomponentImpl");
55 if(MYDEBUG) END_OF("SALOME_ModuleCatalog_AcomponentImpl");
58 //----------------------------------------------------------------------
59 // Function : ~SALOME_ModuleCatalog_AcomponentImpl
60 // Purpose : Destructor
61 //----------------------------------------------------------------------
62 SALOME_ModuleCatalog_AcomponentImpl::~SALOME_ModuleCatalog_AcomponentImpl()
64 if(MYDEBUG) BEGIN_OF("~SALOME_ModuleCatalog_AcomponentImpl");
67 if(MYDEBUG) END_OF("~SALOME_ModuleCatalog_AcomponentImpl");
70 //----------------------------------------------------------------------
71 // Function : GetInterfaceList
72 // Purpose : get a list of the interfaces name of a component
73 //----------------------------------------------------------------------
74 SALOME_ModuleCatalog::ListOfInterfaces*
75 SALOME_ModuleCatalog_AcomponentImpl::GetInterfaceList()
77 if(MYDEBUG) BEGIN_OF("GetInterfaceList");
79 SALOME_ModuleCatalog::ListOfInterfaces_var _list
80 = new SALOME_ModuleCatalog::ListOfInterfaces;
82 // All the interfaces are defined in _list_interfaces affected at the
84 unsigned int _length_interfaces = _Component.interfaces.length();
86 _list->length(_length_interfaces);
88 // Parse all the interfaces to get their name
89 for (unsigned int ind = 0; ind < _length_interfaces; ind++)
91 _list[ind] = CORBA::string_dup(_Component.interfaces[ind].interfacename);
92 if(MYDEBUG) MESSAGE("The component " << _Component.name
93 << " contains " << _list[ind] << " as interface");
96 if(MYDEBUG) END_OF("GetInterfaceList");
100 //----------------------------------------------------------------------
101 // Function : GetInterface
102 // Purpose : get one interface of a component
103 //----------------------------------------------------------------------
104 SALOME_ModuleCatalog::DefinitionInterface*
105 SALOME_ModuleCatalog_AcomponentImpl::GetInterface(const char* interfacename)
106 throw(SALOME_ModuleCatalog::NotFound)
108 if(MYDEBUG) BEGIN_OF("GetInterface");
109 if(MYDEBUG) SCRUTE(interfacename);
111 SALOME_ModuleCatalog::DefinitionInterface *_interface =
112 new SALOME_ModuleCatalog::DefinitionInterface;
116 // looking for the specified interface
117 for (unsigned int ind = 0; ind < _Component.interfaces.length(); ind++)
119 SALOME_ModuleCatalog::DefinitionInterface &I
120 = _Component.interfaces[ind];
122 if (strcmp(interfacename, I.interfacename) == 0)
126 duplicate(*_interface, I);
130 if(MYDEBUG) SCRUTE(_find);
133 // The interface was not found, the exception should be thrown
134 std::string message = "The interface";
135 message += interfacename;
136 message += " of the component ";
137 message += _Component.name;
138 message += " was not found";
139 if(MYDEBUG) MESSAGE(message);
140 throw SALOME_ModuleCatalog::NotFound(message.c_str());
143 if(MYDEBUG) END_OF("GetInterface");
150 //----------------------------------------------------------------------
151 // Function : GetServiceList
152 // Purpose : get a list of the services name of an interface
154 //----------------------------------------------------------------------
155 SALOME_ModuleCatalog::ListOfServices*
156 SALOME_ModuleCatalog_AcomponentImpl::GetServiceList(const char* interfacename)
157 throw(SALOME_ModuleCatalog::NotFound)
159 if(MYDEBUG) BEGIN_OF("GetServiceList");
160 if(MYDEBUG) SCRUTE(interfacename);
162 SALOME_ModuleCatalog::ListOfServices_var _list
163 = new SALOME_ModuleCatalog::ListOfServices;
165 // Variables initialisation
168 // looking for the specified interface
169 for (unsigned int ind = 0; ind < _Component.interfaces.length(); ind++)
171 SALOME_ModuleCatalog::DefinitionInterface & I = _Component.interfaces[ind];
173 if (strcmp(interfacename, I.interfacename) == 0)
177 // Get the list of services name for this interface
178 unsigned int _length_services = I.interfaceservicelist.length();
179 _list->length(_length_services);
180 for (unsigned int ind1 = 0; ind1 < _length_services ; ind1++)
182 _list[ind1] = CORBA::string_dup(I.interfaceservicelist[ind1].ServiceName);
183 if(MYDEBUG) MESSAGE("The interface " << interfacename << " of the component "
184 << _Component.name << " contains " << _list[ind1] << " as a service")
191 // The interface was not found, the exception should be thrown
192 std::string message = "The interface";
193 message += interfacename;
194 message += " of the component ";
195 message += _Component.name;
196 message += " was not found";
197 if(MYDEBUG) MESSAGE(message);
198 throw SALOME_ModuleCatalog::NotFound(message.c_str());
201 if(MYDEBUG) END_OF("GetServiceList");
202 return _list._retn();
206 //----------------------------------------------------------------------
207 // Function : GetService
208 // Purpose : get one service of an interface of a component
209 //----------------------------------------------------------------------
210 SALOME_ModuleCatalog::Service*
211 SALOME_ModuleCatalog_AcomponentImpl::GetService(const char* interfacename,
212 const char* servicename)
213 throw(SALOME_ModuleCatalog::NotFound)
215 if(MYDEBUG) BEGIN_OF("GetService");
216 if(MYDEBUG) SCRUTE(interfacename);
217 if(MYDEBUG) SCRUTE(servicename);
219 Unexpect aCatch( MC_NotFound );
220 SALOME_ModuleCatalog::Service *service = new SALOME_ModuleCatalog::Service;
222 // Variables initialization
226 // looking for the specified interface
227 for (unsigned int ind = 0; ind < _Component.interfaces.length(); ind++)
229 if(MYDEBUG) SCRUTE(ind);
230 if(MYDEBUG) SCRUTE(_Component.interfaces[ind].interfacename);
232 SALOME_ModuleCatalog::DefinitionInterface &I = _Component.interfaces[ind];
233 if (strcmp(interfacename, I.interfacename) == 0)
236 // looking for the specified service
237 for (unsigned int ind1 = 0; ind1 < I.interfaceservicelist.length() ; ind1++)
239 SALOME_ModuleCatalog::Service &S = I.interfaceservicelist[ind1];
240 if(MYDEBUG) SCRUTE(ind1);
241 if(MYDEBUG) SCRUTE(S.ServiceName);
243 if (strcmp(servicename, S.ServiceName) == 0)
246 // Affect the service to be returned
248 duplicate(*service, S);
255 if(MYDEBUG) SCRUTE(_find);
258 // The interface was not found, the exception should be thrown
259 std::string message = "The service";
260 message += servicename;
261 message += " of the interface ";
262 message += interfacename;
263 message += " of the component ";
264 message += _Component.name;
265 message += " was not found";
266 if(MYDEBUG) MESSAGE(message);
267 throw SALOME_ModuleCatalog::NotFound(message.c_str());
270 if(MYDEBUG) END_OF("GetService");
274 //----------------------------------------------------------------------
275 // Function : GetDefaultService
276 // Purpose : get the default service of the interface
277 //----------------------------------------------------------------------
278 SALOME_ModuleCatalog::Service*
279 SALOME_ModuleCatalog_AcomponentImpl::GetDefaultService(const char* interfacename)
280 throw(SALOME_ModuleCatalog::NotFound)
282 if(MYDEBUG) BEGIN_OF("GetDefaultService");
283 if(MYDEBUG) SCRUTE(interfacename);
285 Unexpect aCatch( MC_NotFound );
286 SALOME_ModuleCatalog::Service *_service = new SALOME_ModuleCatalog::Service;
288 // Variables initialisation
291 // looking for the specified interface
292 for (unsigned int ind = 0; ind < _Component.interfaces.length(); ind++)
294 if (strcmp(interfacename, _Component.interfaces[ind].interfacename) == 0)
297 // looking for the defautl service of the wanted interface
298 for (unsigned int ind1 = 0; ind1 < _Component.interfaces[ind].interfaceservicelist.length() ; ind1++)
300 if (_Component.interfaces[ind].interfaceservicelist[ind1].Servicebydefault)
303 // affect the service to be returned
305 duplicate(*_service, _Component.interfaces[ind].interfaceservicelist[ind1]);
314 // The service was not found, the exception should be thrown
315 std::string message = "The default service of the interface ";
316 message += interfacename;
317 message += " of the component ";
318 message += _Component.name;
319 message += " was not found";
320 if(MYDEBUG) MESSAGE(message);
321 throw SALOME_ModuleCatalog::NotFound(message.c_str());
324 if(MYDEBUG) END_OF("GetDefaultService");
328 //----------------------------------------------------------------------
329 // Function : GetPathPrefix
330 // Purpose : get the PathPrefix of a computer
331 //----------------------------------------------------------------------
333 SALOME_ModuleCatalog_AcomponentImpl::GetPathPrefix(const char* machinename)
334 throw(SALOME_ModuleCatalog::NotFound)
336 if(MYDEBUG) BEGIN_OF("GetPathPrefix");
337 if(MYDEBUG) SCRUTE(machinename);
338 Unexpect aCatch( MC_NotFound );
340 // Variables initialisation
344 // Parse all the path prefixes
345 // looking for the wanted computer
346 for (unsigned int ind = 0 ; ind < _Component.paths.length() ; ind++)
348 if (strcmp(machinename, _Component.paths[ind].machine) == 0)
352 // affect the path to be returned
353 const char* _temp = _Component.paths[ind].path ;
354 _path = new char[strlen(_temp)+1];
359 if(MYDEBUG) SCRUTE(_find);
362 // The computer was not found, the exception should be thrown
363 std::string message = "The computer ";
364 message += machinename;
365 message += " was not found in the catalog associated to the component ";
366 message += _Component.name;
367 if(MYDEBUG) MESSAGE(message);
368 throw SALOME_ModuleCatalog::NotFound(message.c_str());
371 if(MYDEBUG) END_OF("GetPathPrefix");
375 //----------------------------------------------------------------------
376 // Function : constraint
377 // Purpose : obtain the constraint affected to a component
378 //----------------------------------------------------------------------
379 char* SALOME_ModuleCatalog_AcomponentImpl::constraint()
381 return CORBA::string_dup(_Component.constraint);
384 //----------------------------------------------------------------------
385 // Function : componentname
386 // Purpose : obtain the componentname
387 //----------------------------------------------------------------------
388 char* SALOME_ModuleCatalog_AcomponentImpl::componentname()
390 return CORBA::string_dup(_Component.name);
393 //----------------------------------------------------------------------
394 // Function : componentusername
395 // Purpose : obtain the componentusername
396 //----------------------------------------------------------------------
397 char* SALOME_ModuleCatalog_AcomponentImpl::componentusername()
399 return CORBA::string_dup(_Component.username);
402 //----------------------------------------------------------------------
403 // Function : multistudy
404 // Purpose : define if a component can be multistudy or not
405 //----------------------------------------------------------------------
406 CORBA::Boolean SALOME_ModuleCatalog_AcomponentImpl::multistudy()
408 return _Component.multistudy ;
412 //----------------------------------------------------------------------
413 // Function : implementation type
414 // Purpose : return the implementation type : C++ (dyn lib), Python (module) or executable
415 //----------------------------------------------------------------------
416 SALOME_ModuleCatalog::ImplType SALOME_ModuleCatalog_AcomponentImpl::implementation_type()
418 return _Component.implementationType ;
421 //----------------------------------------------------------------------
422 // Function : implementation name
423 // Purpose : return the implementation name to exec if the default one is not convenient
424 //----------------------------------------------------------------------
425 char* SALOME_ModuleCatalog_AcomponentImpl::implementation_name()
427 return _Component.implname ;
430 //----------------------------------------------------------------------
431 // Function : component_type
432 // Purpose : define the type of the component
433 //----------------------------------------------------------------------
434 SALOME_ModuleCatalog::ComponentType
435 SALOME_ModuleCatalog_AcomponentImpl::component_type()
437 return _Component.type;
440 //----------------------------------------------------------------------
442 // Purpose : obtain the icone affected to a component (for IAPP)
443 //----------------------------------------------------------------------
444 char* SALOME_ModuleCatalog_AcomponentImpl::component_icone()
446 return CORBA::string_dup(_Component.icon);
450 void SALOME_ModuleCatalog_AcomponentImpl::duplicate
451 (SALOME_ModuleCatalog::ServicesParameter & P_out,
452 const SALOME_ModuleCatalog::ServicesParameter &P_in)
454 // duplicate parameter name
455 P_out.Parametername = CORBA::string_dup(P_in.Parametername);
457 // duplicate parameter type
458 P_out.Parametertype = CORBA::string_dup(P_in.Parametertype);
462 void SALOME_ModuleCatalog_AcomponentImpl::duplicate
463 (SALOME_ModuleCatalog::ServicesDataStreamParameter & P_out,
464 const SALOME_ModuleCatalog::ServicesDataStreamParameter &P_in)
466 // duplicate parameter name
467 P_out.Parametername = CORBA::string_dup(P_in.Parametername);
469 // duplicate parameter type
470 P_out.Parametertype = P_in.Parametertype;
472 // duplicate parameter dependency
473 P_out.Parameterdependency = P_in.Parameterdependency;
477 void SALOME_ModuleCatalog_AcomponentImpl::duplicate
478 (SALOME_ModuleCatalog::Service & S_out,
479 const SALOME_ModuleCatalog::Service &S_in)
482 S_out.TypeOfNode = S_in.TypeOfNode;
484 // duplicate service name
485 S_out.ServiceName = CORBA::string_dup(S_in.ServiceName);
487 // duplicate service by default
488 S_out.Servicebydefault = S_in.Servicebydefault;
490 unsigned int _length;
492 // duplicate in Parameters
493 _length = S_in.ServiceinParameter.length();
494 S_out.ServiceinParameter.length(_length);
496 for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
497 duplicate(S_out.ServiceinParameter[ind2],
498 S_in.ServiceinParameter[ind2]);
500 // duplicate out Parameters
501 _length = S_in.ServiceoutParameter.length();
502 S_out.ServiceoutParameter.length(_length);
504 for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
505 duplicate(S_out.ServiceoutParameter[ind2],
506 S_in.ServiceoutParameter[ind2]);
508 // duplicate in DataStreamParameters
509 _length = S_in.ServiceinDataStreamParameter.length();
510 S_out.ServiceinDataStreamParameter.length(_length);
512 for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
513 duplicate(S_out.ServiceinDataStreamParameter[ind2],
514 S_in.ServiceinDataStreamParameter[ind2]);
516 // duplicate out DataStreamParameters
517 _length = S_in.ServiceoutDataStreamParameter.length();
518 if(MYDEBUG) SCRUTE(_length);
519 S_out.ServiceoutDataStreamParameter.length(_length);
521 for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
522 duplicate(S_out.ServiceoutDataStreamParameter[ind2],
523 S_in.ServiceoutDataStreamParameter[ind2]);
527 void SALOME_ModuleCatalog_AcomponentImpl::duplicate
528 (SALOME_ModuleCatalog::DefinitionInterface & I_out,
529 const SALOME_ModuleCatalog::DefinitionInterface & I_in)
531 //duplicate interface name
532 I_out.interfacename = CORBA::string_dup(I_in.interfacename);
534 // duplicate service list
535 unsigned int _length = I_in.interfaceservicelist.length();
536 if(MYDEBUG) SCRUTE(_length);
537 I_out.interfaceservicelist.length(_length);
539 for (unsigned int ind1 = 0; ind1 < _length ; ind1 ++)
540 duplicate(I_out.interfaceservicelist[ind1],
541 I_in.interfaceservicelist[ind1]);