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