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