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