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