X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSession%2FSALOME_Session_Server.cxx;h=021cc2643e035748ffef4c551dcd52e0c1f627f6;hb=6a1ef75fcca2732b095e43f0837476c5a38c57e1;hp=695015339a978d28812dfa2b20b02e07fac5e410;hpb=449b56fee4cfc04c516a6d34f2eadbf5474a53c7;p=modules%2Fgui.git diff --git a/src/Session/SALOME_Session_Server.cxx b/src/Session/SALOME_Session_Server.cxx index 695015339..021cc2643 100755 --- a/src/Session/SALOME_Session_Server.cxx +++ b/src/Session/SALOME_Session_Server.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE // // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS @@ -30,16 +30,10 @@ #include #include -#include - #include #include #include -#ifdef ENABLE_TESTRECORDER - #include -#endif - #include #include #include @@ -54,7 +48,9 @@ #include #include +#ifdef USE_SALOME_STYLE #include +#endif // USE_SALOME_STYLE #include "GUI_version.h" #include @@ -68,6 +64,12 @@ #include CORBA_SERVER_HEADER(SALOME_Session) #include CORBA_SERVER_HEADER(SALOMEDS) +#ifdef WIN32 +#define sleep _sleep +#endif + +#include + #include #include #include @@ -93,19 +95,24 @@ * - stop Session ( must be idle ) * - get session state */ - +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) void MessageOutput( QtMsgType type, const char* msg ) +#else +void MessageOutput( QtMsgType type, const QMessageLogContext &context, const QString &msg ) +#endif { switch ( type ) { case QtDebugMsg: - //MESSAGE( "Debug: " << msg ); +#ifdef QT_DEBUG_MESSAGE + MESSAGE( "Debug: " << qPrintable( QString(msg) ) ); +#endif break; case QtWarningMsg: - MESSAGE( "Warning: " << msg ); + MESSAGE( "Warning: " << qPrintable( QString(msg) ) ); break; case QtFatalMsg: - MESSAGE( "Fatal: " << msg ); + MESSAGE( "Fatal: " << qPrintable( QString(msg) ) ); break; } } @@ -206,8 +213,8 @@ protected: #endif QString fname = QFileInfo( _fname ).fileName(); if ( exp.exactMatch( fname ) ) { - long fid = Qtx::versionToId( exp.cap( 1 ) ); - if ( fid > 0 ) id = fid; + long fid = Qtx::versionToId( exp.cap( 1 ) ); + if ( fid > 0 ) id = fid; } } return id; @@ -224,7 +231,7 @@ QString SALOME_ResourceMgr::myExtAppVersion = QString(); class SALOME_Session : public SUIT_Session { public: - SALOME_Session() : SUIT_Session() {} + SALOME_Session( int argc, char** argv ) : SUIT_Session( argc, argv ) {} virtual ~SALOME_Session() {} public: @@ -236,18 +243,12 @@ public: } }; -#ifdef ENABLE_TESTRECORDER - class SALOME_QApplication : public TestApplication -#else - class SALOME_QApplication : public QApplication -#endif +class SALOME_QApplication : public QApplication { public: -#ifdef ENABLE_TESTRECORDER - SALOME_QApplication( int& argc, char** argv ) : TestApplication( argc, argv ), myHandler ( 0 ) {} -#else SALOME_QApplication( int& argc, char** argv ) -#ifndef WIN32 +// TODO (QT5 PORTING) Below is a temporary solution, to allow compiling with Qt 5 +#if !defined WIN32 && QT_VERSION < QT_VERSION_CHECK(5, 0, 0) // san: Opening an X display and choosing a visual most suitable for 3D visualization // in order to make SALOME viewers work with non-native X servers : QApplication( (Display*)Qtx::getDisplay(), argc, argv, Qtx::getVisual() ), @@ -255,28 +256,10 @@ public: : QApplication( argc, argv ), #endif myHandler ( 0 ) {} -#endif virtual bool notify( QObject* receiver, QEvent* e ) { -#if OCC_VERSION_LARGE < 0x06010100 - // Disable GUI user actions while python command is executed - if (SUIT_Session::IsPythonExecuted()) { - // Disable mouse and keyboard events - QEvent::Type aType = e->type(); - if (aType == QEvent::MouseButtonPress || aType == QEvent::MouseButtonRelease || - aType == QEvent::MouseButtonDblClick || aType == QEvent::MouseMove || - aType == QEvent::Wheel || aType == QEvent::ContextMenu || - aType == QEvent::KeyPress || aType == QEvent::KeyRelease || - aType == QEvent::Accel || aType == QEvent::AccelOverride) - return false; - } -#endif -#ifdef ENABLE_TESTRECORDER - return myHandler ? myHandler->handle( receiver, e ) : - TestApplication::notify( receiver, e ); -#else try { return myHandler ? myHandler->handle( receiver, e ) : QApplication::notify( receiver, e ); } @@ -295,7 +278,6 @@ public: std::cerr << "Unknown exception caught in Qt handler: it's probably a bug in SALOME platform" << std::endl; } return false; // return false when exception is caught -#endif } SUIT_ExceptionHandler* handler() const { return myHandler; } void setHandler( SUIT_ExceptionHandler* h ) { myHandler = h; } @@ -350,26 +332,34 @@ void shutdownServers( SALOME_NamingService* theNS ) int main( int argc, char **argv ) { // Install Qt debug messages handler +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) qInstallMsgHandler( MessageOutput ); +#else + qInstallMessageHandler( MessageOutput ); +#endif +// TODO (QT5 PORTING) Below is a temporary solution, to allow compiling with Qt 5 +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) //Set a "native" graphic system in case if application runs on the remote host QString remote(getenv("REMOTEHOST")); QString client(getenv("SSH_CLIENT")); if(remote.length() > 0 || client.length() > 0 ) { QApplication::setGraphicsSystem(QLatin1String("native")); } - - // add $QTDIR/plugins to the pluins search path for image plugins - QString qtdir( ::getenv( "QTDIR" ) ); - if ( !qtdir.isEmpty() ) - QApplication::addLibraryPath( QDir( qtdir ).absoluteFilePath( "plugins" ) ); +#endif + // add /plugins dir to the pluins search path for image plugins + QString qtdir = Qtx::qtDir( "plugins" ); + if ( !qtdir.isEmpty() ) + QApplication::addLibraryPath( qtdir ); + + // set "C" locale if requested via preferences { - SALOME_Session s; + SALOME_Session stmp( argc, argv ); QApplication::setApplicationName( "salome" ); - SUIT_ResourceMgr* resMgr = s.createResourceMgr( "SalomeApp" ); + SUIT_ResourceMgr* resMgr = stmp.createResourceMgr( "SalomeApp" ); bool isCloc = resMgr->booleanValue( "language", "locale", true ); - if ( isCloc ) { + if ( isCloc ) { QLocale::setDefault( QLocale::c() ); } else { @@ -385,7 +375,7 @@ int main( int argc, char **argv ) _qappl.setApplicationVersion( salomeVersion() ); // Add application library path (to search style plugin etc...) - QString path = QDir::convertSeparators( SUIT_Tools::addSlash( QString( ::getenv( "GUI_ROOT_DIR" ) ) ) + QString( "bin/salome" ) ); + QString path = QDir::toNativeSeparators( SUIT_Tools::addSlash( QString( ::getenv( "GUI_ROOT_DIR" ) ) ) + QString( "bin/salome" ) ); _qappl.addLibraryPath( path ); bool isGUI = isFound( "GUI", argc, argv ); @@ -560,21 +550,23 @@ int main( int argc, char **argv ) 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; + _SessionMutex.lock(); // lock mutex before leaving loop - it will be unlocked later + break; } // SUIT_Session creation - aGUISession = new SALOME_Session(); + aGUISession = new SALOME_Session( argc, argv ); // Load SalomeApp dynamic library MESSAGE( "creation SUIT_Application" ); SUIT_Application* aGUIApp = aGUISession->startApplication( "SalomeApp", 0, 0 ); if ( aGUIApp ) { +#ifdef USE_SALOME_STYLE Style_Salome::initialize( aGUIApp->resourceMgr() ); if ( aGUIApp->resourceMgr()->booleanValue( "Style", "use_salome_style", true ) ) Style_Salome::apply(); +#endif // USE_SALOME_STYLE if ( !isFound( "noexcepthandler", argc, argv ) ) _qappl.setHandler( aGUISession->handler() ); // after loading SalomeApp application @@ -597,10 +589,15 @@ int main( int argc, char **argv ) } else { // desktop might be closed from: - // - StopSesion() /temporarily/ or - // - Shutdown() /permanently/ + // - StopSesion() (temporarily) or + // - Shutdown() (permanently) stat = session->GetStatSession(); shutdownSession = stat.state == SALOME::shutdown; + // normally "shutdown standalone servers" flag should be false here, if we come from + // StopSesion() or from Shutdown(); + // but we also have to check if somebody explicitly programmatically closed session, + // asking to kill servers also + shutdownAll = aGUISession->exitFlags(); } if ( shutdownAll || shutdownSession ) { _SessionMutex.lock(); // lock mutex before leaving loop - it will be unlocked later @@ -654,15 +651,34 @@ int main( int argc, char **argv ) abort(); //abort program to avoid deadlock in destructors or atexit when shutdown has been interrupted } - PyGILState_Ensure(); - //Destroy orb from python (for chasing memory leaks) + //Destroy orb from python (for chasing memory leaks) //PyRun_SimpleString("from omniORB import CORBA"); //PyRun_SimpleString("orb=CORBA.ORB_init([''], CORBA.ORB_ID)"); //PyRun_SimpleString("orb.destroy()"); - Py_Finalize(); + + // Destroy the ORB: + sleep(2); + //std::cout << "@@@@@ Explicitely destroying the ORB (hoping to kill omniORB threads ...)\n"; + ORB_INIT * init = SINGLETON_::Instance(); + if (init) + init->explicit_destroy(); + //std::cout << "@@@@@ ORB destroyed\n"; + + // After ORB destruction + if(Py_IsInitialized()) + { + PyGILState_Ensure(); + //std::cout << "@@@@@ About to PyFinalize\n"; + Py_Finalize(); + //std::cout << "@@@@@ DONE PyFinalize\n"; + } if ( shutdownAll ) - killOmniNames(); + { + //std::cout << "@@@@@ About to kill omni\n"; + killOmniNames(); + //std::cout << "@@@@@ DONE kill omni\n"; + } MESSAGE( "Salome_Session_Server:endofserver" ); return result;