Salome HOME
Try to kill Salome application when a YACS Launcher job is killed
[modules/kernel.git] / src / ModuleCatalog / SALOME_ModuleCatalog_Client.cxx
index c590b4b102855ed925f0890877682318a7004712..ee162f99e0eda4cbfeb096c737fa9f80a4df967d 100644 (file)
@@ -1,48 +1,55 @@
-//  SALOME ModuleCatalog : implementation of ModuleCatalog server which parsers xml description of modules
+// Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
 //
-//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
-// 
-//  This library is free software; you can redistribute it and/or 
-//  modify it under the terms of the GNU Lesser General Public 
-//  License as published by the Free Software Foundation; either 
-//  version 2.1 of the License. 
-// 
-//  This library is distributed in the hope that it will be useful, 
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
-//  Lesser General Public License for more details. 
-// 
-//  You should have received a copy of the GNU Lesser General Public 
-//  License along with this library; if not, write to the Free Software 
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
-// 
-//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
 //
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+
+//  SALOME ModuleCatalog : implementation of ModuleCatalog server which parsers xml description of modules
 //  File   : SALOME_ModuleCatalog_Client.cxx
 //  Module : SALOME
-
-using namespace std;
+//
 /* $Header$ */
 
-#include <iostream.h>
+#include <iostream>
 #include "SALOME_NamingService.hxx"
 #include "SALOME_ModuleCatalog.hh"
 #include <string>
 #include "utilities.h"
 
+void PrintService(SALOME_ModuleCatalog::Acomponent_ptr C,
+                  const std::string & InterfaceName,
+                  const std::string & ServiceName);
+
+void PrintInterface(SALOME_ModuleCatalog::Acomponent_ptr C,
+                    const std::string & InterfaceName);
+
+void PrintComponent(SALOME_ModuleCatalog::Acomponent_ptr C);
+
 int main(int argc,char **argv)
 {
-  char* name_to_find = "Geometry";
 
   CORBA::ORB_var orb;
   CosNaming::NamingContext_var _rootContext;
   CORBA::Object_var objVar, objVarN;
   try {
 
-       // initialize the ORB
+        // initialize the ORB
 
   orb = CORBA::ORB_init (argc, argv);
 
@@ -51,26 +58,31 @@ int main(int argc,char **argv)
   SALOME_NamingService NS(orb);
   CORBA::Object_var objVarN = NS.Resolve("/Kernel/ModulCatalog");
 
-   SALOME_ModuleCatalog::ModuleCatalog_var Catalogue  = SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN); 
+   SALOME_ModuleCatalog::ModuleCatalog_var Catalogue 
+     = SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN); 
    MESSAGE("Distant catalog of component found")
 
      // Get component list
-   SALOME_ModuleCatalog::ListOfComponents_var list_composants = Catalogue->GetComponentList();
+   SALOME_ModuleCatalog::ListOfComponents_var list_composants 
+     = Catalogue->GetComponentList();
 
 
    // Typed component list
    MESSAGE("Get Typed Component list (GEOM Type)");
-   SALOME_ModuleCatalog::ListOfComponents_var list_typed_composants = Catalogue->GetTypedComponentList(SALOME_ModuleCatalog::GEOM);
+   SALOME_ModuleCatalog::ListOfComponents_var list_typed_composants 
+     = Catalogue->GetTypedComponentList(SALOME_ModuleCatalog::GEOM);
    for (unsigned int ind = 0; ind < list_typed_composants->length();ind++)
      MESSAGE("Component GEOM list : " << list_typed_composants[ind]);      
 
    MESSAGE("Get Typed Component list (SUPERV Type)");
-   SALOME_ModuleCatalog::ListOfComponents_var list_styped_composants = Catalogue->GetTypedComponentList(SALOME_ModuleCatalog::SUPERV);
-   for (unsigned int ind = 0; ind < list_styped_composants->length();ind++)
-      MESSAGE("Component SUPERV list : " << list_styped_composants[ind]);
+   list_typed_composants 
+     = Catalogue->GetTypedComponentList(SALOME_ModuleCatalog::SUPERV);
+   for (unsigned int ind = 0; ind < list_typed_composants->length();ind++)
+      MESSAGE("Component SUPERV list : " << list_typed_composants[ind]);
 
    // Get list of couple (component name, component icone)
-   SALOME_ModuleCatalog::ListOfIAPP_Affich_var list_composants_icone = Catalogue->GetComponentIconeList();
+   SALOME_ModuleCatalog::ListOfIAPP_Affich_var list_composants_icone 
+     = Catalogue->GetComponentIconeList();
    for (unsigned int ind = 0; ind < list_composants_icone->length();ind++)
      {
        MESSAGE("Component name: " << list_composants_icone[ind].modulename);
@@ -85,10 +97,7 @@ int main(int argc,char **argv)
       exit (-1);
    }
  
