Salome HOME
First stable version after merging with V3_2_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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //
23 //
24 //  File   : SALOME_ModuleCatalog_Client.cxx
25 //  Module : SALOME
26
27 /* $Header$ */
28
29 #include <iostream>
30 #include "SALOME_NamingService.hxx"
31 #include "SALOME_ModuleCatalog.hh"
32 #include <string>
33 #include "utilities.h"
34 using namespace std;
35
36 void PrintService(SALOME_ModuleCatalog::Acomponent_ptr C,
37                   const string & InterfaceName,
38                   const string & ServiceName);
39
40 void PrintInterface(SALOME_ModuleCatalog::Acomponent_ptr C,
41                     const string & InterfaceName);
42
43 void PrintComponent(SALOME_ModuleCatalog::Acomponent_ptr C);
44
45 int main(int argc,char **argv)
46 {
47
48   CORBA::ORB_var orb;
49   CosNaming::NamingContext_var _rootContext;
50   CORBA::Object_var objVar, objVarN;
51   try {
52
53         // initialize the ORB
54
55   orb = CORBA::ORB_init (argc, argv);
56
57  
58   // Get CORBA reference of the catalog
59   SALOME_NamingService NS(orb);
60   CORBA::Object_var objVarN = NS.Resolve("/Kernel/ModulCatalog");
61
62    SALOME_ModuleCatalog::ModuleCatalog_var Catalogue 
63      = SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN); 
64    MESSAGE("Distant catalog of component found")
65
66      // Get component list
67    SALOME_ModuleCatalog::ListOfComponents_var list_composants 
68      = Catalogue->GetComponentList();
69
70
71    // Typed component list
72    MESSAGE("Get Typed Component list (GEOM Type)");
73    SALOME_ModuleCatalog::ListOfComponents_var list_typed_composants 
74      = Catalogue->GetTypedComponentList(SALOME_ModuleCatalog::GEOM);
75    for (unsigned int ind = 0; ind < list_typed_composants->length();ind++)
76      MESSAGE("Component GEOM list : " << list_typed_composants[ind]);      
77
78    MESSAGE("Get Typed Component list (SUPERV Type)");
79    list_typed_composants 
80      = Catalogue->GetTypedComponentList(SALOME_ModuleCatalog::SUPERV);
81 #ifndef WNT
82    for (unsigned int ind = 0; ind < list_typed_composants->length();ind++)
83 #else
84    for (ind = 0; ind < list_typed_composants->length();ind++)
85 #endif
86       MESSAGE("Component SUPERV list : " << list_typed_composants[ind]);
87
88    // Get list of couple (component name, component icone)
89    SALOME_ModuleCatalog::ListOfIAPP_Affich_var list_composants_icone 
90      = Catalogue->GetComponentIconeList();
91 #ifndef WNT
92    for (unsigned int ind = 0; ind < list_composants_icone->length();ind++)
93 #else
94    for (ind = 0; ind < list_composants_icone->length();ind++)
95 #endif
96      {
97        MESSAGE("Component name: " << list_composants_icone[ind].modulename);
98        MESSAGE("Component icone: " << list_composants_icone[ind].moduleicone);
99      }
100   
101    // obtain a component (specified as parameter of the client)
102    SALOME_ModuleCatalog::Acomponent_ptr Geom = Catalogue->GetComponent("Geometry");
103    if (CORBA::is_nil (Geom)) 
104    {
105      INFOS("Catalog Error : Component Geometry not found in the catalog")
106       exit (-1);
107    }
108  
109    PrintComponent(Geom);
110
111      // Obtain another component
112    SALOME_ModuleCatalog::Acomponent_ptr Superv = Catalogue->GetComponent("Supervision");
113    if (CORBA::is_nil (Superv)) 
114    {
115      INFOS("Catalog Error : Component Supervision not found in the catalog")
116       exit (-1);
117    }
118    PrintComponent(Superv);
119
120      // obtain prefix path for a computer
121    char* path;
122    path =Superv->GetPathPrefix("omote");
123    MESSAGE("Path prefix pour omote : " << path);
124
125    // obtain prefix path for a computer
126    path =Geom->GetPathPrefix("eri");
127    MESSAGE("Path prefix pour eri : " << path);
128
129     }
130   catch(SALOME_ModuleCatalog::NotFound &ex){
131     INFOS("SALOME_ModuleCatalog::NotFound")
132       cerr << ex.what << endl;
133   }
134     catch(CORBA::SystemException&) {
135       INFOS("Caught CORBA::SystemException.")
136   }
137     catch (CosNaming::NamingContext::CannotProceed &) {
138       INFOS("CosNaming::NamingContext::CannotProceed")
139   }
140     catch (CosNaming::NamingContext::NotFound &) {
141       INFOS("CosNaming::NamingContext::NotFound")
142   }
143     catch (CosNaming::NamingContext::InvalidName &) {
144       INFOS("CosNaming::NamingContext::InvalidName")
145   }
146     catch (CosNaming::NamingContext::AlreadyBound &) {
147       INFOS("CosNaming::NamingContext::AlreadyBound")
148   }
149     catch (CosNaming::NamingContext::NotEmpty &) {
150       INFOS("CosNaming::NamingContext::NotEmpty")
151   }
152
153   catch(CORBA::Exception &sysEx) {
154     INFOS("Caught CORBA::Exception.")
155   }
156
157
158   return 0;
159 }
160
161 void PrintComponent(SALOME_ModuleCatalog::Acomponent_ptr C)
162 {
163   const char *_name = C->componentname();
164
165   MESSAGE("Name : " <<  C->componentname());
166   MESSAGE("Type : " << C->component_type() << " multistudy : " << C->multistudy());
167   MESSAGE("Constraint : " << C->constraint());
168   MESSAGE("Icon : " << C->component_icone());
169
170   // obtain interfaces list of the component
171
172   SALOME_ModuleCatalog::ListOfInterfaces_var _list = C->GetInterfaceList();
173   for (unsigned int i = 0; i < _list->length();i++) {
174     const char * s =  _list[i];
175     PrintInterface(C, s);
176   }
177 }
178
179
180 void PrintInterface(SALOME_ModuleCatalog::Acomponent_ptr C,
181                     const string & InterfaceName)
182 {
183   unsigned int i, n;
184         
185    SALOME_ModuleCatalog::DefinitionInterface_var _interf 
186      = C->GetInterface(InterfaceName.c_str());
187    MESSAGE ("Interface : " << _interf->interfacename);
188
189    SALOME_ModuleCatalog::ListOfInterfaceService S = _interf->interfaceservicelist;
190    n = S.length();
191    for (i = 0; i < n; i++) {
192      const char * _S = S[i].ServiceName;
193      PrintService(C, InterfaceName, _S);
194    }
195 }
196
197 void PrintService(SALOME_ModuleCatalog::Acomponent_ptr C,
198                   const string & InterfaceName,
199                   const string & ServiceName)
200 {
201   int i, n;
202
203    SALOME_ModuleCatalog::Service_var Service 
204      = (ServiceName.compare("") == 0)
205      ? C->GetDefaultService(InterfaceName.c_str())
206      : C->GetService(InterfaceName.c_str(), ServiceName.c_str());
207
208    MESSAGE("Service : " << Service->ServiceName);
209    
210    MESSAGE("In Parameter(s):");
211    n = Service->ServiceinParameter.length();
212    for (i = 0; i<n; i++)
213      {
214        MESSAGE("  Parameter       " 
215                << Service->ServiceinParameter[i].Parametername);
216        MESSAGE("  Type          : "
217                << Service->ServiceinParameter[i].Parametertype);
218      }
219    
220    MESSAGE("Out Parameter(s):");
221    n = Service->ServiceoutParameter.length();
222    for (i = 0; i<n; i++)
223      {
224        MESSAGE("  Parameter       " 
225                << Service->ServiceoutParameter[i].Parametername);
226        MESSAGE("  Type          : "
227                << Service->ServiceoutParameter[i].Parametertype);
228      }
229    
230    MESSAGE("In DataStreamParameter(s):");
231    n = Service->ServiceinDataStreamParameter.length();
232    for (i = 0; i<n; i++)
233      {
234        MESSAGE("  Parameter " 
235                << Service->ServiceinDataStreamParameter[i].Parametername);
236        MESSAGE("  Type          : "
237                << Service->ServiceinDataStreamParameter[i].Parametertype);
238        MESSAGE("  Dependency    : "
239                << Service->ServiceinDataStreamParameter[i].Parametertype);
240      }
241    
242    MESSAGE("Out DataStreamParameter(s):");
243    n = Service->ServiceoutDataStreamParameter.length();
244    for (i = 0; i<n; i++)
245      {
246        MESSAGE("  Parameter " 
247                << Service->ServiceoutDataStreamParameter[i].Parametername);
248        MESSAGE("  Type          : "
249                << Service->ServiceoutDataStreamParameter[i].Parametertype);
250        MESSAGE("  Dependency    : "
251                << Service->ServiceoutDataStreamParameter[i].Parametertype);
252      }
253    
254
255 }
256
257
258