Salome HOME
NRI : Remove dependence with VISU.
[modules/kernel.git] / src / ModuleCatalog / SALOME_ModuleCatalog_Client.cxx
1 using namespace std;
2 /* $Header$ */
3
4 #include <iostream.h>
5 #include "SALOME_NamingService.hxx"
6 #include "SALOME_ModuleCatalog.hh"
7 #include <string>
8 #include "utilities.h"
9
10 int main(int argc,char **argv)
11 {
12   char* name_to_find = "Geometry";
13
14   CORBA::ORB_var orb;
15   CosNaming::NamingContext_var _rootContext;
16   CORBA::Object_var objVar, objVarN;
17   try {
18
19         // initialize the ORB
20
21   orb = CORBA::ORB_init (argc, argv);
22
23  
24   // Get CORBA reference of the catalog
25   SALOME_NamingService NS(orb);
26   CORBA::Object_var objVarN = NS.Resolve("/Kernel/ModulCatalog");
27
28    SALOME_ModuleCatalog::ModuleCatalog_var Catalogue  = SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN); 
29    MESSAGE("Distant catalog of component found")
30
31      // Get component list
32    SALOME_ModuleCatalog::ListOfComponents_var list_composants = Catalogue->GetComponentList();
33
34
35    // Typed component list
36    MESSAGE("Get Typed Component list (GEOM Type)");
37    SALOME_ModuleCatalog::ListOfComponents_var list_typed_composants = Catalogue->GetTypedComponentList(SALOME_ModuleCatalog::GEOM);
38    for (unsigned int ind = 0; ind < list_typed_composants->length();ind++)
39      MESSAGE("Component GEOM list : " << list_typed_composants[ind]);      
40
41    MESSAGE("Get Typed Component list (SUPERV Type)");
42    SALOME_ModuleCatalog::ListOfComponents_var list_styped_composants = Catalogue->GetTypedComponentList(SALOME_ModuleCatalog::SUPERV);
43    for (unsigned int ind = 0; ind < list_styped_composants->length();ind++)
44       MESSAGE("Component SUPERV list : " << list_styped_composants[ind]);
45
46    // Get list of couple (component name, component icone)
47    SALOME_ModuleCatalog::ListOfIAPP_Affich_var list_composants_icone = Catalogue->GetComponentIconeList();
48    for (unsigned int ind = 0; ind < list_composants_icone->length();ind++)
49      {
50        MESSAGE("Component name: " << list_composants_icone[ind].modulename);
51        MESSAGE("Component icone: " << list_composants_icone[ind].moduleicone);
52      }
53   
54    // obtain a component (specified as parameter of the client)
55    SALOME_ModuleCatalog::Acomponent_ptr Geom = Catalogue->GetComponent("Geometry");
56    if (CORBA::is_nil (Geom)) 
57    {
58      INFOS("Catalog Error : Component Geometry not found in the catalog")
59       exit (-1);
60    }
61  
62    MESSAGE("Component of name : " <<  Geom->componentname() << " created ");
63    MESSAGE("Component type : " << Geom->component_type() << " multistudy : " <<Geom->multistudy());
64    MESSAGE("Component constraint : " << Geom->constraint());
65    MESSAGE("Component icone : " << Geom->component_icone());
66
67      // Obtain another component
68    SALOME_ModuleCatalog::Acomponent_ptr Superv = Catalogue->GetComponent("Supervision");
69    if (CORBA::is_nil (Superv)) 
70    {
71      INFOS("Catalog Error : Component Supervision not found in the catalog")
72       exit (-1);
73    }
74  
75    MESSAGE("Component of name : " <<  Superv->componentname() << " created ");
76    MESSAGE("Component type : " << Superv->component_type() << " multistudy : " <<Superv->multistudy());
77    MESSAGE("Component constraint : " << Superv->constraint());
78    MESSAGE("Component icone : " << Superv->component_icone());
79
80      // obtain prefix path for a computer
81    char* path;
82    path =Superv->GetPathPrefix("omote");
83    MESSAGE("Path prefix pour omote : " << path);
84
85    // obtain prefix path for a computer
86    path =Geom->GetPathPrefix("eri");
87    MESSAGE("Path prefix pour eri : " << path);
88
89    // obtain interfaces list of the component
90    SALOME_ModuleCatalog::ListOfInterfaces_var _list = new SALOME_ModuleCatalog::ListOfInterfaces;
91    _list = Geom->GetInterfaceList();
92    for (unsigned int ind = 0; ind < _list->length();ind++)
93      MESSAGE("Interface name : " << _list[ind]);
94
95    // obtain interfaces list of the component
96    SALOME_ModuleCatalog::ListOfInterfaces_var _list1 = new SALOME_ModuleCatalog::ListOfInterfaces;
97    _list1 = Superv->GetInterfaceList();
98    for (unsigned int ind = 0; ind < _list1->length();ind++)
99      MESSAGE("Interface name : " << _list1[ind])
100
101         
102    // Obtain one interface of a component
103    SALOME_ModuleCatalog::DefinitionInterface_var _interf = new SALOME_ModuleCatalog::DefinitionInterface;
104    _interf = Geom->GetInterface("Geometry");
105    MESSAGE ("Interface " << _interf->interfacename << " getted")
106    for (unsigned int ind = 0; ind < _interf->interfaceservicelist.length();ind++)
107      MESSAGE("Service name : " << _interf->interfaceservicelist[ind].ServiceName)
108
109
110    // obtain services list of the component
111         
112    SALOME_ModuleCatalog::ListOfServices_var list_services_component = new SALOME_ModuleCatalog::ListOfServices;
113    list_services_component = Geom->GetServiceList("Geometry");
114    for (unsigned int ind = 0; ind < list_services_component->length();ind++)
115        MESSAGE("Service name : " << list_services_component[ind])
116
117
118     // Get a service of the component
119
120    SALOME_ModuleCatalog::Service_var second_service = new SALOME_ModuleCatalog::Service;
121     second_service = Geom->GetDefaultService("Geometry");
122
123     MESSAGE("Default Service name: " << second_service->ServiceName)
124    for (unsigned int ind1 = 0; ind1 <second_service->ServiceinParameter.length();ind1++)
125      {
126        MESSAGE("Type of the in Parameter of this service : " << second_service->ServiceinParameter[ind1].Parametertype)
127        MESSAGE("Name of the in Parameter of this service : " << second_service->ServiceinParameter[ind1].Parametername)
128      }
129    for (unsigned int ind1 = 0; ind1 <second_service->ServiceoutParameter.length();ind1++)
130      {
131        MESSAGE("Type of the out Parameter of this service : " << second_service->ServiceoutParameter[ind1].Parametertype)
132        MESSAGE("Name of the out Parameter of this service : " << second_service->ServiceoutParameter[ind1].Parametername)
133      }
134
135
136
137     second_service = Geom->GetDefaultService("Geometry");
138
139     MESSAGE("Default Service name: " << second_service->ServiceName)
140    for (unsigned int ind1 = 0; ind1 <second_service->ServiceinParameter.length();ind1++)
141      {
142        MESSAGE("Type of the in Parameter of this service : " << second_service->ServiceinParameter[ind1].Parametertype)
143        MESSAGE("Name of the in Parameter of this service : " << second_service->ServiceinParameter[ind1].Parametername)
144      }
145    for (unsigned int ind1 = 0; ind1 <second_service->ServiceoutParameter.length();ind1++)
146      {
147        MESSAGE("Type of the out Parameter of this service : " << second_service->ServiceoutParameter[ind1].Parametertype)
148        MESSAGE("Name of the out Parameter of this service : " << second_service->ServiceoutParameter[ind1].Parametername)
149      }
150
151
152
153    // Get service of the component
154         
155    SALOME_ModuleCatalog::Service_var service_1 = new SALOME_ModuleCatalog::Service;
156
157    service_1 = Geom->GetService("Geometry","MakeSphere") ;
158
159    MESSAGE("Service name: " << service_1->ServiceName)
160    for (unsigned int ind1 = 0; ind1 <service_1->ServiceinParameter.length();ind1++)
161      {
162        MESSAGE("Type of the in Parameter of this service : " << service_1->ServiceinParameter[ind1].Parametertype)
163        MESSAGE("Name of the in Parameter of this service : " << service_1->ServiceinParameter[ind1].Parametername)
164      }
165
166    for (unsigned int ind1 = 0; ind1 <service_1->ServiceoutParameter.length();ind1++)
167      {
168        MESSAGE("Type of the out Parameter of this service : " << service_1->ServiceoutParameter[ind1].Parametertype)
169        MESSAGE("Name of the out Parameter of this service : " << service_1->ServiceoutParameter[ind1].Parametername)
170      }
171
172    // Test levĂ©e exception
173    service_1 = Geom->GetService("BOX","makeBox") ;
174
175
176     }
177   catch(SALOME_ModuleCatalog::NotFound &ex){
178     INFOS("SALOME_ModuleCatalog::NotFound")
179       cerr << ex.what << endl;
180   }
181     catch(CORBA::SystemException&) {
182       INFOS("Caught CORBA::SystemException.")
183   }
184     catch (CosNaming::NamingContext::CannotProceed &) {
185       INFOS("CosNaming::NamingContext::CannotProceed")
186   }
187     catch (CosNaming::NamingContext::NotFound &) {
188       INFOS("CosNaming::NamingContext::NotFound")
189   }
190     catch (CosNaming::NamingContext::InvalidName &) {
191       INFOS("CosNaming::NamingContext::InvalidName")
192   }
193     catch (CosNaming::NamingContext::AlreadyBound &) {
194       INFOS("CosNaming::NamingContext::AlreadyBound")
195   }
196     catch (CosNaming::NamingContext::NotEmpty &) {
197       INFOS("CosNaming::NamingContext::NotEmpty")
198   }
199
200   catch(CORBA::Exception &sysEx) {
201     INFOS("Caught CORBA::Exception.")
202   }
203
204
205   return 0;
206 }
207
208
209
210
211
212
213
214
215
216
217
218
219
220