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