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