Salome HOME
This commit was generated by cvs2git to create tag 'V1_4_0b1'.
[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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SALOME_ModuleCatalog_Acomponent_impl.cxx
25 //  Author : Estelle Deville
26 //  Module : SALOME
27 //  $Header$
28
29 using namespace std;
30 #include "SALOME_ModuleCatalog_Acomponent_impl.hxx"
31
32 //----------------------------------------------------------------------
33 // Function : SALOME_ModuleCatalog_AcomponentImpl
34 // Purpose  : Constructor
35 //            Affect the component name, type,icone,  a bool to define 
36 //            if it's multistudy or not.
37 //            Affect too the constraint and the interfaces of the component
38 //            and the pathes prefixes for all computers
39 //----------------------------------------------------------------------  
40 SALOME_ModuleCatalog_AcomponentImpl::SALOME_ModuleCatalog_AcomponentImpl(
41                    const char* name,
42                    const char* username,
43                    const char* constraint,  
44                    SALOME_ModuleCatalog::ComponentType componenttype,
45                    CORBA::Boolean componentmultistudy,
46                    const char* icone,
47                    SALOME_ModuleCatalog::ListOfDefInterface list_interfaces,
48                    ListOfPathPrefix pathes)
49 {
50   MESSAGE("Component creation")
51   // Affect component name
52   _component_name = new char[strlen(name)+1];
53  strcpy(_component_name, name);
54
55   // Affect component user name
56   _component_user_name = new char[strlen(username)+1];
57  strcpy(_component_user_name, username);
58
59  // Affect constraint
60  _constraint =new char[strlen(constraint)+1];
61  strcpy(_constraint, constraint);
62
63  // Affect component type
64  _componenttype = componenttype;
65  
66  // Affect component multistudy
67  _componentmultistudy = componentmultistudy;
68
69  // Affect icone
70  _icone =new char[strlen(icone)+1];
71  strcpy(_icone, icone);
72
73  //Affect interfaces
74  _list_interfaces.length(list_interfaces.length());
75  _list_interfaces = list_interfaces;
76
77  // affect path prefixes
78  _pathes.resize(pathes.size());
79  _pathes = pathes ;
80 }
81
82 //----------------------------------------------------------------------
83 // Function : ~SALOME_ModuleCatalog_AcomponentImpl
84 // Purpose  : Destructor 
85 //----------------------------------------------------------------------
86 SALOME_ModuleCatalog_AcomponentImpl::~SALOME_ModuleCatalog_AcomponentImpl()
87 {
88   MESSAGE("Component destruction")
89   // empty memory
90   delete [] _component_name;
91   delete [] _component_user_name;
92   delete [] _constraint;
93 }
94
95 //----------------------------------------------------------------------
96 // Function : GetInterfaceList
97 // Purpose  : get a list of the interfaces name of a component
98 //----------------------------------------------------------------------
99 SALOME_ModuleCatalog::ListOfInterfaces* 
100 SALOME_ModuleCatalog_AcomponentImpl::GetInterfaceList() 
101 {
102   SALOME_ModuleCatalog::ListOfInterfaces_var _list = new SALOME_ModuleCatalog::ListOfInterfaces;
103
104   // All the interfaces are defined in _list_interfaces affected at the
105   // component creation
106   unsigned int _length_interfaces =_list_interfaces.length();
107
108   _list->length(_length_interfaces);
109
110   // Parse all the interfaces to get their name
111   for (unsigned int ind = 0; ind < _length_interfaces; ind++)
112     {
113       _list[ind] = CORBA::string_dup(_list_interfaces[ind].interfacename);
114       MESSAGE("The component " << _component_name << " contains " << _list[ind] << " as interface") 
115     }
116   
117   return _list._retn();
118 }
119
120 //----------------------------------------------------------------------
121 // Function : GetInterface
122 // Purpose  : get one interface of a component
123 //----------------------------------------------------------------------
124 SALOME_ModuleCatalog::DefinitionInterface*
125 SALOME_ModuleCatalog_AcomponentImpl::GetInterface(const char* interfacename)
126                                      throw(SALOME_ModuleCatalog::NotFound)
127 {
128   SALOME_ModuleCatalog::DefinitionInterface_var _interface = new SALOME_ModuleCatalog::DefinitionInterface;
129   SALOME_ModuleCatalog::Service_var _service = new SALOME_ModuleCatalog::Service;
130   // Variables initialisation
131   _interface->interfaceservicelist.length(0);
132   int _length = 0;
133   bool _find = false ;
134   
135   // looking for the specified interface
136   for (unsigned int ind = 0; ind < _list_interfaces.length(); ind++)
137     {
138       if (strcmp(interfacename, _list_interfaces[ind].interfacename) == 0)
139         {
140           // wanted interface
141           _find = true ;
142
143           // Affect the name of the interface
144           _interface->interfacename = interfacename;
145
146           // Affect each service of the wanted interface
147           for (unsigned int ind1 = 0; ind1 <  _list_interfaces[ind].interfaceservicelist.length() ; ind1++)
148             {
149               _interface->interfaceservicelist.length(_length+1);
150               _service = _duplicate_service(_list_interfaces[ind].interfaceservicelist[ind1]);
151               _interface->interfaceservicelist[_length] = _service;     
152              
153               _length++;
154             }
155
156         }
157     }
158   
159   if (!_find)
160     {
161       // The interface was not found, the exception should be thrown
162       char * message = new char[100];
163       strcpy(message, "The interface ");
164       strcat(message,interfacename);
165       strcat(message, " of the component ");
166       strcat(message,_component_name); 
167       strcat(message, " was not found") ;
168       MESSAGE("The interface " << interfacename << " of the component " << _component_name << " was not found")
169         throw SALOME_ModuleCatalog::NotFound(message);
170       delete [] message;
171     }
172
173   return _interface._retn();
174 }
175
176
177
178 //----------------------------------------------------------------------
179 // Function : GetServiceList
180 // Purpose  : get a list of the services name of an interface 
181 //            of a component
182 //----------------------------------------------------------------------
183 SALOME_ModuleCatalog::ListOfServices* 
184 SALOME_ModuleCatalog_AcomponentImpl::GetServiceList(const char* interfacename)
185                                      throw(SALOME_ModuleCatalog::NotFound)
186 {
187   SALOME_ModuleCatalog::ListOfServices_var _list = new SALOME_ModuleCatalog::ListOfServices;
188
189   // Variables initialisation
190   _list->length(0); 
191   bool _find = false ;
192
193   // looking for the specified interface
194   for (unsigned int ind = 0; ind < _list_interfaces.length(); ind++)
195     {
196       if (strcmp(interfacename, _list_interfaces[ind].interfacename) == 0)
197         {
198           _find = true ;
199           // wanted interface
200           // Get the list of services name for this interface
201           unsigned int _length_services = _list_interfaces[ind].interfaceservicelist.length();
202           _list->length(_length_services);
203           for (unsigned int ind1 = 0; ind1 < _length_services ; ind1++)
204             {
205               _list[ind1] = CORBA::string_dup(_list_interfaces[ind].interfaceservicelist[ind1].ServiceName);
206               MESSAGE("The interface " << interfacename << " of the component " << _component_name << " contains " << _list[ind1] << " as a service") 
207             }
208         }
209     }
210
211  if (!_find)
212     {
213       // The interface was not found, the exception should be thrown
214       char * message = new char[100];
215       strcpy(message, "The interface ");
216       strcat(message,interfacename);
217       strcat(message, " of the component ");
218       strcat(message,_component_name); 
219       strcat(message, " was not found") ;
220       MESSAGE("The interface " << interfacename << " of the component " << _component_name << " was not found")
221         throw SALOME_ModuleCatalog::NotFound(message);
222       delete [] message;
223     }
224
225   return _list._retn();
226 }
227
228     
229 //----------------------------------------------------------------------
230 // Function : GetService
231 // Purpose  : get one service of an interface of a component
232 //----------------------------------------------------------------------
233 SALOME_ModuleCatalog::Service* 
234 SALOME_ModuleCatalog_AcomponentImpl::GetService(const char* interfacename, 
235                                                 const char* servicename) 
236                                      throw(SALOME_ModuleCatalog::NotFound)
237 {
238   SALOME_ModuleCatalog::Service_var _service = new SALOME_ModuleCatalog::Service;
239   // Varaibles initialisation
240   bool _find = false ;
241   
242   // looking for the specified interface
243   for (unsigned int ind = 0; ind < _list_interfaces.length(); ind++)
244     {
245       if (strcmp(interfacename, _list_interfaces[ind].interfacename) == 0)
246         {
247           // wanted interface
248           // looking for the specified service
249           for (unsigned int ind1 = 0; ind1 <  _list_interfaces[ind].interfaceservicelist.length() ; ind1++)
250             {
251               if (strcmp(servicename, _list_interfaces[ind].interfaceservicelist[ind1].ServiceName) == 0)
252               {
253                 // Wanted Service
254                 // Affect the service to be returned
255                 _find = true ;
256                 _service = _duplicate_service(_list_interfaces[ind].interfaceservicelist[ind1]);
257               }
258             }
259
260         }
261     }
262   
263   if (!_find)
264     {
265       // The service was not found, the exception should be thrown
266       char * message = new char[100];
267       strcpy(message, "The service ");
268       strcat(message, servicename);
269       strcat(message," of the interface ");
270       strcat(message,interfacename);
271       strcat(message, " of the component ");
272       strcat(message,_component_name); 
273       strcat(message, " was not found") ;
274       MESSAGE("The service " << servicename << " of the interface " << interfacename << " of the component " << _component_name << " was not found")
275         throw SALOME_ModuleCatalog::NotFound(message);
276       delete [] message;
277     }
278
279   return _service._retn();
280 }
281
282 //----------------------------------------------------------------------
283 // Function : GetDefaultService
284 // Purpose  : get the default service of the interface
285 //----------------------------------------------------------------------
286 SALOME_ModuleCatalog::Service* 
287 SALOME_ModuleCatalog_AcomponentImpl::GetDefaultService(const char* interfacename) 
288                                      throw(SALOME_ModuleCatalog::NotFound)
289 {
290   SALOME_ModuleCatalog::Service_var _service = new SALOME_ModuleCatalog::Service;
291
292   // Variables initialisation
293   bool _find = false ;
294
295   // looking for the specified interface
296   for (unsigned int ind = 0; ind < _list_interfaces.length(); ind++)
297     {
298       if (strcmp(interfacename, _list_interfaces[ind].interfacename) == 0)
299         {
300           // wanted interface
301           // looking for the defautl service of the wanted interface
302           for (unsigned int ind1 = 0; ind1 <  _list_interfaces[ind].interfaceservicelist.length() ; ind1++)
303             {
304               if (_list_interfaces[ind].interfaceservicelist[ind1].Servicebydefault)
305               {
306                 // Default Service
307                 // affect the service to be returned
308                 _find = true ;
309                 _service = _duplicate_service(_list_interfaces[ind].interfaceservicelist[ind1]);
310               }
311             }
312
313         }
314     }
315
316   if (!_find)
317     {
318       // The service was not found, the exception should be thrown
319       char * message = new char[100];
320       strcpy(message, "The default service of the interface ");
321       strcat(message,interfacename);
322       strcat(message, " of the component ");
323       strcat(message,_component_name); 
324       strcat(message, " was not found") ;
325       MESSAGE("The default service of the interface " << interfacename << " of the component " << _component_name << " was not found")
326         throw SALOME_ModuleCatalog::NotFound(message);
327       delete [] message;
328     }
329
330   return _service._retn();
331 }
332
333 //----------------------------------------------------------------------
334 // Function : GetPathPrefix
335 // Purpose  : get the PathPrefix of a computer
336 //----------------------------------------------------------------------
337 char* 
338 SALOME_ModuleCatalog_AcomponentImpl::GetPathPrefix(const char* machinename) 
339                                      throw(SALOME_ModuleCatalog::NotFound)
340 {
341   MESSAGE("Begin of GetPathPrefix")
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 < _pathes.size() ; ind++)
349     {
350       for (unsigned int ind1 = 0 ; ind1 < _pathes[ind].ListOfComputer.size() ; ind1++)    
351         {
352           if (strcmp(machinename, _pathes[ind].ListOfComputer[ind1].c_str()) == 0)
353             {
354               _find = true ;
355               // Wanted computer
356               // affect the path to be returned
357                 const char* _temp = _pathes[ind].path.c_str() ;
358                   _path = new char[strlen(_temp)+1];
359               strcpy(_path,_temp);
360             }
361         }
362     }
363
364   if (!_find)
365     {
366       // The computer was not found, the exception should be thrown
367       char * message = new char[100];
368       strcpy(message, "The computer ");
369       strcat(message,machinename); 
370       strcat(message, " was not found in the catalog associated to the component ") ;
371       strcat(message,_component_name);      
372       MESSAGE("The computer " << machinename << " was not found in the catalog associated to the component " << _component_name)
373         throw SALOME_ModuleCatalog::NotFound(message);
374       delete [] message;
375     }
376
377   return _path;
378 }
379
380 //----------------------------------------------------------------------
381 // Function : constraint
382 // Purpose  : obtain the constraint affected to a component
383 //----------------------------------------------------------------------
384 char* SALOME_ModuleCatalog_AcomponentImpl::constraint() 
385 {
386   return CORBA::string_dup(_constraint);
387 }
388
389 //----------------------------------------------------------------------
390 // Function : componentname
391 // Purpose  : obtain the componentname
392 //----------------------------------------------------------------------
393 char* SALOME_ModuleCatalog_AcomponentImpl::componentname()
394 {
395   return CORBA::string_dup(_component_name);
396 }
397
398 //----------------------------------------------------------------------
399 // Function : componentusername
400 // Purpose  : obtain the componentusername
401 //----------------------------------------------------------------------
402 char* SALOME_ModuleCatalog_AcomponentImpl::componentusername()
403 {
404   return CORBA::string_dup(_component_user_name);
405 }
406
407 //----------------------------------------------------------------------
408 // Function : multistudy
409 // Purpose  : define if a component can be multistudy or not
410 //----------------------------------------------------------------------
411 CORBA::Boolean SALOME_ModuleCatalog_AcomponentImpl::multistudy()
412 {
413   return _componentmultistudy ;
414 }
415
416 //----------------------------------------------------------------------
417 // Function : component_type
418 // Purpose  : define the type of the component
419 //----------------------------------------------------------------------
420 SALOME_ModuleCatalog::ComponentType 
421 SALOME_ModuleCatalog_AcomponentImpl::component_type() 
422 {
423   return _componenttype;
424 }
425
426 //----------------------------------------------------------------------
427 // Function : icone
428 // Purpose  : obtain the icone affected to a component (for IAPP)
429 //----------------------------------------------------------------------
430 char* SALOME_ModuleCatalog_AcomponentImpl::component_icone() 
431 {
432   return CORBA::string_dup(_icone);
433 }
434
435 //----------------------------------------------------------------------
436 // Function :  _duplicate_service
437 // Purpose  : duplicate a service
438 //----------------------------------------------------------------------
439 SALOME_ModuleCatalog::Service_var 
440 SALOME_ModuleCatalog_AcomponentImpl::_duplicate_service(SALOME_ModuleCatalog::Service service)
441 {
442   SALOME_ModuleCatalog::Service_var _service = new SALOME_ModuleCatalog::Service;
443
444   // service name
445   _service->ServiceName = CORBA::string_dup(service.ServiceName);
446   // service by default
447   _service->Servicebydefault = service.Servicebydefault;
448
449   // in Parameters service
450   unsigned int _length_in_param = service.ServiceinParameter.length();
451   for(unsigned int ind = 0; ind < _length_in_param; ind++)
452     {
453       _service->ServiceinParameter.length(_length_in_param);
454       // in Parameter type
455       _service->ServiceinParameter[ind].Parametertype = CORBA::string_dup(service.ServiceinParameter[ind].Parametertype);
456       // in Parameter name
457        _service->ServiceinParameter[ind].Parametername = CORBA::string_dup(service.ServiceinParameter[ind].Parametername);
458     }
459
460    // out Parameters service
461   unsigned int _length_out_param = service.ServiceoutParameter.length();
462   for(unsigned int ind = 0; ind < _length_out_param; ind++)
463     {
464       _service->ServiceoutParameter.length(_length_out_param);
465       // out Parameter type
466       _service->ServiceoutParameter[ind].Parametertype = CORBA::string_dup(service.ServiceoutParameter[ind].Parametertype);
467       // out Parameter name
468        _service->ServiceoutParameter[ind].Parametername = CORBA::string_dup(service.ServiceoutParameter[ind].Parametername);
469     }    
470
471   return _service;
472 }