1 // Copyright (C) 2007-2008 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.
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
22 // SALOME ModuleCatalog : implementation of ModuleCatalog server which parsers xml description of modules
23 // File : SALOME_ModuleCatalog_Acomponent_impl.cxx
24 // Author : Estelle Deville
28 #include "SALOME_ModuleCatalog_Acomponent_impl.hxx"
30 #include "Utils_ExceptHandlers.hxx"
31 UNEXPECT_CATCH(MC_NotFound, SALOME_ModuleCatalog::NotFound);
33 #include "utilities.h"
38 static int MYDEBUG = 0;
40 static int MYDEBUG = 0;
43 //----------------------------------------------------------------------
44 // Function : SALOME_ModuleCatalog_AcomponentImpl
45 // Purpose : Constructor
46 // Affect the component name, type,icone, a bool to define
47 // if it's multistudy or not.
48 // Affect too the constraint and the interfaces of the component
49 // and the pathes prefixes for all computers
50 //----------------------------------------------------------------------
51 SALOME_ModuleCatalog_AcomponentImpl::SALOME_ModuleCatalog_AcomponentImpl
52 (SALOME_ModuleCatalog::ComponentDef &C) : _Component(C)
54 if(MYDEBUG) BEGIN_OF("SALOME_ModuleCatalog_AcomponentImpl");
56 if(MYDEBUG) END_OF("SALOME_ModuleCatalog_AcomponentImpl");
59 //----------------------------------------------------------------------
60 // Function : ~SALOME_ModuleCatalog_AcomponentImpl
61 // Purpose : Destructor
62 //----------------------------------------------------------------------
63 SALOME_ModuleCatalog_AcomponentImpl::~SALOME_ModuleCatalog_AcomponentImpl()
65 if(MYDEBUG) BEGIN_OF("~SALOME_ModuleCatalog_AcomponentImpl");
68 if(MYDEBUG) END_OF("~SALOME_ModuleCatalog_AcomponentImpl");
71 //----------------------------------------------------------------------
72 // Function : GetInterfaceList
73 // Purpose : get a list of the interfaces name of a component
74 //----------------------------------------------------------------------
75 SALOME_ModuleCatalog::ListOfInterfaces*
76 SALOME_ModuleCatalog_AcomponentImpl::GetInterfaceList()
78 if(MYDEBUG) BEGIN_OF("GetInterfaceList");
80 SALOME_ModuleCatalog::ListOfInterfaces_var _list
81 = new SALOME_ModuleCatalog::ListOfInterfaces;
83 // All the interfaces are defined in _list_interfaces affected at the
85 unsigned int _length_interfaces = _Component.interfaces.length();
87 _list->length(_length_interfaces);
89 // Parse all the interfaces to get their name
90 for (unsigned int ind = 0; ind < _length_interfaces; ind++)
92 _list[ind] = CORBA::string_dup(_Component.interfaces[ind].interfacename);
93 if(MYDEBUG) MESSAGE("The component " << _Component.name
94 << " contains " << _list[ind] << " as interface");
97 if(MYDEBUG) END_OF("GetInterfaceList");
101 //----------------------------------------------------------------------
102 // Function : GetInterface
103 // Purpose : get one interface of a component
104 //----------------------------------------------------------------------
105 SALOME_ModuleCatalog::DefinitionInterface*
106 SALOME_ModuleCatalog_AcomponentImpl::GetInterface(const char* interfacename)
107 throw(SALOME_ModuleCatalog::NotFound)
109 if(MYDEBUG) BEGIN_OF("GetInterface");
110 if(MYDEBUG) SCRUTE(interfacename);
112 SALOME_ModuleCatalog::DefinitionInterface *_interface =
113 new SALOME_ModuleCatalog::DefinitionInterface;
117 // looking for the specified interface
118 for (unsigned int ind = 0; ind < _Component.interfaces.length(); ind++)
120 SALOME_ModuleCatalog::DefinitionInterface &I
121 = _Component.interfaces[ind];
123 if (strcmp(interfacename, I.interfacename) == 0)
127 duplicate(*_interface, I);
131 if(MYDEBUG) SCRUTE(_find);
134 // The interface was not found, the exception should be thrown
135 string message = "The interface";
136 message += interfacename;
137 message += " of the component ";
138 message += _Component.name;
139 message += " was not found";
140 if(MYDEBUG) MESSAGE(message);
141 throw SALOME_ModuleCatalog::NotFound(message.c_str());
144 if(MYDEBUG) END_OF("GetInterface");
151 //----------------------------------------------------------------------
152 // Function : GetServiceList
153 // Purpose : get a list of the services name of an interface
155 //----------------------------------------------------------------------
156 SALOME_ModuleCatalog::ListOfServices*
157 SALOME_ModuleCatalog_AcomponentImpl::GetServiceList(const char* interfacename)
158 throw(SALOME_ModuleCatalog::NotFound)
160 if(MYDEBUG) BEGIN_OF("GetServiceList");
161 if(MYDEBUG) SCRUTE(interfacename);
163 SALOME_ModuleCatalog::ListOfServices_var _list
164 = new SALOME_ModuleCatalog::ListOfServices;
166 // Variables initialisation
169 // looking for the specified interface
170 for (unsigned int ind = 0; ind < _Component.interfaces.length(); ind++)
172 SALOME_ModuleCatalog::DefinitionInterface & I = _Component.interfaces[ind];
174 if (strcmp(interfacename, I.interfacename) == 0)
178 // Get the list of services name for this interface
179 unsigned int _length_services = I.interfaceservicelist.length();
180 _list->length(_length_services);
181 for (unsigned int ind1 = 0; ind1 < _length_services ; ind1++)
183 _list[ind1] = CORBA::string_dup(I.interfaceservicelist[ind1].ServiceName);
184 if(MYDEBUG) MESSAGE("The interface " << interfacename << " of the component "
185 << _Component.name << " contains " << _list[ind1] << " as a service")
192 // The interface was not found, the exception should be thrown
193 string message = "The interface";
194 message += interfacename;
195 message += " of the component ";
196 message += _Component.name;
197 message += " was not found";
198 if(MYDEBUG) MESSAGE(message);
199 throw SALOME_ModuleCatalog::NotFound(message.c_str());
202 if(MYDEBUG) END_OF("GetServiceList");
203 return _list._retn();
207 //----------------------------------------------------------------------
208 // Function : GetService
209 // Purpose : get one service of an interface of a component
210 //----------------------------------------------------------------------
211 SALOME_ModuleCatalog::Service*
212 SALOME_ModuleCatalog_AcomponentImpl::GetService(const char* interfacename,
213 const char* servicename)
214 throw(SALOME_ModuleCatalog::NotFound)
216 if(MYDEBUG) BEGIN_OF("GetService");
217 if(MYDEBUG) SCRUTE(interfacename);
218 if(MYDEBUG) SCRUTE(servicename);
220 Unexpect aCatch( MC_NotFound );
221 SALOME_ModuleCatalog::Service *service = new SALOME_ModuleCatalog::Service;
223 // Variables initialization
227 // looking for the specified interface
228 for (unsigned int ind = 0; ind < _Component.interfaces.length(); ind++)
230 if(MYDEBUG) SCRUTE(ind);
231 if(MYDEBUG) SCRUTE(_Component.interfaces[ind].interfacename);
233 SALOME_ModuleCatalog::DefinitionInterface &I = _Component.interfaces[ind];
234 if (strcmp(interfacename, I.interfacename) == 0)
237 // looking for the specified service
238 for (unsigned int ind1 = 0; ind1 < I.interfaceservicelist.length() ; ind1++)
240 SALOME_ModuleCatalog::Service &S = I.interfaceservicelist[ind1];
241 if(MYDEBUG) SCRUTE(ind1);
242 if(MYDEBUG) SCRUTE(S.ServiceName);
244 if (strcmp(servicename, S.ServiceName) == 0)
247 // Affect the service to be returned
249 duplicate(*service, S);
256 if(MYDEBUG) SCRUTE(_find);
259 // The interface was not found, the exception should be thrown
260 string message = "The service";
261 message += servicename;
262 message += " of the interface ";
263 message += interfacename;
264 message += " of the component ";
265 message += _Component.name;
266 message += " was not found";
267 if(MYDEBUG) MESSAGE(message);
268 throw SALOME_ModuleCatalog::NotFound(message.c_str());
271 if(MYDEBUG) END_OF("GetService");
275 //----------------------------------------------------------------------
276 // Function : GetDefaultService
277 // Purpose : get the default service of the interface
278 //----------------------------------------------------------------------
279 SALOME_ModuleCatalog::Service*
280 SALOME_ModuleCatalog_AcomponentImpl::GetDefaultService(const char* interfacename)
281 throw(SALOME_ModuleCatalog::NotFound)
283 if(MYDEBUG) BEGIN_OF("GetDefaultService");
284 if(MYDEBUG) SCRUTE(interfacename);
286 Unexpect aCatch( MC_NotFound );
287 SALOME_ModuleCatalog::Service *_service = new SALOME_ModuleCatalog::Service;
289 // Variables initialisation
292 // looking for the specified interface
293 for (unsigned int ind = 0; ind < _Component.interfaces.length(); ind++)
295 if (strcmp(interfacename, _Component.interfaces[ind].interfacename) == 0)
298 // looking for the defautl service of the wanted interface
299 for (unsigned int ind1 = 0; ind1 < _Component.interfaces[ind].interfaceservicelist.length() ; ind1++)
301 if (_Component.interfaces[ind].interfaceservicelist[ind1].Servicebydefault)
304 // affect the service to be returned
306 duplicate(*_service, _Component.interfaces[ind].interfaceservicelist[ind1]);
315 // The service was not found, the exception should be thrown
316 string message = "The default service of the interface ";
317 message += interfacename;
318 message += " of the component ";
319 message += _Component.name;
320 message += " was not found";
321 if(MYDEBUG) MESSAGE(message);
322 throw SALOME_ModuleCatalog::NotFound(message.c_str());
325 if(MYDEBUG) END_OF("GetDefaultService");
329 //----------------------------------------------------------------------
330 // Function : GetPathPrefix
331 // Purpose : get the PathPrefix of a computer
332 //----------------------------------------------------------------------
334 SALOME_ModuleCatalog_AcomponentImpl::GetPathPrefix(const char* machinename)
335 throw(SALOME_ModuleCatalog::NotFound)
337 if(MYDEBUG) BEGIN_OF("GetPathPrefix");
338 if(MYDEBUG) SCRUTE(machinename);
339 Unexpect aCatch( MC_NotFound );
341 // Variables initialisation
345 // Parse all the path prefixes
346 // looking for the wanted computer
347 for (unsigned int ind = 0 ; ind < _Component.paths.length() ; ind++)
349 if (strcmp(machinename, _Component.paths[ind].machine) == 0)
353 // affect the path to be returned
354 const char* _temp = _Component.paths[ind].path ;
355 _path = new char[strlen(_temp)+1];
360 if(MYDEBUG) SCRUTE(_find);
363 // The computer was not found, the exception should be thrown
364 string message = "The computer ";
365 message += machinename;
366 message += " was not found in the catalog associated to the component ";
367 message += _Component.name;
368 if(MYDEBUG) MESSAGE(message);
369 throw SALOME_ModuleCatalog::NotFound(message.c_str());
372 if(MYDEBUG) END_OF("GetPathPrefix");
376 //----------------------------------------------------------------------
377 // Function : constraint
378 // Purpose : obtain the constraint affected to a component
379 //----------------------------------------------------------------------
380 char* SALOME_ModuleCatalog_AcomponentImpl::constraint()
382 return CORBA::string_dup(_Component.constraint);
385 //----------------------------------------------------------------------
386 // Function : componentname
387 // Purpose : obtain the componentname
388 //----------------------------------------------------------------------
389 char* SALOME_ModuleCatalog_AcomponentImpl::componentname()
391 return CORBA::string_dup(_Component.name);
394 //----------------------------------------------------------------------
395 // Function : componentusername
396 // Purpose : obtain the componentusername
397 //----------------------------------------------------------------------
398 char* SALOME_ModuleCatalog_AcomponentImpl::componentusername()
400 return CORBA::string_dup(_Component.username);
403 //----------------------------------------------------------------------
404 // Function : multistudy
405 // Purpose : define if a component can be multistudy or not
406 //----------------------------------------------------------------------
407 CORBA::Boolean SALOME_ModuleCatalog_AcomponentImpl::multistudy()
409 return _Component.multistudy ;
413 //----------------------------------------------------------------------
414 // Function : implementation type
415 // Purpose : return the implementation type : C++ (dyn lib), Python (module) or executable
416 //----------------------------------------------------------------------
417 SALOME_ModuleCatalog::ImplType SALOME_ModuleCatalog_AcomponentImpl::implementation_type()
419 return _Component.implementationType ;
422 //----------------------------------------------------------------------
423 // Function : implementation name
424 // Purpose : return the implementation name to exec if the default one is not convenient
425 //----------------------------------------------------------------------
426 char* SALOME_ModuleCatalog_AcomponentImpl::implementation_name()
428 return _Component.implname ;
431 //----------------------------------------------------------------------
432 // Function : component_type
433 // Purpose : define the type of the component
434 //----------------------------------------------------------------------
435 SALOME_ModuleCatalog::ComponentType
436 SALOME_ModuleCatalog_AcomponentImpl::component_type()
438 return _Component.type;
441 //----------------------------------------------------------------------
443 // Purpose : obtain the icone affected to a component (for IAPP)
444 //----------------------------------------------------------------------
445 char* SALOME_ModuleCatalog_AcomponentImpl::component_icone()
447 return CORBA::string_dup(_Component.icon);
451 void SALOME_ModuleCatalog_AcomponentImpl::duplicate
452 (SALOME_ModuleCatalog::ServicesParameter & P_out,
453 const SALOME_ModuleCatalog::ServicesParameter &P_in)
455 // duplicate parameter name
456 P_out.Parametername = CORBA::string_dup(P_in.Parametername);
458 // duplicate parameter type
459 P_out.Parametertype = CORBA::string_dup(P_in.Parametertype);
463 void SALOME_ModuleCatalog_AcomponentImpl::duplicate
464 (SALOME_ModuleCatalog::ServicesDataStreamParameter & P_out,
465 const SALOME_ModuleCatalog::ServicesDataStreamParameter &P_in)
467 // duplicate parameter name
468 P_out.Parametername = CORBA::string_dup(P_in.Parametername);
470 // duplicate parameter type
471 P_out.Parametertype = P_in.Parametertype;
473 // duplicate parameter dependency
474 P_out.Parameterdependency = P_in.Parameterdependency;
478 void SALOME_ModuleCatalog_AcomponentImpl::duplicate
479 (SALOME_ModuleCatalog::Service & S_out,
480 const SALOME_ModuleCatalog::Service &S_in)
483 S_out.TypeOfNode = S_in.TypeOfNode;
485 // duplicate service name
486 S_out.ServiceName = CORBA::string_dup(S_in.ServiceName);
488 // duplicate service by default
489 S_out.Servicebydefault = S_in.Servicebydefault;
491 unsigned int _length;
493 // duplicate in Parameters
494 _length = S_in.ServiceinParameter.length();
495 S_out.ServiceinParameter.length(_length);
497 for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
498 duplicate(S_out.ServiceinParameter[ind2],
499 S_in.ServiceinParameter[ind2]);
501 // duplicate out Parameters
502 _length = S_in.ServiceoutParameter.length();
503 S_out.ServiceoutParameter.length(_length);
505 for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
506 duplicate(S_out.ServiceoutParameter[ind2],
507 S_in.ServiceoutParameter[ind2]);
509 // duplicate in DataStreamParameters
510 _length = S_in.ServiceinDataStreamParameter.length();
511 S_out.ServiceinDataStreamParameter.length(_length);
513 for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
514 duplicate(S_out.ServiceinDataStreamParameter[ind2],
515 S_in.ServiceinDataStreamParameter[ind2]);
517 // duplicate out DataStreamParameters
518 _length = S_in.ServiceoutDataStreamParameter.length();
519 if(MYDEBUG) SCRUTE(_length);
520 S_out.ServiceoutDataStreamParameter.length(_length);
522 for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
523 duplicate(S_out.ServiceoutDataStreamParameter[ind2],
524 S_in.ServiceoutDataStreamParameter[ind2]);
528 void SALOME_ModuleCatalog_AcomponentImpl::duplicate
529 (SALOME_ModuleCatalog::DefinitionInterface & I_out,
530 const SALOME_ModuleCatalog::DefinitionInterface & I_in)
532 //duplicate interface name
533 I_out.interfacename = CORBA::string_dup(I_in.interfacename);
535 // duplicate service list
536 unsigned int _length = I_in.interfaceservicelist.length();
537 if(MYDEBUG) SCRUTE(_length);
538 I_out.interfaceservicelist.length(_length);
540 for (unsigned int ind1 = 0; ind1 < _length ; ind1 ++)
541 duplicate(I_out.interfaceservicelist[ind1],
542 I_in.interfaceservicelist[ind1]);