Salome HOME
Copyright update 2022
[modules/gui.git] / src / Session / Session_ServerCheck.cxx
index c7b67a7a3a053d6ed3d36fab1eaf48cd0aa6dda4..75a2feffb65f82e525de3cc11a17be992d373e43 100644 (file)
@@ -1,11 +1,14 @@
-// Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
+// Copyright (C) 2007-2022  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
 //
 // 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.
+// version 2.1 of the License, or (at your option) any later version.
 //
-// This library is distributed in the hope that it will be useful
+// 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.
 //
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
-// File:      Session_ServerCheck.cxx
-// Author:    Vadim SANDLER
 
+// File   : Session_ServerCheck.cxx
+// Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
+//
 #include "Session_ServerCheck.hxx"
-#include <QtxSplash.h>
 
 #include <SALOMEconfig.h>
 #include CORBA_CLIENT_HEADER(SALOME_Session)
 #include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog)
 #include CORBA_CLIENT_HEADER(SALOME_Component)
 
-#include "Utils_ORB_INIT.hxx"
 #include "Utils_SINGLETON.hxx"
 #include "SALOME_NamingService.hxx"
+#include "Basics_Utils.hxx"
 #include "utilities.h"
-#include "OpUtil.hxx"
+#include "Qtx.h"
 
+#include <QApplication> 
+#include <QWaitCondition>
+#include <QMutexLocker>
+#include <QStringList>
+
+//
 // Default settings
-const int __DEFAULT__ATTEMPTS__ = 300;      // number of checks attemtps
-                                            // can be overrided by CSF_RepeatServerRequest
-                                            // environment variable
-const int __DEFAULT__DELAY__    = 100000;   // delay between attempts (microseconds)
-                                            // can be overrided by CSF_DelayServerRequest
-                                            // environment variable
+//
+
+/*!
+  \brief Default number of attemtps to check SALOME server.
+
+  This value can be changed by setting the CSF_RepeatServerRequest
+  environment variable. For example, to set number of check attempts
+  for each server to 1000:
+  \code
+  setenv CSF_RepeatServerRequest 1000
+  \endcode
+*/
+const int __DEFAULT__ATTEMPTS__ = 300;
+
+/*!
+  \brief Default delay between attempts (in microseconds).
+
+  This value can be changed by setting the CSF_DelayServerRequest
+  environment variable. For example, to set delay between attemtps
+  to check SALOME servers to 100000 (0.1 second):
+  \code
+  setenv CSF_DelayServerRequest 100000
+  \endcode
+*/
+const int __DEFAULT__DELAY__ = 50000;
+
+// The exception being thrown out of a destructor,
+// that is not allowed by default in C++11.
+
+#if __cplusplus >= 201103L
+# define TYPE_NOEXCEPT noexcept(false)
+#else
+# define TYPE_NOEXCEPT
+#endif
+
+/*!
+  \classSession_ServerCheck::Locker
+  \brief Automatic locker/unlocker.
+  \internal
+*/
+
+template<class MY_CLS>
+class Session_ServerCheck<MY_CLS>::Locker
+{
+public:
+  /*!
+    \brief Constructor. Tries to aquire lock.
+  */
+  Locker( Session_ServerCheck* sc ) 
+    : myChecker( sc )
+  {
+    myChecker->myMutex->lock();
+    myChecker->myMutex->unlock();
+  }
+  /*!
+    \brief Destructor. Wakes the calling thread and goes sleeping.
+  */
+  ~Locker() TYPE_NOEXCEPT
+  {
+    myChecker->myWC->wakeAll();
+    myChecker->usleep( myChecker->myDelay );
+  }
+private:
+  Session_ServerCheck* myChecker;
+};
+
+/*!
+  \class Session_ServerCheck
+  \brief The class Session_ServerCheck is used to check SALOME
+  servers availability.
+  
+  It runs in the secondrary thread. The number of attemts to check
+  each SALOME server and the time delay between checks can be specified
+  via setting the CSF_RepeatServerRequest and CSF_DelayServerRequest
+  environment variables.
+
+  Total number of the check attempts can be retrieved via totalSteps()
+  method and current check step can be retrieved via currentStep() method.
+
+  The method currentMessage() can be used to get the information message
+  about what SALOME server is currently checked. If any error occured (some
+  server could not be found) the thread loop is stopped and error status
+  is set. Error message can be retrieved with the error() method.
+*/
 
 /*!
-  Constructor
+  \brief Constructor.
+  \param mutex a mutex used to serialize progress operations (splash)
+  \param wc a wait condition used in combination with \a mutex
 */