-   MESSAGE("Component of name : " <<  Geom->componentname() << " created ");
-   MESSAGE("Component type : " << Geom->component_type() << " multistudy : " <<Geom->multistudy());
-   MESSAGE("Component constraint : " << Geom->constraint());
-   MESSAGE("Component icone : " << Geom->component_icone());
+   PrintComponent(Geom);
 
      // Obtain another component
    SALOME_ModuleCatalog::Acomponent_ptr Superv = Catalogue->GetComponent("Supervision");
@@ -97,11 +106,7 @@ int main(int argc,char **argv)
      INFOS("Catalog Error : Component Supervision not found in the catalog")
       exit (-1);
    }
-   MESSAGE("Component of name : " <<  Superv->componentname() << " created ");
-   MESSAGE("Component type : " << Superv->component_type() << " multistudy : " <<Superv->multistudy());
-   MESSAGE("Component constraint : " << Superv->constraint());
-   MESSAGE("Component icone : " << Superv->component_icone());
+   PrintComponent(Superv);
 
      // obtain prefix path for a computer
    char* path;
@@ -112,97 +117,10 @@ int main(int argc,char **argv)
    path =Geom->GetPathPrefix("eri");
    MESSAGE("Path prefix pour eri : " << path);
 
-   // obtain interfaces list of the component
-   SALOME_ModuleCatalog::ListOfInterfaces_var _list = new SALOME_ModuleCatalog::ListOfInterfaces;
-   _list = Geom->GetInterfaceList();
-   for (unsigned int ind = 0; ind < _list->length();ind++)
-     MESSAGE("Interface name : " << _list[ind]);
-
-   // obtain interfaces list of the component
-   SALOME_ModuleCatalog::ListOfInterfaces_var _list1 = new SALOME_ModuleCatalog::ListOfInterfaces;
-   _list1 = Superv->GetInterfaceList();
-   for (unsigned int ind = 0; ind < _list1->length();ind++)
-     MESSAGE("Interface name : " << _list1[ind])
-
-       
-   // Obtain one interface of a component
-   SALOME_ModuleCatalog::DefinitionInterface_var _interf = new SALOME_ModuleCatalog::DefinitionInterface;
-   _interf = Geom->GetInterface("Geometry");
-   MESSAGE ("Interface " << _interf->interfacename << " getted")
-   for (unsigned int ind = 0; ind < _interf->interfaceservicelist.length();ind++)
-     MESSAGE("Service name : " << _interf->interfaceservicelist[ind].ServiceName)
-
-
-   // obtain services list of the component
-       
-   SALOME_ModuleCatalog::ListOfServices_var list_services_component = new SALOME_ModuleCatalog::ListOfServices;
-   list_services_component = Geom->GetServiceList("Geometry");
-   for (unsigned int ind = 0; ind < list_services_component->length();ind++)
-       MESSAGE("Service name : " << list_services_component[ind])
-
-
-    // Get a service of the component
-
-   SALOME_ModuleCatalog::Service_var second_service = new SALOME_ModuleCatalog::Service;
-    second_service = Geom->GetDefaultService("Geometry");
-
-    MESSAGE("Default Service name: " << second_service->ServiceName)
-   for (unsigned int ind1 = 0; ind1 <second_service->ServiceinParameter.length();ind1++)
-     {
-       MESSAGE("Type of the in Parameter of this service : " << second_service->ServiceinParameter[ind1].Parametertype)
-       MESSAGE("Name of the in Parameter of this service : " << second_service->ServiceinParameter[ind1].Parametername)
-     }
-   for (unsigned int ind1 = 0; ind1 <second_service->ServiceoutParameter.length();ind1++)
-     {
-       MESSAGE("Type of the out Parameter of this service : " << second_service->ServiceoutParameter[ind1].Parametertype)
-       MESSAGE("Name of the out Parameter of this service : " << second_service->ServiceoutParameter[ind1].Parametername)
-     }
-
-
-
-    second_service = Geom->GetDefaultService("Geometry");
-
-    MESSAGE("Default Service name: " << second_service->ServiceName)
-   for (unsigned int ind1 = 0; ind1 <second_service->ServiceinParameter.length();ind1++)
-     {
-       MESSAGE("Type of the in Parameter of this service : " << second_service->ServiceinParameter[ind1].Parametertype)
-       MESSAGE("Name of the in Parameter of this service : " << second_service->ServiceinParameter[ind1].Parametername)
-     }
-   for (unsigned int ind1 = 0; ind1 <second_service->ServiceoutParameter.length();ind1++)
-     {
-       MESSAGE("Type of the out Parameter of this service : " << second_service->ServiceoutParameter[ind1].Parametertype)
-       MESSAGE("Name of the out Parameter of this service : " << second_service->ServiceoutParameter[ind1].Parametername)
-     }
-
-
-
-   // Get service of the component
-       
-   SALOME_ModuleCatalog::Service_var service_1 = new SALOME_ModuleCatalog::Service;
-
-   service_1 = Geom->GetService("Geometry","MakeSphere") ;
-
-   MESSAGE("Service name: " << service_1->ServiceName)
-   for (unsigned int ind1 = 0; ind1 <service_1->ServiceinParameter.length();ind1++)
-     {
-       MESSAGE("Type of the in Parameter of this service : " << service_1->ServiceinParameter[ind1].Parametertype)
-       MESSAGE("Name of the in Parameter of this service : " << service_1->ServiceinParameter[ind1].Parametername)
-     }
-
-   for (unsigned int ind1 = 0; ind1 <service_1->ServiceoutParameter.length();ind1++)
-     {
-       MESSAGE("Type of the out Parameter of this service : " << service_1->ServiceoutParameter[ind1].Parametertype)
-       MESSAGE("Name of the out Parameter of this service : " << service_1->ServiceoutParameter[ind1].Parametername)
-     }
-
-   // Test levĂ©e exception
-   service_1 = Geom->GetService("BOX","makeBox") ;
-
-
     }
   catch(SALOME_ModuleCatalog::NotFound &ex){
     INFOS("SALOME_ModuleCatalog::NotFound")
-      cerr << ex.what << endl;
+      std::cerr << ex.what << std::endl;
   }
     catch(CORBA::SystemException&) {
       INFOS("Caught CORBA::SystemException.")
@@ -223,7 +141,7 @@ int main(int argc,char **argv)
       INFOS("CosNaming::NamingContext::NotEmpty")
   }
 
