Salome HOME
ENV: Windows porting.
[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 /* $Header$ */
28
29 #include <iostream.h>
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    for (unsigned int ind = 0; ind < list_typed_composants->length();ind++)
82       MESSAGE("Component SUPERV list : " << list_typed_composants[ind]);
83
84    // Get list of couple (component name, component icone)
85    SALOME_ModuleCatalog::ListOfIAPP_Affich_var list_composants_icone 
86      = Catalogue->GetComponentIconeList();
87    for (unsigned int ind = 0; ind < list_composants_icone->length();ind++)
88      {
89        MESSAGE("Component name: " << list_composants_icone[ind].modulename);
90        MESSAGE("Component icone: " << list_composants_icone[ind].moduleicone);
91      }
92   
93    // obtain a component (specified as parameter of the client)
94    SALOME_ModuleCatalog::Acomponent_ptr Geom = Catalogue->GetComponent("Geometry");
95    if (CORBA::is_nil (Geom)) 
96    {
97      INFOS("Catalog Error : Component Geometry not found in the catalog")
98       exit (-1);
99    }
100  
101    PrintComponent(Geom);
102
103      // Obtain another component
104    SALOME_ModuleCatalog::Acomponent_ptr Superv = Catalogue->GetComponent("Supervision");
105    if (CORBA::is_nil (Superv)) 
106    {
107      INFOS("Catalog Error : Component Supervision not found in the catalog")
108       exit (-1);
109    }
110    PrintComponent(Superv);
111
112      // obtain prefix path for a computer
113    char* path;
114    path =Superv->GetPathPrefix("omote");
115    MESSAGE("Path prefix pour omote : " << path);
116
117    // obtain prefix path for a computer
118    path =Geom->GetPathPrefix("eri");
119    MESSAGE("Path prefix pour eri : " << path);
120
121     }
122   catch(SALOME_ModuleCatalog::NotFound &ex){
123     INFOS("SALOME_ModuleCatalog::NotFound")
124       cerr << ex.what << endl;
125   }
126     catch(CORBA::SystemException&) {
127       INFOS("Caught CORBA::SystemException.")
128   }
129     catch (CosNaming::NamingContext::CannotProceed &) {
130       INFOS("CosNaming::NamingContext::CannotProceed")
131   }
132     catch (CosNaming::NamingContext::NotFound &) {
133       INFOS("CosNaming::NamingContext::NotFound")
134   }
135     catch (CosNaming::NamingContext::InvalidName &) {
136       INFOS("CosNaming::NamingContext::InvalidName")
137   }
138     catch (CosNaming::NamingContext::AlreadyBound &) {
139       INFOS("CosNaming::NamingContext::AlreadyBound")
140   }
141     catch (CosNaming::NamingContext::NotEmpty &) {
142       INFOS("CosNaming::NamingContext::NotEmpty")
143   }
144
145   catch(CORBA::Exception &sysEx) {
146     INFOS("Caught CORBA::Exception.")
147   }
148
149
150   return 0;
151 }
152
153 void PrintComponent(SALOME_ModuleCatalog::Acomponent_ptr C)
154 {
155   const char *_name = C->componentname();
156
157   MESSAGE("Name : " <<  C->componentname());
158   MESSAGE("Type : " << C->component_type() << " multistudy : " << C->multistudy());
159   MESSAGE("Constraint : " << C->constraint());
160   MESSAGE("Icon : " << C->component_icone());
161
162   // obtain interfaces list of the component
163
164   SALOME_ModuleCatalog::ListOfInterfaces_var _list = C->GetInterfaceList();
165   for (unsigned int i = 0; i < _list->length();i++) {
166     const char * s =  _list[i];
167     PrintInterface(C, s);
168   }
169 }
170
171
172 void PrintInterface(SALOME_ModuleCatalog::Acomponent_ptr C,
173                     const string & InterfaceName)
174 {
175   unsigned int i, n;
176         
177    SALOME_ModuleCatalog::DefinitionInterface_var _interf 
178      = C->GetInterface(InterfaceName.c_str());
179    MESSAGE ("Interface : " << _interf->interfacename);
180
181    SALOME_ModuleCatalog::ListOfInterfaceService S = _interf->interfaceservicelist;
182    n = S.length();
183    for (i = 0; i < n; i++) {
184      const char * _S = S[i].ServiceName;
185      PrintService(C, InterfaceName, _S);
186    }
187 }
188
189 void PrintService(SALOME_ModuleCatalog::Acomponent_ptr C,
190                   const string & InterfaceName,
191                   const string & ServiceName)
192 {
193   int i, n;
194
195    SALOME_ModuleCatalog::Service_var Service 
196      = (ServiceName.compare("") == 0)
197      ? C->GetDefaultService(InterfaceName.c_str())
198      : C->GetService(InterfaceName.c_str(), ServiceName.c_str());
199
200    MESSAGE("Service : " << Service->ServiceName);
201    
202    MESSAGE("In Parameter(s):");
203    n = Service->ServiceinParameter.length();
204    for (i = 0; i<n; i++)
205      {
206        MESSAGE("  Parameter       " 
207                << Service->ServiceinParameter[i].Parametername);
208        MESSAGE("  Type          : "
209                << Service->ServiceinParameter[i].Parametertype);
210      }
211    
212    MESSAGE("Out Parameter(s):");
213    n = Service->ServiceoutParameter.length();
214    for (i = 0; i<n; i++)
215      {
216        MESSAGE("  Parameter       " 
217                << Service->ServiceoutParameter[i].Parametername);
218        MESSAGE("  Type          : "
219                << Service->ServiceoutParameter[i].Parametertype);
220      }
221    
222    MESSAGE("In DataStreamParameter(s):");
223    n = Service->ServiceinDataStreamParameter.length();
224    for (i = 0; i<n; i++)
225      {
226        MESSAGE("  Parameter " 
227                << Service->ServiceinDataStreamParameter[i].Parametername);
228        MESSAGE("  Type          : "
229                << Service->ServiceinDataStreamParameter[i].Parametertype);
230        MESSAGE("  Dependency    : "
231                << Service->ServiceinDataStreamParameter[i].Parametertype);
232      }
233    
234    MESSAGE("Out DataStreamParameter(s):");
235    n = Service->ServiceoutDataStreamParameter.length();
236    for (i = 0; i<n; i++)
237      {
238        MESSAGE("  Parameter " 
239                << Service->ServiceoutDataStreamParameter[i].Parametername);
240        MESSAGE("  Type          : "
241                << Service->ServiceoutDataStreamParameter[i].Parametertype);
242        MESSAGE("  Dependency    : "
243                << Service->ServiceoutDataStreamParameter[i].Parametertype);
244      }
245    
246
247 }
248
249
250