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