-  catch(CORBA::Exception &sysEx) {
+  catch(CORBA::Exception &) {
     INFOS("Caught CORBA::Exception.")
   }
 
@@ -231,16 +149,99 @@ int main(int argc,char **argv)
   return 0;
 }
 
+void PrintComponent(SALOME_ModuleCatalog::Acomponent_ptr C)
+{
+  MESSAGE("Name : " <<  C->componentname());
+  MESSAGE("Type : " << C->component_type() << " multistudy : " << C->multistudy());
+  MESSAGE("Constraint : " << C->constraint());
+  MESSAGE("Icon : " << C->component_icone());
 
+  // obtain interfaces list of the component
 
+  SALOME_ModuleCatalog::ListOfInterfaces_var _list = C->GetInterfaceList();
+  for (unsigned int i = 0; i < _list->length();i++) {
+    const char * s =  _list[i];
+    PrintInterface(C, s);
+  }
+}
 
 
+void PrintInterface(SALOME_ModuleCatalog::Acomponent_ptr C,
+                    const std::string & InterfaceName)
+{
+  unsigned int i, n;
+        
+   SALOME_ModuleCatalog::DefinitionInterface_var _interf 
+     = C->GetInterface(InterfaceName.c_str());
+   MESSAGE ("Interface : " << _interf->interfacename);
+
+   SALOME_ModuleCatalog::ListOfInterfaceService S = _interf->interfaceservicelist;
+   n = S.length();
+   for (i = 0; i < n; i++) {
+     const char * _S = S[i].ServiceName;
+     PrintService(C, InterfaceName, _S);
+   }
+}
 
+void PrintService(SALOME_ModuleCatalog::Acomponent_ptr C,
+                  const std::string & InterfaceName,
+                  const std::string & ServiceName)
+{
+  int i, n;
+
+   SALOME_ModuleCatalog::Service_var Service 
+     = (ServiceName.compare("") == 0)
+     ? C->GetDefaultService(InterfaceName.c_str())
+     : C->GetService(InterfaceName.c_str(), ServiceName.c_str());
+
+   MESSAGE("Service : " << Service->ServiceName);
+   
+   MESSAGE("In Parameter(s):");
+   n = Service->ServiceinParameter.length();
+   for (i = 0; i<n; i++)
+     {
+       MESSAGE("  Parameter       " 
+               << Service->ServiceinParameter[i].Parametername);
+       MESSAGE("  Type          : "
+               << Service->ServiceinParameter[i].Parametertype);
+     }
+   
+   MESSAGE("Out Parameter(s):");
+   n = Service->ServiceoutParameter.length();
+   for (i = 0; i<n; i++)
+     {
+       MESSAGE("  Parameter       " 
+               << Service->ServiceoutParameter[i].Parametername);
+       MESSAGE("  Type          : "
+               << Service->ServiceoutParameter[i].Parametertype);
+     }
+   
+   MESSAGE("In DataStreamParameter(s):");
+   n = Service->ServiceinDataStreamParameter.length();
+   for (i = 0; i<n; i++)
+     {
+       MESSAGE("  Parameter " 
+               << Service->ServiceinDataStreamParameter[i].Parametername);
+       MESSAGE("  Type          : "
+               << Service->ServiceinDataStreamParameter[i].Parametertype);
+       MESSAGE("  Dependency    : "
+               << Service->ServiceinDataStreamParameter[i].Parametertype);
+     }
+   
+   MESSAGE("Out DataStreamParameter(s):");
+   n = Service->ServiceoutDataStreamParameter.length();
+   for (i = 0; i<n; i++)
+     {
+       MESSAGE("  Parameter " 
+               << Service->ServiceoutDataStreamParameter[i].Parametername);
+       MESSAGE("  Type          : "
+               << Service->ServiceoutDataStreamParameter[i].Parametertype);
+       MESSAGE("  Dependency    : "
+               << Service->ServiceoutDataStreamParameter[i].Parametertype);
+     }
+   
 
-
-
-
-
+}