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