From: rahuel Date: Fri, 5 Nov 2004 08:45:15 +0000 (+0000) Subject: ContainersManager X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=8865d3c60cf12111960c630f9b13f546e2451b55;p=modules%2Fkernel.git ContainersManager --- diff --git a/src/TestContainer/TestComponentPy.py b/src/TestContainer/TestComponentPy.py index 2dacf6dbb..f6397f326 100755 --- a/src/TestContainer/TestComponentPy.py +++ b/src/TestContainer/TestComponentPy.py @@ -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" + diff --git a/src/TestContainer/TestContainer.cxx b/src/TestContainer/TestContainer.cxx index 3ebb10ee2..2fcc21eb5 100644 --- a/src/TestContainer/TestContainer.cxx +++ b/src/TestContainer/TestContainer.cxx @@ -31,6 +31,7 @@ #include #include #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.")