1 // SALOME ModuleCatalog : implementation of ModuleCatalog server which parsers xml description of modules
3 // Copyright (C) 2003 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
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"
39 static int MYDEBUG = 0;
41 static int MYDEBUG = 0;
44 //----------------------------------------------------------------------
45 // Function : SALOME_ModuleCatalog_AcomponentImpl
46 // Purpose : Constructor
47 // Affect the component name, type,icone, a bool to define
48 // if it's multistudy or not.
49 // Affect too the constraint and the interfaces of the component
50 // and the pathes prefixes for all computers
51 //----------------------------------------------------------------------
52 SALOME_ModuleCatalog_AcomponentImpl::SALOME_ModuleCatalog_AcomponentImpl
53 (SALOME_ModuleCatalog::Component &C) : _Component(C)
55 if(MYDEBUG) BEGIN_OF("SALOME_ModuleCatalog_AcomponentImpl");
57 if(MYDEBUG) END_OF("SALOME_ModuleCatalog_AcomponentImpl");
60 //----------------------------------------------------------------------
61 // Function : ~SALOME_ModuleCatalog_AcomponentImpl
62 // Purpose : Destructor
63 //----------------------------------------------------------------------
64 SALOME_ModuleCatalog_AcomponentImpl::~SALOME_ModuleCatalog_AcomponentImpl()
66 if(MYDEBUG) BEGIN_OF("~SALOME_ModuleCatalog_AcomponentImpl");
69 if(MYDEBUG) END_OF("~SALOME_ModuleCatalog_AcomponentImpl");
72 //----------------------------------------------------------------------
73 // Function : GetInterfaceList
74 // Purpose : get a list of the interfaces name of a component
75 //----------------------------------------------------------------------
76 SALOME_ModuleCatalog::ListOfInterfaces*
77 SALOME_ModuleCatalog_AcomponentImpl::GetInterfaceList()
79 if(MYDEBUG) BEGIN_OF("GetInterfaceList");
81 SALOME_ModuleCatalog::ListOfInterfaces_var _list
82 = new SALOME_ModuleCatalog::ListOfInterfaces;
84 // All the interfaces are defined in _list_interfaces affected at the
86 unsigned int _length_interfaces = _Component.interfaces.length();
88 _list->length(_length_interfaces);
90 // Parse all the interfaces to get their name
91 for (unsigned int ind = 0; ind < _length_interfaces; ind++)
93 _list[ind] = CORBA::string_dup(_Component.interfaces[ind].interfacename);
94 if(MYDEBUG) MESSAGE("The component " << _Component.name
95 << " contains " << _list[ind] << " as interface");
98 if(MYDEBUG) END_OF("GetInterfaceList");
102 //----------------------------------------------------------------------
103 // Function : GetInterface
104 // Purpose : get one interface of a component
105 //----------------------------------------------------------------------
106 SALOME_ModuleCatalog::DefinitionInterface*
107 SALOME_ModuleCatalog_AcomponentImpl::GetInterface(const char* interfacename)
108 throw(SALOME_ModuleCatalog::NotFound)
110 if(MYDEBUG) BEGIN_OF("GetInterface");
111 if(MYDEBUG) SCRUTE(interfacename);
113 SALOME_ModuleCatalog::DefinitionInterface *_interface =
114 new SALOME_ModuleCatalog::DefinitionInterface;
118 // looking for the specified interface
119 for (unsigned int ind = 0; ind < _Component.interfaces.length(); ind++)
121 SALOME_ModuleCatalog::DefinitionInterface &I
122 = _Component.interfaces[ind];
124 if (strcmp(interfacename, I.interfacename) == 0)
128 duplicate(*_interface, I);
132 if(MYDEBUG) SCRUTE(_find);
135 // The interface was not found, the exception should be thrown
136 string message = "The interface";
137 message += interfacename;
138 message += " of the component ";
139 message += _Component.name;
140 message += " was not found";
141 if(MYDEBUG) MESSAGE(message);
142 throw SALOME_ModuleCatalog::NotFound(message.c_str());
145 if(MYDEBUG) END_OF("GetInterface");
152 //----------------------------------------------------------------------
153 // Function : GetServiceList
154 // Purpose : get a list of the services name of an interface
156 //----------------------------------------------------------------------
157 SALOME_ModuleCatalog::ListOfServices*
158 SALOME_ModuleCatalog_AcomponentImpl::GetServiceList(const char* interfacename)
159 throw(SALOME_ModuleCatalog::NotFound)
161 if(MYDEBUG) BEGIN_OF("GetServiceList");
162 if(MYDEBUG) SCRUTE(interfacename);
164 SALOME_ModuleCatalog::ListOfServices_var _list
165 = new SALOME_ModuleCatalog::ListOfServices;
167 // Variables initialisation
170 // looking for the specified interface
171 for (unsigned int ind = 0; ind < _Component.interfaces.length(); ind++)
173 SALOME_ModuleCatalog::DefinitionInterface & I = _Component.interfaces[ind];
175 if (strcmp(interfacename, I.interfacename) == 0)
179 // Get the list of services name for this interface
180 unsigned int _length_services = I.interfaceservicelist.length();
181 _list->length(_length_services);
182 for (unsigned int ind1 = 0; ind1 < _length_services ; ind1++)
184 _list[ind1] = CORBA::string_dup(I.interfaceservicelist[ind1].ServiceName);
185 if(MYDEBUG) MESSAGE("The interface " << interfacename << " of the component "
186 << _Component.name << " contains " << _list[ind1] << " as a service")
193 // The interface was not found, the exception should be thrown
194 string message = "The interface";
195 message += interfacename;
196 message += " of the component ";
197 message += _Component.name;
198 message += " was not found";
199 if(MYDEBUG) MESSAGE(message);
200 throw SALOME_ModuleCatalog::NotFound(message.c_str());
203 if(MYDEBUG) END_OF("GetServiceList");
204 return _list._retn();
208 //----------------------------------------------------------------------
209 // Function : GetService
210 // Purpose : get one service of an interface of a component
211 //----------------------------------------------------------------------
212 SALOME_ModuleCatalog::Service*
213 SALOME_ModuleCatalog_AcomponentImpl::GetService(const char* interfacename,
214 const char* servicename)
215 throw(SALOME_ModuleCatalog::NotFound)
217 if(MYDEBUG) BEGIN_OF("GetService");
218 if(MYDEBUG) SCRUTE(interfacename);
219 if(MYDEBUG) SCRUTE(servicename);
221 Unexpect aCatch( MC_NotFound );
222 SALOME_ModuleCatalog::Service *service = new SALOME_ModuleCatalog::Service;
224 // Variables initialization
228 // looking for the specified interface
229 for (unsigned int ind = 0; ind < _Component.interfaces.length(); ind++)
231 if(MYDEBUG) SCRUTE(ind);
232 if(MYDEBUG) SCRUTE(_Component.interfaces[ind].interfacename);
234 SALOME_ModuleCatalog::DefinitionInterface &I = _Component.interfaces[ind];
235 if (strcmp(interfacename, I.interfacename) == 0)
238 // looking for the specified service
239 for (unsigned int ind1 = 0; ind1 < I.interfaceservicelist.length() ; ind1++)
241 SALOME_ModuleCatalog::Service &S = I.interfaceservicelist[ind1];
242 if(MYDEBUG) SCRUTE(ind1);
243 if(MYDEBUG) SCRUTE(S.ServiceName);
245 if (strcmp(servicename, S.ServiceName) == 0)
248 // Affect the service to be returned
250 duplicate(*service, S);
257 if(MYDEBUG) SCRUTE(_find);
260 // The interface was not found, the exception should be thrown
261 string message = "The service";
262 message += servicename;
263 message += " of the interface ";
264 message += interfacename;
265 message += " of the component ";
266 message += _Component.name;
267 message += " was not found";
268 if(MYDEBUG) MESSAGE(message);
269 throw SALOME_ModuleCatalog::NotFound(message.c_str());
272 if(MYDEBUG) END_OF("GetService");
276 //----------------------------------------------------------------------
277 // Function : GetDefaultService
278 // Purpose : get the default service of the interface
279 //----------------------------------------------------------------------
280 SALOME_ModuleCatalog::Service*
281 SALOME_ModuleCatalog_AcomponentImpl::GetDefaultService(const char* interfacename)
282 throw(SALOME_ModuleCatalog::NotFound)
284 if(MYDEBUG) BEGIN_OF("GetDefaultService");
285 if(MYDEBUG) SCRUTE(interfacename);
287 Unexpect aCatch( MC_NotFound );
288 SALOME_ModuleCatalog::Service *_service = new SALOME_ModuleCatalog::Service;
290 // Variables initialisation
293 // looking for the specified interface
294 for (unsigned int ind = 0; ind < _Component.interfaces.length(); ind++)
296 if (strcmp(interfacename, _Component.interfaces[ind].interfacename) == 0)
299 // looking for the defautl service of the wanted interface
300 for (unsigned int ind1 = 0; ind1 < _Component.interfaces[ind].interfaceservicelist.length() ; ind1++)
302 if (_Component.interfaces[ind].interfaceservicelist[ind1].Servicebydefault)
305 // affect the service to be returned
307 duplicate(*_service, _Component.interfaces[ind].interfaceservicelist[ind1]);
316 // The service was not found, the exception should be thrown
317 string message = "The default service of the interface ";
318 message += interfacename;
319 message += " of the component ";
320 message += _Component.name;
321 message += " was not found";
322 if(MYDEBUG) MESSAGE(message);
323 throw SALOME_ModuleCatalog::NotFound(message.c_str());
326 if(MYDEBUG) END_OF("GetDefaultService");
330 //----------------------------------------------------------------------
331 // Function : GetPathPrefix
332 // Purpose : get the PathPrefix of a computer
333 //----------------------------------------------------------------------
335 SALOME_ModuleCatalog_AcomponentImpl::GetPathPrefix(const char* machinename)
336 throw(SALOME_ModuleCatalog::NotFound)
338 if(MYDEBUG) BEGIN_OF("GetPathPrefix");
339 if(MYDEBUG) SCRUTE(machinename);
340 Unexpect aCatch( MC_NotFound );
342 // Variables initialisation
346 // Parse all the path prefixes
347 // looking for the wanted computer
348 for (unsigned int ind = 0 ; ind < _Component.paths.length() ; ind++)
350 if (strcmp(machinename, _Component.paths[ind].machine) == 0)
354 // affect the path to be returned
355 const char* _temp = _Component.paths[ind].path ;
356 _path = new char[strlen(_temp)+1];
361 if(MYDEBUG) SCRUTE(_find);
364 // The computer was not found, the exception should be thrown
365 string message = "The computer ";
366 message += machinename;
367 message += " was not found in the catalog associated to the component ";
368 message += _Component.name;
369 if(MYDEBUG) MESSAGE(message);
370 throw SALOME_ModuleCatalog::NotFound(message.c_str());
373 if(MYDEBUG) END_OF("GetPathPrefix");
377 //----------------------------------------------------------------------
378 // Function : constraint
379 // Purpose : obtain the constraint affected to a component
380 //----------------------------------------------------------------------
381 char* SALOME_ModuleCatalog_AcomponentImpl::constraint()
383 return CORBA::string_dup(_Component.constraint);
386 //----------------------------------------------------------------------
387 // Function : componentname
388 // Purpose : obtain the componentname
389 //----------------------------------------------------------------------
390 char* SALOME_ModuleCatalog_AcomponentImpl::componentname()
392 return CORBA::string_dup(_Component.name);
395 //----------------------------------------------------------------------
396 // Function : componentusername
397 // Purpose : obtain the componentusername
398 //----------------------------------------------------------------------
399 char* SALOME_ModuleCatalog_AcomponentImpl::componentusername()
401 return CORBA::string_dup(_Component.username);
404 //----------------------------------------------------------------------
405 // Function : multistudy
406 // Purpose : define if a component can be multistudy or not
407 //----------------------------------------------------------------------
408 CORBA::Boolean SALOME_ModuleCatalog_AcomponentImpl::multistudy()
410 return _Component.multistudy ;
414 //----------------------------------------------------------------------
415 // Function : implementation type
416 // Purpose : define if a component is implemented in C++ or Python
417 //----------------------------------------------------------------------
418 CORBA::Boolean SALOME_ModuleCatalog_AcomponentImpl::implementation_type()
420 return _Component.implementationType ;
423 //----------------------------------------------------------------------
424 // Function : component_type
425 // Purpose : define the type of the component
426 //----------------------------------------------------------------------
427 SALOME_ModuleCatalog::ComponentType
428 SALOME_ModuleCatalog_AcomponentImpl::component_type()
430 return _Component.type;
433 //----------------------------------------------------------------------
435 // Purpose : obtain the icone affected to a component (for IAPP)
436 //----------------------------------------------------------------------
437 char* SALOME_ModuleCatalog_AcomponentImpl::component_icone()
439 return CORBA::string_dup(_Component.icon);
443 void SALOME_ModuleCatalog_AcomponentImpl::duplicate
444 (SALOME_ModuleCatalog::ServicesParameter & P_out,
445 const SALOME_ModuleCatalog::ServicesParameter &P_in)
447 // duplicate parameter name
448 P_out.Parametername = CORBA::string_dup(P_in.Parametername);
450 // duplicate parameter type
451 P_out.Parametertype = CORBA::string_dup(P_in.Parametertype);
455 void SALOME_ModuleCatalog_AcomponentImpl::duplicate
456 (SALOME_ModuleCatalog::ServicesDataStreamParameter & P_out,
457 const SALOME_ModuleCatalog::ServicesDataStreamParameter &P_in)
459 // duplicate parameter name
460 P_out.Parametername = CORBA::string_dup(P_in.Parametername);
462 // duplicate parameter type
463 P_out.Parametertype = P_in.Parametertype;
465 // duplicate parameter dependency
466 P_out.Parameterdependency = P_in.Parameterdependency;
470 void SALOME_ModuleCatalog_AcomponentImpl::duplicate
471 (SALOME_ModuleCatalog::Service & S_out,
472 const SALOME_ModuleCatalog::Service &S_in)
475 S_out.TypeOfNode = S_in.TypeOfNode;
477 // duplicate service name
478 S_out.ServiceName = CORBA::string_dup(S_in.ServiceName);
480 // duplicate service by default
481 S_out.Servicebydefault = S_in.Servicebydefault;
483 unsigned int _length;
485 // duplicate in Parameters
486 _length = S_in.ServiceinParameter.length();
487 S_out.ServiceinParameter.length(_length);
489 for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
490 duplicate(S_out.ServiceinParameter[ind2],
491 S_in.ServiceinParameter[ind2]);
493 // duplicate out Parameters
494 _length = S_in.ServiceoutParameter.length();
495 S_out.ServiceoutParameter.length(_length);
498 for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
500 for (ind2 = 0; ind2 < _length ; ind2 ++)
502 duplicate(S_out.ServiceoutParameter[ind2],
503 S_in.ServiceoutParameter[ind2]);
505 // duplicate in DataStreamParameters
506 _length = S_in.ServiceinDataStreamParameter.length();
507 S_out.ServiceinDataStreamParameter.length(_length);
510 for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
512 for (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);
523 for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
525 for (ind2 = 0; ind2 < _length ; ind2 ++)
527 duplicate(S_out.ServiceoutDataStreamParameter[ind2],
528 S_in.ServiceoutDataStreamParameter[ind2]);
532 void SALOME_ModuleCatalog_AcomponentImpl::duplicate
533 (SALOME_ModuleCatalog::DefinitionInterface & I_out,
534 const SALOME_ModuleCatalog::DefinitionInterface & I_in)
536 //duplicate interface name
537 I_out.interfacename = CORBA::string_dup(I_in.interfacename);
539 // duplicate service list
540 unsigned int _length = I_in.interfaceservicelist.length();
541 if(MYDEBUG) SCRUTE(_length);
542 I_out.interfaceservicelist.length(_length);
544 for (unsigned int ind1 = 0; ind1 < _length ; ind1 ++)
545 duplicate(I_out.interfaceservicelist[ind1],
546 I_in.interfaceservicelist[ind1]);