From b54f002cbf043db44d0f6dd5c59ed30dd55f4926 Mon Sep 17 00:00:00 2001 From: mkr Date: Thu, 8 Nov 2007 11:22:51 +0000 Subject: [PATCH] IMP NPAL13547: Checkbox to kill SALOME completely. --- src/STD/STD_Application.cxx | 8 +-- src/STD/STD_CloseDlg.cxx | 69 ++++++++++++++++++++++++ src/STD/STD_CloseDlg.h | 19 +++++++ src/Session/SALOME_Session_Server.cxx | 77 ++++++++++++++++++++++++++- src/Session/Session_Session_i.hxx | 1 + 5 files changed, 170 insertions(+), 4 deletions(-) diff --git a/src/STD/STD_Application.cxx b/src/STD/STD_Application.cxx index 41f98bcaa..f1b175ad6 100755 --- a/src/STD/STD_Application.cxx +++ b/src/STD/STD_Application.cxx @@ -514,10 +514,12 @@ bool STD_Application::onSaveAsDoc() /*!Closing session.*/ void STD_Application::onExit() { - int aAnswer = SUIT_MessageBox::info2( desktop(), tr( "INF_DESK_EXIT" ), tr( "QUE_DESK_EXIT" ), - tr( "BUT_OK" ), tr( "BUT_CANCEL" ), 1, 2, 2 ); - if ( aAnswer == 1 ) + STD_ExitDlg* dlg = new STD_ExitDlg(desktop()); + if( dlg->exec() == QDialog::Accepted ) { + SUIT_Session::session()->serversShutdown(dlg->isServersShutdown()); + delete dlg; SUIT_Session::session()->closeSession(); + } } /*!Virtual slot. Not implemented here.*/ diff --git a/src/STD/STD_CloseDlg.cxx b/src/STD/STD_CloseDlg.cxx index ff09c551a..d94fc5fff 100644 --- a/src/STD/STD_CloseDlg.cxx +++ b/src/STD/STD_CloseDlg.cxx @@ -98,3 +98,72 @@ void STD_CloseDlg::onButtonClicked() if ( btn == m_pb3 ) done( 3 ); } + +/*! + * \brief creates a Exit dialog box + * \param parent a parent widget + * \param modal bool argument, if true the dialog box is a modal dialog box + * \param f style flags + */ + +STD_ExitDlg::STD_ExitDlg( QWidget* parent, bool modal, WFlags f ) +: QDialog( parent, "", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ) +{ + setSizeGripEnabled( true ); + setCaption( tr( "INF_DESK_EXIT" ) ); + + QVBoxLayout* m_vbL = new QVBoxLayout( this ); + m_vbL->setMargin( 11 ); + m_vbL->setSpacing( 6 ); + + QLabel* m_lIcon = new QLabel( this, "m_lDescr" ); + QPixmap pm = QMessageBox::standardIcon( QMessageBox::Question ); + m_lIcon->setPixmap( pm ); + m_lIcon->setScaledContents( false ); + m_lIcon->setAlignment( Qt::AlignCenter ); + + QLabel* m_lDescr = new QLabel (this, "m_lDescr"); + m_lDescr->setText ( tr ("QUE_DESK_EXIT") ); + m_lDescr->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) ); + + myServersShutdown = new QCheckBox(tr("SHUTDOWN_SERVERS"), this); + myServersShutdown->setChecked(true); + + QVBoxLayout* m_vl1 = new QVBoxLayout(); + m_vl1->setMargin( 10 ); m_vl1->setSpacing( 16 ); + m_vl1->addWidget( m_lDescr ); + m_vl1->addWidget( myServersShutdown ); + + QHBoxLayout* m_hl1 = new QHBoxLayout(); + m_hl1->setMargin( 0 ); m_hl1->setSpacing( 6 ); + m_hl1->addWidget( m_lIcon ); + m_hl1->addStretch(); + m_hl1->addLayout( m_vl1 ); + m_hl1->addStretch(); + + QPushButton* m_pbOk = new QPushButton( tr ("BUT_OK"), this ); + QPushButton* m_pbCancel = new QPushButton( tr ("BUT_CANCEL"), this ); + + QGridLayout* m_hl2 = new QGridLayout(); + m_hl2->setMargin( 0 ); m_hl2->setSpacing( 6 ); + m_hl2->addWidget( m_pbOk, 0, 0 ); + m_hl2->setColStretch( 1, 5 ); + m_hl2->addWidget( m_pbCancel, 0, 2 ); + + m_vbL->addStretch(); + m_vbL->addLayout( m_hl1 ); + m_vbL->addStretch(); + m_vbL->addLayout( m_hl2 ); + + connect( m_pbOk, SIGNAL( clicked() ), this, SLOT( accept() ) ); + connect( m_pbCancel, SIGNAL( clicked() ), this, SLOT( reject() ) ); +} + +/*! + * \brief get the check box status + */ +bool STD_ExitDlg::isServersShutdown() +{ + return myServersShutdown->isChecked(); +} + diff --git a/src/STD/STD_CloseDlg.h b/src/STD/STD_CloseDlg.h index 6975e88f4..a6f56ea4d 100644 --- a/src/STD/STD_CloseDlg.h +++ b/src/STD/STD_CloseDlg.h @@ -20,6 +20,7 @@ #define STD_CloseDlg_H #include +#include /*! \class QDialog * \brief For more information see QT documentation. @@ -58,5 +59,23 @@ private: QPushButton* m_pb4; }; +/*!\class STD_ExitDlg + * \brief Describes a dialog box shown on question about quit application + */ +class STD_ExitDlg: public QDialog +{ + Q_OBJECT + +public: + STD_ExitDlg ( QWidget * parent = 0, bool modal = FALSE, WFlags f = 0 ) ; + ~STD_ExitDlg ( ) { }; + + bool isServersShutdown(); + +private: + QCheckBox* myServersShutdown; + +}; + #endif diff --git a/src/Session/SALOME_Session_Server.cxx b/src/Session/SALOME_Session_Server.cxx index 8ae6b7d2f..af7004f6c 100755 --- a/src/Session/SALOME_Session_Server.cxx +++ b/src/Session/SALOME_Session_Server.cxx @@ -31,6 +31,11 @@ #include "SALOME_NamingService.hxx" #include "SALOMETraceCollector.hxx" +#include "SALOME_ModuleCatalog_impl.hxx" +#include "OpUtil.hxx" +#include "RegistryService.hxx" +#include "ConnectionManager_i.hxx" + #include #ifndef WNT #include @@ -303,6 +308,73 @@ bool isFound( const char* str, int argc, char** argv ) return false; } +// shutdown standalone servers +void shutdownServers( SALOME_NamingService* theNS ) +{ + // get each Container from NamingService => shutdown it + // (the order is inverse to the order of servers initialization) + + CORBA::Object_var objS = theNS->Resolve("/Kernel/Session"); + SALOME::Session_var session = SALOME::Session::_narrow(objS); + if (!CORBA::is_nil(session)) { + session->ping(); + + string hostname = GetHostname(); + string containerName = "/Containers/" + hostname; + + // 1) SuperVisionContainer + string containerNameSV = containerName + "/SuperVisionContainer"; + CORBA::Object_var objSV = theNS->Resolve(containerNameSV.c_str()); + Engines::Container_var SVcontainer = Engines::Container::_narrow(objSV) ; + if ( !CORBA::is_nil(SVcontainer) && ( session->getPID() != SVcontainer->getPID() ) ) + SVcontainer->Shutdown(); + + // 2) FactoryServerPy + string containerNameFSP = containerName + "/FactoryServerPy"; + CORBA::Object_var objFSP = theNS->Resolve(containerNameFSP.c_str()); + Engines::Container_var FSPcontainer = Engines::Container::_narrow(objFSP) ; + if ( !CORBA::is_nil(FSPcontainer) && ( session->getPID() != FSPcontainer->getPID() ) ) + FSPcontainer->Shutdown(); + + // 3) FactoryServer + string containerNameFS = containerName + "/FactoryServer"; + CORBA::Object_var objFS = theNS->Resolve(containerNameFS.c_str()); + Engines::Container_var FScontainer = Engines::Container::_narrow(objFS) ; + if ( !CORBA::is_nil(FScontainer) && ( session->getPID() != FScontainer->getPID() ) ) + FScontainer->Shutdown(); + + // 4) ContainerManager + CORBA::Object_var objCM=theNS->Resolve("/ContainerManager"); + Engines::ContainerManager_var contMan=Engines::ContainerManager::_narrow(objCM); + if ( !CORBA::is_nil(contMan) && ( session->getPID() != contMan->getPID() ) ) + contMan->ShutdownWithExit(); + + // 5) ConnectionManager + CORBA::Object_var objCnM=theNS->Resolve("/ConnectionManager"); + Engines::ConnectionManager_var connMan=Engines::ConnectionManager::_narrow(objCnM); + if ( !CORBA::is_nil(connMan) && ( session->getPID() != connMan->getPID() ) ) + connMan->ShutdownWithExit(); + + // 6) SALOMEDS + 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(); + + // 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(); + + // 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(); + } +} + // ---------------------------- MAIN ----------------------- int main( int argc, char **argv ) { @@ -537,8 +609,11 @@ int main( int argc, char **argv ) delete splash; splash = 0; - if ( result == SUIT_Session::FROM_GUI ) // desktop is closed by user from GUI + if ( result == SUIT_Session::FROM_GUI ) { // desktop is closed by user from GUI + if ( aGUISession->isServersShutdown() ) + shutdownServers( _NS ); break; + } } delete aGUISession; diff --git a/src/Session/Session_Session_i.hxx b/src/Session/Session_Session_i.hxx index bfdee09a5..58f5fdb31 100755 --- a/src/Session/Session_Session_i.hxx +++ b/src/Session/Session_Session_i.hxx @@ -68,6 +68,7 @@ public: CORBA::Long GetActiveStudyId(); void ping(){}; + CORBA::Long getPID() { return (CORBA::Long)getpid(); }; //! Restors a visual state of the study at theSavePoint bool restoreVisualState(CORBA::Long theSavePoint); -- 2.39.2