Back to index

salome-gui  6.5.0
SALOME_Session_Server.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  SALOME Session : implementation of Session.idl
00024 //  File : SALOME_Session_Server.cxx
00025 //  Author : Paul RASCLE, EDF
00026 //  Module : SALOME
00027 
00028 #include <SALOME_NamingService.hxx>
00029 #include <SALOME_ModuleCatalog_impl.hxx>
00030 #include <SALOME_LifeCycleCORBA.hxx>
00031 #include <SALOME_Event.h>
00032 
00033 #include <Basics_OCCTVersion.hxx>
00034 
00035 #include <Container_init_python.hxx>
00036 #include <ConnectionManager_i.hxx>
00037 #include <RegistryService.hxx>
00038 
00039 #ifdef ENABLE_TESTRECORDER
00040   #include <TestApplication.h>
00041 #endif
00042 
00043 #include <OpUtil.hxx>
00044 #include <Utils_ORB_INIT.hxx>
00045 #include <Utils_SINGLETON.hxx>
00046 #include <Utils_SALOME_Exception.hxx>
00047 #include <Utils_CorbaException.hxx>
00048 
00049 #include <utilities.h>
00050 #include "Session_ServerLauncher.hxx"
00051 #include "Session_ServerCheck.hxx"
00052 #include "Session_Session_i.hxx"
00053 
00054 #include <Qtx.h>
00055 #include <QtxSplash.h>
00056 
00057 #include <Style_Salome.h>
00058 
00059 #include "GUI_version.h"
00060 #include <SUIT_Tools.h>
00061 #include <SUIT_Session.h>
00062 #include <SUIT_Application.h>
00063 #include <SUIT_Desktop.h>
00064 #include <SUIT_ResourceMgr.h>
00065 #include <SUIT_ExceptionHandler.h>
00066 
00067 #include <SALOMEconfig.h>
00068 #include CORBA_SERVER_HEADER(SALOME_Session)
00069 #include CORBA_SERVER_HEADER(SALOMEDS)
00070 
00071 #include <QDir>
00072 #include <QFile>
00073 #include <QApplication>
00074 #include <QMutex>
00075 #include <QWaitCondition>
00076 #include <QRegExp>
00077 #include <QTextStream>
00078 
00085 
00086 
00097 PyObject* salome_shared_modules_module = 0;
00098 
00099 void MessageOutput( QtMsgType type, const char* msg )
00100 {
00101   switch ( type )
00102   {
00103   case QtDebugMsg:
00104     //MESSAGE( "Debug: " << msg );
00105     break;
00106   case QtWarningMsg:
00107     MESSAGE( "Warning: " << msg );
00108     break;
00109   case QtFatalMsg:
00110     MESSAGE( "Fatal: " << msg );
00111     break;
00112   }
00113 }
00114 
00115 /* XPM */
00116 static const char* pixmap_not_found_xpm[] = {
00117 "16 16 3 1",
00118 "       c None",
00119 ".      c #000000",
00120 "+      c #A80000",
00121 "                ",
00122 "                ",
00123 "    .     .     ",
00124 "   .+.   .+.    ",
00125 "  .+++. .+++.   ",
00126 "   .+++.+++.    ",
00127 "    .+++++.     ",
00128 "     .+++.      ",
00129 "    .+++++.     ",
00130 "   .+++.+++.    ",
00131 "  .+++. .+++.   ",
00132 "   .+.   .+.    ",
00133 "    .     .     ",
00134 "                ",
00135 "                ",
00136 "                "};
00137 
00138 QString salomeVersion()
00139 {
00140   return GUI_VERSION_STR;
00141 }
00142 
00143 class SALOME_ResourceMgr : public SUIT_ResourceMgr
00144 {
00145 public:
00146   SALOME_ResourceMgr( const QString& app, const QString& resVarTemplate ) : SUIT_ResourceMgr( app, resVarTemplate )
00147   {
00148     setCurrentFormat( "xml" );
00149     setOption( "translators", QString( "%P_msg_%L.qm|%P_icons.qm|%P_images.qm" ) );
00150     setDefaultPixmap( QPixmap( pixmap_not_found_xpm ) );
00151   }
00152   static void initResourceMgr()
00153   {
00154     if ( myExtAppName.isNull() || myExtAppVersion.isNull() ) {
00155       SALOME_ResourceMgr resMgr( "SalomeApp", QString( "%1Config" ) );
00156       resMgr.loadLanguage( "LightApp",  "en" );
00157       resMgr.loadLanguage( "SalomeApp", "en" );
00158 
00159       myExtAppName = QObject::tr( "APP_NAME" ).trimmed();
00160       if ( myExtAppName == "APP_NAME" || myExtAppName.toLower() == "salome" ) 
00161         myExtAppName = "SalomeApp";
00162       myExtAppVersion = QObject::tr( "APP_VERSION" );
00163       if ( myExtAppVersion == "APP_VERSION" ) {
00164         if ( myExtAppName != "SalomeApp" )
00165           myExtAppVersion = "";
00166         else myExtAppVersion = salomeVersion();
00167       }
00168     }
00169   }
00170   QString version() const { return myExtAppVersion; }
00171 
00172 protected:
00173   QString userFileName( const QString& appName, const bool for_load ) const
00174   { 
00175     if ( version().isEmpty()  ) return ""; 
00176     return SUIT_ResourceMgr::userFileName( myExtAppName, for_load );
00177   }
00178 
00179   virtual long userFileId( const QString& _fname ) const
00180   {
00181     long id = -1;
00182     if ( !myExtAppName.isEmpty() ) {
00183 #ifdef WIN32
00184       QRegExp exp( QString( "%1\\.%2\\.([a-zA-Z0-9.]+)$" ).arg( myExtAppName ).arg( currentFormat() ) );
00185 #else
00186       QRegExp exp( QString( "\\.%1rc\\.([a-zA-Z0-9.]+)$" ).arg( myExtAppName ) );
00187 #endif
00188       QRegExp vers_exp( "^([0-9]+)([A-Za-z]?)([0-9]*)$" );
00189       
00190       QString fname = QFileInfo( _fname ).fileName();
00191       if( exp.exactMatch( fname ) ) {
00192         QStringList vers = exp.cap( 1 ).split( ".", QString::SkipEmptyParts );
00193         int major=0, minor=0;
00194         int release = 0, dev1 = 0, dev2 = 0;
00195        if ( vers.count() > 0 ) major = vers[0].toInt();
00196        if ( vers.count() > 1 ) minor = vers[1].toInt();
00197        if ( vers.count() > 2 ) {
00198          if( vers_exp.indexIn( vers[2] ) != -1 ) {
00199            release = vers_exp.cap( 1 ).toInt();
00200            dev1 = vers_exp.cap( 2 )[ 0 ].toLatin1();
00201            dev2 = vers_exp.cap( 3 ).toInt();
00202          }
00203        }
00204         
00205         int dev = dev1*100+dev2;
00206        id = major;
00207         id*=100; id+=minor;
00208         id*=100; id+=release;
00209         id*=10000;
00210         if ( dev > 0 ) id+=dev-10000;
00211       }
00212     }
00213     return id;
00214   }
00215 
00216 public:
00217   static QString myExtAppName;
00218   static QString myExtAppVersion;
00219 };
00220 
00221 QString SALOME_ResourceMgr::myExtAppName    = QString();
00222 QString SALOME_ResourceMgr::myExtAppVersion = QString();
00223 
00224 class SALOME_Session : public SUIT_Session
00225 {
00226 public:
00227   SALOME_Session() : SUIT_Session() {}
00228   virtual ~SALOME_Session() {}
00229 
00230 protected:
00231   virtual SUIT_ResourceMgr* createResourceMgr( const QString& appName ) const
00232   {
00233     SALOME_ResourceMgr::initResourceMgr();
00234     SALOME_ResourceMgr* resMgr = new SALOME_ResourceMgr( appName, QString( "%1Config" ) );
00235     return resMgr;
00236   }
00237 };
00238 
00239 #ifdef ENABLE_TESTRECORDER
00240   class SALOME_QApplication : public TestApplication
00241 #else
00242   class SALOME_QApplication : public QApplication
00243 #endif
00244 {
00245 public:
00246 #ifdef ENABLE_TESTRECORDER
00247   SALOME_QApplication( int& argc, char** argv ) : TestApplication( argc, argv ), myHandler ( 0 ) {}
00248 #else
00249   SALOME_QApplication( int& argc, char** argv )
00250 #ifndef WIN32
00251   // san: Opening an X display and choosing a visual most suitable for 3D visualization
00252   // in order to make SALOME viewers work with non-native X servers
00253   : QApplication( (Display*)Qtx::getDisplay(), argc, argv, Qtx::getVisual() ),
00254 #else
00255   : QApplication( argc, argv ), 
00256 #endif
00257     myHandler ( 0 ) {}
00258 #endif
00259 
00260   virtual bool notify( QObject* receiver, QEvent* e )
00261   {
00262 #if OCC_VERSION_LARGE < 0x06010100
00263     // Disable GUI user actions while python command is executed
00264     if (SUIT_Session::IsPythonExecuted()) {
00265       // Disable mouse and keyboard events
00266       QEvent::Type aType = e->type();
00267       if (aType == QEvent::MouseButtonPress || aType == QEvent::MouseButtonRelease ||
00268           aType == QEvent::MouseButtonDblClick || aType == QEvent::MouseMove ||
00269           aType == QEvent::Wheel || aType == QEvent::ContextMenu ||
00270           aType == QEvent::KeyPress || aType == QEvent::KeyRelease ||
00271           aType == QEvent::Accel || aType == QEvent::AccelOverride)
00272         return false;
00273     }
00274 #endif
00275 
00276 #ifdef ENABLE_TESTRECORDER
00277     return myHandler ? myHandler->handle( receiver, e ) :
00278       TestApplication::notify( receiver, e );
00279 #else
00280     try {
00281       return myHandler ? myHandler->handle( receiver, e ) : QApplication::notify( receiver, e );
00282     }
00283     catch (std::exception& e) {
00284       std::cerr << e.what()  << std::endl;
00285     }
00286     catch (CORBA::Exception& e) {
00287       std::cerr << "Caught CORBA::Exception"  << std::endl;
00288       CORBA::Any tmp;
00289       tmp<<= e;
00290       CORBA::TypeCode_var tc = tmp.type();
00291       const char *p = tc->name();
00292       std::cerr << "notify(): CORBA exception of the kind : " << p << " is caught" << std::endl;
00293     }
00294     catch (...) {
00295       std::cerr << "Unknown exception caught in Qt handler: it's probably a bug in SALOME platform" << std::endl;
00296     }
00297     return false;  // return false when exception is caught
00298 #endif
00299   }
00300   SUIT_ExceptionHandler* handler() const { return myHandler; }
00301   void setHandler( SUIT_ExceptionHandler* h ) { myHandler = h; }
00302 
00303 private:
00304   SUIT_ExceptionHandler* myHandler;
00305 };
00306 
00307 // class which calls SALOME::Session::GetInterface() from another thread
00308 // to avoid mutual lock ( if called from the same thread as main()
00309 class GetInterfaceThread : public QThread
00310 {
00311 public:
00312   GetInterfaceThread( SALOME::Session_var s ) : session ( s )
00313   {
00314     start();
00315   }
00316 protected:
00317   virtual void run()
00318   {
00319     if ( !CORBA::is_nil( session ) )
00320       session->GetInterface();
00321     else
00322       printf( "\nFATAL ERROR: SALOME::Session object is nil! Can not display GUI\n\n" );
00323   }
00324 private:
00325   SALOME::Session_var session;
00326 };
00327 
00328 // returns true if 'str' is found in argv
00329 bool isFound( const char* str, int argc, char** argv )
00330 {
00331   for ( int i = 1; i <= ( argc-1 ); i++ )
00332     if ( !strcmp( argv[i], str ) )
00333       return true;
00334   return false;
00335 }
00336 
00337 void killOmniNames()
00338 {
00339   SALOME_LifeCycleCORBA::killOmniNames();
00340 }
00341 
00342 // shutdown standalone servers
00343 void shutdownServers( SALOME_NamingService* theNS )
00344 {
00345   SALOME_LifeCycleCORBA lcc(theNS);
00346   lcc.shutdownServers();
00347 }
00348 
00349 // ---------------------------- MAIN -----------------------
00350 int main( int argc, char **argv )
00351 {
00352   // Install Qt debug messages handler
00353   qInstallMsgHandler( MessageOutput );
00354   
00355   // add $QTDIR/plugins to the pluins search path for image plugins
00356   QString qtdir( ::getenv( "QTDIR" ) );
00357   if ( !qtdir.isEmpty() )
00358     QApplication::addLibraryPath( QDir( qtdir ).absoluteFilePath( "plugins" ) );
00359 
00360   // Create Qt application instance;
00361   // this should be done the very first!
00362   SALOME_QApplication _qappl( argc, argv );
00363   _qappl.setOrganizationName( "salome" );
00364   _qappl.setApplicationName( "salome" );
00365   _qappl.setApplicationVersion( salomeVersion() );
00366 
00367   // Add application library path (to search style plugin etc...)
00368   QString path = QDir::convertSeparators( SUIT_Tools::addSlash( QString( ::getenv( "GUI_ROOT_DIR" ) ) ) + QString( "bin/salome" ) );
00369   _qappl.addLibraryPath( path );
00370 
00371   bool isGUI    = isFound( "GUI",    argc, argv );
00372   bool isSplash = isFound( "SPLASH", argc, argv );
00373   // Show splash screen (only if both the "GUI" and "SPLASH" parameters are set)
00374   // Note, that user preferences are not taken into account for splash settings -
00375   // it is a property of the application!
00376   QtxSplash* splash = 0;
00377   if ( isGUI && isSplash ) {
00378     // ...create resource manager
00379     SUIT_ResourceMgr resMgr( "SalomeApp", QString( "%1Config" ) );
00380     resMgr.setCurrentFormat( "xml" );
00381     resMgr.setWorkingMode( QtxResourceMgr::IgnoreUserValues );
00382     resMgr.loadLanguage( "LightApp" );
00383     //
00384     splash = QtxSplash::splash( QPixmap() );
00385     splash->readSettings( &resMgr );
00386     if ( splash->pixmap().isNull() )
00387       splash->setPixmap( resMgr.loadPixmap( "LightApp", QObject::tr( "ABOUT_SPLASH" ) ) );
00388     if ( splash->pixmap().isNull() ) {
00389       delete splash;
00390       splash = 0;
00391     }
00392     else {
00393       splash->setOption( "%A", QObject::tr( "APP_NAME" ) );
00394       splash->setOption( "%V", QObject::tr( "ABOUT_VERSION" ).arg( salomeVersion() ) );
00395       splash->setOption( "%L", QObject::tr( "ABOUT_LICENSE" ) );
00396       splash->setOption( "%C", QObject::tr( "ABOUT_COPYRIGHT" ) );
00397       splash->show();
00398       QApplication::instance()->processEvents();
00399     }
00400   }
00401 
00402   
00403   // Initialization
00404   int result = -1;
00405 
00406   CORBA::ORB_var orb;
00407   PortableServer::POA_var poa;
00408 
00409   SUIT_Session* aGUISession = 0;
00410   SALOME_NamingService* _NS = 0;
00411   GetInterfaceThread* guiThread = 0;
00412   Session_ServerLauncher* myServerLauncher = 0;
00413 
00414   try {
00415     // ...initialize Python (only once)
00416     int   _argc   = 1;
00417     char* _argv[] = {(char*)""};
00418     KERNEL_PYTHON::init_python( _argc,_argv );
00419     PyEval_RestoreThread( KERNEL_PYTHON::_gtstate );
00420     if ( !KERNEL_PYTHON::salome_shared_modules_module ) // import only once
00421       KERNEL_PYTHON::salome_shared_modules_module = PyImport_ImportModule( "salome_shared_modules" );
00422     if ( !KERNEL_PYTHON::salome_shared_modules_module ) {
00423       INFOS( "salome_shared_modules_module == NULL" );
00424       PyErr_Print();
00425     }
00426     PyEval_ReleaseThread( KERNEL_PYTHON::_gtstate );
00427 
00428     // ...create ORB, get RootPOA object, NamingService, etc.
00429     ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance();
00430     ASSERT( SINGLETON_<ORB_INIT>::IsAlreadyExisting() );
00431     int orbArgc = 1;
00432     orb = init( orbArgc, argv );
00433 
00434     CORBA::Object_var obj = orb->resolve_initial_references( "RootPOA" );
00435     poa = PortableServer::POA::_narrow( obj );
00436 
00437     PortableServer::POAManager_var pman = poa->the_POAManager();
00438     pman->activate() ;
00439     MESSAGE( "pman->activate()" );
00440 
00441     _NS = new SALOME_NamingService( orb );
00442 
00443     result = 0;
00444   }
00445   catch ( SALOME_Exception& e ) {
00446     INFOS( "run(): SALOME::SALOME_Exception is caught: "<<e.what() );
00447   }
00448   catch ( CORBA::SystemException& e ) {
00449     INFOS( "Caught CORBA::SystemException." );
00450   }
00451   catch ( CORBA::Exception& e ) {
00452     INFOS( "Caught CORBA::Exception." );
00453     CORBA::Any tmp;
00454     tmp<<= e;
00455     CORBA::TypeCode_var tc = tmp.type();
00456     const char *p = tc->name();
00457     INFOS ( "run(): CORBA exception of the kind : "<<p<< " is caught" );
00458   }
00459   catch ( std::exception& e ) {
00460     INFOS( "run(): An exception has been caught: " <<e.what() );
00461   }
00462   catch (...) {
00463     INFOS( "Caught unknown exception." );
00464   }
00465 
00466   QMutex _GUIMutex, _SessionMutex, _SplashMutex;
00467   QWaitCondition _ServerLaunch, _SessionStarted, _SplashStarted;
00468 
00469   // lock session mutex to ensure that GetInterface is not called
00470   // until all initialization is done
00471   _SessionMutex.lock();
00472 
00473   if ( !result ) {
00474     // Start embedded servers launcher (Registry, SALOMEDS, etc.)
00475     // ...lock mutex to block embedded servers launching thread until wait( mutex )
00476     _GUIMutex.lock();  
00477     // ...create launcher
00478     myServerLauncher = new Session_ServerLauncher( argc, argv, orb, poa, &_GUIMutex, &_ServerLaunch, &_SessionMutex, &_SessionStarted );
00479     // ...block this thread until launcher is ready
00480     _ServerLaunch.wait( &_GUIMutex );
00481     
00482     // Start servers check thread (splash)
00483     if ( splash ) {
00484       // ...lock mutex to block splash thread until wait( mutex )
00485       _SplashMutex.lock();
00486       // ...create servers checking thread
00487       Session_ServerCheck sc( &_SplashMutex, &_SplashStarted );
00488       // ... set initial progress
00489       splash->setProgress( 0, sc.totalSteps() );
00490       // start check loop 
00491       while ( true ) {
00492         int step    = sc.currentStep();
00493         int total   = sc.totalSteps();
00494         QString msg = sc.currentMessage();
00495         QString err = sc.error();
00496         if ( !err.isEmpty() ) {
00497           QtxSplash::setError( err );
00498           QApplication::instance()->processEvents();
00499           result = -1;
00500           break;
00501         }
00502         QtxSplash::setStatus( msg, step );
00503         QApplication::instance()->processEvents();
00504         if ( step >= total )
00505           break;
00506         // ...block this thread until servers checking is finished
00507         _SplashStarted.wait( &_SplashMutex );
00508       }
00509       // ...unlock mutex 'cause it is no more needed
00510       _SplashMutex.unlock();
00511     }
00512 
00513     // Finalize embedded servers launcher 
00514     // ...block this thread until launcher is finished
00515     _ServerLaunch.wait( &_GUIMutex );
00516     // ...unlock mutex 'cause it is no more needed
00517     _GUIMutex.unlock();
00518   }
00519 
00520   // Obtain Session interface reference
00521   CORBA::Object_var obj = _NS->Resolve( "/Kernel/Session" );
00522   SALOME::Session_var session = SALOME::Session::_narrow( obj ) ;
00523 
00524   bool shutdownAll = false;
00525   bool shutdownSession = false;
00526   if ( !result ) {
00527     // Launch GUI activator
00528     if ( isGUI ) {
00529       if ( splash )
00530         splash->setStatus( QApplication::translate( "", "Activating desktop..." ) );
00531       // ...create GUI launcher
00532       MESSAGE( "Session activated, Launch IAPP..." );
00533       guiThread = new GetInterfaceThread( session );
00534     }
00535 
00536     // GUI activation
00537     // Allow multiple activation/deactivation of GUI
00538     while ( true ) {
00539       MESSAGE( "waiting wakeAll()" );
00540       _SessionStarted.wait( &_SessionMutex ); // to be reseased by Launch server thread when ready:
00541       // atomic operation lock - unlock on mutex
00542       // unlock mutex: serverThread runs, calls _ServerLaunch->wakeAll()
00543       // this thread wakes up, and lock mutex
00544 
00545       _SessionMutex.unlock();
00546 
00547       // Session might be shutdowning here, check status
00548       SALOME::StatSession stat = session->GetStatSession();
00549       shutdownSession = stat.state == SALOME::shutdown;
00550       if ( shutdownSession ) {
00551        _SessionMutex.lock(); // lock mutex before leaving loop - it will be unlocked later
00552        break;
00553       }
00554 
00555       // SUIT_Session creation
00556       aGUISession = new SALOME_Session();
00557 
00558       // Load SalomeApp dynamic library
00559       MESSAGE( "creation SUIT_Application" );
00560       SUIT_Application* aGUIApp = aGUISession->startApplication( "SalomeApp", 0, 0 );
00561       if ( aGUIApp )
00562       {
00563         Style_Salome::initialize( aGUIApp->resourceMgr() );
00564         if ( aGUIApp->resourceMgr()->booleanValue( "Style", "use_salome_style", true ) )
00565           Style_Salome::apply();
00566 
00567         if ( !isFound( "noexcepthandler", argc, argv ) )
00568           _qappl.setHandler( aGUISession->handler() ); // after loading SalomeApp application
00569                                                        // aGUISession contains SalomeApp_ExceptionHandler
00570         // Run GUI loop
00571         MESSAGE( "run(): starting the main event loop" );
00572 
00573         if ( splash )
00574           splash->finish( aGUIApp->desktop() );
00575        
00576         result = _qappl.exec();
00577         
00578         splash = 0;
00579        
00580         if ( result == SUIT_Session::NORMAL ) {
00581          // desktop is explicitly closed by user from GUI
00582          // exit flags says if it's necessary to shutdown all servers
00583          // all session server only
00584           shutdownAll = aGUISession->exitFlags();
00585        }
00586        else {
00587          // desktop might be closed from:
00588          // - StopSesion() /temporarily/ or
00589          // - Shutdown() /permanently/
00590          stat = session->GetStatSession();
00591          shutdownSession = stat.state == SALOME::shutdown;
00592        }
00593        if ( shutdownAll || shutdownSession ) {
00594          _SessionMutex.lock(); // lock mutex before leaving loop - it will be unlocked later
00595          break;
00596        }
00597       }
00598 
00599       delete aGUISession;
00600       aGUISession = 0;
00601       
00602       // Prepare _GUIMutex for a new GUI activation
00603       _SessionMutex.lock();
00604     }
00605   }
00606 
00607   // unlock Session mutex
00608   _SessionMutex.unlock();
00609   
00610   if ( shutdownAll )
00611     shutdownServers( _NS );
00612 
00613   if ( myServerLauncher )
00614     myServerLauncher->KillAll(); // kill embedded servers
00615 
00616   // Unregister session server
00617   SALOME_Session_i* sessionServant = dynamic_cast<SALOME_Session_i*>( poa->reference_to_servant( session.in() ) );
00618   if ( sessionServant )
00619     sessionServant->NSunregister();
00620 
00621   delete aGUISession;
00622   delete guiThread;
00623   delete myServerLauncher;
00624   delete _NS;
00625 
00626   try  {
00627     orb->shutdown(0);
00628   }
00629   catch (...) {
00631     // VSR: silently skip exception:
00632     // CORBA.BAD_INV_ORDER.BAD_INV_ORDER_ORBHasShutdown 
00633     // exception is raised when orb->destroy() is called and
00634     // cpp continer is launched in the embedded mode
00636     // std::cerr << "Caught unexpected exception on shutdown : ignored !!" << std::endl;
00637     if ( shutdownAll )
00638       killOmniNames();
00639     abort(); //abort program to avoid deadlock in destructors or atexit when shutdown has been interrupted
00640   }
00641 
00642   PyGILState_Ensure();
00643   //Destroy orb from python (for chasing memory leaks)
00644   //PyRun_SimpleString("from omniORB import CORBA");
00645   //PyRun_SimpleString("orb=CORBA.ORB_init([''], CORBA.ORB_ID)");
00646   //PyRun_SimpleString("orb.destroy()");
00647   Py_Finalize();
00648 
00649   if ( shutdownAll )
00650     killOmniNames();
00651 
00652   MESSAGE( "Salome_Session_Server:endofserver" );
00653   return result;
00654 }