Back to index

salome-kernel  6.5.0
SALOME_ModuleCatalog_Client.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  SALOME ModuleCatalog : implementation of ModuleCatalog server which parsers xml description of modules
00024 //  File   : SALOME_ModuleCatalog_Client.cxx
00025 //  Module : SALOME
00026 //
00027 /* $Header: /home/server/cvs/KERNEL/KERNEL_SRC/src/ModuleCatalog/SALOME_ModuleCatalog_Client.cxx,v 1.8.2.1.10.2.12.1 2012-04-12 14:05:17 vsr Exp $ */
00028 
00029 #include <iostream>
00030 #include "SALOME_NamingService.hxx"
00031 #include "SALOME_ModuleCatalog.hh"
00032 #include <string>
00033 #include "utilities.h"
00034 
00035 void PrintService(SALOME_ModuleCatalog::Acomponent_ptr C,
00036                   const std::string & InterfaceName,
00037                   const std::string & ServiceName);
00038 
00039 void PrintInterface(SALOME_ModuleCatalog::Acomponent_ptr C,
00040                     const std::string & InterfaceName);
00041 
00042 void PrintComponent(SALOME_ModuleCatalog::Acomponent_ptr C);
00043 
00044 int main(int argc,char **argv)
00045 {
00046 
00047   CORBA::ORB_var orb;
00048   CosNaming::NamingContext_var _rootContext;
00049   CORBA::Object_var objVar, objVarN;
00050   try {
00051 
00052         // initialize the ORB
00053 
00054   orb = CORBA::ORB_init (argc, argv);
00055 
00056  
00057   // Get CORBA reference of the catalog
00058   SALOME_NamingService NS(orb);
00059   CORBA::Object_var objVarN = NS.Resolve("/Kernel/ModulCatalog");
00060 
00061    SALOME_ModuleCatalog::ModuleCatalog_var Catalogue 
00062      = SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN); 
00063    MESSAGE("Distant catalog of component found")
00064 
00065      // Get component list
00066    SALOME_ModuleCatalog::ListOfComponents_var list_composants 
00067      = Catalogue->GetComponentList();
00068 
00069 
00070    // Typed component list
00071    MESSAGE("Get Typed Component list (GEOM Type)");
00072    SALOME_ModuleCatalog::ListOfComponents_var list_typed_composants 
00073      = Catalogue->GetTypedComponentList(SALOME_ModuleCatalog::GEOM);
00074    for (unsigned int ind = 0; ind < list_typed_composants->length();ind++)
00075      MESSAGE("Component GEOM list : " << list_typed_composants[ind]);      
00076 
00077    MESSAGE("Get Typed Component list (SUPERV Type)");
00078    list_typed_composants 
00079      = Catalogue->GetTypedComponentList(SALOME_ModuleCatalog::SUPERV);
00080    for (unsigned int ind = 0; ind < list_typed_composants->length();ind++)
00081       MESSAGE("Component SUPERV list : " << list_typed_composants[ind]);
00082 
00083    // Get list of couple (component name, component icone)
00084    SALOME_ModuleCatalog::ListOfIAPP_Affich_var list_composants_icone 
00085      = Catalogue->GetComponentIconeList();
00086    for (unsigned int ind = 0; ind < list_composants_icone->length();ind++)
00087      {
00088        MESSAGE("Component name: " << list_composants_icone[ind].modulename);
00089        MESSAGE("Component icone: " << list_composants_icone[ind].moduleicone);
00090      }
00091   
00092    // obtain a component (specified as parameter of the client)
00093    SALOME_ModuleCatalog::Acomponent_ptr Geom = Catalogue->GetComponent("Geometry");
00094    if (CORBA::is_nil (Geom)) 
00095    {
00096      INFOS("Catalog Error : Component Geometry not found in the catalog")
00097       exit (-1);
00098    }
00099  
00100    PrintComponent(Geom);
00101 
00102      // Obtain another component
00103    SALOME_ModuleCatalog::Acomponent_ptr Superv = Catalogue->GetComponent("Supervision");
00104    if (CORBA::is_nil (Superv)) 
00105    {
00106      INFOS("Catalog Error : Component Supervision not found in the catalog")
00107       exit (-1);
00108    }
00109    PrintComponent(Superv);
00110 
00111      // obtain prefix path for a computer
00112    char* path;
00113    path =Superv->GetPathPrefix("omote");
00114    MESSAGE("Path prefix pour omote : " << path);
00115 
00116    // obtain prefix path for a computer
00117    path =Geom->GetPathPrefix("eri");
00118    MESSAGE("Path prefix pour eri : " << path);
00119 
00120     }
00121   catch(SALOME_ModuleCatalog::NotFound &ex){
00122     INFOS("SALOME_ModuleCatalog::NotFound")
00123       std::cerr << ex.what << std::endl;
00124   }
00125     catch(CORBA::SystemException&) {
00126       INFOS("Caught CORBA::SystemException.")
00127   }
00128     catch (CosNaming::NamingContext::CannotProceed &) {
00129       INFOS("CosNaming::NamingContext::CannotProceed")
00130   }
00131     catch (CosNaming::NamingContext::NotFound &) {
00132       INFOS("CosNaming::NamingContext::NotFound")
00133   }
00134     catch (CosNaming::NamingContext::InvalidName &) {
00135       INFOS("CosNaming::NamingContext::InvalidName")
00136   }
00137     catch (CosNaming::NamingContext::AlreadyBound &) {
00138       INFOS("CosNaming::NamingContext::AlreadyBound")
00139   }
00140     catch (CosNaming::NamingContext::NotEmpty &) {
00141       INFOS("CosNaming::NamingContext::NotEmpty")
00142   }
00143 
00144   catch(CORBA::Exception &) {
00145     INFOS("Caught CORBA::Exception.")
00146   }
00147 
00148 
00149   return 0;
00150 }
00151 
00152 void PrintComponent(SALOME_ModuleCatalog::Acomponent_ptr C)
00153 {
00154   MESSAGE("Name : " <<  C->componentname());
00155   MESSAGE("Type : " << C->component_type() << " multistudy : " << C->multistudy());
00156   MESSAGE("Constraint : " << C->constraint());
00157   MESSAGE("Icon : " << C->component_icone());
00158 
00159   // obtain interfaces list of the component
00160 
00161   SALOME_ModuleCatalog::ListOfInterfaces_var _list = C->GetInterfaceList();
00162   for (unsigned int i = 0; i < _list->length();i++) {
00163     const char * s =  _list[i];
00164     PrintInterface(C, s);
00165   }
00166 }
00167 
00168 
00169 void PrintInterface(SALOME_ModuleCatalog::Acomponent_ptr C,
00170                     const std::string & InterfaceName)
00171 {
00172   unsigned int i, n;
00173         
00174    SALOME_ModuleCatalog::DefinitionInterface_var _interf 
00175      = C->GetInterface(InterfaceName.c_str());
00176    MESSAGE ("Interface : " << _interf->interfacename);
00177 
00178    SALOME_ModuleCatalog::ListOfInterfaceService S = _interf->interfaceservicelist;
00179    n = S.length();
00180    for (i = 0; i < n; i++) {
00181      const char * _S = S[i].ServiceName;
00182      PrintService(C, InterfaceName, _S);
00183    }
00184 }
00185 
00186 void PrintService(SALOME_ModuleCatalog::Acomponent_ptr C,
00187                   const std::string & InterfaceName,
00188                   const std::string & ServiceName)
00189 {
00190   int i, n;
00191 
00192    SALOME_ModuleCatalog::Service_var Service 
00193      = (ServiceName.compare("") == 0)
00194      ? C->GetDefaultService(InterfaceName.c_str())
00195      : C->GetService(InterfaceName.c_str(), ServiceName.c_str());
00196 
00197    MESSAGE("Service : " << Service->ServiceName);
00198    
00199    MESSAGE("In Parameter(s):");
00200    n = Service->ServiceinParameter.length();
00201    for (i = 0; i<n; i++)
00202      {
00203        MESSAGE("  Parameter       " 
00204                << Service->ServiceinParameter[i].Parametername);
00205        MESSAGE("  Type          : "
00206                << Service->ServiceinParameter[i].Parametertype);
00207      }
00208    
00209    MESSAGE("Out Parameter(s):");
00210    n = Service->ServiceoutParameter.length();
00211    for (i = 0; i<n; i++)
00212      {
00213        MESSAGE("  Parameter       " 
00214                << Service->ServiceoutParameter[i].Parametername);
00215        MESSAGE("  Type          : "
00216                << Service->ServiceoutParameter[i].Parametertype);
00217      }
00218    
00219    MESSAGE("In DataStreamParameter(s):");
00220    n = Service->ServiceinDataStreamParameter.length();
00221    for (i = 0; i<n; i++)
00222      {
00223        MESSAGE("  Parameter " 
00224                << Service->ServiceinDataStreamParameter[i].Parametername);
00225        MESSAGE("  Type          : "
00226                << Service->ServiceinDataStreamParameter[i].Parametertype);
00227        MESSAGE("  Dependency    : "
00228                << Service->ServiceinDataStreamParameter[i].Parametertype);
00229      }
00230    
00231    MESSAGE("Out DataStreamParameter(s):");
00232    n = Service->ServiceoutDataStreamParameter.length();
00233    for (i = 0; i<n; i++)
00234      {
00235        MESSAGE("  Parameter " 
00236                << Service->ServiceoutDataStreamParameter[i].Parametername);
00237        MESSAGE("  Type          : "
00238                << Service->ServiceoutDataStreamParameter[i].Parametertype);
00239        MESSAGE("  Dependency    : "
00240                << Service->ServiceoutDataStreamParameter[i].Parametertype);
00241      }
00242    
00243 
00244 }
00245 
00246 
00247