From: stv Date: Mon, 27 Jun 2005 11:23:15 +0000 (+0000) Subject: try () catch () mechanism modified. X-Git-Tag: T3_0_0_a4~14 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b33fcc22b6ebc8d7210afede1a3ad289d9cf3102;p=modules%2Fgui.git try () catch () mechanism modified. --- diff --git a/src/Session/SALOME_Session_Server.cxx b/src/Session/SALOME_Session_Server.cxx index 621aada17..2b2405e81 100755 --- a/src/Session/SALOME_Session_Server.cxx +++ b/src/Session/SALOME_Session_Server.cxx @@ -1,30 +1,29 @@ -// SALOME Session : implementation of Session.idl +// SALOME Session : implementation of Session.idl // -// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS // +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. // +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. // -// File : SALOME_Session_Server.cxx -// Author : Paul RASCLE, EDF -// Module : SALOME -// $Header$ +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : SALOME_Session_Server.cxx +// Author : Paul RASCLE, EDF +// Module : SALOME #include #include "Utils_ORB_INIT.hxx" @@ -54,33 +53,31 @@ #include "Session_Session_i.hxx" #include "Session_ServerLauncher.hxx" +#include "SUIT_Tools.h" #include "SUIT_Session.h" #include "SUIT_Application.h" #include "SUIT_MessageBox.h" -#include "SUIT_Tools.h" - #include "SUIT_ExceptionHandler.h" -using namespace std; -extern "C" int HandleSignals(QApplication *theQApplication); +extern "C" int HandleSignals( QApplication *theQApplication ); /*! - read arguments, define list of server to launch with their arguments. - * - wait for naming service - * - create and run a thread for launch of all servers - * - */ + * - wait for naming service + * - create and run a thread for launch of all servers + * +*/ //! CORBA server for SALOME Session /*! - * SALOME_Session Server launches a SALOME session servant. - * The servant registers to the Naming Service. - * See SALOME_Session.idl for interface specification. + * SALOME_Session Server launches a SALOME session servant. + * The servant registers to the Naming Service. + * See SALOME_Session.idl for interface specification. * - * Main services offered by the servant are: - * - launch GUI - * - stop Session (must be idle) - * - get session state + * Main services offered by the servant are: + * - launch GUI + * - stop Session ( must be idle ) + * - get session state */ QString salomeVersion() @@ -112,11 +109,12 @@ QString salomeVersion() return ver; } -PyObject *salome_shared_modules_module = NULL; +PyObject* salome_shared_modules_module = 0; -void MessageOutput( QtMsgType type, const char *msg ) +void MessageOutput( QtMsgType type, const char* msg ) { - switch ( type ) { + switch ( type ) + { case QtDebugMsg: MESSAGE( "Debug: " << msg ); break; @@ -146,39 +144,36 @@ protected: } }; -class SALOME_QApplication : public QApplication +class SALOME_QApplication : public QApplication { public: - SALOME_QApplication( int& argc, char** argv ) : QApplication( argc, argv ) - { - myHandler = 0; - } - - virtual bool notify( QObject* receiver, QEvent* e ) + SALOME_QApplication( int& argc, char** argv ) : QApplication( argc, argv ), myHandler ( 0 ) {} + + virtual bool notify( QObject* receiver, QEvent* e ) { return myHandler ? myHandler->handle( receiver, e ) : - QApplication::notify( receiver, e ); + QApplication::notify( receiver, e ); } - SUIT_ExceptionHandler* handler() const { return myHandler; } + SUIT_ExceptionHandler* handler() const { return myHandler; } void setHandler( SUIT_ExceptionHandler* h ) { myHandler = h; } private: - SUIT_ExceptionHandler* myHandler; + SUIT_ExceptionHandler* myHandler; }; // class which calls SALOME::Session::GetInterface() from another thread -// to avoid mutual lock (if called from the same thread as main() +// to avoid mutual lock ( if called from the same thread as main() class GetInterfaceThread : public QThread { -public: +public: GetInterfaceThread( SALOME::Session_var s ) : session ( s ) {} protected: virtual void run() { if ( !CORBA::is_nil( session ) ) - session->GetInterface(); + session->GetInterface(); else - printf( "\nFATAL ERROR: SALOME::Session object is nil! Can not display GUI\n\n" ); + printf( "\nFATAL ERROR: SALOME::Session object is nil! Can not display GUI\n\n" ); } private: SALOME::Session_var session; @@ -187,193 +182,199 @@ private: // returns true if 'str' is found in argv bool isFound( const char* str, int argc, char** argv ) { - for ( int i = 1; i <= (argc-1); i++ ) + for ( int i = 1; i <= ( argc-1 ); i++ ) if ( !strcmp( argv[i], str ) ) return true; return false; } // ---------------------------- MAIN ----------------------- -int main(int argc, char **argv) +int main( int argc, char **argv ) { qInstallMsgHandler( MessageOutput ); // QApplication should be create before all other operations - // When uses QApplication::libraryPaths() (example, QFile::encodeName()) + // When uses QApplication::libraryPaths() ( example, QFile::encodeName() ) // qApp used for detection of the executable dir path. SALOME_QApplication _qappl( argc, argv ); - ASSERT( QObject::connect(&_qappl, SIGNAL( lastWindowClosed() ), &_qappl, SLOT( quit() ) ) ); - QString path( ::getenv( "GUI_ROOT_DIR" ) ); - if ( !path.isEmpty() ) - path += QDir::separator(); - path += QString( "bin/salome" ); + ASSERT( QObject::connect( &_qappl, SIGNAL( lastWindowClosed() ), &_qappl, SLOT( quit() ) ) ); + + QString path = QDir::convertSeparators( SUIT_Tools::addSlash( QString( ::getenv( "GUI_ROOT_DIR" ) ) ) + QString( "bin/salome" ) ); _qappl.addLibraryPath( path ); + _qappl.setStyle( "salome" ); - /* - Python initialisation : only once - */ - - int _argc = 1; - char* _argv[] = {""}; - KERNEL_PYTHON::init_python(_argc,_argv); - PyEval_RestoreThread(KERNEL_PYTHON::_gtstate); - if ( !KERNEL_PYTHON::salome_shared_modules_module ) // import only once - { - KERNEL_PYTHON::salome_shared_modules_module = - PyImport_ImportModule("salome_shared_modules"); - } - if ( !KERNEL_PYTHON::salome_shared_modules_module ) - { - INFOS("salome_shared_modules_module == NULL"); - PyErr_Print(); - PyErr_Clear(); - } - PyEval_ReleaseThread(KERNEL_PYTHON::_gtstate); - int result = -1; - // 1. create ORB, get RootPOA object, NamingService, etc. - ORB_INIT &init = *SINGLETON_::Instance() ; - ASSERT(SINGLETON_::IsAlreadyExisting()) ; - int orbArgc = 1; - CORBA::ORB_var &orb = init( orbArgc , argv ) ; - SALOMETraceCollector *myThreadTrace = SALOMETraceCollector::instance(orb); + CORBA::ORB_var orb; + PortableServer::POA_var poa; + + SUIT_Session* aGUISession = 0; + SALOME_NamingService* _NS = 0; GetInterfaceThread* guiThread = 0; + SALOMETraceCollector* myThreadTrace = 0; + Session_ServerLauncher* myServerLauncher = 0; - try - { + try { + + // Python initialisation : only once + + int _argc = 1; + char* _argv[] = {""}; + KERNEL_PYTHON::init_python( _argc,_argv ); + PyEval_RestoreThread( KERNEL_PYTHON::_gtstate ); + if ( !KERNEL_PYTHON::salome_shared_modules_module ) // import only once + KERNEL_PYTHON::salome_shared_modules_module = PyImport_ImportModule( "salome_shared_modules" ); + if ( !KERNEL_PYTHON::salome_shared_modules_module ) + { + INFOS( "salome_shared_modules_module == NULL" ); + PyErr_Print(); + PyErr_Clear(); + } + PyEval_ReleaseThread( KERNEL_PYTHON::_gtstate ); + + // Create ORB, get RootPOA object, NamingService, etc. + ORB_INIT &init = *SINGLETON_::Instance(); + ASSERT( SINGLETON_::IsAlreadyExisting() ); + int orbArgc = 1; + orb = init( orbArgc, argv ); + myThreadTrace = SALOMETraceCollector::instance( orb ); + + // Install SALOME thread event handler SALOME_Event::GetSessionThread(); - CORBA::Object_var obj = orb->resolve_initial_references("RootPOA"); - PortableServer::POA_var poa = PortableServer::POA::_narrow(obj); + CORBA::Object_var obj = orb->resolve_initial_references( "RootPOA" ); + poa = PortableServer::POA::_narrow( obj ); - PortableServer::POAManager_var pman = poa->the_POAManager() ; + PortableServer::POAManager_var pman = poa->the_POAManager(); pman->activate() ; - INFOS("pman->activate()"); + INFOS( "pman->activate()" ); - SALOME_NamingService *_NS = new SALOME_NamingService(orb); + _NS = new SALOME_NamingService( orb ); - // CORBA Servant Launcher - QMutex _GUIMutex ; - QWaitCondition _ServerLaunch, _SessionStarted; - _GUIMutex.lock(); // to block Launch server thread until wait(mutex) - - // 2. activate embedded CORBA servers: Registry, SALOMEDS, etc. - Session_ServerLauncher* myServerLauncher - = new Session_ServerLauncher(argc, argv, orb, poa, &_GUIMutex, &_ServerLaunch, &_SessionStarted); + result = 0; + } + catch ( SALOME_Exception& e ) { + INFOS( "run(): SALOME::SALOME_Exception is caught: "<name(); + INFOS ( "run(): CORBA exception of the kind : "<start(); - - _ServerLaunch.wait(&_GUIMutex); // to be reseased by Launch server thread when ready - // show splash screen if "SPLASH" parameter was passed (default) - if ( isFound( "SPLASH", argc, argv ) ) + _ServerLaunch.wait( &_GUIMutex ); // to be reseased by Launch server thread when ready: + + // show splash screen if "SPLASH" parameter was passed ( default ) + if ( isFound( "SPLASH", argc, argv ) ) { // create temporary resource manager just to load splash icon SUIT_ResourceMgr resMgr( "SalomeApp", QString( "%1Config" ) ); resMgr.setVersion( salomeVersion() ); resMgr.setCurrentFormat( "xml" ); resMgr.loadLanguage( "SalomeApp", "en" ); - // create splash object: widget (splash with progress bar) and "pinging" thread + + // create splash object: widget ( splash with progress bar ) and "pinging" thread InquireServersGUI splash; splash.setPixmap( resMgr.loadPixmap( "SalomeApp", QObject::tr( "ABOUT" ) ) ); SUIT_Tools::centerWidget( &splash, _qappl.desktop() ); - + _qappl.setMainWidget( &splash ); QObject::connect( &_qappl, SIGNAL( lastWindowClosed() ), &_qappl, SLOT( quit() ) ); - splash.show(); // display splash with running progress bar - _qappl.exec(); // wait untill splash closes (progress runs till end or Cancel is pressed) - - //int q = 0; - //while ( q++ < 10 ) - // sleep( 1 ); - - if ( splash.getExitStatus() ) // 1 is error - exit( splash.getExitStatus() ); // quit applicaiton + splash.show(); // display splash with running progress bar + _qappl.exec(); // wait untill splash closes ( progress runs till end or Cancel is pressed ) + + result = splash.getExitStatus(); // 1 is error } else _SessionStarted.wait(); + } - // call Session::GetInterface() if "GUI" parameter was passed (default) - if ( isFound( "GUI", argc, argv ) ) - { - CORBA::Object_var obj = _NS->Resolve("/Kernel/Session"); - SALOME::Session_var session = SALOME::Session::_narrow( obj ) ; - ASSERT (! CORBA::is_nil( session ) ); + // call Session::GetInterface() if "GUI" parameter was passed ( default ) + if ( !result && isFound( "GUI", argc, argv ) ) + { + CORBA::Object_var obj = _NS->Resolve( "/Kernel/Session" ); + SALOME::Session_var session = SALOME::Session::_narrow( obj ) ; + ASSERT ( ! CORBA::is_nil( session ) ); - INFOS("Session activated, Launch IAPP..."); - guiThread = new GetInterfaceThread( session ); - guiThread->start(); - } + INFOS( "Session activated, Launch IAPP..." ); + guiThread = new GetInterfaceThread( session ); + guiThread->start(); + } - // 3. GUI activation + if ( !result ) + { + + // GUI activation // Allow multiple activation/deactivation of GUI - while ( 1 ) + while ( true ) { - MESSAGE("waiting wakeAll()"); - _ServerLaunch.wait(&_GUIMutex); // to be reseased by Launch server thread when ready: + MESSAGE( "waiting wakeAll()" ); + _ServerLaunch.wait( &_GUIMutex ); // to be reseased by Launch server thread when ready: // atomic operation lock - unlock on mutex - // unlock mutex: serverThread runs, calls _ServerLaunch->wakeAll() + // unlock mutex: serverThread runs, calls _ServerLaunch->wakeAll() // this thread wakes up, and lock mutex - + _GUIMutex.unlock(); - // 3.1 SUIT_Session creation - SUIT_Session* aGUISession = new SALOME_Session(); - INFOS("creation SUIT_Application"); - - SCRUTE(_NS); - - // 3.3 run GUI loop - // T2.12 - catch exceptions thrown on attempts to modified a locked study - MESSAGE("run(): starting the main event loop"); - - // 3.2 load SalomeApp dynamic library + // SUIT_Session creation + aGUISession = new SALOME_Session(); + + // Load SalomeApp dynamic library + INFOS( "creation SUIT_Application" ); SUIT_Application* aGUIApp = aGUISession->startApplication( "SalomeApp", 0, 0 ); - if ( aGUIApp ) + if ( aGUIApp ) { _qappl.setHandler( aGUISession->handler() ); // after loading SalomeApp application // aGUISession contains SalomeApp_ExceptionHandler + // Run GUI loop + MESSAGE( "run(): starting the main event loop" ); result = _qappl.exec(); if ( result == SUIT_Session::FROM_GUI ) // desktop is closed by user from GUI break; } + delete aGUISession; + aGUISession = 0; + // Prepare _GUIMutex for a new GUI activation - _GUIMutex.lock(); + _GUIMutex.lock(); } - - //orb->shutdown(0); - myServerLauncher->KillAll(); // kill embedded servers - } - catch (SALOME_Exception& e) - { - INFOS("run(): SALOME::SALOME_Exception is caught: "<name(); - INFOS ("run(): CORBA exception of the kind : "<KillAll(); // kill embedded servers + + delete aGUISession; + delete guiThread; + delete myServerLauncher; + delete _NS; delete myThreadTrace; - if ( guiThread ) - delete guiThread; - return result ; + + return result; } diff --git a/src/Session/Session_Session_i.cxx b/src/Session/Session_Session_i.cxx index e383b774f..8da4a3472 100755 --- a/src/Session/Session_Session_i.cxx +++ b/src/Session/Session_Session_i.cxx @@ -1,23 +1,23 @@ // SALOME Session : implementation of Session.idl // // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org // // // @@ -48,13 +48,13 @@ using namespace std; //============================================================================= /*! SALOME_Session_i * constructor - */ + */ //============================================================================= -SALOME_Session_i::SALOME_Session_i(int argc, - char ** argv, - CORBA::ORB_ptr orb, - PortableServer::POA_ptr poa, +SALOME_Session_i::SALOME_Session_i(int argc, + char ** argv, + CORBA::ORB_ptr orb, + PortableServer::POA_ptr poa, QMutex* GUIMutex, QWaitCondition* GUILauncher) { @@ -72,7 +72,7 @@ SALOME_Session_i::SALOME_Session_i(int argc, //============================================================================= /*! GetVisuComponent * returns Visu component - */ + */ //============================================================================= Engines::Component_ptr SALOME_Session_i::GetComponent(const char* theLibraryName) @@ -90,19 +90,19 @@ Engines::Component_ptr SALOME_Session_i::GetComponent(const char* theLibraryName //============================================================================= /*! ~SALOME_Session_i * destructor - */ + */ //============================================================================= SALOME_Session_i::~SALOME_Session_i() { - //MESSAGE("destructor end"); + //MESSAGE("destructor end"); } //============================================================================= /*! NSregister * tries to find the Corba Naming Service and to register the session, * gives naming service interface to _IAPPThread - */ + */ //============================================================================= void SALOME_Session_i::NSregister() @@ -122,30 +122,31 @@ void SALOME_Session_i::NSregister() { INFOS("Caught unknown exception from Naming Service"); } - //MESSAGE("Session registered in Naming Service"); + //MESSAGE("Session registered in Naming Service"); } //============================================================================= /*! GetInterface * Launches the GUI if there is none. * The Corba method is oneway (corba client does'nt wait for GUI completion) - */ + */ //============================================================================= void SALOME_Session_i::GetInterface() { _GUIMutex->lock(); _GUIMutex->unlock(); - if( !SUIT_Session::session() ) { + if ( !SUIT_Session::session() ) + { _GUILauncher->wakeAll(); MESSAGE("SALOME_Session_i::GetInterface() called, starting GUI...") - } + } } //============================================================================= /*! StopSession * Kills the session if there are no active studies nore GUI - */ + */ //============================================================================= class CloseEvent : public SALOME_Event { @@ -162,12 +163,12 @@ void SALOME_Session_i::StopSession() { ProcessVoidEvent( new CloseEvent() ); } - + //============================================================================= /*! StatSession * Send a SALOME::StatSession structure (see idl) to the client * (number of running studies and presence of GUI) - */ + */ //============================================================================= class QtLock @@ -181,13 +182,13 @@ public: SALOME::StatSession SALOME_Session_i::GetStatSession() { // update Session state - _GUIMutex->lock(); + _GUIMutex->lock(); _runningStudies = 0; { QtLock lock; _isGUI = SUIT_Session::session(); - if ( _isGUI && SUIT_Session::session()->activeApplication() ) + if ( _isGUI && SUIT_Session::session()->activeApplication() ) _runningStudies = SUIT_Session::session()->activeApplication()->getNbStudies(); }