]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
ContainersManager
authorrahuel <rahuel@opencascade.com>
Fri, 5 Nov 2004 08:45:15 +0000 (08:45 +0000)
committerrahuel <rahuel@opencascade.com>
Fri, 5 Nov 2004 08:45:15 +0000 (08:45 +0000)
src/TestContainer/TestComponentPy.py
src/TestContainer/TestContainer.cxx

index 2dacf6dbbd5e886165a12cbda5abebbef970e5d8..f6397f32652a9a1c616fd3b4b41c1f0966b16beb 100755 (executable)
@@ -34,6 +34,7 @@ import string
 from omniORB import CORBA
 import CosNaming
 import Engines
+import Containers
 
 
 #initialise the ORB
@@ -47,28 +48,78 @@ if rootContext is None:
     print "Name Service Reference is invalid"
     sys.exit(1)
 
-#resolve the name /Containers.dir/FactoryServerPy.object
-myMachine=string.split(os.getenv( "HOSTNAME" ),'.')
-machineName= myMachine[0]
-containerName = "FactoryServerPy"
-name = [CosNaming.NameComponent("Containers","dir"),
-        CosNaming.NameComponent(machineName,"dir"),
-        CosNaming.NameComponent(containerName,"object")]
+name = [CosNaming.NameComponent("Kernel","dir"),
+        CosNaming.NameComponent("ContainersManager","object")]
 
 try:
-    obj = rootContext.resolve(name)
+    obj = rootContext.resolve( name )
 except CosNaming.NamingContext.NotFound, ex:
-    print  containerName , " not found in Naming Service"
+    print "/Kernel/ContainersManager not found in Naming Service"
     sys.exit(1)
 
-container = obj._narrow(Engines.Container)
-print container._get_machineName()
-comp = container.load_impl("SALOME_TestComponentPy","SALOME_TestComponentPy")
-print comp._get_instanceName()
+MyContainersMgr = obj._narrow(Containers.Manager)
+
+MyContainersMgr.ping()
+
+Params = MyContainersMgr.Parameters()
+
+Params.ContainerName = 'TestContainerPy'
+Params.ContainerType = Engines.PythonContainer
+
+#resolve the name /Containers.dir/FactoryServerPy.object
+#myMachine=string.split(os.getenv( "HOSTNAME" ),'.')
+#machineName= myMachine[0]
+#containerName = "FactoryServerPy"
+#name = [CosNaming.NameComponent("Containers","dir"),
+        #CosNaming.NameComponent(machineName,"dir"),
+        #CosNaming.NameComponent(containerName,"object")]
+comp = MyContainersMgr.FindOrLoad_Component( Params , "SALOME_TestComponentPy" )
 comp.ping()
+
 comptest = comp._narrow(Engines.TestComponent)
 if comptest is None:
-    print "probleme cast"
-print comptest.Coucou(1)
+    print "probleme narrow(Engines.TestComponent)"
+    sys.exit(1)
+
+print "comptest",comptest.Coucou(1)
+
+container = comptest.GetContainerRef()
+container.ping()
+print "container._get_name()",container._get_name()
+print "container._get_machineName()",container._get_machineName()
+
+comptest.destroy()
+print "Component SALOME_TestComponentPy destroyed"
+
+try :
+    container.destroy()
+except :
+    print ""
+
+print "Container TestContainerPy destroyed"
+
+
+from LifeCycleCORBA import *
+lcc = LifeCycleCORBA( orb )
+
+lcccomptest  = lcc.FindOrLoadComponent( 'TestContainerPy' , 'SALOME_TestComponentPy' )
+
+print "lcccomptest",lcccomptest.Coucou(1)
+
+lcccontainer = lcccomptest.GetContainerRef()
+lcccontainer.ping()
+print "lcccontainer._get_name()",lcccontainer._get_name()
+print "lcccontainer._get_machineName()",lcccontainer._get_machineName()
+
+lcccomptest.destroy()
+print "Component SALOME_TestComponentPy destroyed"
+
+try :
+    lcccontainer.destroy()
+except :
+    print ""
+
+print "Container TestContainerPy destroyed"
+
 
 
index 3ebb10ee22dd1d415df54c0efbba365c13df06ea..2fcc21eb57a63852526f823b2a2be8fa4958d508 100644 (file)
@@ -31,6 +31,7 @@
 #include <unistd.h>
 #include <SALOMEconfig.h>
 #include CORBA_CLIENT_HEADER(SALOME_Component)
+#include CORBA_CLIENT_HEADER(ContainersManager)
 #include CORBA_CLIENT_HEADER(SALOME_TestComponent)
 
 #include "SALOME_NamingService.hxx"
@@ -138,18 +139,48 @@ int main (int argc, char * argv[])
       SALOME_NamingService _NS(orb) ;
       string containerName = "/Containers/" ;
       string hostName = GetHostname();
-      containerName += hostName + "/FactoryServer";
+      containerName += hostName + "/TestContainerCpp";
 
+      Engines::Container_var iGenFact = Engines::Container::_nil() ;
+      MESSAGE( "TestContainer : " << containerName.c_str() ) ;
       obj = _NS.Resolve(containerName.c_str()) ;
-      Engines::Container_var iGenFact = Engines::Container::_narrow(obj);
+      if ( !CORBA::is_nil( obj ) ) {
+        try {
+          iGenFact = Engines::Container::_narrow( obj ) ;
+          iGenFact->ping() ;
+       }
+       catch ( ... ) {
+          INFOS("TestContainerCpp unreachable") ;
+       }
+      }
+      if ( CORBA::is_nil( iGenFact ) ) {
+        obj = _NS.Resolve( "/Kernel/ContainersManager" ) ;
+        if ( !CORBA::is_nil( obj ) ) {
+          try {
+            Containers::Manager_var MyContainersMgr = Containers::Manager::_narrow( obj ) ;
+            MyContainersMgr->ping() ;
+            Containers::MachineParameters * Params = MyContainersMgr->Parameters() ;
+            Params->ContainerName = "TestContainerCpp" ;
+            iGenFact = MyContainersMgr->FindOrStartContainer( *Params ) ;
+         }
+         catch ( ... ) {
+            INFOS("ContainersManager unreachable") ;
+         }
+       }
+      }
+
+//      obj = _NS.Resolve(containerName.c_str()) ;
+//      Engines::Container_var iGenFact = Engines::Container::_narrow(obj);
 
       Engines::TestComponent_var m1;
     
       for (int iter = 0; iter < 3 ; iter++)
        {
          INFOS("----------------------------------------------------" << iter);   
-          string dirn = getenv("KERNEL_ROOT_DIR");
-          dirn += "/lib/salome/libSalomeTestComponentEngine.so";
+//          string dirn = getenv("KERNEL_ROOT_DIR");
+//          dirn += "/lib/salome/libSalomeTestComponentEngine.so";
+          iGenFact->ping() ;
+          string dirn = "libSalomeTestComponentEngine.so";
           obj = iGenFact->load_impl("SalomeTestComponent",dirn.c_str());
          m1 = Engines::TestComponent::_narrow(obj);
          INFOS("recup m1");
@@ -161,7 +192,11 @@ int main (int argc, char * argv[])
        }    
       // Clean-up.
       iGenFact->finalize_removal() ;
+      INFOS("finalize_removal done" );
+      iGenFact->destroy() ;
+      INFOS("Container destroyed" );
       orb->destroy();
+      INFOS("orb destroyed" );
     }
   catch(CORBA::COMM_FAILURE& ex) {
     INFOS("Caught system exception COMM_FAILURE -- unable to contact the object.")