From fd1c17ec0e6a97fbefd5229b112a29bda430acc5 Mon Sep 17 00:00:00 2001 From: Anthony GEAY Date: Fri, 19 Feb 2021 22:25:42 +0100 Subject: [PATCH] WIP --- src/Session/SALOME_Session_Server.cxx | 2 +- src/Session/Session_NS_wrapper.cxx | 36 +++++++++++ src/Session/Session_NS_wrapper.hxx | 16 +++-- src/Session/Session_ServerCheck.cxx | 92 ++++++++++----------------- src/Session/Session_ServerCheck.hxx | 1 + 5 files changed, 83 insertions(+), 64 deletions(-) diff --git a/src/Session/SALOME_Session_Server.cxx b/src/Session/SALOME_Session_Server.cxx index 4b7d802d0..775e3034e 100644 --- a/src/Session/SALOME_Session_Server.cxx +++ b/src/Session/SALOME_Session_Server.cxx @@ -642,7 +642,7 @@ int AbstractGUIApp::main(int argc, char **argv) // ...lock mutex to block splash thread until wait( mutex ) _SplashMutex.lock(); // ...create servers checking thread - Session_ServerCheck sc(&_SplashMutex, &_SplashStarted); + Session_ServerCheck sc(&_SplashMutex, &_SplashStarted); // ... set initial progress splash->setProgress(0, sc.totalSteps()); // start check loop diff --git a/src/Session/Session_NS_wrapper.cxx b/src/Session/Session_NS_wrapper.cxx index 0c2f25bbe..6d6d05a24 100644 --- a/src/Session/Session_NS_wrapper.cxx +++ b/src/Session/Session_NS_wrapper.cxx @@ -196,6 +196,30 @@ void OldStyleNS::activateSALOMEDS(CORBA::ORB_var orb, PortableServer::POA_var po } } +#include "Utils_ORB_INIT.hxx" +#include "Utils_SINGLETON.hxx" + +CORBA::Object_var OldStyleNS::forServerChecker(const char *NSName, int argc, char **argv) +{ + ORB_INIT& init = *SINGLETON_::Instance(); + CORBA::ORB_var orb = init( argc, argv ); + SALOME_NamingService &NS = *SINGLETON_::Instance(); + ASSERT( SINGLETON_::IsAlreadyExisting() ); + NS.init_orb( orb ); + CORBA::Object_var obj = NS.Resolve( NSName ); + return obj; +} + +CosNaming::NamingContext_var OldStyleNS::checkTrueNamingServiceIfExpected(int argc, char **argv, bool& forceOK) +{ + forceOK = false;//tell checker : do as before + ORB_INIT& init = *SINGLETON_::Instance(); + CORBA::ORB_var orb = init( argc, argv ); + CORBA::Object_var obj = orb->resolve_initial_references( "NameService" ); + CosNaming::NamingContext_var _root_context = CosNaming::NamingContext::_narrow( obj ); + return _root_context; +} + Engines_Container_i *NewStyleNS::activateContainer(CORBA::ORB_var orb, PortableServer::POA_var poa, int argc, char **argv) { return KERNEL::getContainerSA(); @@ -216,3 +240,15 @@ void NewStyleNS::activateSALOMEDS(CORBA::ORB_var orb, PortableServer::POA_var po { ClientFactory::createStudyWithoutNS(orb,poa); } + +CORBA::Object_var NewStyleNS::forServerChecker(const char *NSName, int argc, char **argv) +{ + SALOME_Fake_NamingService ns; + return ns.Resolve(NSName); +} + +CosNaming::NamingContext_var NewStyleNS::checkTrueNamingServiceIfExpected(int argc, char **argv, bool& forceOK) +{ + forceOK = true;//tell checker : forget it's always OK + return CosNaming::NamingContext::_nil(); +} diff --git a/src/Session/Session_NS_wrapper.hxx b/src/Session/Session_NS_wrapper.hxx index a0b34e415..835814129 100644 --- a/src/Session/Session_NS_wrapper.hxx +++ b/src/Session/Session_NS_wrapper.hxx @@ -38,9 +38,11 @@ public: CORBA::Object_ptr Resolve(const char* Path) { return _NS.Resolve(Path); } RealNS *getNS() { return &_NS; } Engines_Container_i *activateContainer(CORBA::ORB_var orb, PortableServer::POA_var poa, int argc, char** argv); - void activateContainerManager(CORBA::ORB_var orb); - void activateSession(CORBA::ORB_var orb, PortableServer::POA_var poa, QMutex *GUIMutex, QWaitCondition *GUILauncher, int argc, char ** argv); - void activateSALOMEDS(CORBA::ORB_var orb, PortableServer::POA_var poa); + static void activateContainerManager(CORBA::ORB_var orb); + static void activateSession(CORBA::ORB_var orb, PortableServer::POA_var poa, QMutex *GUIMutex, QWaitCondition *GUILauncher, int argc, char ** argv); + static void activateSALOMEDS(CORBA::ORB_var orb, PortableServer::POA_var poa); + static CORBA::Object_var forServerChecker(const char *NSName, int argc, char **argv); + static CosNaming::NamingContext_var checkTrueNamingServiceIfExpected(int argc, char **argv, bool& forceOK); private: RealNS _NS; }; @@ -57,9 +59,11 @@ public: CORBA::Object_ptr Resolve(const char* Path) { return _NS.Resolve(Path); } RealNS *getNS() { return &_NS; } Engines_Container_i *activateContainer(CORBA::ORB_var orb, PortableServer::POA_var poa, int argc, char** argv); - void activateContainerManager(CORBA::ORB_var orb); - void activateSession(CORBA::ORB_var orb, PortableServer::POA_var poa, QMutex *GUIMutex, QWaitCondition *GUILauncher, int argc, char ** argv); - void activateSALOMEDS(CORBA::ORB_var orb, PortableServer::POA_var poa); + static void activateContainerManager(CORBA::ORB_var orb); + static void activateSession(CORBA::ORB_var orb, PortableServer::POA_var poa, QMutex *GUIMutex, QWaitCondition *GUILauncher, int argc, char ** argv); + static void activateSALOMEDS(CORBA::ORB_var orb, PortableServer::POA_var poa); + static CORBA::Object_var forServerChecker(const char *NSName, int argc, char **argv); + static CosNaming::NamingContext_var checkTrueNamingServiceIfExpected(int argc, char **argv, bool& forceOK); private: RealNS _NS; }; diff --git a/src/Session/Session_ServerCheck.cxx b/src/Session/Session_ServerCheck.cxx index 1a1e6a94b..f43a218c8 100644 --- a/src/Session/Session_ServerCheck.cxx +++ b/src/Session/Session_ServerCheck.cxx @@ -87,7 +87,8 @@ const int __DEFAULT__DELAY__ = 50000; \internal */ -class Session_ServerCheck::Locker +template +class Session_ServerCheck::Locker { public: /*! @@ -135,7 +136,8 @@ private: \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 ) +template +Session_ServerCheck::Session_ServerCheck( QMutex* mutex, QWaitCondition* wc ) : QThread(), myMutex( mutex ), myWC( wc ), @@ -169,7 +171,8 @@ Session_ServerCheck::Session_ServerCheck( QMutex* mutex, QWaitCondition* wc ) /*! \brief Destructor */ -Session_ServerCheck::~Session_ServerCheck() +template +Session_ServerCheck::~Session_ServerCheck() { terminate(); while( isRunning() ); @@ -179,7 +182,8 @@ Session_ServerCheck::~Session_ServerCheck() \brief Get current information message. \return current message */ -QString Session_ServerCheck::currentMessage() +template +QString Session_ServerCheck::currentMessage() { static QStringList messages; if ( messages.isEmpty() ) { @@ -204,7 +208,8 @@ QString Session_ServerCheck::currentMessage() \brief Get error message. \return error message or null string of there was no any error */ -QString Session_ServerCheck::error() +template +QString Session_ServerCheck::error() { QMutexLocker locker( &myDataMutex ); return myError; @@ -214,7 +219,8 @@ QString Session_ServerCheck::error() \brief Get current step. \return current step */ -int Session_ServerCheck::currentStep() +template +int Session_ServerCheck::currentStep() { QMutexLocker locker( &myDataMutex ); return myCurrentStep; @@ -224,7 +230,8 @@ int Session_ServerCheck::currentStep() \brief Get total number of check steps. \return total number of steps */ -int Session_ServerCheck::totalSteps() +template +int Session_ServerCheck::totalSteps() { QMutexLocker locker( &myDataMutex ); int cnt = 5; // base servers @@ -238,7 +245,8 @@ int Session_ServerCheck::totalSteps() \brief Modify current step. \param step new current step value */ -void Session_ServerCheck::setStep( const int step ) +template +void Session_ServerCheck::setStep( const int step ) { QMutexLocker locker( &myDataMutex ); myCurrentStep = step; @@ -248,7 +256,8 @@ void Session_ServerCheck::setStep( const int step ) \brief Set error message. \param msg error message */ -void Session_ServerCheck::setError( const QString& msg ) +template +void Session_ServerCheck::setError( const QString& msg ) { QMutexLocker locker( &myDataMutex ); myError = msg; @@ -257,7 +266,8 @@ void Session_ServerCheck::setError( const QString& msg ) /*! \brief Thread loop function. Performs SALOME servers check. */ -void Session_ServerCheck::run() +template +void Session_ServerCheck::run() { // start check servers int current = 0; @@ -271,11 +281,9 @@ void Session_ServerCheck::run() setStep( current * myAttempts + i ); try { - ORB_INIT& init = *SINGLETON_::Instance(); - CORBA::ORB_var orb = init( args.argc(), args.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 ) ) { + 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; } @@ -302,12 +310,7 @@ void Session_ServerCheck::run() setStep( current * myAttempts + i ); try { - ORB_INIT& init = *SINGLETON_::Instance(); - CORBA::ORB_var orb = init( args.argc(), args.argv() ); - SALOME_NamingService &NS = *SINGLETON_::Instance(); - ASSERT( SINGLETON_::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" ); @@ -351,12 +354,7 @@ void Session_ServerCheck::run() setStep( current * myAttempts + i ); try { - ORB_INIT& init = *SINGLETON_::Instance(); - CORBA::ORB_var orb = init( args.argc(), args.argv() ); - SALOME_NamingService &NS = *SINGLETON_::Instance(); - ASSERT( SINGLETON_::IsAlreadyExisting() ); - NS.init_orb( orb ); - CORBA::Object_var obj = NS.Resolve( "/Study" ); + 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" ); @@ -400,12 +398,7 @@ void Session_ServerCheck::run() setStep( current * myAttempts + i ); try { - ORB_INIT& init = *SINGLETON_::Instance(); - CORBA::ORB_var orb = init( args.argc(), args.argv() ); - SALOME_NamingService &NS = *SINGLETON_::Instance(); - ASSERT( SINGLETON_::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" ); @@ -449,12 +442,7 @@ void Session_ServerCheck::run() setStep( current * myAttempts + i ); try { - ORB_INIT& init = *SINGLETON_::Instance(); - CORBA::ORB_var orb = init( args.argc(), args.argv() ); - SALOME_NamingService &NS = *SINGLETON_::Instance(); - ASSERT( SINGLETON_::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" ); @@ -499,13 +487,8 @@ void Session_ServerCheck::run() setStep( current * myAttempts + i ); try { - ORB_INIT& init = *SINGLETON_::Instance(); - CORBA::ORB_var orb = init( args.argc(), args.argv() ); - SALOME_NamingService &NS = *SINGLETON_::Instance(); - ASSERT( SINGLETON_::IsAlreadyExisting() ); - NS.init_orb( orb ); QString containerName = QString( "/Containers/%1/FactoryServer" ).arg( Kernel_Utils::GetHostname().c_str() ); - CORBA::Object_var obj = NS.Resolve( containerName.toLatin1() ); + 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" ); @@ -551,13 +534,8 @@ void Session_ServerCheck::run() setStep( current * myAttempts + i ); try { - ORB_INIT& init = *SINGLETON_::Instance(); - CORBA::ORB_var orb = init( args.argc(), args.argv() ); - SALOME_NamingService &NS = *SINGLETON_::Instance(); - ASSERT( SINGLETON_::IsAlreadyExisting() ); - NS.init_orb( orb ); QString containerName = QString( "/Containers/%1/FactoryServerPy" ).arg( Kernel_Utils::GetHostname().c_str() ); - CORBA::Object_var obj = NS.Resolve( containerName.toLatin1() ); + 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" ); @@ -603,13 +581,8 @@ void Session_ServerCheck::run() setStep( current * myAttempts + i ); try { - ORB_INIT& init = *SINGLETON_::Instance(); - CORBA::ORB_var orb = init( args.argc(), args.argv() ); - SALOME_NamingService &NS = *SINGLETON_::Instance(); - ASSERT( SINGLETON_::IsAlreadyExisting() ); - NS.init_orb( orb ); QString containerName = QString( "/Containers/%1/SuperVisionContainer" ).arg( Kernel_Utils::GetHostname().c_str() ); - CORBA::Object_var obj = NS.Resolve( containerName.toLatin1() ); + 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" ); @@ -647,3 +620,8 @@ void Session_ServerCheck::run() } } } + +#include "Session_NS_wrapper.hxx" + +template class Session_ServerCheck; +template class Session_ServerCheck; diff --git a/src/Session/Session_ServerCheck.hxx b/src/Session/Session_ServerCheck.hxx index d6733f7d4..e6aedc60b 100644 --- a/src/Session/Session_ServerCheck.hxx +++ b/src/Session/Session_ServerCheck.hxx @@ -33,6 +33,7 @@ class QWaitCondition; +template class SESSION_EXPORT Session_ServerCheck : public QThread { class Locker; -- 2.39.2