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