From 8f86cd474574056fefaddb12fcc7bf0785e06e26 Mon Sep 17 00:00:00 2001 From: rahuel Date: Fri, 5 Nov 2004 07:20:26 +0000 Subject: [PATCH] ContainersManager --- src/Container/Component_i.cxx | 44 +++++---- src/Container/Container_i.cxx | 173 +++++++++++++++++++--------------- 2 files changed, 125 insertions(+), 92 deletions(-) diff --git a/src/Container/Component_i.cxx b/src/Container/Component_i.cxx index 3d31862b7..ceb811a86 100644 --- a/src/Container/Component_i.cxx +++ b/src/Container/Component_i.cxx @@ -27,6 +27,7 @@ // $Header$ #include "SALOME_Component_i.hxx" +#include "SALOME_NamingService.hxx" #include "RegistryConnexion.hxx" #include "OpUtil.hxx" #include @@ -58,6 +59,8 @@ Engines_Component_i::Engines_Component_i(CORBA::ORB_ptr orb, _contId = contId ; CORBA::Object_var o = _poa->id_to_reference(*contId); // container ior... const CORBA::String_var ior = _orb->object_to_string(o); + MESSAGE("Component constructor RegistryConnexion ior "<< ior << " _instanceName " + << _instanceName.c_str() ); _myConnexionToRegistry = new RegistryConnexion(0, 0, ior, "theSession", _instanceName.c_str()); _notifSupplier = new NOTIFICATION_Supplier(instanceName, notif); @@ -91,6 +94,31 @@ Engines_Component_i::~Engines_Component_i() // _myConnexionToRegistry = 0 ; } +void Engines_Component_i::destroy() +{ + MESSAGE("Engines_Component_i::destroy()"); + + delete _notifSupplier; + _notifSupplier = 0; + + delete _myConnexionToRegistry; + _myConnexionToRegistry = 0 ; + + string aRegisteredName = GetContainerRef()->name() + string("/") + _interfaceName ; + SALOME_NamingService * _NamingService = new SALOME_NamingService( _orb ) ; + MESSAGE("Engines_Component_i::destroy NamingService->Destroy_Name " << aRegisteredName ) ; + _NamingService->Destroy_Name( aRegisteredName.c_str() ) ; + + delete _NamingService ; + + _poa->deactivate_object( *_id ) ; + CORBA::release( _poa ) ; + delete( _id ) ; + _thisObj->_remove_ref(); + + MESSAGE("Engines_Component_i::destroyed") ; +} + char* Engines_Component_i::instanceName() { return CORBA::string_dup(_instanceName.c_str()) ; } @@ -105,22 +133,6 @@ void Engines_Component_i::ping() << pthread_self()); } -void Engines_Component_i::destroy() -{ - MESSAGE("Engines_Component_i::destroy()"); - - delete _notifSupplier; - _notifSupplier = 0; - - delete _myConnexionToRegistry; - _myConnexionToRegistry = 0 ; - _poa->deactivate_object(*_id) ; - CORBA::release(_poa) ; - delete(_id) ; - _thisObj->_remove_ref(); - MESSAGE("Engines_Component_i::destroyed") ; -} - Engines::Container_ptr Engines_Component_i::GetContainerRef() { MESSAGE("Engines_Component_i::GetContainerRef"); diff --git a/src/Container/Container_i.cxx b/src/Container/Container_i.cxx index e16c47ad7..8721982a7 100644 --- a/src/Container/Container_i.cxx +++ b/src/Container/Container_i.cxx @@ -95,6 +95,7 @@ Engines_Container_i::Engines_Container_i (CORBA::ORB_ptr orb, MESSAGE("SALOME_Container usage : SALOME_Container ServerName -ORBInitRef NameService=corbaname::hostname:tcpipPortNumber") ; // exit(0) ; } + MESSAGE( "LD_LIBRARY_PATH " << getenv( "LD_LIBRARY_PATH" ) ) ; SCRUTE(hostname); @@ -139,6 +140,16 @@ Engines_Container_i::~Engines_Container_i() MESSAGE("Container_i::~Container_i()"); } +void Engines_Container_i::destroy() { + MESSAGE( "Container_i::destroy : " << _containerName.c_str() ) ; + _NS->Destroy_Name( _containerName.c_str() ) ; + _poa->deactivate_object( *_id ) ; + CORBA::release( _poa ) ; + delete( _id ) ; + this->_remove_ref(); + MESSAGE( "Container_i::destroyed" ) ; +} + char* Engines_Container_i::name() { return CORBA::string_dup(_containerName.c_str()) ; @@ -156,17 +167,24 @@ void Engines_Container_i::ping() MESSAGE("Engines_Container_i::ping() pid "<< getpid()); } +Engines::ContainerType Engines_Container_i::type() +{ + MESSAGE( "Engines_Container_i::type() "<< Engines::CppContainer ); + return Engines::CppContainer ; +} + // Kill current container bool Engines_Container_i::Kill_impl() { MESSAGE("Engines_Container_i::Kill() pid "<< getpid() << " containerName " << _containerName.c_str() << " machineName " << GetHostname().c_str()); - exit( 0 ) ; + destroy() ; + return true ; } // Launch a new container from the current container -Engines::Container_ptr Engines_Container_i::start_impl( - const char* ContainerName ) { +Engines::Container_ptr Engines_Container_i::start_impl( const char* ContainerName , + const Engines::ContainerType aContainerType ) { MESSAGE("start_impl argc " << _argc << " ContainerName " << ContainerName << hex << this << dec) ; _numInstanceMutex.lock() ; // lock on the instance number @@ -203,82 +221,65 @@ Engines::Container_ptr Engines_Container_i::start_impl( MESSAGE(" argv" << i << " " << _argv[ i ]) ; i++ ; } - string shstr = string(getenv("KERNEL_ROOT_DIR")) + "/bin/salome/SALOME_Container "; + string shstr = string( getenv( "KERNEL_ROOT_DIR" ) ) + "/bin/salome/" ; // string shstr( "./runSession SALOME_Container " ) ; - shstr += ContainerName ; - if ( _argc == 4 ) { - shstr += " " ; - shstr += _argv[ 2 ] ; - shstr += " " ; - shstr += _argv[ 3 ] ; - } - shstr += " > /tmp/" ; - shstr += ContainerName ; - shstr += ".log 2>&1 &" ; - MESSAGE("system(" << shstr << ")") ; - int status = system( shstr.c_str() ) ; - if (status == -1) { - INFOS("Engines_Container_i::start_impl SALOME_Container failed (system command status -1)") ; - } - else if (status == 217) { - INFOS("Engines_Container_i::start_impl SALOME_Container failed (system command status 217)") ; - } - INFOS(machineName() << " Engines_Container_i::start_impl SALOME_Container launch done"); - -// pid_t pid = fork() ; -// if ( pid == 0 ) { -// string anExe( _argv[ 0 ] ) ; -// anExe += "runSession" ; -// char * args[ 6 ] ; -// args[ 0 ] = "runSession" ; -// args[ 1 ] = "SALOME_Container" ; -// args[ 2 ] = strdup( ContainerName ) ; -// args[ 3 ] = strdup( _argv[ 2 ] ) ; -// args[ 4 ] = strdup( _argv[ 3 ] ) ; -// args[ 5 ] = NULL ; -// MESSAGE("execl(" << anExe.c_str() << " , " << args[ 0 ] << " , " -// << args[ 1 ] << " , " << args[ 2 ] << " , " << args[ 3 ] -// << " , " << args[ 4 ] << ")") ; -// int status = execv( anExe.c_str() , args ) ; -// if (status == -1) { -// INFOS("Engines_Container_i::start_impl execl failed (system command status -1)") ; -// perror( "Engines_Container_i::start_impl execl error ") ; -// } -// else { -// INFOS(machineName() << " Engines_Container_i::start_impl execl done"); -// } -// exit(0) ; -// } - - obj = Engines::Container::_nil() ; - try { - string cont("/Containers/"); - cont += machineName() ; - cont += "/" ; - cont += ContainerName; - nilvar = true ; - int count = 20 ; - while ( nilvar && count >= 0) { - sleep( 1 ) ; - obj = _NS->Resolve(cont.c_str()); - nilvar = CORBA::is_nil( obj ) ; - if ( nilvar ) { - INFOS(count << ". " << machineName() - << " start_impl unknown container " << cont.c_str()); - count -= 1 ; + if ( aContainerType != Engines::UndefinedContainerType ) { + if ( aContainerType == Engines::CppContainer ) { + shstr += "SALOME_Container " ; + } + else if ( aContainerType == Engines::PythonContainer ) { + shstr += "SALOME_ContainerPy.py " ; + } + shstr += ContainerName ; + if ( _argc == 4 ) { + shstr += " " ; + shstr += _argv[ 2 ] ; + shstr += " " ; + shstr += _argv[ 3 ] ; + } + shstr += " > /tmp/" ; + shstr += ContainerName ; + shstr += ".log 2>&1 &" ; + MESSAGE("system(" << shstr << ")") ; + int status = system( shstr.c_str() ) ; + if (status == -1) { + INFOS("Engines_Container_i::start_impl SALOME_Container failed (system command status -1)") ; + } + else if (status == 217) { + INFOS("Engines_Container_i::start_impl SALOME_Container failed (system command status 217)") ; + } + INFOS(machineName() << " Engines_Container_i::start_impl SALOME_Container launch done"); + + obj = Engines::Container::_nil() ; + try { + string cont("/Containers/"); + cont += machineName() ; + cont += "/" ; + cont += ContainerName; + nilvar = true ; + int count = 20 ; + while ( nilvar && count >= 0) { + sleep( 1 ) ; + obj = _NS->Resolve(cont.c_str()); + nilvar = CORBA::is_nil( obj ) ; + if ( nilvar ) { + INFOS(count << ". " << machineName() + << " start_impl unknown container " << cont.c_str()); + count -= 1 ; + } + } + _numInstanceMutex.unlock() ; + if ( !nilvar ) { + MESSAGE("start_impl container found after new launch of SALOME_Container") ; } + return Engines::Container::_narrow(obj); } - _numInstanceMutex.unlock() ; - if ( !nilvar ) { - MESSAGE("start_impl container found after new launch of SALOME_Container") ; + catch (ServiceUnreachable&) { + INFOS(machineName() << "Caught exception: Naming Service Unreachable"); + } + catch (...) { + INFOS(machineName() << "Caught unknown exception."); } - return Engines::Container::_narrow(obj); - } - catch (ServiceUnreachable&) { - INFOS(machineName() << "Caught exception: Naming Service Unreachable"); - } - catch (...) { - INFOS(machineName() << "Caught unknown exception."); } _numInstanceMutex.unlock() ; MESSAGE("start_impl container not found after new launch of SALOME_Container") ; @@ -453,7 +454,7 @@ void SigIntHandler(int what , siginfo_t * siginfo , // Get the PID of the Container -long Engines_Container_i::getPID() { +CORBA::Long Engines_Container_i::getPID() { return(_pid); } @@ -462,3 +463,23 @@ long Engines_Container_i::getPID() { char* Engines_Container_i::getHostName() { return((char*)(GetHostname().c_str())); } + +ostream & operator<< (ostream & f ,const Engines::ContainerType & t ) { + switch (t) { + case Engines::UndefinedContainerType : + f << "UndefinedContainer"; + break; + case Engines::CppContainer : + f << "CppContainer"; + break; + case Engines::PythonContainer : + f << "PythonContainer"; + break; + default : + f << "UnknownContainerType"; + break; + } + + return f; +} + -- 2.39.2