-Session_ServerCheck::Session_ServerCheck( QMutex* mutex, QWaitCondition* wc )
-  : QThread(),
-    myMutex( mutex ),
-    myWC( wc ),
-    myCheckCppContainer( false ),
-    myCheckPyContainer( false ),
-    myCheckSVContainer( false ),
-    myAttempts( __DEFAULT__ATTEMPTS__ ),
-    myDelay   ( __DEFAULT__DELAY__ )
+template<class MY_NS>
+Session_ServerCheck<MY_NS>::Session_ServerCheck( QMutex* mutex, QWaitCondition* wc )
+: QThread(),
+  myMutex( mutex ),
+  myWC( wc ),
+  myCheckCppContainer( false ),
+  myCheckPyContainer( false ),
+  myCheckSVContainer( false ),
+  myAttempts( __DEFAULT__ATTEMPTS__ ),
+  myDelay   ( __DEFAULT__DELAY__ ),
+  myCurrentStep( 0 )
 {
   char* cenv;
   // try to get nb of attempts from environment variable
@@ -64,14 +155,12 @@ Session_ServerCheck::Session_ServerCheck( QMutex* mutex, QWaitCondition* wc )
   if ( ( cenv = getenv( "CSF_DelayServerRequest" ) ) && atoi( cenv ) > 0 )
     myDelay = atoi( cenv );
 
-  // check if it is necessary to wait containers
-  for ( int i = 1; i < qApp->argc(); i++ ) {
-    if ( !strcmp( qApp->argv()[i], "CPP" ) )
-      myCheckCppContainer = true;
-    if ( !strcmp( qApp->argv()[i], "PY" ) )
-      myCheckPyContainer = true;
-    if ( !strcmp( qApp->argv()[i], "SUPERV" ) )
-      myCheckSVContainer = true;
+  // parse command line check if it is necessary to wait SALOME containers
+  QStringList args = QApplication::arguments();
+  for ( int i = 1; i < args.count(); i++ ) {
+    myCheckCppContainer = myCheckCppContainer || args[i] == "CPP";
+    myCheckPyContainer  = myCheckPyContainer  || args[i] == "PY";
+    myCheckSVContainer  = myCheckSVContainer  || args[i] == "SUPERV";
   }
   
   // start thread
@@ -79,70 +168,123 @@ Session_ServerCheck::Session_ServerCheck( QMutex* mutex, QWaitCondition* wc )
 }
 
 /*!
-  Destructor
+  \brief Destructor
 */
-Session_ServerCheck::~Session_ServerCheck()
+template<class MY_NS>
+Session_ServerCheck<MY_NS>::~Session_ServerCheck()
 {
+  terminate();
+  while( isRunning() );
 }
 
 /*!
-  Thread loop. Checnk SALOME servers and shows status message
-  in the splash screen.
+  \brief Get current information message.
+  \return current message
 */
-void Session_ServerCheck::run()
+template<class MY_NS>
+QString Session_ServerCheck<MY_NS>::currentMessage()
 {
-  // automatic locker
-  class Locker
-  {
-  public:
-    QMutex*         _m;
-    QWaitCondition* _wc;
-    Locker( QMutex* m, QWaitCondition* wc ) : _m( m ), _wc( wc )
-    {
-      _m->lock();
-      _m->unlock(); 
-    }
-    ~Locker()
-    {
-      _wc->wakeAll();
-    }
-  };
+  static QStringList messages;
+  if ( messages.isEmpty() ) {
+    messages << tr( "Waiting for naming service..." ); 
+    messages << tr( "Waiting for registry server..." );
+    messages << tr( "Waiting for study server..." );
+    messages << tr( "Waiting for module catalogue server..." );
+    messages << tr( "Waiting for session server..." );
+    messages << tr( "Waiting for C++ container..." );
+    messages << tr( "Waiting for Python container..." );
+    messages << tr( "Waiting for Supervision container..." );
+  }
+  QMutexLocker locker( &myDataMutex );
+  QString msg;
+  int idx = myCurrentStep / myAttempts;
+  if ( idx >= 0 && idx < messages.count() )
+    msg = messages[ idx ];
+  return msg;
+}
 
-  // lock mutex (ensure splash is shown)
-  Locker locker( myMutex, myWC );
+/*!
+  \brief Get error message.
+  \return error message or null string of there was no any error
+*/
+template<class MY_NS>
+QString Session_ServerCheck<MY_NS>::error()
+{
+  QMutexLocker locker( &myDataMutex );
+  return myError;
+}
 
-  // set initial splash status
-  QtxSplash* splash = QtxSplash::splash();
+/*!
+  \brief Get current step.
+  \return current step
+*/
+template<class MY_NS>
+int Session_ServerCheck<MY_NS>::currentStep()
+{
+  QMutexLocker locker( &myDataMutex );
+  return myCurrentStep;
+}
 
+/*!
+  \brief Get total number of check steps.
+  \return total number of steps
+*/
+template<class MY_NS>
+int Session_ServerCheck<MY_NS>::totalSteps()
+{
+  QMutexLocker locker( &myDataMutex );
   int cnt = 5;                       // base servers
   if ( myCheckCppContainer ) cnt++;  // + C++ container
   if ( myCheckPyContainer )  cnt++;  // + Python container
   if ( myCheckSVContainer )  cnt++;  // + supervision container
+  return cnt * myAttempts;
+}
+
+/*!
+  \brief Modify current step.
+  \param step new current step value
+*/
+template<class MY_NS>
+void Session_ServerCheck<MY_NS>::setStep( const int step )
+{
+  QMutexLocker locker( &myDataMutex );
+  myCurrentStep = step;
+}
 
-  splash->setProgress( 0, cnt * myAttempts );
-  QString initialInfo = splash->message();
-  QString info = initialInfo.isEmpty() ? "%1" : QString( "%1\n%2" ).arg( initialInfo );
+/*!
+  \brief Set error message.
+  \param msg error message
+*/
+template<class MY_NS>
+void Session_ServerCheck<MY_NS>::setError( const QString& msg )
+{
+  QMutexLocker locker( &myDataMutex );
+  myError = msg;
+}
 
+/*!
+  \brief Thread loop function. Performs SALOME servers check.
+*/
+template<class MY_NS>
+void Session_ServerCheck<MY_NS>::run()
+{
   // start check servers
-  int i;
   int current = 0;
-  bool bOk;
   QString error;
-  int    argc = qApp->argc();
-  char** argv = qApp->argv();
-
+  Qtx::CmdLineArgs args;
+  
   // 1. Check naming service
-  bOk = false;
-  for ( i = 0; i < myAttempts ; i++ ) {
-    QtxSplash::setStatus( info.arg( "Waiting for naming service..." ), current * myAttempts + i );
-    QThread::usleep( i == 0 ? 500000 : myDelay );
+  for ( int i = 0; i < myAttempts; i++ ) {
+    Locker locker( this );
+
+    setStep( current * myAttempts + i );
+
     try {
-      CORBA::ORB_var orb = CORBA::ORB_init( argc, argv );
-      CORBA::Object_var obj = orb->resolve_initial_references( "NameService" );
-      CosNaming::NamingContext_var _root_context = CosNaming::NamingContext::_narrow( obj );
-      if ( !CORBA::is_nil( _root_context ) ) {
-       bOk = true;
-       break;
+      bool forceOK = false;
+      CosNaming::NamingContext_var _root_context = MY_NS::checkTrueNamingServiceIfExpected(args.argc(), args.argv(),forceOK);
+      if ( forceOK ||  !CORBA::is_nil( _root_context ) ) {
+        setStep( ++current * myAttempts );
+        break;
       }
     }
     catch( CORBA::COMM_FAILURE& ) {
@@ -151,32 +293,30 @@ void Session_ServerCheck::run()
     catch( ... ) {
       MESSAGE( "Unknown Exception: unable to contact the naming service" );
     }
+
+    if ( i == myAttempts-1 ) {
+      setError( tr( "Unable to contact the naming service." ) + "\n" );
+      return;
+    }
   }
-  if ( !bOk ) {
-    QtxSplash::error( "Unable to contact the naming service.\n%1" );
-    return;
-  }
-  QtxSplash::setStatus( info.arg( "Waiting for naming service...OK" ), ++current * myAttempts );
-  QThread::usleep( 300000 );
-  
+
+  QString errfmt = "\n%1";
+
   // 2. Check registry server
-  bOk = false;
-  for ( i = 0; i < myAttempts ; i++ ) {
-    QtxSplash::setStatus( info.arg( "Waiting for registry server..." ), current * myAttempts + i );
-    QThread::usleep( i == 0 ? 500000 : myDelay );
+  for ( int i = 0; i < myAttempts ; i++ ) {
+    Locker locker( this );
+
+    setStep( current * myAttempts + i );
+
     try {
-      CORBA::ORB_var orb = CORBA::ORB_init( argc, argv );
-      SALOME_NamingService &NS = *SINGLETON_<SALOME_NamingService>::Instance();
-      ASSERT( SINGLETON_<SALOME_NamingService>::IsAlreadyExisting() );
-      NS.init_orb( orb );
-      CORBA::Object_var obj = NS.Resolve( "/Registry" );
+      CORBA::Object_var obj = MY_NS::forServerChecker("/Registry", args.argc(), args.argv());
       Registry::Components_var registry = Registry::Components::_narrow( obj );
       if ( !CORBA::is_nil( registry ) ) {
-       MESSAGE( "/Registry is found" );
-       registry->ping();
-       MESSAGE( "Registry was activated" );
-       bOk = true;
-       break;
+        MESSAGE( "/Registry is found" );
+        registry->ping();
+        MESSAGE( "Registry was activated" );
+        setStep( ++current * myAttempts );
+        break;
       }
     }
     catch ( ServiceUnreachable& ) {
@@ -199,32 +339,28 @@ void Session_ServerCheck::run()
       MESSAGE( "Caught unknown exception." );
       error = "Caught unknown exception.";
     }
+
+    if ( i == myAttempts-1 ) {
+      setError( tr( "Registry server is not found." ) + errfmt.arg( error ) );
+      return;
+    }
   }
-  if ( !bOk ) {
-    QtxSplash::error( QString( "Registry server is not found.\n%1" ).arg ( error ) );
-    return;
-  }
-  QtxSplash::setStatus( info.arg( "Waiting for registry server...OK" ), ++current * myAttempts );
-  QThread::usleep( 300000 );
 
   // 3. Check data server
-  bOk = false;
-  for ( i = 0; i < myAttempts ; i++ ) {
-    QtxSplash::setStatus( info.arg( "Waiting for study server..." ), current * myAttempts + i );
-    QThread::usleep( i == 0 ? 500000 : myDelay );
+  for ( int i = 0; i < myAttempts ; i++ ) {
+    Locker locker( this );
+
+    setStep( current * myAttempts + i );
+
     try {
-      CORBA::ORB_var orb = CORBA::ORB_init( argc, argv );
-      SALOME_NamingService &NS = *SINGLETON_<SALOME_NamingService>::Instance();
-      ASSERT( SINGLETON_<SALOME_NamingService>::IsAlreadyExisting() );
-      NS.init_orb( orb );
-      CORBA::Object_var obj = NS.Resolve( "/myStudyManager" );
-      SALOMEDS::StudyManager_var studyManager = SALOMEDS::StudyManager::_narrow( obj );
-      if ( !CORBA::is_nil( studyManager ) ) {
-       MESSAGE( "/myStudyManager is found" );
-       studyManager->ping();
-       MESSAGE( "StudyManager was activated" );
-       bOk = true;
-       break;
+      CORBA::Object_var obj = MY_NS::forServerChecker("/Study", args.argc(), args.argv());
+      SALOMEDS::Study_var study = SALOMEDS::Study::_narrow( obj );
+      if ( !CORBA::is_nil( study ) ) {
+        MESSAGE( "/Study is found" );
+        study->ping();
+        MESSAGE( "Study was activated" );
+        setStep( ++current * myAttempts );
+        break;
       }
     }
     catch ( ServiceUnreachable& ) {
@@ -247,32 +383,28 @@ void Session_ServerCheck::run()
       MESSAGE( "Caught unknown exception." );
       error = "Caught unknown exception.";
     }
-  }
-  if ( !bOk ) {
-    QtxSplash::error( QString( "Study server is not found.\n%1" ).arg ( error ) );
-    return;
-  }
-  QtxSplash::setStatus( info.arg( "Waiting for study server...OK" ), ++current * myAttempts );
-  QThread::usleep( 300000 );
 
+    if ( i == myAttempts-1 ) {
+      setError( tr( "Study server is not found." ) + errfmt.arg( error ) );
+      return;
+    }
+  }
+  
   // 4. Check module catalogue server
-  bOk = false;
-  for ( i = 0; i < myAttempts ; i++ ) {
-    QtxSplash::setStatus( info.arg( "Waiting for module catalogue server..." ), current * myAttempts + i );
-    QThread::usleep( i == 0 ? 500000 : myDelay );
+  for ( int i = 0; i < myAttempts ; i++ ) {
+    Locker locker( this );
+
+    setStep( current * myAttempts + i );
+
     try {
-      CORBA::ORB_var orb = CORBA::ORB_init( argc, argv );
-      SALOME_NamingService &NS = *SINGLETON_<SALOME_NamingService>::Instance();
-      ASSERT( SINGLETON_<SALOME_NamingService>::IsAlreadyExisting() );
-      NS.init_orb( orb );
-      CORBA::Object_var obj = NS.Resolve( "/Kernel/ModulCatalog" );
+      CORBA::Object_var obj = MY_NS::forServerChecker("/Kernel/ModulCatalog", args.argc(), args.argv());
       SALOME_ModuleCatalog::ModuleCatalog_var catalog = SALOME_ModuleCatalog::ModuleCatalog::_narrow( obj );
       if ( !CORBA::is_nil( catalog ) ){
-       MESSAGE( "/Kernel/ModulCatalog is found" );
-       catalog->ping();
-       MESSAGE( "ModuleCatalog was activated" );
-       bOk = true;
-       break;
+        MESSAGE( "/Kernel/ModulCatalog is found" );
+        catalog->ping();
+        MESSAGE( "ModuleCatalog was activated" );
+        setStep( ++current * myAttempts );
+        break;
       }
     }
     catch ( ServiceUnreachable& ) {
@@ -295,32 +427,28 @@ void Session_ServerCheck::run()
       MESSAGE( "Caught unknown exception." );
       error = "Caught unknown exception.";
     }
+
+    if ( i == myAttempts-1 ) {
+      setError( tr( "Module catalogue server is not found." ) + errfmt.arg( error ) );
+      return;
+    }
   }
-  if ( !bOk ) {
-    QtxSplash::error( QString( "Module catalogue server is not found.\n%1" ).arg ( error ) );
-    return;
-  }
-  QtxSplash::setStatus( info.arg( "Waiting for module catalogue server...OK" ), ++current * myAttempts );
-  QThread::usleep( 300000 );
 
   // 5. Check data server
-  bOk = false;
-  for ( i = 0; i < myAttempts ; i++ ) {
-    QtxSplash::setStatus( info.arg( "Waiting for session server..." ), current * myAttempts + i );
-    QThread::usleep( i == 0 ? 500000 : myDelay );
+  for ( int i = 0; i < myAttempts ; i++ ) {
+    Locker locker( this );
+
+    setStep( current * myAttempts + i );
+
     try {
-      CORBA::ORB_var orb = CORBA::ORB_init( argc, argv );
-      SALOME_NamingService &NS = *SINGLETON_<SALOME_NamingService>::Instance();
-      ASSERT( SINGLETON_<SALOME_NamingService>::IsAlreadyExisting() );
-      NS.init_orb( orb );
-      CORBA::Object_var obj = NS.Resolve( "/Kernel/Session" );
+      CORBA::Object_var obj = MY_NS::forServerChecker("/Kernel/Session", args.argc(), args.argv());
       SALOME::Session_var session = SALOME::Session::_narrow( obj );
       if ( !CORBA::is_nil( session ) ) {
-       MESSAGE( "/Kernel/Session is found" );
-       session->ping();
-       MESSAGE( "SALOME_Session was activated" );
-       bOk = true;
-       break;
+        MESSAGE( "/Kernel/Session is found" );
+        session->ping();
+        MESSAGE( "SALOME_Session was activated" );
+        setStep( ++current * myAttempts );
+        break;
       }
     }
     catch ( ServiceUnreachable& ) {
@@ -343,167 +471,156 @@ void Session_ServerCheck::run()
       MESSAGE( "Caught unknown exception." );
       error = "Caught unknown exception.";
     }
+
+    if ( i == myAttempts-1 ) {
+      setError( tr( "Session server is not found." ) + errfmt.arg( error ) );
+      return;
+    }
   }
-  if ( !bOk ) {
-    QtxSplash::error( QString( "Session server is not found.\n%1" ).arg ( error ) );
-    return;
-  }
-  QtxSplash::setStatus( info.arg( "Waiting for session server...OK" ), ++current * myAttempts );
-  QThread::usleep( 300000 );
 
   // 6. Check C++ container
   if ( myCheckCppContainer ) {
-    bOk = false;
-    for ( i = 0; i < myAttempts ; i++ ) {
-      QtxSplash::setStatus( info.arg( "Waiting for C++ container..." ), current * myAttempts + i );
-      QThread::usleep( i == 0 ? 500000 : myDelay );
+    for ( int i = 0; i < myAttempts ; i++ ) {
+      Locker locker( this );
+      
+      setStep( current * myAttempts + i );
+
       try {
-       CORBA::ORB_var orb = CORBA::ORB_init( argc, argv );
-       SALOME_NamingService &NS = *SINGLETON_<SALOME_NamingService>::Instance();
-       ASSERT( SINGLETON_<SALOME_NamingService>::IsAlreadyExisting() );
-       NS.init_orb( orb );
-       QString containerName = QString( "/Containers/%1/FactoryServer" ).arg( GetHostname().c_str() );
-       CORBA::Object_var obj = NS.Resolve( containerName.latin1() );
-       Engines::Container_var FScontainer = Engines::Container::_narrow( obj );
-       if ( !CORBA::is_nil( FScontainer ) ) {
-         MESSAGE( containerName.latin1() << " is found" );
-         FScontainer->ping();
-         MESSAGE( "FactoryServer container was activated" );
-         bOk = true;
-         break;
-       }
+        QString containerName = QString( "/Containers/%1/FactoryServer" ).arg( Kernel_Utils::GetHostname().c_str() );
+        CORBA::Object_var obj = MY_NS::forServerChecker(containerName.toLatin1(), args.argc(), args.argv());
+        Engines::Container_var FScontainer = Engines::Container::_narrow( obj );
+        if ( !CORBA::is_nil( FScontainer ) ) {
+          MESSAGE( containerName.toLatin1().constData() << " is found" );
+          FScontainer->ping();
+          MESSAGE( "FactoryServer container was activated" );
+          setStep( ++current * myAttempts );
+          break;
+        }
       }
       catch ( ServiceUnreachable& ) {
-       MESSAGE( "Caught exception: Naming Service unreachable." );
-       error = "Naming service unreachable";
+        MESSAGE( "Caught exception: Naming Service unreachable." );
+        error = "Naming service unreachable";
       }
       catch ( CORBA::COMM_FAILURE& ) {
-       MESSAGE( "Caught CORBA::SystemException CommFailure." );
-       error = "Caught CORBA::SystemException CommFailure.";
+        MESSAGE( "Caught CORBA::SystemException CommFailure." );
+        error = "Caught CORBA::SystemException CommFailure.";
       }
       catch ( CORBA::SystemException& ) {
-       MESSAGE( "Caught CORBA::SystemException." );
-       error = "Caught CORBA::SystemException.";
+        MESSAGE( "Caught CORBA::SystemException." );
+        error = "Caught CORBA::SystemException.";
       }
       catch ( CORBA::Exception& ) {
-       MESSAGE( "Caught CORBA::Exception." );
-       error = "Caught CORBA::Exception.";
+        MESSAGE( "Caught CORBA::Exception." );
+        error = "Caught CORBA::Exception.";
       }
       catch (...) {
-       MESSAGE( "Caught unknown exception." );
-       error = "Caught unknown exception.";
+        MESSAGE( "Caught unknown exception." );
+        error = "Caught unknown exception.";
+      }
+      
+      if ( i == myAttempts-1 ) {
+        setError( tr( "C++ container is not found." ) + errfmt.arg( error ) );
+        return;
       }
     }
-    if ( !bOk ) {
-      QtxSplash::error( QString( "C++ container is not found.\n%1" ).arg ( error ) );
-      return;
-    }
-    QtxSplash::setStatus( info.arg( "Waiting for C++ container...OK" ), ++current * myAttempts );
-    QThread::usleep( 300000 );
   }
 
   // 7. Check Python container
   if ( myCheckPyContainer ) {
-    bOk = false;
-    for ( i = 0; i < myAttempts ; i++ ) {
-      QtxSplash::setStatus( info.arg( "Waiting for Python container..." ), current * myAttempts + i );
-      QThread::usleep( i == 0 ? 500000 : myDelay );
+    for ( int i = 0; i < myAttempts ; i++ ) {
+      Locker locker( this );
+      
+      setStep( current * myAttempts + i );
+
       try {
-       CORBA::ORB_var orb = CORBA::ORB_init( argc, argv );
-       SALOME_NamingService &NS = *SINGLETON_<SALOME_NamingService>::Instance();
-       ASSERT( SINGLETON_<SALOME_NamingService>::IsAlreadyExisting() );
-       NS.init_orb( orb );
-       QString containerName = QString( "/Containers/%1/FactoryServerPy" ).arg( GetHostname().c_str() );
-       CORBA::Object_var obj = NS.Resolve( containerName.latin1() );
-       Engines::Container_var FSPcontainer = Engines::Container::_narrow( obj );
-       if ( !CORBA::is_nil( FSPcontainer ) ) {
-         MESSAGE( containerName.latin1() << " is found" );
-         FSPcontainer->ping();
-         MESSAGE("FactoryServerPy container was activated");
-         bOk = true;
-         break;
-       }
+        QString containerName = QString( "/Containers/%1/FactoryServerPy" ).arg( Kernel_Utils::GetHostname().c_str() );
+        CORBA::Object_var obj = MY_NS::forServerChecker(containerName.toLatin1(), args.argc(), args.argv());
+        Engines::Container_var FSPcontainer = Engines::Container::_narrow( obj );
+        if ( !CORBA::is_nil( FSPcontainer ) ) {
+          MESSAGE( containerName.toLatin1().constData() << " is found" );
+          FSPcontainer->ping();
+          MESSAGE("FactoryServerPy container was activated");
+          setStep( ++current * myAttempts );
+          break;
+        }
       }
       catch ( ServiceUnreachable& ) {
-       MESSAGE( "Caught exception: Naming Service unreachable." );
-       error = "Naming service unreachable";
+        MESSAGE( "Caught exception: Naming Service unreachable." );
+        error = "Naming service unreachable";
       }
       catch ( CORBA::COMM_FAILURE& ) {
-       MESSAGE( "Caught CORBA::SystemException CommFailure." );
-       error = "Caught CORBA::SystemException CommFailure.";
+        MESSAGE( "Caught CORBA::SystemException CommFailure." );
+        error = "Caught CORBA::SystemException CommFailure.";
       }
       catch ( CORBA::SystemException& ) {
-       MESSAGE( "Caught CORBA::SystemException." );
-       error = "Caught CORBA::SystemException.";
+        MESSAGE( "Caught CORBA::SystemException." );
+        error = "Caught CORBA::SystemException.";
       }
       catch ( CORBA::Exception& ) {
-       MESSAGE( "Caught CORBA::Exception." );
-       error = "Caught CORBA::Exception.";
+        MESSAGE( "Caught CORBA::Exception." );
+        error = "Caught CORBA::Exception.";
       }
       catch (...) {
-       MESSAGE( "Caught unknown exception." );
-       error = "Caught unknown exception.";
+        MESSAGE( "Caught unknown exception." );
+        error = "Caught unknown exception.";
+      }
+
+      if ( i == myAttempts-1 ) {
+        setError( tr( "Python container is not found." ) + errfmt.arg( error ) );
+        return;
       }
     }
-    if ( !bOk ) {
-      QtxSplash::error( QString( "Python container is not found.\n%1" ).arg ( error ) );
-      return;
-    }
-    QtxSplash::setStatus( info.arg( "Waiting for Python container...OK" ), ++current * myAttempts );
-    QThread::usleep( 300000 );
   }
 
   // 8. Check supervision container
   if ( myCheckSVContainer ) {
-    bOk = false;
-    for ( i = 0; i < myAttempts ; i++ ) {
-      QtxSplash::setStatus( info.arg( "Waiting for Supervision container..." ), current * myAttempts + i );
-      QThread::usleep( i == 0 ? 500000 : myDelay );
+    for ( int i = 0; i < myAttempts ; i++ ) {
+      Locker locker( this );
+      
+      setStep( current * myAttempts + i );
+
       try {
-       CORBA::ORB_var orb = CORBA::ORB_init( argc, argv );
-       SALOME_NamingService &NS = *SINGLETON_<SALOME_NamingService>::Instance();
-       ASSERT( SINGLETON_<SALOME_NamingService>::IsAlreadyExisting() );
-       NS.init_orb( orb );
-       QString containerName = QString( "/Containers/%1/SuperVisionContainer" ).arg( GetHostname().c_str() );
-       CORBA::Object_var obj = NS.Resolve( containerName.latin1() );
-       Engines::Container_var SVcontainer = Engines::Container::_narrow( obj );
-       if ( !CORBA::is_nil( SVcontainer ) ) {
-         MESSAGE( containerName.latin1() << " is found" );
-         SVcontainer->ping();
-         MESSAGE("SuperVisionContainer container was activated");
-         bOk = true;
-         break;
-       }
+        QString containerName = QString( "/Containers/%1/SuperVisionContainer" ).arg( Kernel_Utils::GetHostname().c_str() );
+        CORBA::Object_var obj = MY_NS::forServerChecker(containerName.toLatin1(), args.argc(), args.argv());
+        Engines::Container_var SVcontainer = Engines::Container::_narrow( obj );
+        if ( !CORBA::is_nil( SVcontainer ) ) {
+          MESSAGE( containerName.toLatin1().constData() << " is found" );
+          SVcontainer->ping();
+          MESSAGE("SuperVisionContainer container was activated");
+          setStep( ++current * myAttempts );
+          break;
+        }
       }
       catch ( ServiceUnreachable& ) {
-       MESSAGE( "Caught exception: Naming Service unreachable." );
-       error = "Naming service unreachable";
+        MESSAGE( "Caught exception: Naming Service unreachable." );
+        error = "Naming service unreachable";
       }
       catch ( CORBA::COMM_FAILURE& ) {
-       MESSAGE( "Caught CORBA::SystemException CommFailure." );
-       error = "Caught CORBA::SystemException CommFailure.";
+        MESSAGE( "Caught CORBA::SystemException CommFailure." );
+        error = "Caught CORBA::SystemException CommFailure.";
       }
       catch ( CORBA::SystemException& ) {
-       MESSAGE( "Caught CORBA::SystemException." );
-       error = "Caught CORBA::SystemException.";
+        MESSAGE( "Caught CORBA::SystemException." );
+        error = "Caught CORBA::SystemException.";
       }
       catch ( CORBA::Exception& ) {
-       MESSAGE( "Caught CORBA::Exception." );
-       error = "Caught CORBA::Exception.";
+        MESSAGE( "Caught CORBA::Exception." );
+        error = "Caught CORBA::Exception.";
       }
       catch (...) {
-       MESSAGE( "Caught unknown exception." );
-       error = "Caught unknown exception.";
+        MESSAGE( "Caught unknown exception." );
+        error = "Caught unknown exception.";
+      }
+    
+      if ( i == myAttempts-1 ) {
+        setError( tr( "Supervision container is not found." ) + errfmt.arg( error ) );
+        return;
       }
     }
-    if ( !bOk ) {
-      QtxSplash::error( QString( "Supervision container is not found.\n%1" ).arg ( error ) );
-      return;
-    }
-    QtxSplash::setStatus( info.arg( "Waiting for Supervision container...OK" ), ++current * myAttempts );
-    QThread::usleep( 300000 );
   }
-  // clear splash status
-  splash->setProgress( 0, 0 );
-  splash->setStatus( initialInfo );
 }
+
+#include "Session_NS_wrapper.hxx"
+
+template class Session_ServerCheck<OldStyleNS>;
+template class Session_ServerCheck<NewStyleNS>;