From: jfa Date: Thu, 31 Jan 2008 11:22:40 +0000 (+0000) Subject: patchShutdownAndLeaks.dat by Christian CAREMOLI. X-Git-Tag: for_M2008_07022008~5 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=a1b0b7baaaefa1ba9a5dcdcfc3dbcf9343a2cb37;p=modules%2Fgui.git patchShutdownAndLeaks.dat by Christian CAREMOLI. --- diff --git a/src/Session/SALOME_Session_Server.cxx b/src/Session/SALOME_Session_Server.cxx index 635c5724f..01bed2abd 100755 --- a/src/Session/SALOME_Session_Server.cxx +++ b/src/Session/SALOME_Session_Server.cxx @@ -310,6 +310,33 @@ bool isFound( const char* str, int argc, char** argv ) return false; } +void killOmniNames( ) +{ + QString fileName( ::getenv ("OMNIORB_CONFIG") ); + QString portNumber; + if ( !fileName.isEmpty() ) + { + QFile aFile( fileName ); + if ( aFile.open(IO_ReadOnly) ) { + QRegExp re("InitRef = .*:([0-9]+)$"); + QTextStream stream ( &aFile ); + while ( !stream.atEnd() ) { + QString textLine = stream.readLine(); + if ( re.search( textLine ) > -1 ) + portNumber = re.cap(1); + } + aFile.close(); + } + } + + if ( !portNumber.isEmpty() ) + { + QString cmd ; + cmd = QString( "ps -eo pid,command | grep -v grep | grep -E \"omniNames.*%1\" | awk '{cmd=sprintf(\"kill -9 %s\",$1); system(cmd)}'" ).arg( portNumber ); + system ( cmd.latin1() ); + } +} + // shutdown standalone servers void shutdownServers( SALOME_NamingService* theNS ) { @@ -367,40 +394,22 @@ void shutdownServers( SALOME_NamingService* theNS ) CORBA::Object_var objSDS = theNS->Resolve("/myStudyManager"); SALOMEDS::StudyManager_var studyManager = SALOMEDS::StudyManager::_narrow(objSDS) ; if ( !CORBA::is_nil(studyManager) && ( session->getPID() != studyManager->getPID() ) ) - studyManager->ShutdownWithExit(); + studyManager->Shutdown(); // 7) ModuleCatalog CORBA::Object_var objMC=theNS->Resolve("/Kernel/ModulCatalog"); SALOME_ModuleCatalog::ModuleCatalog_var catalog = SALOME_ModuleCatalog::ModuleCatalog::_narrow(objMC); if ( !CORBA::is_nil(catalog) && ( session->getPID() != catalog->getPID() ) ) - catalog->ShutdownWithExit(); + catalog->shutdown(); // 8) Registry CORBA::Object_var objR = theNS->Resolve("/Registry"); Registry::Components_var registry = Registry::Components::_narrow(objR); if ( !CORBA::is_nil(registry) && ( session->getPID() != registry->getPID() ) ) - registry->end(); + registry->Shutdown(); // 9) Kill OmniNames - QString fileName( ::getenv ("OMNIORB_CONFIG") ); - QString portNumber; - if ( !fileName.isEmpty() ) { - QFile aFile( fileName ); - if ( aFile.open(IO_ReadOnly) ) { - QRegExp re("InitRef = .*:([0-9]+)$"); - QTextStream stream ( &aFile ); - while ( !stream.atEnd() ) { - QString textLine = stream.readLine(); - if ( re.search( textLine ) > -1 ) - portNumber = re.cap(1); - } - aFile.close(); - } - } - if ( !portNumber.isEmpty() ) { - QString cmd = QString( "ps -eo pid,command | grep -v grep | grep -E \"omniNames.*%1\" | awk '{cmd=sprintf(\"kill -9 %s\",$1); system(cmd)}'" ).arg( portNumber ); - system ( cmd.latin1() ); - } + //killOmniNames(); } } @@ -670,8 +679,19 @@ int main( int argc, char **argv ) delete myServerLauncher; delete _NS; - LocalTraceBufferPool *bp1 = LocalTraceBufferPool::instance(); - LocalTraceBufferPool::deleteInstance(bp1); + PyGILState_STATE gstate = PyGILState_Ensure(); + Py_Finalize(); + + try + { + orb->destroy(); + } + catch(...) + { + std::cerr << "Caught unexpected exception on destroy : ignored !!" << std::endl; + } + + killOmniNames(); return result; } diff --git a/src/Session/Session_ServerLauncher.cxx b/src/Session/Session_ServerLauncher.cxx index 3909efc01..c13c71a7a 100755 --- a/src/Session/Session_ServerLauncher.cxx +++ b/src/Session/Session_ServerLauncher.cxx @@ -96,7 +96,7 @@ void Session_ServerLauncher::run() _ServerLaunch->wakeAll(); // run ORB - _orb->run(); // this thread waits, during omniORB process events + //_orb->run(); // No need to call orb->run() : it waits on a lock. Qt is already waiting in the mainloop. } /*! diff --git a/src/Session/Session_ServerThread.cxx b/src/Session/Session_ServerThread.cxx index fcdcacceb..c29a4807d 100755 --- a/src/Session/Session_ServerThread.cxx +++ b/src/Session/Session_ServerThread.cxx @@ -193,9 +193,10 @@ void Session_ServerThread::ActivateModuleCatalog(int argc, // Tell the POA that the objects are ready to accept requests. - _root_poa->activate_object (Catalogue_i); + PortableServer::ObjectId_var id= _root_poa->activate_object (Catalogue_i); + Catalogue_i->_remove_ref(); - CORBA::Object_ptr myCata = Catalogue_i->_this(); + CORBA::Object_var myCata = Catalogue_i->_this(); _NS->Register(myCata ,"/Kernel/ModulCatalog"); } catch(CORBA::SystemException&) @@ -430,10 +431,11 @@ void Session_ServerThread::ActivateEngine(int /*argc*/, char ** /*argv*/) { MESSAGE("SalomeApp_Engine thread started"); SalomeApp_Engine_i* anEngine = new SalomeApp_Engine_i(); - /*PortableServer::ObjectId_var id = */_root_poa->activate_object( anEngine ); + PortableServer::ObjectId_var id =_root_poa->activate_object( anEngine ); MESSAGE("poa->activate_object( SalomeApp_Engine )"); CORBA::Object_var obj = anEngine->_this(); + anEngine->_remove_ref(); _NS->Register( obj ,"/SalomeAppEngine"); } @@ -493,6 +495,7 @@ void Session_SessionThread::ActivateSession(int argc, CORBA::Object_var obj = mySALOME_Session->_this(); CORBA::String_var sior(_orb->object_to_string(obj)); + mySALOME_Session->_remove_ref(); mySALOME_Session->NSregister(); } diff --git a/src/Session/Session_Session_i.cxx b/src/Session/Session_Session_i.cxx index 81787737e..92da744bc 100755 --- a/src/Session/Session_Session_i.cxx +++ b/src/Session/Session_Session_i.cxx @@ -64,6 +64,7 @@ SALOME_Session_i::SALOME_Session_i(int argc, _poa = PortableServer::POA::_duplicate(poa) ; _GUIMutex = GUIMutex; _GUILauncher = GUILauncher; + _NS = new SALOME_NamingService(_orb); //MESSAGE("constructor end"); } @@ -87,6 +88,7 @@ Engines::Component_ptr SALOME_Session_i::GetComponent(const char* theLibraryName */ SALOME_Session_i::~SALOME_Session_i() { + delete _NS; //MESSAGE("destructor end"); } @@ -96,10 +98,10 @@ SALOME_Session_i::~SALOME_Session_i() */ void SALOME_Session_i::NSregister() { - SALOME::Session_ptr pSession = SALOME::Session::_narrow(_this()); + CORBA::Object_var obref=_this(); + SALOME::Session_var pSession = SALOME::Session::_narrow(obref); try { - _NS = new SALOME_NamingService(_orb); _NS->Register(pSession, "/Kernel/Session"); } catch (ServiceUnreachable&)