Salome HOME
A patch from Paul RASCLE for: kernel documentation with doxygen, modification on...
[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   MESSAGE("Name : " <<  C->componentname());
164   MESSAGE("Type : " << C->component_type() << " multistudy : " << C->multistudy());
165   MESSAGE("Constraint : " << C->constraint());
166   MESSAGE("Icon : " << C->component_icone());
167
168   // obtain interfaces list of the component
169
170   SALOME_ModuleCatalog::ListOfInterfaces_var _list = C->GetInterfaceList();
171   for (unsigned int i = 0; i < _list->length();i++) {
172     const char * s =  _list[i];
173     PrintInterface(C, s);
174   }
175 }
176
177
178 void PrintInterface(SALOME_ModuleCatalog::Acomponent_ptr C,
179                     const string & InterfaceName)
180 {
181   unsigned int i, n;
182         
183    SALOME_ModuleCatalog::DefinitionInterface_var _interf 
184      = C->GetInterface(InterfaceName.c_str());
185    MESSAGE ("Interface : " << _interf->interfacename);
186
187    SALOME_ModuleCatalog::ListOfInterfaceService S = _interf->interfaceservicelist;
188    n = S.length();
189    for (i = 0; i < n; i++) {
190      const char * _S = S[i].ServiceName;
191      PrintService(C, InterfaceName, _S);
192    }
193 }
194
195 void PrintService(SALOME_ModuleCatalog::Acomponent_ptr C,
196                   const string & InterfaceName,
197                   const string & ServiceName)
198 {
199   int i, n;
200
201    SALOME_ModuleCatalog::Service_var Service 
202      = (ServiceName.compare("") == 0)
203      ? C->GetDefaultService(InterfaceName.c_str())
204      : C->GetService(InterfaceName.c_str(), ServiceName.c_str());
205
206    MESSAGE("Service : " << Service->ServiceName);
207    
208    MESSAGE("In Parameter(s):");
209    n = Service->ServiceinParameter.length();
210    for (i = 0; i<n; i++)
211      {
212        MESSAGE("  Parameter       " 
213                << Service->ServiceinParameter[i].Parametername);
214        MESSAGE("  Type          : "
215                << Service->ServiceinParameter[i].Parametertype);
216      }
217    
218    MESSAGE("Out Parameter(s):");
219    n = Service->ServiceoutParameter.length();
220    for (i = 0; i<n; i++)
221      {
222        MESSAGE("  Parameter       " 
223                << Service->ServiceoutParameter[i].Parametername);
224        MESSAGE("  Type          : "
225                << Service->ServiceoutParameter[i].Parametertype);
226      }
227    
228    MESSAGE("In DataStreamParameter(s):");
229    n = Service->ServiceinDataStreamParameter.length();
230    for (i = 0; i<n; i++)
231      {
232        MESSAGE("  Parameter " 
233                << Service->ServiceinDataStreamParameter[i].Parametername);
234        MESSAGE("  Type          : "
235                << Service->ServiceinDataStreamParameter[i].Parametertype);
236        MESSAGE("  Dependency    : "
237                << Service->ServiceinDataStreamParameter[i].Parametertype);
238      }
239    
240    MESSAGE("Out DataStreamParameter(s):");
241    n = Service->ServiceoutDataStreamParameter.length();
242    for (i = 0; i<n; i++)
243      {
244        MESSAGE("  Parameter " 
245                << Service->ServiceoutDataStreamParameter[i].Parametername);
246        MESSAGE("  Type          : "
247                << Service->ServiceoutDataStreamParameter[i].Parametertype);
248        MESSAGE("  Dependency    : "
249                << Service->ServiceoutDataStreamParameter[i].Parametertype);
250      }
251    
252
253 }
254
255
256