Salome HOME
Updated copyright comment
[modules/kernel.git] / src / ModuleCatalog / SALOME_ModuleCatalog_Acomponent_impl.cxx
1 // Copyright (C) 2007-2024  CEA, EDF, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  SALOME ModuleCatalog : implementation of ModuleCatalog server which parsers xml description of modules
24 //  File   : SALOME_ModuleCatalog_Acomponent_impl.cxx
25 //  Author : Estelle Deville
26 //  Module : SALOME
27 //  $Header$
28 //
29 #include "SALOME_ModuleCatalog_Acomponent_impl.hxx"
30
31 #include "Utils_ExceptHandlers.hxx"
32 UNEXPECT_CATCH(MC_NotFound, SALOME_ModuleCatalog::NotFound)
33
34 #include "utilities.h"
35
36
37 //----------------------------------------------------------------------
38 // Function : SALOME_ModuleCatalog_AcomponentImpl
39 // Purpose  : Constructor
40 //            Affect the component name, type,icon
41 //            Affect too the constraint and the interfaces of the component
42 //            and the path prefixes for all computers
43 //----------------------------------------------------------------------  
44 SALOME_ModuleCatalog_AcomponentImpl::SALOME_ModuleCatalog_AcomponentImpl
45 (SALOME_ModuleCatalog::ComponentDef &C) : _Component(C)
46 {
47   BEGIN_OF("SALOME_ModuleCatalog_AcomponentImpl");
48
49   END_OF("SALOME_ModuleCatalog_AcomponentImpl");
50 }
51
52 //----------------------------------------------------------------------
53 // Function : ~SALOME_ModuleCatalog_AcomponentImpl
54 // Purpose  : Destructor 
55 //----------------------------------------------------------------------
56 SALOME_ModuleCatalog_AcomponentImpl::~SALOME_ModuleCatalog_AcomponentImpl()
57 {
58   BEGIN_OF("~SALOME_ModuleCatalog_AcomponentImpl");
59
60   END_OF("~SALOME_ModuleCatalog_AcomponentImpl");
61 }
62
63 //----------------------------------------------------------------------
64 // Function : GetInterfaceList
65 // Purpose  : get a list of the interfaces name of a component
66 //----------------------------------------------------------------------
67 SALOME_ModuleCatalog::ListOfInterfaces* 
68 SALOME_ModuleCatalog_AcomponentImpl::GetInterfaceList() 
69 {
70   BEGIN_OF("GetInterfaceList");
71
72   SALOME_ModuleCatalog::ListOfInterfaces_var _list 
73     = new SALOME_ModuleCatalog::ListOfInterfaces;
74
75   // All the interfaces are defined in _list_interfaces affected at the
76   // component creation
77   unsigned int _length_interfaces = _Component.interfaces.length();
78
79   _list->length(_length_interfaces);
80
81   // Parse all the interfaces to get their name
82   for (unsigned int ind = 0; ind < _length_interfaces; ind++)
83     {
84       _list[ind] = CORBA::string_dup(_Component.interfaces[ind].interfacename);
85       MESSAGE("The component " << _Component.name 
86                           << " contains " << _list[ind] << " as interface");
87     }
88   
89   END_OF("GetInterfaceList");
90   return _list._retn();
91 }
92
93 //----------------------------------------------------------------------
94 // Function : GetInterface
95 // Purpose  : get one interface of a component
96 //----------------------------------------------------------------------
97 SALOME_ModuleCatalog::DefinitionInterface*
98 SALOME_ModuleCatalog_AcomponentImpl::GetInterface(const char* interfacename)
99 {
100   BEGIN_OF("GetInterface");
101   SCRUTE(interfacename);
102
103   SALOME_ModuleCatalog::DefinitionInterface *_interface =
104           new SALOME_ModuleCatalog::DefinitionInterface;
105
106   bool _find = false ;
107   
108   // looking for the specified interface
109   for (unsigned int ind = 0; ind < _Component.interfaces.length(); ind++)
110     {
111       SALOME_ModuleCatalog::DefinitionInterface &I
112         = _Component.interfaces[ind];
113
114       if (strcmp(interfacename, I.interfacename) == 0)
115         {
116           // wanted interface
117           _find = true ;
118           duplicate(*_interface, I);
119         }
120     }
121
122   SCRUTE(_find);
123   if (!_find)
124     {
125       // The interface was not found, the exception should be thrown
126                 std::string message = "The interface";
127       message += interfacename;
128       message += " of the component ";
129       message += _Component.name;
130       message += " was not found"; 
131       MESSAGE(message);
132       throw SALOME_ModuleCatalog::NotFound(message.c_str());
133     }
134
135   END_OF("GetInterface");
136
137   return _interface;
138 }
139
140
141
142 //----------------------------------------------------------------------
143 // Function : GetServiceList
144 // Purpose  : get a list of the services name of an interface 
145 //            of a component
146 //----------------------------------------------------------------------
147 SALOME_ModuleCatalog::ListOfServices* 
148 SALOME_ModuleCatalog_AcomponentImpl::GetServiceList(const char* interfacename)
149 {
150   BEGIN_OF("GetServiceList");
151   SCRUTE(interfacename);
152
153   SALOME_ModuleCatalog::ListOfServices_var _list 
154     = new SALOME_ModuleCatalog::ListOfServices;
155
156   // Variables initialisation
157   bool _find = false ;
158
159   // looking for the specified interface
160   for (unsigned int ind = 0; ind < _Component.interfaces.length(); ind++)
161     {
162       SALOME_ModuleCatalog::DefinitionInterface & I = _Component.interfaces[ind];
163
164       if (strcmp(interfacename, I.interfacename) == 0)
165         {
166           _find = true ;
167           // wanted interface
168           // Get the list of services name for this interface
169           unsigned int _length_services = I.interfaceservicelist.length();
170           _list->length(_length_services);
171           for (unsigned int ind1 = 0; ind1 < _length_services ; ind1++)
172             {
173               _list[ind1] = CORBA::string_dup(I.interfaceservicelist[ind1].ServiceName);
174               MESSAGE("The interface " << interfacename << " of the component " 
175                                   << _Component.name << " contains " << _list[ind1] << " as a service");
176             }
177         }
178     }
179
180  if (!_find)
181     {
182       // The interface was not found, the exception should be thrown
183       std::string message = "The interface";
184       message += interfacename;
185       message += " of the component ";
186       message += _Component.name;
187       message += " was not found"; 
188       MESSAGE(message);
189       throw SALOME_ModuleCatalog::NotFound(message.c_str());
190     }
191
192   END_OF("GetServiceList");
193   return _list._retn();
194 }
195
196     
197 //----------------------------------------------------------------------
198 // Function : GetService
199 // Purpose  : get one service of an interface of a component
200 //----------------------------------------------------------------------
201 SALOME_ModuleCatalog::Service* 
202 SALOME_ModuleCatalog_AcomponentImpl::GetService(const char* interfacename, 
203                                                 const char* servicename) 
204 {
205   BEGIN_OF("GetService");
206   SCRUTE(interfacename);
207   SCRUTE(servicename);
208
209   Unexpect aCatch( MC_NotFound );
210   SALOME_ModuleCatalog::Service *service = new SALOME_ModuleCatalog::Service;
211
212   // Variables initialization
213   bool _find = false ;
214   
215
216   // looking for the specified interface
217   for (unsigned int ind = 0; ind < _Component.interfaces.length(); ind++)
218     {
219       SCRUTE(ind);
220       SCRUTE(_Component.interfaces[ind].interfacename);
221
222       SALOME_ModuleCatalog::DefinitionInterface &I = _Component.interfaces[ind];
223       if (strcmp(interfacename, I.interfacename) == 0)
224         {
225           // wanted interface
226           // looking for the specified service
227           for (unsigned int ind1 = 0; ind1 <  I.interfaceservicelist.length() ; ind1++)
228             {
229               SALOME_ModuleCatalog::Service &S = I.interfaceservicelist[ind1];
230               SCRUTE(ind1);
231               SCRUTE(S.ServiceName);
232
233               if (strcmp(servicename, S.ServiceName) == 0)
234               {
235                 // Wanted Service
236                 // Affect the service to be returned
237                 _find = true ;
238                 duplicate(*service, S);
239               }
240             }
241
242         }
243     }
244   
245   SCRUTE(_find);
246   if (!_find)
247     {
248       // The interface was not found, the exception should be thrown
249       std::string message = "The service";
250       message += servicename;
251       message += " of the interface ";
252       message += interfacename;
253       message += " of the component ";
254       message += _Component.name;
255       message += " was not found"; 
256       MESSAGE(message);
257       throw SALOME_ModuleCatalog::NotFound(message.c_str());
258     }
259
260   END_OF("GetService");
261   return service;
262 }
263
264 //----------------------------------------------------------------------
265 // Function : GetDefaultService
266 // Purpose  : get the default service of the interface
267 //----------------------------------------------------------------------
268 SALOME_ModuleCatalog::Service* 
269 SALOME_ModuleCatalog_AcomponentImpl::GetDefaultService(const char* interfacename) 
270 {
271   BEGIN_OF("GetDefaultService");
272   SCRUTE(interfacename);
273
274   Unexpect aCatch( MC_NotFound );
275   SALOME_ModuleCatalog::Service *_service = new  SALOME_ModuleCatalog::Service;
276
277   // Variables initialisation
278   bool _find = false ;
279
280   // looking for the specified interface
281   for (unsigned int ind = 0; ind < _Component.interfaces.length(); ind++)
282     {
283       if (strcmp(interfacename, _Component.interfaces[ind].interfacename) == 0)
284         {
285           // wanted interface
286           // looking for the default service of the wanted interface
287           for (unsigned int ind1 = 0; ind1 <  _Component.interfaces[ind].interfaceservicelist.length() ; ind1++)
288             {
289               if (_Component.interfaces[ind].interfaceservicelist[ind1].Servicebydefault)
290               {
291                 // Default Service
292                 // affect the service to be returned
293                 _find = true ;
294                 duplicate(*_service, _Component.interfaces[ind].interfaceservicelist[ind1]);
295               }
296             }
297
298         }
299     }
300
301   if (!_find)
302     {
303       // The service was not found, the exception should be thrown
304       std::string message = "The default service of the interface ";
305       message += interfacename;
306       message += " of the component ";
307       message += _Component.name;
308       message += " was not found";
309       MESSAGE(message);
310       throw SALOME_ModuleCatalog::NotFound(message.c_str());
311     }
312
313   END_OF("GetDefaultService");
314   return _service;
315 }
316
317 //----------------------------------------------------------------------
318 // Function : GetPathPrefix
319 // Purpose  : get the PathPrefix of a computer
320 //----------------------------------------------------------------------
321 char* 
322 SALOME_ModuleCatalog_AcomponentImpl::GetPathPrefix(const char* machinename) 
323 {
324   BEGIN_OF("GetPathPrefix");
325   SCRUTE(machinename);
326   Unexpect aCatch( MC_NotFound );
327
328  // Variables initialisation
329   char* _path = NULL;
330   bool _find = false ;
331
332   // Parse all the path prefixes
333   // looking for the wanted computer
334   for (unsigned int ind = 0 ; ind < _Component.paths.length() ; ind++)
335     {
336       if (strcmp(machinename, _Component.paths[ind].machine) == 0)
337             {
338               _find = true ;
339               // Wanted computer
340               // affect the path to be returned
341                 const char* _temp = _Component.paths[ind].path ;
342                 _path = new char[strlen(_temp)+1];
343                 strcpy(_path,_temp);
344             }
345      }
346
347    SCRUTE(_find);
348    if (!_find)
349      {
350        // The computer was not found, the exception should be thrown
351        std::string message = "The computer ";
352        message += machinename;
353        message += " was not found in the catalog associated to the component ";
354        message += _Component.name;
355        MESSAGE(message);
356        throw SALOME_ModuleCatalog::NotFound(message.c_str());
357      }
358
359   END_OF("GetPathPrefix");
360   return _path;
361 }
362
363 //----------------------------------------------------------------------
364 // Function : constraint
365 // Purpose  : obtain the constraint affected to a component
366 //----------------------------------------------------------------------
367 char* SALOME_ModuleCatalog_AcomponentImpl::constraint() 
368 {
369   return CORBA::string_dup(_Component.constraint);
370 }
371
372 //----------------------------------------------------------------------
373 // Function : componentname
374 // Purpose  : obtain the componentname
375 //----------------------------------------------------------------------
376 char* SALOME_ModuleCatalog_AcomponentImpl::componentname()
377 {
378   return CORBA::string_dup(_Component.name);
379 }
380
381 //----------------------------------------------------------------------
382 // Function : componentusername
383 // Purpose  : obtain the componentusername
384 //----------------------------------------------------------------------
385 char* SALOME_ModuleCatalog_AcomponentImpl::componentusername()
386 {
387   return CORBA::string_dup(_Component.username);
388 }
389
390 //----------------------------------------------------------------------
391 // Function : implementation type
392 // Purpose  : return the implementation type :  C++ (dyn lib), Python (module) or executable
393 //----------------------------------------------------------------------
394 SALOME_ModuleCatalog::ImplType SALOME_ModuleCatalog_AcomponentImpl::implementation_type()
395 {
396   return _Component.implementationType ;
397 }
398
399 //----------------------------------------------------------------------
400 // Function : implementation name
401 // Purpose  : return the implementation name to exec if the default one is not convenient
402 //----------------------------------------------------------------------
403 char* SALOME_ModuleCatalog_AcomponentImpl::implementation_name()
404 {
405   return _Component.implname ;
406 }
407
408 //----------------------------------------------------------------------
409 // Function : component_type
410 // Purpose  : define the type of the component
411 //----------------------------------------------------------------------
412 SALOME_ModuleCatalog::ComponentType 
413 SALOME_ModuleCatalog_AcomponentImpl::component_type() 
414 {
415   return _Component.type;
416 }
417
418 //----------------------------------------------------------------------
419 // Function : icone
420 // Purpose  : obtain the icone affected to a component (for IAPP)
421 //----------------------------------------------------------------------
422 char* SALOME_ModuleCatalog_AcomponentImpl::component_icone() 
423 {
424   return CORBA::string_dup(_Component.icon);
425 }
426
427
428 void SALOME_ModuleCatalog_AcomponentImpl::duplicate
429 (SALOME_ModuleCatalog::ServicesParameter & P_out,
430  const SALOME_ModuleCatalog::ServicesParameter &P_in)
431 {
432   // duplicate parameter name
433   P_out.Parametername = CORBA::string_dup(P_in.Parametername);
434   
435   // duplicate parameter type
436   P_out.Parametertype = CORBA::string_dup(P_in.Parametertype);
437 }
438
439
440 void SALOME_ModuleCatalog_AcomponentImpl::duplicate
441 (SALOME_ModuleCatalog::ServicesDataStreamParameter & P_out,
442  const SALOME_ModuleCatalog::ServicesDataStreamParameter &P_in)
443 {
444   // duplicate parameter name
445   P_out.Parametername = CORBA::string_dup(P_in.Parametername);
446   
447   // duplicate parameter type
448   P_out.Parametertype = P_in.Parametertype;
449
450   // duplicate parameter dependency
451   P_out.Parameterdependency = P_in.Parameterdependency;
452
453 }
454
455 void SALOME_ModuleCatalog_AcomponentImpl::duplicate
456 (SALOME_ModuleCatalog::Service & S_out,
457  const SALOME_ModuleCatalog::Service &S_in)
458 {
459   // type of node
460   S_out.TypeOfNode = S_in.TypeOfNode;
461
462     // duplicate service name
463   S_out.ServiceName = CORBA::string_dup(S_in.ServiceName);
464   
465   // duplicate service by default
466   S_out.Servicebydefault = S_in.Servicebydefault;
467
468   unsigned int _length;
469
470   // duplicate in Parameters
471   _length = S_in.ServiceinParameter.length();
472   S_out.ServiceinParameter.length(_length);
473
474   for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
475     duplicate(S_out.ServiceinParameter[ind2],
476               S_in.ServiceinParameter[ind2]);
477   
478   // duplicate out Parameters
479   _length = S_in.ServiceoutParameter.length();
480   S_out.ServiceoutParameter.length(_length);
481
482   for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
483     duplicate(S_out.ServiceoutParameter[ind2],
484               S_in.ServiceoutParameter[ind2]);
485   
486   // duplicate in DataStreamParameters
487   _length = S_in.ServiceinDataStreamParameter.length();
488   S_out.ServiceinDataStreamParameter.length(_length);
489
490   for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
491     duplicate(S_out.ServiceinDataStreamParameter[ind2],
492               S_in.ServiceinDataStreamParameter[ind2]);
493   
494   // duplicate out DataStreamParameters
495   _length = S_in.ServiceoutDataStreamParameter.length();
496   SCRUTE(_length);
497   S_out.ServiceoutDataStreamParameter.length(_length);
498   
499   for (unsigned int ind2 = 0; ind2 < _length ; ind2 ++)
500     duplicate(S_out.ServiceoutDataStreamParameter[ind2],
501               S_in.ServiceoutDataStreamParameter[ind2]);
502 }
503
504
505 void SALOME_ModuleCatalog_AcomponentImpl::duplicate
506 (SALOME_ModuleCatalog::DefinitionInterface & I_out,
507  const SALOME_ModuleCatalog::DefinitionInterface & I_in)
508 {
509   //duplicate interface name
510   I_out.interfacename = CORBA::string_dup(I_in.interfacename);
511   
512   // duplicate service list
513   unsigned int _length = I_in.interfaceservicelist.length();
514   SCRUTE(_length);
515   I_out.interfaceservicelist.length(_length);
516   
517   for (unsigned int ind1 = 0; ind1 < _length ; ind1 ++)
518     duplicate(I_out.interfaceservicelist[ind1],
519               I_in.interfaceservicelist[ind1]);
520 }
521
522