From 3acf3ad5303453bbcaaee49a3b19d347cf3be5ce Mon Sep 17 00:00:00 2001 From: vsr Date: Tue, 13 Mar 2012 09:22:22 +0000 Subject: [PATCH] Implement Shutdown() method for the SALOME Session server --- src/Session/SALOME_Session_Server.cxx | 51 +++++++++++++++++++-------- src/Session/Session_Session_i.cxx | 40 +++++++++++++++------ src/Session/Session_Session_i.hxx | 4 +++ 3 files changed, 70 insertions(+), 25 deletions(-) diff --git a/src/Session/SALOME_Session_Server.cxx b/src/Session/SALOME_Session_Server.cxx index e8c0e7145..ddd8200fb 100755 --- a/src/Session/SALOME_Session_Server.cxx +++ b/src/Session/SALOME_Session_Server.cxx @@ -515,7 +515,8 @@ int main( int argc, char **argv ) _GUIMutex.unlock(); } - bool shutdown = false; + bool shutdownAll = false; + bool shutdownSession = false; if ( !result ) { // Launch GUI activator if ( isGUI ) { @@ -541,6 +542,17 @@ int main( int argc, char **argv ) _SessionMutex.unlock(); + // Session might be shutdowning here, check status + CORBA::Object_var obj = _NS->Resolve( "/Kernel/Session" ); + SALOME::Session_var session = SALOME::Session::_narrow( obj ) ; + ASSERT ( ! CORBA::is_nil( session ) ); + SALOME::StatSession stat = session->GetStatSession(); + shutdownSession = stat.state == SALOME::shutdown; + if ( shutdownSession ) { + _SessionMutex.lock(); // lock mutex before leaving loop - it will be unlocked later + break; + } + // SUIT_Session creation aGUISession = new SALOME_Session(); @@ -561,24 +573,33 @@ int main( int argc, char **argv ) if ( splash ) splash->finish( aGUIApp->desktop() ); - + result = _qappl.exec(); splash = 0; - - if ( result == SUIT_Session::NORMAL ) { // desktop is closed by user from GUI - shutdown = aGUISession->exitFlags(); - if(shutdown) - { - _SessionMutex.lock(); - break; - } - } + + if ( result == SUIT_Session::NORMAL ) { + // desktop is explicitly closed by user from GUI + // exit flags says if it's necessary to shutdown all servers + // all session server only + shutdownAll = aGUISession->exitFlags(); + } + else { + // desktop might be closed from: + // - StopSesion() /temporarily/ or + // - Shutdown() /permanently/ + stat = session->GetStatSession(); + shutdownSession = stat.state == SALOME::shutdown; + } + if ( shutdownAll || shutdownSession ) { + _SessionMutex.lock(); // lock mutex before leaving loop - it will be unlocked later + break; + } } delete aGUISession; aGUISession = 0; - + // Prepare _GUIMutex for a new GUI activation _SessionMutex.lock(); } @@ -587,7 +608,7 @@ int main( int argc, char **argv ) // unlock Session mutex _SessionMutex.unlock(); - if ( shutdown ) + if ( shutdownAll ) shutdownServers( _NS ); if ( myServerLauncher ) @@ -609,7 +630,7 @@ int main( int argc, char **argv ) // cpp continer is launched in the embedded mode ////////////////////////////////////////////////////////////// // std::cerr << "Caught unexpected exception on shutdown : ignored !!" << std::endl; - if ( shutdown ) + if ( shutdownAll ) killOmniNames(); abort(); //abort program to avoid deadlock in destructors or atexit when shutdown has been interrupted } @@ -621,7 +642,7 @@ int main( int argc, char **argv ) //PyRun_SimpleString("orb.destroy()"); Py_Finalize(); - if ( shutdown ) + if ( shutdownAll ) killOmniNames(); MESSAGE( "Salome_Session_Server:endofserver" ); diff --git a/src/Session/Session_Session_i.cxx b/src/Session/Session_Session_i.cxx index 86048a0bd..73d03c3da 100755 --- a/src/Session/Session_Session_i.cxx +++ b/src/Session/Session_Session_i.cxx @@ -69,6 +69,7 @@ SALOME_Session_i::SALOME_Session_i(int argc, _GUIMutex = GUIMutex; _GUILauncher = GUILauncher; _NS = new SALOME_NamingService(_orb); + _isShuttingDown = false; //MESSAGE("constructor end"); } @@ -131,8 +132,8 @@ void SALOME_Session_i::GetInterface() if ( !SUIT_Session::session() ) { _GUILauncher->wakeAll(); - MESSAGE("SALOME_Session_i::GetInterface() called, starting GUI...") - } + MESSAGE("SALOME_Session_i::GetInterface() called, starting GUI..."); + } } /*! @@ -142,19 +143,35 @@ class CloseEvent : public SALOME_Event { public: virtual void Execute() { - SUIT_Session* session = SUIT_Session::session(); - session->closeSession( SUIT_Session::DONT_SAVE ); - //if ( SUIT_Application::getDesktop() ) - // QAD_Application::getDesktop()->closeDesktop( true ); + if ( SUIT_Session::session() ) + SUIT_Session::session()->closeSession( SUIT_Session::DONT_SAVE ); } }; /*! - Processes event to close session + Stop session (close all GUI windows) */ void SALOME_Session_i::StopSession() { - ProcessVoidEvent( new CloseEvent() ); + _GUIMutex->lock(); + _GUIMutex->unlock(); + if ( SUIT_Session::session() ) { + ProcessVoidEvent( new CloseEvent() ); + } +} + +//! Shutdown session +void SALOME_Session_i::Shutdown() +{ + _GUIMutex->lock(); + _isShuttingDown = true; + _GUIMutex->unlock(); + if ( SUIT_Session::session() ) { + ProcessVoidEvent( new CloseEvent() ); + } + else { + _GUILauncher->wakeAll(); + } } /*! @@ -182,16 +199,19 @@ SALOME::StatSession SALOME_Session_i::GetStatSession() _runningStudies = SUIT_Session::session()->activeApplication()->getNbStudies(); } - _GUIMutex->unlock(); - // getting stat info SALOME::StatSession_var myStats = new SALOME::StatSession ; if (_runningStudies) myStats->state = SALOME::running ; + else if (_isShuttingDown) + myStats->state = SALOME::shutdown ; else myStats->state = SALOME::asleep ; myStats->runningStudies = _runningStudies ; myStats->activeGUI = _isGUI ; + + _GUIMutex->unlock(); + return myStats._retn() ; } diff --git a/src/Session/Session_Session_i.hxx b/src/Session/Session_Session_i.hxx index c7a6685fb..fa20deed6 100755 --- a/src/Session/Session_Session_i.hxx +++ b/src/Session/Session_Session_i.hxx @@ -60,6 +60,9 @@ public: //! Get session state SALOME::StatSession GetStatSession(); + //! Shutdown session + void Shutdown(); + //! Register the servant to Naming Service void NSregister(); @@ -89,6 +92,7 @@ protected: int _runningStudies ; CORBA::ORB_var _orb; PortableServer::POA_var _poa; + bool _isShuttingDown; }; #endif -- 2.39.2