Salome HOME
Fix
[modules/kernel.git] / src / ModuleCatalog / SALOME_ModuleCatalog_Client.cxx
1 // Copyright (C) 2007-2013  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.
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    char* path;
113    path =Superv->GetPathPrefix("omote");
114    MESSAGE("Path prefix pour omote : " << path);
115
116    // obtain prefix path for a computer
117    path =Geom->GetPathPrefix("eri");
118    MESSAGE("Path prefix pour eri : " << path);
119
120     }
121   catch(SALOME_ModuleCatalog::NotFound &ex){
122     INFOS("SALOME_ModuleCatalog::NotFound")
123       std::cerr << ex.what << std::endl;
124   }
125     catch(CORBA::SystemException&) {
126       INFOS("Caught CORBA::SystemException.")
127   }
128     catch (CosNaming::NamingContext::CannotProceed &) {
129       INFOS("CosNaming::NamingContext::CannotProceed")
130   }
131     catch (CosNaming::NamingContext::NotFound &) {
132       INFOS("CosNaming::NamingContext::NotFound")
133   }
134     catch (CosNaming::NamingContext::InvalidName &) {
135       INFOS("CosNaming::NamingContext::InvalidName")
136   }
137     catch (CosNaming::NamingContext::AlreadyBound &) {
138       INFOS("CosNaming::NamingContext::AlreadyBound")
139   }
140     catch (CosNaming::NamingContext::NotEmpty &) {
141       INFOS("CosNaming::NamingContext::NotEmpty")
142   }
143
144   catch(CORBA::Exception &) {
145     INFOS("Caught CORBA::Exception.")
146   }
147
148
149   return 0;
150 }
151
152 void PrintComponent(SALOME_ModuleCatalog::Acomponent_ptr C)
153 {
154   MESSAGE("Name : " <<  C->componentname());
155   MESSAGE("Type : " << C->component_type() << " multistudy : " << C->multistudy());
156   MESSAGE("Constraint : " << C->constraint());
157   MESSAGE("Icon : " << C->component_icone());
158
159   // obtain interfaces list of the component
160
161   SALOME_ModuleCatalog::ListOfInterfaces_var _list = C->GetInterfaceList();
162   for (unsigned int i = 0; i < _list->length();i++) {
163     const char * s =  _list[i];
164     PrintInterface(C, s);
165   }
166 }
167
168
169 void PrintInterface(SALOME_ModuleCatalog::Acomponent_ptr C,
170                     const std::string & InterfaceName)
171 {
172   unsigned int i, n;
173         
174    SALOME_ModuleCatalog::DefinitionInterface_var _interf 
175      = C->GetInterface(InterfaceName.c_str());
176    MESSAGE ("Interface : " << _interf->interfacename);
177
178    SALOME_ModuleCatalog::ListOfInterfaceService S = _interf->interfaceservicelist;
179    n = S.length();
180    for (i = 0; i < n; i++) {
181      const char * _S = S[i].ServiceName;
182      PrintService(C, InterfaceName, _S);
183    }
184 }
185
186 void PrintService(SALOME_ModuleCatalog::Acomponent_ptr C,
187                   const std::string & InterfaceName,
188                   const std::string & ServiceName)
189 {
190   int i, n;
191
192    SALOME_ModuleCatalog::Service_var Service 
193      = (ServiceName.compare("") == 0)
194      ? C->GetDefaultService(InterfaceName.c_str())
195      : C->GetService(InterfaceName.c_str(), ServiceName.c_str());
196
197    MESSAGE("Service : " << Service->ServiceName);
198    
199    MESSAGE("In Parameter(s):");
200    n = Service->ServiceinParameter.length();
201    for (i = 0; i<n; i++)
202      {
203        MESSAGE("  Parameter       " 
204                << Service->ServiceinParameter[i].Parametername);
205        MESSAGE("  Type          : "
206                << Service->ServiceinParameter[i].Parametertype);
207      }
208    
209    MESSAGE("Out Parameter(s):");
210    n = Service->ServiceoutParameter.length();
211    for (i = 0; i<n; i++)
212      {
213        MESSAGE("  Parameter       " 
214                << Service->ServiceoutParameter[i].Parametername);
215        MESSAGE("  Type          : "
216                << Service->ServiceoutParameter[i].Parametertype);
217      }
218    
219    MESSAGE("In DataStreamParameter(s):");
220    n = Service->ServiceinDataStreamParameter.length();
221    for (i = 0; i<n; i++)
222      {
223        MESSAGE("  Parameter " 
224                << Service->ServiceinDataStreamParameter[i].Parametername);
225        MESSAGE("  Type          : "
226                << Service->ServiceinDataStreamParameter[i].Parametertype);
227        MESSAGE("  Dependency    : "
228                << Service->ServiceinDataStreamParameter[i].Parametertype);
229      }
230    
231    MESSAGE("Out DataStreamParameter(s):");
232    n = Service->ServiceoutDataStreamParameter.length();
233    for (i = 0; i<n; i++)
234      {
235        MESSAGE("  Parameter " 
236                << Service->ServiceoutDataStreamParameter[i].Parametername);
237        MESSAGE("  Type          : "
238                << Service->ServiceoutDataStreamParameter[i].Parametertype);
239        MESSAGE("  Dependency    : "
240                << Service->ServiceoutDataStreamParameter[i].Parametertype);
241      }
242    
243
244 }
245
246
247