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