Salome HOME
GUI evolutions for salome gui without neither NS nor other servers.
authorAnthony Geay <anthony.geay@edf.fr>
Thu, 18 Feb 2021 09:13:14 +0000 (10:13 +0100)
committerAnthony Geay <anthony.geay@edf.fr>
Fri, 26 Feb 2021 06:13:10 +0000 (07:13 +0100)
29 files changed:
CMakeLists.txt
SalomeGUIConfig.cmake.in
src/STD/STD_Application.cxx
src/SalomeApp/CMakeLists.txt
src/SalomeApp/SalomeApp_Application.cxx
src/SalomeApp/SalomeApp_Application.h
src/SalomeApp/SalomeApp_Application_Entry.cxx [new file with mode: 0644]
src/SalomeApp/SalomeApp_Application_SL.cxx [new file with mode: 0644]
src/SalomeApp/SalomeApp_Application_SL.h [new file with mode: 0644]
src/SalomeApp/SalomeApp_Application_SL_Entry.cxx [new file with mode: 0644]
src/SalomeApp/SalomeApp_Engine_i.cxx
src/SalomeApp/SalomeApp_Engine_i.h
src/Session/CMakeLists.txt
src/Session/SALOME_Session_Server.cxx
src/Session/SALOME_Session_Server_No_Server.cxx [new file with mode: 0644]
src/Session/SALOME_Session_Server_With_Server.cxx [new file with mode: 0644]
src/Session/Session_NS_wrapper.cxx [new file with mode: 0644]
src/Session/Session_NS_wrapper.hxx [new file with mode: 0644]
src/Session/Session_Promises.cxx [new file with mode: 0644]
src/Session/Session_Promises.hxx [new file with mode: 0644]
src/Session/Session_ServerCheck.cxx
src/Session/Session_ServerCheck.hxx
src/Session/Session_ServerLauncher.cxx
src/Session/Session_ServerLauncher.hxx
src/Session/Session_ServerThread.cxx
src/Session/Session_ServerThread.hxx
src/Session/Session_Session_i.cxx
src/Session/Session_Session_i.hxx
src/Session/salome2810.cxx [new file with mode: 0644]

index 9d401f948cd3db80f383795d99a865c6022d7137..8f67a2d97cd2f98fafe42ab2147343722b8aa5c8 100644 (file)
@@ -407,7 +407,7 @@ ENDIF(SALOME_USE_PYCONSOLE)
 # CORBA specific targets:
 IF(NOT SALOME_LIGHT_ONLY)
   LIST(APPEND _${PROJECT_NAME}_exposed_targets
-       SalomeIDLGUI SalomeSession SalomeApp SalomeGuiHelpers SalomeTreeData ToolsGUI)
+       SalomeIDLGUI SalomeSession SalomeApp SalomeAppSL SalomeAppImpl SalomeGuiHelpers SalomeTreeData ToolsGUI)
 ENDIF(NOT SALOME_LIGHT_ONLY)
 
 # Add all targets to the build-tree export set
index d24b44d3b00d1b2e1474e69cef9a7d90c6210a8d..925c10c243f82410d6dd3b873e63a2a9d1ed5707 100644 (file)
@@ -201,6 +201,8 @@ SET(GUI_QDS QDS)
 SET(GUI_qtx qtx)
 SET(GUI_QxScene QxScene)
 SET(GUI_SalomeApp SalomeApp)
+SET(GUI_SalomeAppSL SalomeAppSL)
+SET(GUI_SalomeAppImpl SalomeAppImpl)
 SET(GUI_SalomeIDLGUI SalomeIDLGUI)
 SET(GUI_SalomeObject SalomeObject)
 SET(GUI_SalomePrs SalomePrs)
index 4a391e3484dcdf2d274c7897b69d253477590b52..fab9459698bfd54b92d47dc554d7605960fc2e7e 100644 (file)
@@ -114,7 +114,7 @@ void STD_Application::closeApplication()
     study->closeDocument();
     emit appClosed();
     setActiveStudy( 0 );
-    delete study;
+    //delete study;
 
     afterCloseDoc();
   }
index 10ae94a8101b5aa2c2677218d61d196ffe10c570..ed06db29bd198eb54352f6d70ee59ade1a442a49 100644 (file)
@@ -124,7 +124,8 @@ ENDIF()
 # --- headers ---
 
 # header files / to be processed by moc
-SET(_moc_HEADERS   
+SET(_moc_HEADERS
+  SalomeApp_Application_SL.h
   SalomeApp_Application.h
   SalomeApp_CheckFileDlg.h
   SalomeApp_DataModel.h
@@ -184,6 +185,7 @@ QT_WRAP_MOC(_moc_SOURCES ${_moc_HEADERS})
 
 # sources / static
 SET(_other_SOURCES
+  SalomeApp_Application_SL.cxx
   SalomeApp_Application.cxx
   SalomeApp_CheckFileDlg.cxx
   SalomeApp_DataModel.cxx
@@ -226,14 +228,22 @@ SET(_py_SCRIPTS
 
 # --- rules ---
 
-ADD_LIBRARY(SalomeApp ${SalomeApp_SOURCES})
-TARGET_LINK_LIBRARIES(SalomeApp ${_link_LIBRARIES})
-INSTALL(TARGETS SalomeApp EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_LIBS})
+ADD_LIBRARY(SalomeAppImpl ${SalomeApp_SOURCES})
+TARGET_LINK_LIBRARIES(SalomeAppImpl ${_link_LIBRARIES})
+
+ADD_LIBRARY(SalomeApp SalomeApp_Application_Entry.cxx)
+TARGET_LINK_LIBRARIES(SalomeApp SalomeAppImpl)
+
+ADD_LIBRARY(SalomeAppSL SalomeApp_Application_SL_Entry.cxx)
+TARGET_LINK_LIBRARIES(SalomeAppSL SalomeAppImpl)
+
+INSTALL(TARGETS SalomeAppImpl SalomeApp SalomeAppSL EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_LIBS})
 
 INSTALL(FILES ${SalomeApp_HEADERS} DESTINATION ${SALOME_INSTALL_HEADERS})
 QT_INSTALL_TS_RESOURCES("${_ts_RESOURCES}" "${SALOME_GUI_INSTALL_RES_DATA}")
 
 INSTALL(FILES ${_other_RESOURCES} DESTINATION ${SALOME_GUI_INSTALL_RES_DATA})
+install(FILES ${_other_RESOURCES} RENAME SalomeAppSL.xml DESTINATION ${SALOME_GUI_INSTALL_RES_DATA})
 
 SALOME_INSTALL_SCRIPTS("${_py_SCRIPTS}"  ${SALOME_INSTALL_PYTHON})
 SALOME_INSTALL_SCRIPTS("${_bin_SCRIPTS}" ${SALOME_INSTALL_SCRIPT_PYTHON})
index bfb209efa370c4ea8660a88c7c3e3346e2f661ac..d5cc4fb4452aa4856d1726df763a1babf3726086 100644 (file)
 
 #include <SALOMEDS_Tool.hxx>
 
+std::unique_ptr<SALOME_NamingService_Abstract> SalomeApp_Application::_ns;
+
 /*!Internal class that updates object browser item properties */
 // temporary commented
 /*class SalomeApp_Updater : public OB_Updater
@@ -173,18 +175,13 @@ namespace
   };
 }
 
-/*!Create new instance of SalomeApp_Application.*/
-extern "C" SALOMEAPP_EXPORT SUIT_Application* createApplication()
-{
-  return new SalomeApp_Application();
-}
-
 /*!Constructor.*/
-SalomeApp_Application::SalomeApp_Application()
-  : LightApp_Application(),
-    myIsCloseFromExit( false ),
-    myToIgnoreMessages( false )
+SalomeApp_Application::SalomeApp_Application(SALOME_NamingService_Abstract *ns):myIsCloseFromExit( false ),myToIgnoreMessages( false )
 {
+  if(!ns)
+    _ns.reset(new SALOME_NamingService(orb()));
+  else
+    _ns.reset(ns);
 }
 
 /*!Destructor.
@@ -1368,10 +1365,9 @@ _PTR(Study) SalomeApp_Application::getStudy()
 }
 
 /*!Create and return SALOME_NamingService.*/
-SALOME_NamingServiceSalomeApp_Application::namingService()
+SALOME_NamingService_Abstract *SalomeApp_Application::namingService()
 {
-  static SALOME_NamingService _ns(orb());
-  return &_ns;
+  return _ns.get();
 }
 
 /*!Create and return SALOME_LifeCycleCORBA.*/
index 5f4da65f06bd9b21f1a77be96a8107dc6b64948d..a29b67c21df1bf1dcfacddd90e8757df438e677e 100644 (file)
@@ -44,6 +44,8 @@
 
 #include <QPointer>
 
+#include <memory>
+
 class LightApp_Preferences;
 class SalomeApp_Study;
 #ifndef DISABLE_PYCONSOLE
@@ -82,7 +84,7 @@ protected:
   enum { LoadStudyId = LightApp_Application::OpenStudyId + 1, NewAndScriptId };
 
 public:
-  SalomeApp_Application();
+  SalomeApp_Application(SALOME_NamingService_Abstract *ns = nullptr);
   virtual ~SalomeApp_Application();
 
   virtual void                        updateObjectBrowser( const bool = true );
@@ -97,7 +99,7 @@ public:
 
   static CORBA::ORB_var               orb();
   static _PTR(Study)                  getStudy();
-  static SALOME_NamingService*        namingService();
+  static SALOME_NamingService_Abstract* namingService();
   static SALOME_LifeCycleCORBA*       lcc();
 
   SUIT_ViewManager*                   newViewManager(const QString&);
@@ -210,6 +212,8 @@ signals:
                                                          bool theIsStudySaved );
   void                                notebookVarUpdated( QString theVarName );
   void                                objectDoubleClicked( SUIT_DataObject* );
+protected:
+  static std::unique_ptr<SALOME_NamingService_Abstract> _ns;
 };
 
 #ifdef WIN32
diff --git a/src/SalomeApp/SalomeApp_Application_Entry.cxx b/src/SalomeApp/SalomeApp_Application_Entry.cxx
new file mode 100644 (file)
index 0000000..4af758f
--- /dev/null
@@ -0,0 +1,26 @@
+// Copyright (C) 2021  CEA/DEN, EDF R&D
+//
+// 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, or (at your option) any later version.
+//
+// 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "SalomeApp_Application.h"
+
+/*!Create new instance of SalomeApp_Application.*/
+extern "C" SALOMEAPP_EXPORT SUIT_Application* createApplication()
+{
+  return new SalomeApp_Application;
+}
diff --git a/src/SalomeApp/SalomeApp_Application_SL.cxx b/src/SalomeApp/SalomeApp_Application_SL.cxx
new file mode 100644 (file)
index 0000000..def6831
--- /dev/null
@@ -0,0 +1,26 @@
+// Copyright (C) 2021  CEA/DEN, EDF R&D
+//
+// 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, or (at your option) any later version.
+//
+// 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "SalomeApp_Application_SL.h"
+
+#include "SALOME_Fake_NamingService.hxx"
+
+SalomeApp_Application_SL::SalomeApp_Application_SL():SalomeApp_Application( new SALOME_Fake_NamingService )
+{
+}
diff --git a/src/SalomeApp/SalomeApp_Application_SL.h b/src/SalomeApp/SalomeApp_Application_SL.h
new file mode 100644 (file)
index 0000000..9d9b735
--- /dev/null
@@ -0,0 +1,28 @@
+// Copyright (C) 2021  CEA/DEN, EDF R&D
+//
+// 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, or (at your option) any later version.
+//
+// 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#pragma once
+
+#include "SalomeApp_Application.h"
+
+class SALOMEAPP_EXPORT SalomeApp_Application_SL : public SalomeApp_Application
+{
+public:
+  SalomeApp_Application_SL();
+};
diff --git a/src/SalomeApp/SalomeApp_Application_SL_Entry.cxx b/src/SalomeApp/SalomeApp_Application_SL_Entry.cxx
new file mode 100644 (file)
index 0000000..9094003
--- /dev/null
@@ -0,0 +1,26 @@
+// Copyright (C) 2021  CEA/DEN, EDF R&D
+//
+// 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, or (at your option) any later version.
+//
+// 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "SalomeApp_Application_SL.h"
+
+/*!Create new instance of SalomeApp_Application.*/
+extern "C" SALOMEAPP_EXPORT SUIT_Application* createApplication()
+{
+  return new SalomeApp_Application_SL;
+}
index 4f5a82f0004e52a230a6ed45935e1cd96aeee314..cc3742d7ccb11d7fe2a403a2037e786fd9eb7fc9 100644 (file)
@@ -366,10 +366,9 @@ PortableServer::POA_var SalomeApp_Engine_i::poa()
 /*!
   \return 
 */
-SALOME_NamingService* SalomeApp_Engine_i::namingService()
+SALOME_NamingService_Abstract* SalomeApp_Engine_i::namingService()
 {
-  static SALOME_NamingService _ns(orb());
-  return &_ns;
+  return SalomeApp_Application::namingService();
 }
 
 /*!
index 2b4137a524f7f5fb1409b5d21fa9e504b898328b..9de78b81089af0010c83dbfdea7bdfccd326bceb 100644 (file)
@@ -38,7 +38,7 @@
 #include <SALOMEconfig.h>
 #include CORBA_SERVER_HEADER(SalomeApp_Engine)
 
-class SALOME_NamingService;
+class SALOME_NamingService_Abstract;
 
 class SALOMEAPP_EXPORT SalomeApp_Engine_i: public POA_SalomeApp::Engine,
                                           public Engines_Component_i
@@ -99,7 +99,7 @@ public:
 private:
   static CORBA::ORB_var              orb();
   static PortableServer::POA_var     poa();
-  static SALOME_NamingService*       namingService();
+  static SALOME_NamingService_Abstract*       namingService();
 private:
   MapOfFiles                         myListOfFiles;
   bool                               myKeepFiles;
index 50358adae3b6c43ff5dfdae0fa74d4bb3eb7a99e..8e525a27bc6be73a69d75c94222b74977b20e73c 100644 (file)
@@ -81,6 +81,8 @@ SET(SalomeSession_HEADERS
   Session_ServerLauncher.hxx
   Session_ServerThread.hxx
   Session_Session_i.hxx
+  Session_Promises.hxx
+  Session_NS_wrapper.hxx
 )
 
 # --- resources ---
@@ -98,6 +100,8 @@ SET(SalomeSession_SOURCES
   Session_ServerLauncher.cxx
   Session_ServerThread.cxx
   Session_Session_i.cxx
+  Session_Promises.cxx
+  Session_NS_wrapper.cxx
 )
 
 # --- rules ---
@@ -106,9 +110,17 @@ ADD_LIBRARY(SalomeSession ${SalomeSession_SOURCES})
 TARGET_LINK_LIBRARIES(SalomeSession ${_link_LIBRARIES})
 INSTALL(TARGETS SalomeSession EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_LIBS}) 
 
-ADD_EXECUTABLE(SALOME_Session_Server SALOME_Session_Server.cxx)
+ADD_EXECUTABLE(SALOME_Session_Server SALOME_Session_Server_With_Server.cxx)
 TARGET_LINK_LIBRARIES(SALOME_Session_Server ${_link_LIBRARIES} SalomeSession)
 INSTALL(TARGETS SALOME_Session_Server EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_BINS})
 
+ADD_EXECUTABLE(SALOME_Session_Server_No_Server SALOME_Session_Server_No_Server.cxx)
+TARGET_LINK_LIBRARIES(SALOME_Session_Server_No_Server ${_link_LIBRARIES} SalomeSession)
+INSTALL(TARGETS SALOME_Session_Server_No_Server EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_BINS})
+
+add_executable(salome2810 salome2810.cxx)
+target_link_libraries(salome2810 ${QT_LIBRARIES})
+install(TARGETS salome2810 DESTINATION ${SALOME_INSTALL_BINS})
+
 INSTALL(FILES ${SalomeSession_HEADERS} DESTINATION ${SALOME_INSTALL_HEADERS})
 QT_INSTALL_TS_RESOURCES("${_ts_RESOURCES}" "${SALOME_GUI_INSTALL_RES_DATA}")
index 0bf8344fd95fa9e9633920dfd8e160f921ff9781..13271628d807bf95be18b482e4fae41211482d19 100644 (file)
@@ -21,7 +21,7 @@
 //
 
 #include <Container_init_python.hxx> // this include must be the first one as it includes Python.h
-#include <Basics_Utils.hxx> 
+#include <Basics_Utils.hxx>
 #include <ConnectionManager_i.hxx>
 #include <OpUtil.hxx>
 #include <RegistryService.hxx>
@@ -37,6 +37,8 @@
 #include "Session_Session_i.hxx"
 #include "Session_ServerCheck.hxx"
 #include "Session_ServerLauncher.hxx"
+#include "Session_Promises.hxx"
+#include "Session_NS_wrapper.hxx"
 
 #include "GUI_version.h"
 #include "Qtx.h"
@@ -64,6 +66,7 @@
 #include <shellapi.h>
 #endif
 #include <time.h>
+#include <memory>
 
 #include <QApplication>
 #include <QDir>
@@ -93,7 +96,7 @@
 
 namespace
 {
-  std::string handleCorbaException( const CORBA::Exception& e )
+  std::string handleCorbaException(const CORBA::Exception &e)
   {
     std::string message;
     CORBA::Any tmp;
@@ -104,32 +107,32 @@ namespace
   }
 
   //! Custom handler to manage Qt messages
-  class MsgHandler: public QtxMsgHandlerCallback
+  class MsgHandler : public QtxMsgHandlerCallback
   {
   public:
     MsgHandler() {}
-    void qtMessage( QtMsgType type, const QMessageLogContext& /*context*/, const QString& message )
+    void qtMessage(QtMsgType type, const QMessageLogContext & /*context*/, const QString &message)
     {
       (void)message; // unused in debug mode
-      switch ( type )
+      switch (type)
       {
       case QtDebugMsg:
 #ifdef QT_DEBUG_MESSAGE
-        MESSAGE( "Debug: " << qPrintable( message ) );
+        MESSAGE("Debug: " << qPrintable(message));
 #endif
         break;
       case QtWarningMsg:
-        MESSAGE( "Warning: " << qPrintable( message ) );
+        MESSAGE("Warning: " << qPrintable(message));
         break;
       case QtCriticalMsg:
-        MESSAGE( "Critical: " << qPrintable( message ) );
+        MESSAGE("Critical: " << qPrintable(message));
         break;
       case QtFatalMsg:
-        MESSAGE( "Fatal: " << qPrintable( message ) );
+        MESSAGE("Fatal: " << qPrintable(message));
         break;
       case QtInfoMsg:
       default:
-        MESSAGE( "Information: " << qPrintable( message ) );
+        MESSAGE("Information: " << qPrintable(message));
         break;
       }
     }
@@ -146,11 +149,11 @@ namespace
   class ResourceMgr : public SUIT_ResourceMgr
   {
   public:
-    ResourceMgr( const QString& appName = "SalomeApp" ) : SUIT_ResourceMgr( appName, "%1Config" )
+    ResourceMgr(const QString &appName = "SalomeApp") : SUIT_ResourceMgr(appName, "%1Config")
     {
       customize(); // activate customization
-      setCurrentFormat( "xml" );
-      setOption( "translators", QString( "%P_msg_%L.qm|%P_icons.qm|%P_images.qm" ) );
+      setCurrentFormat("xml");
+      setOption("translators", QString("%P_msg_%L.qm|%P_icons.qm|%P_images.qm"));
     }
 
     QString customName() const { return myCustomAppName; }
@@ -162,33 +165,35 @@ namespace
       // Try to retrieve actual application name and version from translation files.
       // We create temporary resource manager and load LightApp and SalomeApp translations.
       // This procedure is supposed to be done only once, at first call.
-      if ( myCustomAppName.isNull() ) {
-        SUIT_ResourceMgr mgr( "SalomeApp", "%1Config" );
-        mgr.setCurrentFormat( "xml" );
-        mgr.setWorkingMode( IgnoreUserValues ); // prevent reading data from user's file
-        mgr.loadLanguage( "LightApp",  "en" );
-        mgr.loadLanguage( "SalomeApp", "en" );
+      if (myCustomAppName.isNull())
+      {
+        SUIT_ResourceMgr mgr("SalomeApp", "%1Config");
+        mgr.setCurrentFormat("xml");
+        mgr.setWorkingMode(IgnoreUserValues); // prevent reading data from user's file
+        mgr.loadLanguage("LightApp", "en");
+        mgr.loadLanguage("SalomeApp", "en");
 
         // actual application name can be customized via APP_NAME resource key
-        myCustomAppName = QObject::tr( "APP_NAME" ).trimmed();
-        if ( myCustomAppName == "APP_NAME" || myCustomAppName.toLower() == "salome" ) 
+        myCustomAppName = QObject::tr("APP_NAME").trimmed();
+        if (myCustomAppName == "APP_NAME" || myCustomAppName.toLower() == "salome")
           myCustomAppName = "SalomeApp"; // fallback name
 
         // actual application name can be customized via APP_VERSION resource key
-        myCustomAppVersion = QObject::tr( "APP_VERSION" ).trimmed();
-        if ( myCustomAppVersion == "APP_VERSION" )
+        myCustomAppVersion = QObject::tr("APP_VERSION").trimmed();
+        if (myCustomAppVersion == "APP_VERSION")
           myCustomAppVersion = myCustomAppName == "SalomeApp" ? salomeVersion() : ""; // fallback version
       }
     }
 
   protected:
-    QString userFileName( const QString& /*appName*/, const bool forLoad ) const
+    QString userFileName(const QString & /*appName*/, const bool forLoad) const
     {
-      if ( version().isEmpty() ) return ""; 
-      return SUIT_ResourceMgr::userFileName( myCustomAppName, forLoad );
+      if (version().isEmpty())
+        return "";
+      return SUIT_ResourceMgr::userFileName(myCustomAppName, forLoad);
     }
 
-    virtual long userFileId( const QString& _fname ) const
+    virtual long userFileId(const QString &_fname) const
     {
       //////////////////////////////////////////////////////////////////////////////////////////////
       // In SALOME and SALOME-based applications the user preferences file is named as
@@ -205,7 +210,7 @@ namespace
       // directory. For backward compatibility, when user preferences from nearest
       // version of application is searched, user home directory is also looked through,
       // with lower priority.
-      // 
+      //
       // Since version 6.6.0 of SALOME, user file name on Linux is no more prefixed by dot
       // symbol since it is stored in the hidden ~/.config/salome directory. However, dot-prefixed
       // files are also taken into account (with lower priority) for backward compatibility.
@@ -228,13 +233,14 @@ namespace
       //////////////////////////////////////////////////////////////////////////////////////////////
 
       long id = -1;
-      if ( !myCustomAppName.isEmpty() ) {
+      if (!myCustomAppName.isEmpty())
+      {
 #ifdef WIN32
         // On Windows, user file name is something like SalomeApp.xml.6.5.0 where
         // - SalomeApp is an application name (can be customized)
         // - xml is a file format (xml or ini)
         // - 6.5.0 is an application version, can include alfa/beta/rc marks, e.g. 6.5.0a3, 6.5.0rc1
-        QRegExp exp( QString( "%1\\.%2\\.([a-zA-Z0-9.]+)" ).arg( myCustomAppName ).arg( currentFormat() ) );
+        QRegExp exp(QString("%1\\.%2\\.([a-zA-Z0-9.]+)").arg(myCustomAppName).arg(currentFormat()));
 #else
         // On Linux, user file name is something like SalomeApprc.6.5.0 where
         // - SalomeApp is an application name (can be customized)
@@ -243,12 +249,14 @@ namespace
         // VSR 24/09/2012: issue 0021781: since version 6.6.0 user filename is not prepended with "."
         // when it is stored in the ~/.config/<appname> directory;
         // for backward compatibility we also check files prepended with "." with lower priority
-        QRegExp exp( QString( "\\.?%1rc\\.([a-zA-Z0-9.]+)" ).arg( myCustomAppName ) );
+        QRegExp exp(QString("\\.?%1rc\\.([a-zA-Z0-9.]+)").arg(myCustomAppName));
 #endif
-        QString fname = QFileInfo( _fname ).fileName();
-        if ( exp.exactMatch( fname ) ) {
-          long fid = Qtx::versionToId( exp.cap( 1 ) );
-          if ( fid > 0 ) id = fid;
+        QString fname = QFileInfo(_fname).fileName();
+        if (exp.exactMatch(fname))
+        {
+          long fid = Qtx::versionToId(exp.cap(1));
+          if (fid > 0)
+            id = fid;
         }
       }
       return id;
@@ -265,9 +273,9 @@ namespace
   class Session : public SUIT_Session
   {
   public:
-    virtual SUIT_ResourceMgr* createResourceMgr( const QString& appName ) const
+    virtual SUIT_ResourceMgr *createResourceMgr(const QString &appName) const
     {
-      return new ResourceMgr( appName );
+      return new ResourceMgr(appName);
     }
   };
 
@@ -276,40 +284,46 @@ namespace
   class Application : public QApplication
   {
   public:
-    Application( int& argc, char** argv )
-      : QApplication( argc, argv ), 
-        myHandler ( 0 )
+    Application(int &argc, char **argv)
+        : QApplication(argc, argv),
+          myHandler(0)
     {
-      myDebug = !Qtx::getenv( "SALOME_DEBUG_EXCEPTIONS" ).isEmpty();
+      myDebug = !Qtx::getenv("SALOME_DEBUG_EXCEPTIONS").isEmpty();
     }
 
-    virtual bool notify( QObject* receiver, QEvent* e )
+    virtual bool notify(QObject *receiver, QEvent *e)
     {
-      if ( myDebug || !myHandler ) {
-        return QApplication::notify( receiver, e );
+      if (myDebug || !myHandler)
+      {
+        return QApplication::notify(receiver, e);
       }
-      else {
-        try {
-          return myHandler->handle( receiver, e );
+      else
+      {
+        try
+        {
+          return myHandler->handle(receiver, e);
         }
-        catch ( std::exception& e ) {
+        catch (std::exception &e)
+        {
           std::cerr << "notify(): Caught exception : " << e.what() << std::endl;
         }
-        catch ( CORBA::Exception& e ) {
-          std::cerr << "notify(): Caught CORBA exception : " << handleCorbaException( e ) << std::endl;
+        catch (CORBA::Exception &e)
+        {
+          std::cerr << "notify(): Caught CORBA exception : " << handleCorbaException(e) << std::endl;
         }
-        catch (...) {
+        catch (...)
+        {
           std::cerr << "notify(): Caught unknown exception : there's probably a bug in SALOME platform" << std::endl;
         }
-        return false;  // return false when exception is caught
+        return false; // return false when exception is caught
       }
     }
 
-    SUIT_ExceptionHandlerhandler() const { return myHandler; }
-    void setHandler( SUIT_ExceptionHandler* h ) { myHandler = h; }
+    SUIT_ExceptionHandler *handler() const { return myHandler; }
+    void setHandler(SUIT_ExceptionHandler *h) { myHandler = h; }
 
   private:
-    SUIT_ExceptionHandlermyHandler;
+    SUIT_ExceptionHandler *myHandler;
     bool myDebug;
   };
 
@@ -318,7 +332,7 @@ namespace
   class GetInterfaceThread : public QThread
   {
   public:
-    GetInterfaceThread( SALOME::Session_var s ) : session ( s )
+    GetInterfaceThread(SALOME::Session_var s) : session(s)
     {
       start();
     }
@@ -326,7 +340,7 @@ namespace
   protected:
     virtual void run()
     {
-      if ( !CORBA::is_nil( session ) )
+      if (!CORBA::is_nil(session))
         session->GetInterface();
       else
         std::cerr << "FATAL ERROR: SALOME::Session object is nil! Cannot display GUI" << std::endl;
@@ -340,111 +354,181 @@ namespace
   //  Option that results to \c true is specified via \a trueOption parameter.
   //  Option that results to \c false is specified via \a falseOption parameter (empty for default).
   //  Default value for the result (returned if both \a trueOption \a falseOption are not given) is specified via \c defValue parameter.
-  bool boolCmdOption( const QString trueOption, const QString falseOption = QString(), bool defValue = false )
+  bool boolCmdOption(const QString trueOption, const QString falseOption = QString(), bool defValue = false)
   {
     bool value = defValue;
 
     QStringList args = QApplication::arguments();
-    foreach ( QString arg, args )
+    foreach (QString arg, args)
     {
-      if ( arg == trueOption )
+      if (arg == trueOption)
         value = true;
-      else if ( arg == falseOption )
+      else if (arg == falseOption)
         value = false;
     }
     return value;
   }
 
-  // Kill omniNames process
-  void killOmniNames()
+  // Shutdown standalone servers
+  void shutdownServers(SALOME_NamingService *theNS, bool remoteLauncher)
   {
-    SALOME_LifeCycleCORBA::killOmniNames();
+    SALOME_LifeCycleCORBA lcc(theNS);
+    lcc.shutdownServers(!remoteLauncher);
   }
+} // end of anonymous namespace
 
-  // Shutdown standalone servers
-  void shutdownServers( SALOME_NamingService* theNS, bool remoteLauncher )
+template<class GUI_APP_STYLE>
+int AbstractGUIAppMain(int argc, char **argv);
+
+class GUIAppOldStyle
+{
+public:
+  using NamingServiceImplementation = OldStyleNS;
+  void connectToNSIfNeeded(CORBA::ORB_ptr orb) { _NS.reset(new SALOME_NamingService(orb)); }
+  void shutdownCORBAStufIfNeeded(bool shutdownAll, CORBA::ORB_ptr orb);
+  void killOtherServersIfNeeded() { SALOME_LifeCycleCORBA::killOmniNames(); }
+  SALOME::Session_var getSession();
+  void shutdownRemoteServersIfNeeded(bool remoteLauncher);
+private:
+  std::unique_ptr<SALOME_NamingService> _NS;
+};
+
+class GUIAppNewStyle
+{
+public:
+  using NamingServiceImplementation = NewStyleNS;
+  void connectToNSIfNeeded(CORBA::ORB_ptr orb) { /*! nothing */ }
+  void shutdownCORBAStufIfNeeded(bool shutdownAll, CORBA::ORB_ptr orb) { /*! nothing */ }
+  void killOtherServersIfNeeded() { /*! nothing */ }
+  SALOME::Session_var getSession();
+  void shutdownRemoteServersIfNeeded(bool remoteLauncher) { /*! nothing */ }
+};
+
+void GUIAppOldStyle::shutdownCORBAStufIfNeeded(bool shutdownAll, CORBA::ORB_ptr orb)
+{
+  try
   {
-    SALOME_LifeCycleCORBA lcc( theNS );
-    lcc.shutdownServers( !remoteLauncher );
+    orb->shutdown(0);
   }
-} // end of anonymous namespace
+  catch (...)
+  {
+    //////////////////////////////////////////////////////////////
+    // VSR: silently skip exception:
+    // CORBA.BAD_INV_ORDER.BAD_INV_ORDER_ORBHasShutdown
+    // exception is raised when orb->destroy() is called and
+    // cpp continer is launched in the embedded mode
+    //////////////////////////////////////////////////////////////
+    if (shutdownAll)
+      SALOME_LifeCycleCORBA::killOmniNames();
+    abort(); //abort program to avoid deadlock in destructors or atexit when shutdown has been interrupted
+  }
+  // Destroy ORB
+  sleep(2);
+  ORB_INIT *init = SINGLETON_<ORB_INIT>::Instance();
+  if (init)
+    init->explicit_destroy();
+}
+
+SALOME::Session_var GUIAppOldStyle::getSession()
+{
+  CORBA::Object_var obj = _NS->Resolve("/Kernel/Session");
+  SALOME::Session_var session = SALOME::Session::_narrow(obj);
+  return session;
+}
+void GUIAppOldStyle::shutdownRemoteServersIfNeeded(bool remoteLauncher)
+{
+  shutdownServers(_NS.get(), remoteLauncher);
+}
+
+SALOME::Session_var GUIAppNewStyle::getSession()
+{
+  SALOME::Session_var session = GetSessionRefSingleton()->get_future().get();
+  return session;
+}
 
 // ---------------------------- MAIN -----------------------
-int main( int argc, char **argv )
+template<class GUI_APP_STYLE>
+int AbstractGUIAppMain(int argc, char **argv)
 {
+  using NamingServiceImplementation = typename GUI_APP_STYLE::NamingServiceImplementation;
+  GUI_APP_STYLE self;
   // Set-up application settings configuration (as for QSettings)
   // Note: these are default settings which can be customized (see below)
-  QApplication::setOrganizationName( "salome" );
-  QApplication::setApplicationName( "salome" );
-  QApplication::setApplicationVersion( salomeVersion() );
+  QApplication::setOrganizationName("salome");
+  QApplication::setApplicationName("salome");
+  QApplication::setApplicationVersion(salomeVersion());
 
   // Install Qt debug messages handler
   MsgHandler msgHandler;
-  qInstallMessageHandler( QtxMsgHandler );
+  qInstallMessageHandler(QtxMsgHandler);
 
   // Add <qtdir>/plugins dir to the pluins search path for image plugins
-  QString qtdir = Qtx::qtDir( "plugins" );
-  if ( !qtdir.isEmpty() )
-    QApplication::addLibraryPath( qtdir );
+  QString qtdir = Qtx::qtDir("plugins");
+  if (!qtdir.isEmpty())
+    QApplication::addLibraryPath(qtdir);
 
   // Add application library path (to search style plugin etc...)
-  QString path = SUIT_Tools::addSlash( Qtx::getenv( "GUI_ROOT_DIR" ) ) + "bin/salome";
-  QApplication::addLibraryPath( QDir::toNativeSeparators( path ) );
+  QString path = SUIT_Tools::addSlash(Qtx::getenv("GUI_ROOT_DIR")) + "bin/salome";
+  QApplication::addLibraryPath(QDir::toNativeSeparators(path));
 
-  // QSurfaceFormat should be set before creation of QApplication,  
+  // QSurfaceFormat should be set before creation of QApplication,
   // so to avoid conflicts beetween SALOME and ParaView QSurfaceFormats we should merge theirs formats
   // (see void Qtx::initDefaultSurfaceFormat()) and set the resultant format here.
-  Qtx::initDefaultSurfaceFormat(); 
+  Qtx::initDefaultSurfaceFormat();
 
   // Create Qt application instance: this should be done as early as possible!
   // Note: QApplication forces setting locale LC_ALL to system one: setlocale(LC_ALL, "").
-  Application app( argc, argv );
+  Application app(argc, argv);
 
   // Initialize Python (only once)
   // Note: Python forces setting locale LC_CTYPE to system one: setlocale(LC_CTYPE, "").
-  char* py_argv[] = {(char*)""};
-  KERNEL_PYTHON::init_python( 1, py_argv );
+  char *py_argv[] = {(char *)""};
+  KERNEL_PYTHON::init_python(1, py_argv);
 
   // Create auxiliary resource manager to access application settings
   ResourceMgr resMgr;
-  resMgr.setWorkingMode( ResourceMgr::IgnoreUserValues );
-  resMgr.loadLanguage( "LightApp", "en" );
-  resMgr.loadLanguage( "SalomeApp", "en" );
-  resMgr.loadLanguage( "Session" );
+  resMgr.setWorkingMode(ResourceMgr::IgnoreUserValues);
+  resMgr.loadLanguage("LightApp", "en");
+  resMgr.loadLanguage("SalomeApp", "en");
+  resMgr.loadLanguage("Session");
 
   // Set-up application settings configuration possible customized via resources
-  if ( resMgr.customName() != "SalomeApp" ) {
-    QApplication::setApplicationName( resMgr.customName() );
-    QApplication::setApplicationVersion( resMgr.version() );
+  if (resMgr.customName() != "SalomeApp")
+  {
+    QApplication::setApplicationName(resMgr.customName());
+    QApplication::setApplicationVersion(resMgr.version());
   }
 
   // Force default "C" locale if requested via user's preferences
   // Note: this does not change whole application locale (changed via setlocale() function),
   // but only affects GUI behavior
-  resMgr.setWorkingMode( ResourceMgr::AllowUserValues ); // we must take into account user preferences
-  if ( resMgr.booleanValue( "language", "locale", true ) )
-    QLocale::setDefault( QLocale::c() );
-  resMgr.setWorkingMode( ResourceMgr::IgnoreUserValues );
+  resMgr.setWorkingMode(ResourceMgr::AllowUserValues); // we must take into account user preferences
+  if (resMgr.booleanValue("language", "locale", true))
+    QLocale::setDefault(QLocale::c());
+  resMgr.setWorkingMode(ResourceMgr::IgnoreUserValues);
 
-  bool isGUI    = boolCmdOption( "--show-desktop", "--hide-desktop", true ); // true by default
-  bool isSplash = boolCmdOption( "--show-splash", "--hide-splash", true ); // true by default
+  bool isGUI = boolCmdOption("--show-desktop", "--hide-desktop", true);  // true by default
+  bool isSplash = boolCmdOption("--show-splash", "--hide-splash", true); // true by default
 
   // Show splash screen (only if both the "GUI" and "SPLASH" options are true)
-  QtxSplash* splash = 0;
-  if ( isGUI && isSplash ) {
-    splash = QtxSplash::splash( QPixmap() );
-    splash->readSettings( &resMgr );
-    if ( splash->pixmap().isNull() )
-      splash->setPixmap( resMgr.loadPixmap( "LightApp", QObject::tr( "ABOUT_SPLASH" ) ) );
-    if ( splash->pixmap().isNull() ) {
+  QtxSplash *splash = 0;
+  if (isGUI && isSplash)
+  {
+    splash = QtxSplash::splash(QPixmap());
+    splash->readSettings(&resMgr);
+    if (splash->pixmap().isNull())
+      splash->setPixmap(resMgr.loadPixmap("LightApp", QObject::tr("ABOUT_SPLASH")));
+    if (splash->pixmap().isNull())
+    {
       delete splash;
       splash = 0;
     }
-    else {
-      splash->setOption( "%A", QObject::tr( "APP_NAME" ) );
-      splash->setOption( "%V", QObject::tr( "ABOUT_VERSION" ).arg( resMgr.version() ) );
-      splash->setOption( "%L", QObject::tr( "ABOUT_LICENSE" ) );
-      splash->setOption( "%C", QObject::tr( "ABOUT_COPYRIGHT" ) );
+    else
+    {
+      splash->setOption("%A", QObject::tr("APP_NAME"));
+      splash->setOption("%V", QObject::tr("ABOUT_VERSION").arg(resMgr.version()));
+      splash->setOption("%L", QObject::tr("ABOUT_LICENSE"));
+      splash->setOption("%C", QObject::tr("ABOUT_COPYRIGHT"));
       splash->show();
       QApplication::instance()->processEvents();
     }
@@ -456,53 +540,59 @@ int main( int argc, char **argv )
   CORBA::ORB_var orb;
   PortableServer::POA_var poa;
 
-  SUIT_Session* aGUISession = 0;
-  SALOME_NamingService* _NS = 0;
-  GetInterfaceThread* guiThread = 0;
-  Session_ServerLauncher* myServerLauncher = 0;
+  SUIT_Session *aGUISession = 0;
+  GetInterfaceThread *guiThread = 0;
+  Session_ServerLauncher<NamingServiceImplementation> *myServerLauncher = nullptr;
 
 #if defined(WIN32) && defined(UNICODE)
-  char** new_argv = NULL;
+  char **new_argv = NULL;
 #endif
 
   bool remoteLauncher = false;
 
-  try {
+  try
+  {
     // ...create ORB, get RootPOA object, NamingService, etc.
     ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance();
-    ASSERT( SINGLETON_<ORB_INIT>::IsAlreadyExisting() );
+    ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
     int orbArgc = 1;
-    if( std::string(argv[1]).find("-ORBInitRef") != std::string::npos ){
+    if (std::string(argv[1]).find("-ORBInitRef") != std::string::npos)
+    {
       orbArgc = 3;
       remoteLauncher = true;
     }
-    orb = init( orbArgc, argv );
+    orb = init(orbArgc, argv);
 
-    CORBA::Object_var obj = orb->resolve_initial_references( "RootPOA" );
-    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();
-    pman->activate() ;
-    MESSAGE( "POA manager activated" );
+    pman->activate();
+    MESSAGE("POA manager activated");
 
-    _NS = new SALOME_NamingService( orb );
+    self.connectToNSIfNeeded(orb);
 
     result = 0;
   }
-  catch ( SALOME_Exception& e ) {
-    INFOS( "run(): Caught SALOME_Exception : " << e.what() );
+  catch (SALOME_Exception &e)
+  {
+    INFOS("run(): Caught SALOME_Exception : " << e.what());
   }
-  catch ( CORBA::SystemException& e ) {
-    INFOS( "run(): Caught CORBA::SystemException : " << handleCorbaException( e ) );
+  catch (CORBA::SystemException &e)
+  {
+    INFOS("run(): Caught CORBA::SystemException : " << handleCorbaException(e));
   }
-  catch ( CORBA::Exception& e ) {
-    INFOS( "run(): Caught CORBA::Exception : " << handleCorbaException( e ) );
+  catch (CORBA::Exception &e)
+  {
+    INFOS("run(): Caught CORBA::Exception : " << handleCorbaException(e));
   }
-  catch ( std::exception& e ) {
-    INFOS( "run(): Caught exception : " << e.what() );
+  catch (std::exception &e)
+  {
+    INFOS("run(): Caught exception : " << e.what());
   }
-  catch (...) {
-    INFOS( "run(): Caught unknown exception" );
+  catch (...)
+  {
+    INFOS("run(): Caught unknown exception");
   }
 
   QMutex _GUIMutex, _SessionMutex, _SplashMutex;
@@ -512,91 +602,98 @@ int main( int argc, char **argv )
   // until all initialization is done
   _SessionMutex.lock();
 
-  if ( !result ) {
+  if (!result)
+  {
     // Start embedded servers launcher (Registry, SALOMEDS, etc.)
     // ...lock mutex to block embedded servers launching thread until wait( mutex )
-    _GUIMutex.lock();  
+    _GUIMutex.lock();
     // ...create launcher
 #if defined(WIN32) && defined(UNICODE)
-       LPWSTR *szArglist = NULL;
-       int nArgs;
-       int i;
-       szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);      
-       new_argv = new char*[nArgs];
-       for (i = 0; i < nArgs; i++) {
-               new_argv[i] = (char*) Kernel_Utils::utf8_encode(szArglist[i]);
-       }
-       // Free memory allocated for CommandLineToArgvW arguments.
-       LocalFree(szArglist);
-       myServerLauncher = new Session_ServerLauncher(nArgs, new_argv, orb, poa, &_GUIMutex, &_ServerLaunch, &_SessionMutex, &_SessionStarted); 
+    LPWSTR *szArglist = NULL;
+    int nArgs;
+    int i;
+    szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);
+    new_argv = new char *[nArgs];
+    for (i = 0; i < nArgs; i++)
+    {
+      new_argv[i] = (char *)Kernel_Utils::utf8_encode(szArglist[i]);
+    }
+    // Free memory allocated for CommandLineToArgvW arguments.
+    LocalFree(szArglist);
+    myServerLauncher = new Session_ServerLauncher<NamingServiceImplementation>(nArgs, new_argv, orb, poa, &_GUIMutex, &_ServerLaunch, &_SessionMutex, &_SessionStarted);
 #else
-    myServerLauncher = new Session_ServerLauncher( argc, argv, orb, poa, &_GUIMutex, &_ServerLaunch, &_SessionMutex, &_SessionStarted );
+    myServerLauncher = new Session_ServerLauncher<NamingServiceImplementation>(argc, argv, orb, poa, &_GUIMutex, &_ServerLaunch, &_SessionMutex, &_SessionStarted);
 #endif
     // ...block this thread until launcher is ready
-    _ServerLaunch.wait( &_GUIMutex );
+    _ServerLaunch.wait(&_GUIMutex);
 
     // Start servers check thread (splash)
-    if ( splash ) {
+    if (splash)
+    {
       // ...lock mutex to block splash thread until wait( mutex )
       _SplashMutex.lock();
       // ...create servers checking thread
-      Session_ServerCheck sc( &_SplashMutex, &_SplashStarted );
+      Session_ServerCheck<NamingServiceImplementation> sc(&_SplashMutex, &_SplashStarted);
       // ... set initial progress
-      splash->setProgress( 0, sc.totalSteps() );
-      // start check loop 
-      while ( true ) {
-        int step    = sc.currentStep();
-        int total   = sc.totalSteps();
+      splash->setProgress(0, sc.totalSteps());
+      // start check loop
+      while (true)
+      {
+        int step = sc.currentStep();
+        int total = sc.totalSteps();
         QString msg = sc.currentMessage();
         QString err = sc.error();
-        if ( !err.isEmpty() ) {
-          QtxSplash::setError( err );
+        if (!err.isEmpty())
+        {
+          QtxSplash::setError(err);
           QApplication::instance()->processEvents();
           result = -1;
           break;
         }
-        QtxSplash::setStatus( msg, step );
+        QtxSplash::setStatus(msg, step);
         QApplication::instance()->processEvents();
-        if ( step >= total )
+        if (step >= total)
           break;
         // ...block this thread until servers checking is finished
-        _SplashStarted.wait( &_SplashMutex );
+        _SplashStarted.wait(&_SplashMutex);
       }
       // ...unlock mutex 'cause it is no more needed
       _SplashMutex.unlock();
     }
 
-    // Finalize embedded servers launcher 
+    // Finalize embedded servers launcher
     // ...block this thread until launcher is finished
-    _ServerLaunch.wait( &_GUIMutex );
+    _ServerLaunch.wait(&_GUIMutex);
     // ...unlock mutex 'cause it is no more needed
     _GUIMutex.unlock();
   }
 
   // Obtain Session interface reference
-  CORBA::Object_var obj = _NS->Resolve( "/Kernel/Session" );
-  SALOME::Session_var session = SALOME::Session::_narrow( obj ) ;
+  SALOME::Session_var session = self.getSession();
 
   bool shutdownAll = false;
   bool shutdownSession = false;
-  bool debugExceptions = boolCmdOption( "--no-exception-handler" ) ||
-    resMgr.booleanValue( "launch", "noexcepthandler", false );
+  bool debugExceptions = boolCmdOption("--no-exception-handler") ||
+                         resMgr.booleanValue("launch", "noexcepthandler", false);
 
-  if ( !result ) {
+  if (!result)
+  {
     // Launch GUI activator
-    if ( isGUI ) {
-      if ( splash )
-        splash->setStatus( QObject::tr( "Activating desktop..." ) );
+    if (isGUI)
+    {
+      if (splash)
+        splash->setStatus(QObject::tr("Activating desktop..."));
       // ...create GUI launcher
-      MESSAGE( "Session activated, Launch IAPP..." );
-      guiThread = new GetInterfaceThread( session );
+      MESSAGE("Session activated, Launch IAPP...");
+      guiThread = new GetInterfaceThread(session);
     }
 
     // GUI activation
     // Allow multiple activation/deactivation of GUI
-    while ( true ) {
-      MESSAGE( "waiting wakeAll()" );
-      _SessionStarted.wait( &_SessionMutex ); // to be reseased by Launch server thread when ready:
+    while (true)
+    {
+      MESSAGE("waiting wakeAll()");
+      _SessionStarted.wait(&_SessionMutex); // to be reseased by Launch server thread when ready:
       // atomic operation lock - unlock on mutex
       // unlock mutex: serverThread runs, calls _ServerLaunch->wakeAll()
       // this thread wakes up, and lock mutex
@@ -606,7 +703,8 @@ int main( int argc, char **argv )
       // Session might be shutdowning here, check status
       SALOME::StatSession stat = session->GetStatSession();
       shutdownSession = stat.state == SALOME::shutdown;
-      if ( shutdownSession ) {
+      if (shutdownSession)
+      {
         _SessionMutex.lock(); // lock mutex before leaving loop - it will be unlocked later
         break;
       }
@@ -615,37 +713,39 @@ int main( int argc, char **argv )
       aGUISession = new Session();
 
       // Load SalomeApp dynamic library
-      MESSAGE( "creation SUIT_Application" );
-      SUIT_Application* aGUIApp = aGUISession->startApplication( "SalomeApp", 0, 0 );
-      if ( aGUIApp )
+      MESSAGE("creation SUIT_Application");
+      SUIT_Application *aGUIApp = aGUISession->startApplication(NamingServiceImplementation::LibName, 0, 0);
+      if (aGUIApp)
       {
 #ifdef USE_SALOME_STYLE
-        Style_Salome::initialize( aGUIApp->resourceMgr() );
-        if ( aGUIApp->resourceMgr()->booleanValue( "Style", "use_salome_style", true ) )
+        Style_Salome::initialize(aGUIApp->resourceMgr());
+        if (aGUIApp->resourceMgr()->booleanValue("Style", "use_salome_style", true))
           Style_Salome::apply();
 #endif // USE_SALOME_STYLE
 
-        if ( !debugExceptions )
-          app.setHandler( aGUISession->handler() ); // after loading SalomeApp application
-                                                    // aGUISession contains SalomeApp_ExceptionHandler
+        if (!debugExceptions)
+          app.setHandler(aGUISession->handler()); // after loading SalomeApp application
+                                                  // aGUISession contains SalomeApp_ExceptionHandler
 
         // Run GUI loop
-        MESSAGE( "run(): starting the main event loop" );
+        MESSAGE("run(): starting the main event loop");
 
-        if ( splash )
-          splash->finish( aGUIApp->desktop() );
+        if (splash)
+          splash->finish(aGUIApp->desktop());
 
         result = app.exec();
 
         splash = 0;
 
-        if ( result == SUIT_Session::NORMAL ) {
+        if (result == SUIT_Session::NORMAL)
+        {
           // desktop is explicitly closed by user from GUI
           // exit flags says if it's necessary to shutdown all servers
           // all session server only
           shutdownAll = aGUISession->exitFlags();
         }
-        else {
+        else
+        {
           // desktop might be closed from:
           // - StopSesion() (temporarily) or
           // - Shutdown() (permanently)
@@ -657,7 +757,8 @@ int main( int argc, char **argv )
           // asking to kill servers also
           shutdownAll = aGUISession->exitFlags();
         }
-        if ( shutdownAll || shutdownSession ) {
+        if (shutdownAll || shutdownSession)
+        {
           _SessionMutex.lock(); // lock mutex before leaving loop - it will be unlocked later
           break;
         }
@@ -675,65 +776,40 @@ int main( int argc, char **argv )
   _SessionMutex.unlock();
 
   // Shutdown embedded servers
-  if ( myServerLauncher )
+  if (myServerLauncher)
     myServerLauncher->ShutdownAll();
 
   // Shutdown standalone servers
-  if ( shutdownAll )
-    shutdownServers( _NS, remoteLauncher );
+  if (shutdownAll)
+    self.shutdownRemoteServersIfNeeded(remoteLauncher);
 
   // Kill embedded servers
-  if ( myServerLauncher )
+  if (myServerLauncher)
     myServerLauncher->KillAll();
 
   // Unregister session server
-  SALOME_Session_i* sessionServant = 
-    dynamic_cast<SALOME_Session_i*>( poa->reference_to_servant( session.in() ) );
-  if ( sessionServant )
+  SALOME_Session_i *sessionServant =
+      dynamic_cast<SALOME_Session_i *>(poa->reference_to_servant(session.in()));
+  if (sessionServant)
     sessionServant->NSunregister();
 
   delete aGUISession;
   delete guiThread;
   delete myServerLauncher;
-  delete _NS;
 #if defined(WIN32) && defined(UNICODE)
   delete[] new_argv;
 #endif
-
-  try {
-    orb->shutdown(0);
-  }
-  catch (...) {
-    //////////////////////////////////////////////////////////////
-    // VSR: silently skip exception:
-    // CORBA.BAD_INV_ORDER.BAD_INV_ORDER_ORBHasShutdown 
-    // exception is raised when orb->destroy() is called and
-    // cpp continer is launched in the embedded mode
-    //////////////////////////////////////////////////////////////
-    if ( shutdownAll )
-      killOmniNames();
-    abort(); //abort program to avoid deadlock in destructors or atexit when shutdown has been interrupted
-  }
-
-  // Destroy ORB
-  sleep(2);
-  ORB_INIT* init = SINGLETON_<ORB_INIT>::Instance();
-  if ( init )
-    init->explicit_destroy();
-
+  self.shutdownCORBAStufIfNeeded(shutdownAll,orb);
   // Finalize Python
-  if ( Py_IsInitialized() )
+  if (Py_IsInitialized())
   {
     PyGILState_Ensure();
     Py_Finalize();
   }
-
   // Kill omniNames process
-  if ( shutdownAll )
-  {
-    killOmniNames();
-  }
+  if (shutdownAll)
+    self.killOtherServersIfNeeded();
 
-  MESSAGE( "Salome_Session_Server:endofserver" );
+  MESSAGE("Salome_Session_Server:endofserver");
   return result;
 }
diff --git a/src/Session/SALOME_Session_Server_No_Server.cxx b/src/Session/SALOME_Session_Server_No_Server.cxx
new file mode 100644 (file)
index 0000000..596f9ad
--- /dev/null
@@ -0,0 +1,26 @@
+// Copyright (C) 2021  CEA/DEN, EDF R&D
+//
+// 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, or (at your option) any later version.
+//
+// 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "SALOME_Session_Server.cxx"
+
+
+int main(int argc, char **argv)
+{
+  return AbstractGUIAppMain<GUIAppNewStyle>(argc, argv);
+}
diff --git a/src/Session/SALOME_Session_Server_With_Server.cxx b/src/Session/SALOME_Session_Server_With_Server.cxx
new file mode 100644 (file)
index 0000000..1479f75
--- /dev/null
@@ -0,0 +1,25 @@
+// Copyright (C) 2021  CEA/DEN, EDF R&D
+//
+// 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, or (at your option) any later version.
+//
+// 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "SALOME_Session_Server.cxx"
+
+int main(int argc, char **argv)
+{
+  return AbstractGUIAppMain<GUIAppOldStyle>(argc, argv);
+}
diff --git a/src/Session/Session_NS_wrapper.cxx b/src/Session/Session_NS_wrapper.cxx
new file mode 100644 (file)
index 0000000..a5dd110
--- /dev/null
@@ -0,0 +1,264 @@
+// Copyright (C) 2021  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// 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, or (at your option) any later version.
+//
+// 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "Session_NS_wrapper.hxx"
+
+#include "SALOME_Fake_NamingService.hxx"
+#include "SALOME_Container_i.hxx"
+#include "SALOME_Launcher.hxx"
+#include "SALOMEDSClient_ClientFactory.hxx"
+
+#include "Session_Session_i.hxx"
+#include "Session_Promises.hxx"
+#include "utilities.h"
+
+const char OldStyleNS::LibName[]="SalomeApp";
+const char NewStyleNS::LibName[]="SalomeAppSL";
+
+void CommonActivateSession(CORBA::ORB_var orb, PortableServer::POA_var poa, QMutex *GUIMutex, QWaitCondition *GUILauncher, SALOME_NamingService_Abstract *ns, int argc, char ** argv)
+{
+  try {
+    MESSAGE("Session thread started");
+    SALOME_Session_i * mySALOME_Session = nullptr;
+    if(!ns)
+      mySALOME_Session = new SALOME_Session_i(argc, argv, orb, poa, GUIMutex, GUILauncher);
+    else
+      mySALOME_Session = new SALOME_Session_i(argc, argv, orb, poa, GUIMutex, GUILauncher,ns);
+    PortableServer::ObjectId_var mySALOME_Sessionid = poa->activate_object(mySALOME_Session);
+    MESSAGE("poa->activate_object(mySALOME_Session)");
+    
+    CORBA::Object_var obj = mySALOME_Session->_this();
+    SALOME::Session_var objC = SALOME::Session::_narrow(obj);
+    GetSessionRefSingleton()->set_value(objC);
+    CORBA::String_var sior(orb->object_to_string(obj));
+    mySALOME_Session->_remove_ref();
+    
+    mySALOME_Session->NSregister();
+  }
+  catch (CORBA::SystemException&) {
+    INFOS("Caught CORBA::SystemException.");
+  }
+  catch (CORBA::Exception&) {
+    INFOS("Caught CORBA::Exception.");
+  }
+  catch (...) {
+    INFOS("Caught unknown exception.");
+  }
+}
+
+Engines_Container_i *OldStyleNS::activateContainer(CORBA::ORB_var orb, PortableServer::POA_var poa, int argc, char **argv)
+{
+  Engines_Container_i *_container = nullptr;
+  try
+  {
+    MESSAGE("Container thread started");
+
+    // get or create the child POA
+
+    PortableServer::POA_var factory_poa;
+    try
+    {
+      factory_poa = poa->find_POA("factory_poa", 0);
+      // 0 = no activation (already done if exists)
+    }
+    catch (PortableServer::POA::AdapterNonExistent &)
+    {
+      MESSAGE("factory_poa does not exists, create...");
+      // define policy objects
+      PortableServer::ImplicitActivationPolicy_var implicitActivation =
+          poa->create_implicit_activation_policy(PortableServer::NO_IMPLICIT_ACTIVATION);
+      // default = NO_IMPLICIT_ACTIVATION
+      PortableServer::ThreadPolicy_var threadPolicy =
+          poa->create_thread_policy(PortableServer::ORB_CTRL_MODEL);
+      // default = ORB_CTRL_MODEL, other choice SINGLE_THREAD_MODEL
+
+      // create policy list
+      CORBA::PolicyList policyList;
+      policyList.length(2);
+      policyList[0] = PortableServer::ImplicitActivationPolicy::
+          _duplicate(implicitActivation);
+      policyList[1] = PortableServer::ThreadPolicy::
+          _duplicate(threadPolicy);
+
+      PortableServer::POAManager_var nil_mgr = PortableServer::POAManager::_nil();
+      factory_poa = poa->create_POA("factory_poa",
+                                    nil_mgr,
+                                    policyList);
+      //with nil_mgr instead of pman,
+      //a new POA manager is created with the new POA
+
+      // destroy policy objects
+      implicitActivation->destroy();
+      threadPolicy->destroy();
+
+      // obtain the factory poa manager
+      PortableServer::POAManager_var pmanfac = factory_poa->the_POAManager();
+      pmanfac->activate();
+      MESSAGE("pmanfac->activate()");
+    }
+
+    char *containerName = (char *)"";
+    if (argc > 1)
+    {
+      containerName = argv[1];
+    }
+    _container = new Engines_Container_i(orb, poa, containerName, argc, argv, nullptr, false);
+  }
+  catch (CORBA::SystemException &)
+  {
+    INFOS("Caught CORBA::SystemException.");
+  }
+  catch (PortableServer::POA::WrongPolicy &)
+  {
+    INFOS("Caught CORBA::WrongPolicyException.");
+  }
+  catch (PortableServer::POA::ServantAlreadyActive &)
+  {
+    INFOS("Caught CORBA::ServantAlreadyActiveException");
+  }
+  catch (CORBA::Exception &)
+  {
+    INFOS("Caught CORBA::Exception.");
+  }
+  catch (...)
+  {
+    INFOS("Caught unknown exception.");
+  }
+  return _container;
+}
+
+void OldStyleNS::activateContainerManager(CORBA::ORB_var orb)
+{
+  try {
+    PortableServer::POA_var root_poa=PortableServer::POA::_the_root_poa();
+    std::cout << "Activate SalomeLauncher ......!!!! " << std::endl;
+    new SALOME_Launcher(orb,root_poa);
+  }
+  catch(CORBA::SystemException&) {
+    INFOS("Caught CORBA::SystemException.");
+  }
+  catch(PortableServer::POA::WrongPolicy&) {
+    INFOS("Caught CORBA::WrongPolicyException.");
+  }
+  catch(PortableServer::POA::ServantAlreadyActive&) {
+    INFOS("Caught CORBA::ServantAlreadyActiveException");
+  }
+  catch(CORBA::Exception&) {
+    INFOS("Caught CORBA::Exception.");
+  }
+  catch(...) {
+    INFOS("Caught unknown exception.");
+  }
+}
+
+void OldStyleNS::activateSession(CORBA::ORB_var orb, PortableServer::POA_var poa, QMutex *GUIMutex, QWaitCondition *GUILauncher, int argc, char ** argv)
+{
+  CommonActivateSession(orb,poa,GUIMutex,GUILauncher,nullptr,argc,argv);
+}
+
+void OldStyleNS::activateSALOMEDS(CORBA::ORB_var orb, PortableServer::POA_var poa)
+{
+  try {
+    MESSAGE("SALOMEDS thread started");
+    // We allocate the objects on the heap.  Since these are reference
+    // counted objects, they will be deleted by the POA when they are no
+    // longer needed.    
+    
+    ClientFactory::createStudy(orb,poa);
+  }
+  catch(CORBA::SystemException&) {
+    INFOS( "Caught CORBA::SystemException." );
+  }
+  catch(CORBA::Exception&) {
+    INFOS( "Caught CORBA::Exception." );
+  }
+  catch(omniORB::fatalException& fe) {
+    INFOS( "Caught omniORB::fatalException:" );
+    INFOS( "  file: " << fe.file() );
+    INFOS( "  line: " << fe.line() );
+    INFOS( "  mesg: " << fe.errmsg() );
+  }
+  catch(...) {
+    INFOS( "Caught unknown exception." );
+  }
+}
+
+#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_<ORB_INIT>::Instance();
+  CORBA::ORB_var 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( 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_<ORB_INIT>::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;
+}
+
+#include "SALOME_KernelServices.hxx"
+
+void NewStyleNS::defineDefaultSALOMEKERNELNamingService()
+{
+  KERNEL::assignNamingServiceSL();
+}
+
+Engines_Container_i *NewStyleNS::activateContainer(CORBA::ORB_var orb, PortableServer::POA_var poa, int argc, char **argv)
+{
+  return KERNEL::getContainerSA();
+}
+
+void NewStyleNS::activateContainerManager(CORBA::ORB_var orb)
+{
+  KERNEL::getLauncherSA();
+}
+
+void NewStyleNS::activateSession(CORBA::ORB_var orb, PortableServer::POA_var poa, QMutex *GUIMutex, QWaitCondition *GUILauncher, int argc, char ** argv)
+{
+  SALOME_Fake_NamingService *ns=new SALOME_Fake_NamingService;
+  CommonActivateSession(orb,poa,GUIMutex,GUILauncher,ns,argc,argv);
+}
+
+void NewStyleNS::activateSALOMEDS(CORBA::ORB_var orb, PortableServer::POA_var poa)
+{
+  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
new file mode 100644 (file)
index 0000000..85518af
--- /dev/null
@@ -0,0 +1,73 @@
+// Copyright (C) 2021  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// 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, or (at your option) any later version.
+//
+// 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#pragma once
+
+#include "SALOME_NamingService.hxx"
+
+#include "omniORB4/CORBA.h"
+
+class QMutex;
+class QWaitCondition;
+
+class Engines_Container_i;
+
+class OldStyleNS
+{
+public:
+  using RealNS = SALOME_NamingService;
+public:
+  OldStyleNS(CORBA::ORB_ptr orb):_NS(orb) {}
+  void Register(CORBA::Object_ptr ObjRef, const char* Path) { _NS.Register(ObjRef,Path); }
+  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);
+  static void defineDefaultSALOMEKERNELNamingService() { /* nothing to do by default true NamingService server is considered */ }
+  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);
+  static const char LibName[];
+private:
+  RealNS _NS;
+};
+
+#include "SALOME_Fake_NamingService.hxx"
+
+class NewStyleNS
+{
+public:
+  using RealNS = SALOME_Fake_NamingService;
+public:
+  NewStyleNS(CORBA::ORB_ptr orb):_NS(orb) {}
+  void Register(CORBA::Object_ptr ObjRef, const char* Path) { _NS.Register(ObjRef,Path); }
+  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);
+  static void defineDefaultSALOMEKERNELNamingService();
+  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);
+  static const char LibName[];
+private:
+  RealNS _NS;
+};
diff --git a/src/Session/Session_Promises.cxx b/src/Session/Session_Promises.cxx
new file mode 100644 (file)
index 0000000..b3a8d7d
--- /dev/null
@@ -0,0 +1,26 @@
+// Copyright (C) 2021  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// 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, or (at your option) any later version.
+//
+// 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "Session_Promises.hxx"
+
+std::promise<SALOME::Session_var> *GetSessionRefSingleton()
+{
+    static std::promise<SALOME::Session_var> _my_unique_study_ref;
+    return &_my_unique_study_ref;
+}
diff --git a/src/Session/Session_Promises.hxx b/src/Session/Session_Promises.hxx
new file mode 100644 (file)
index 0000000..be47159
--- /dev/null
@@ -0,0 +1,27 @@
+// Copyright (C) 2021  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// 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, or (at your option) any later version.
+//
+// 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#pragma once
+
+#include "SALOMEconfig.h"
+#include CORBA_SERVER_HEADER(SALOME_Session)
+
+#include <future>
+
+std::promise<SALOME::Session_var> *GetSessionRefSingleton();
index 1a1e6a94b6bca7a63f0b45cee546d99257e5f219..f43a218c824a441fb959552f8a09b9218d61b65b 100644 (file)
@@ -87,7 +87,8 @@ const int __DEFAULT__DELAY__ = 50000;
   \internal
 */
 
-class Session_ServerCheck::Locker
+template<class MY_CLS>
+class Session_ServerCheck<MY_CLS>::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<class MY_NS>
+Session_ServerCheck<MY_NS>::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<class MY_NS>
+Session_ServerCheck<MY_NS>::~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<class MY_NS>
+QString Session_ServerCheck<MY_NS>::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<class MY_NS>
+QString Session_ServerCheck<MY_NS>::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<class MY_NS>
+int Session_ServerCheck<MY_NS>::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<class MY_NS>
+int Session_ServerCheck<MY_NS>::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<class MY_NS>
+void Session_ServerCheck<MY_NS>::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<class MY_NS>
+void Session_ServerCheck<MY_NS>::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<class MY_NS>
+void Session_ServerCheck<MY_NS>::run()
 {
   // start check servers
   int current = 0;
@@ -271,11 +281,9 @@ void Session_ServerCheck::run()
     setStep( current * myAttempts + i );
 
     try {
-      ORB_INIT& init = *SINGLETON_<ORB_INIT>::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_<ORB_INIT>::Instance();
-      CORBA::ORB_var orb = init( args.argc(), args.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" );
@@ -351,12 +354,7 @@ void Session_ServerCheck::run()
     setStep( current * myAttempts + i );
 
     try {
-      ORB_INIT& init = *SINGLETON_<ORB_INIT>::Instance();
-      CORBA::ORB_var orb = init( args.argc(), args.argv() );
-      SALOME_NamingService &NS = *SINGLETON_<SALOME_NamingService>::Instance();
-      ASSERT( SINGLETON_<SALOME_NamingService>::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_<ORB_INIT>::Instance();
-      CORBA::ORB_var orb = init( args.argc(), args.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" );
@@ -449,12 +442,7 @@ void Session_ServerCheck::run()
     setStep( current * myAttempts + i );
 
     try {
-      ORB_INIT& init = *SINGLETON_<ORB_INIT>::Instance();
-      CORBA::ORB_var orb = init( args.argc(), args.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" );
@@ -499,13 +487,8 @@ void Session_ServerCheck::run()
       setStep( current * myAttempts + i );
 
       try {
-        ORB_INIT& init = *SINGLETON_<ORB_INIT>::Instance();
-        CORBA::ORB_var orb = init( args.argc(), args.argv() );
-        SALOME_NamingService &NS = *SINGLETON_<SALOME_NamingService>::Instance();
-        ASSERT( SINGLETON_<SALOME_NamingService>::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_<ORB_INIT>::Instance();
-        CORBA::ORB_var orb = init( args.argc(), args.argv() );
-        SALOME_NamingService &NS = *SINGLETON_<SALOME_NamingService>::Instance();
-        ASSERT( SINGLETON_<SALOME_NamingService>::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_<ORB_INIT>::Instance();
-        CORBA::ORB_var orb = init( args.argc(), args.argv() );
-        SALOME_NamingService &NS = *SINGLETON_<SALOME_NamingService>::Instance();
-        ASSERT( SINGLETON_<SALOME_NamingService>::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<OldStyleNS>;
+template class Session_ServerCheck<NewStyleNS>;
index d6733f7d4a4f7a0b69651a5bcc0dcb602fc00467..e6aedc60b468b37600a03111f37d9001780fc9b2 100644 (file)
@@ -33,6 +33,7 @@
 
 class QWaitCondition;
 
+template<class MY_NS>
 class SESSION_EXPORT Session_ServerCheck : public QThread
 {
   class Locker;
index 6471c26bcd08121b6300f8f0e90d256f41849bcc..fd8f638db445e06dbf2d259fcac807053153b306 100644 (file)
@@ -36,7 +36,8 @@
 /*! 
    default constructor not for use
  */
-Session_ServerLauncher::Session_ServerLauncher()
+template<class MY_NS>
+Session_ServerLauncher<MY_NS>::Session_ServerLauncher()
 {
   ASSERT(0); // must not be called
 }
@@ -44,14 +45,15 @@ Session_ServerLauncher::Session_ServerLauncher()
 /*! 
   constructor
 */
-Session_ServerLauncher::Session_ServerLauncher(int argc,
-                                               char ** argv, 
-                                               CORBA::ORB_ptr orb, 
-                                               PortableServer::POA_ptr poa,
-                                               QMutex *GUIMutex,
-                                               QWaitCondition *ServerLaunch,
-                                               QMutex *SessionMutex,
-                                               QWaitCondition *SessionStarted)
+template<class MY_NS>
+Session_ServerLauncher<MY_NS>::Session_ServerLauncher(int argc,
+                                                      char ** argv, 
+                                                      CORBA::ORB_ptr orb, 
+                                                      PortableServer::POA_ptr poa,
+                                                      QMutex *GUIMutex,
+                                                      QWaitCondition *ServerLaunch,
+                                                      QMutex *SessionMutex,
+                                                      QWaitCondition *SessionStarted)
 {
   _argc = argc;
   _argv = argv;
@@ -61,7 +63,7 @@ Session_ServerLauncher::Session_ServerLauncher(int argc,
   _ServerLaunch = ServerLaunch;
   _SessionMutex = SessionMutex;
   _SessionStarted = SessionStarted;
-
+  MY_NS::defineDefaultSALOMEKERNELNamingService();
   // start thread
   start();
 }
@@ -69,14 +71,16 @@ Session_ServerLauncher::Session_ServerLauncher(int argc,
 /*! 
   destructor
 */
-Session_ServerLauncher::~Session_ServerLauncher()
+template<class MY_NS>
+Session_ServerLauncher<MY_NS>::~Session_ServerLauncher()
 {
 }
 
 /*! 
   Check args and activate servers
 */
-void Session_ServerLauncher::run()
+template<class MY_NS>
+void Session_ServerLauncher<MY_NS>::run()
 {
   // wait until main thread is ready
   _GUIMutex->lock();          // ... lock mutex (it is unlocked my calling thread 
@@ -104,7 +108,8 @@ void Session_ServerLauncher::run()
 /*! 
   controls and dispatchs arguments given with command
 */
-void Session_ServerLauncher::CheckArgs()
+template<class MY_NS>
+void Session_ServerLauncher<MY_NS>::CheckArgs()
 {
   int argState = 0;
   ServArg aServArg(0,0,0);
@@ -135,8 +140,8 @@ void Session_ServerLauncher::CheckArgs()
             }
             // Temporary solution
 
-            for (int i=0; i<Session_ServerThread::NB_SRV_TYP; i++)
-                if (strcmp(_argv[iarg],Session_ServerThread::_serverTypes[i])==0)
+            for (int i=0; i<Session_ServerThread<MY_NS>::NB_SRV_TYP; i++)
+                if (strcmp(_argv[iarg],Session_ServerThread<MY_NS>::_serverTypes[i])==0)
                   {
                     aServArg._servType = i;
                     argState = 2;
@@ -166,7 +171,7 @@ void Session_ServerLauncher::CheckArgs()
             if (strcmp(_argv[iarg],")")==0)   // end of arguments = ')'
               {
                 aServArg._lastArg=iarg-1;     // arg before ')'
-                MESSAGE("server : "<< Session_ServerThread::_serverTypes[aServArg._servType]);
+                MESSAGE("server : "<< Session_ServerThread<MY_NS>::_serverTypes[aServArg._servType]);
                 for (int i=aServArg._firstArg; i<=aServArg._lastArg; i++)
                   MESSAGE("  arg : " << _argCopy[i]);
                 _argServToLaunch.push_back(aServArg);
@@ -189,7 +194,8 @@ void Session_ServerLauncher::CheckArgs()
     throw SALOME_Exception(LOCALIZED("Error in command arguments, missing parenthesis ')'"));
 }
 
-void Session_ServerLauncher::ActivateAll()
+template<class MY_NS>
+void Session_ServerLauncher<MY_NS>::ActivateAll()
 {
   std::list<ServArg>::iterator itServ;
   for (itServ = _argServToLaunch.begin(); itServ !=_argServToLaunch.end(); itServ++)
@@ -198,7 +204,7 @@ void Session_ServerLauncher::ActivateAll()
     char** argv = new char*[argc+1];
     argv[argc]=0; // for Engines_Container_i constructor...
     int servType = (*itServ)._servType;
-    argv[0]=strdup(Session_ServerThread::_serverTypes[servType]);
+    argv[0]=strdup(Session_ServerThread<MY_NS>::_serverTypes[servType]);
     if (argc>1)
     {
       for (int i=0; i<argc-1; i++)
@@ -208,8 +214,7 @@ void Session_ServerLauncher::ActivateAll()
 
     MESSAGE("*** activating [" << argc << "] : " << argv[0]);
 
-    Session_ServerThread* aServerThread
-      = new Session_ServerThread(argc, argv, _orb,_root_poa);
+    Session_ServerThread<MY_NS>* aServerThread = new Session_ServerThread<MY_NS>(argc, argv, _orb,_root_poa);
     _serverThreads.push_front(aServerThread);
     
     aServerThread->Init();
@@ -223,17 +228,19 @@ void Session_ServerLauncher::ActivateAll()
   int argc=1;
   char** argv = new char*[argc];
   argv[0] = (char*)"Session";
-  Session_SessionThread* aServerThread
-    = new Session_SessionThread(argc, argv, _orb,_root_poa,_SessionMutex,_SessionStarted);
+  Session_SessionThread<MY_NS>* aServerThread
+    = new Session_SessionThread<MY_NS>(argc, argv, _orb,_root_poa,_SessionMutex,_SessionStarted);
   _serverThreads.push_front(aServerThread);
   aServerThread->Init();
   delete[] argv;
 }
 
-void Session_ServerLauncher::ShutdownAll()
+template <class MY_NS>
+void Session_ServerLauncher<MY_NS>::ShutdownAll()
 {
   MESSAGE("Session_ServerLauncher::ShutdownAll()");
-  std::list<Session_ServerThread*>::reverse_iterator itServ;
+  using Session_ServerThreadT = Session_ServerThread<MY_NS>;
+  typename std::list<Session_ServerThreadT*>::reverse_iterator itServ;
   for (itServ = _serverThreads.rbegin(); itServ !=_serverThreads.rend(); itServ++)
   {
     (*itServ)->Shutdown();
@@ -243,12 +250,20 @@ void Session_ServerLauncher::ShutdownAll()
 /*! 
   Destruction des classes serveur dans l'ordre inverse de creation
 */
-void Session_ServerLauncher::KillAll()
+template <class MY_NS>
+void Session_ServerLauncher<MY_NS>::KillAll()
 {
   MESSAGE("Session_ServerLauncher::KillAll()");
-  std::list<Session_ServerThread*>::reverse_iterator itServ;
+  using Session_ServerThreadT = Session_ServerThread<MY_NS>;
+  typename std::list<Session_ServerThreadT*>::reverse_iterator itServ;
   for (itServ = _serverThreads.rbegin(); itServ !=_serverThreads.rend(); itServ++)
   {
     delete (*itServ);
   }
 }
+
+#include "Session_NS_wrapper.hxx" 
+
+template class Session_ServerLauncher<OldStyleNS>;
+
+template class Session_ServerLauncher<NewStyleNS>;
index 33e8187a68907ae7592fc651965889dcf914f023..719157e4002e85ff9b35f24c2bbe2372bf22a0c7 100644 (file)
@@ -48,12 +48,14 @@ inline ServArg::ServArg(int servType, int firstArg, int lastArg):
   _servType(servType),_firstArg(firstArg),_lastArg(lastArg)
 {}
 
+template <class MY_NS>
 class Session_ServerThread;
 
 class QMutex;
 class QWaitCondition;
 
-class SESSION_EXPORT Session_ServerLauncher: public QThread
+template<class MY_NS>
+class SESSION_EXPORT Session_ServerLauncher : public QThread
 {
 public:
   Session_ServerLauncher();
@@ -85,7 +87,7 @@ private:
   QWaitCondition*                  _SessionStarted;
   std::list<ServArg>               _argServToLaunch;
   std::vector<std::string>         _argCopy;
-  std::list<Session_ServerThread*> _serverThreads;
+  std::list< Session_ServerThread<MY_NS>* > _serverThreads;
 };
 
 #endif
index 0d042a0422e1cf676094c22d4031b101cc6f5a97..84eb438fa87f3df157267ebf3707b78b49465761 100644 (file)
 //  Author : Paul RASCLE, EDF
 
 #include "Session_ServerThread.hxx"
+#include "Session_Promises.hxx"
 
 #include <SALOME_NamingService.hxx>
 #include <SALOME_Container_i.hxx>
 #include <SALOME_Launcher.hxx>
-#include <SALOMEDSClient_ClientFactory.hxx>
 #include <SALOME_ModuleCatalog_impl.hxx>
 #include <RegistryService.hxx>
 
 #include <QMutex>
 #include <QWaitCondition>
 
-const int Session_ServerThread::NB_SRV_TYP = 6;
-const char* Session_ServerThread::_serverTypes[NB_SRV_TYP] = {"Container",
-                                                              "ModuleCatalog",
-                                                              "Registry",
-                                                              "SALOMEDS",
-                                                              "Session",
-                                                              "ContainerManager"};
+template<class MY_NS>
+const int Session_ServerThread<MY_NS>::NB_SRV_TYP = 6;
+
+template<class MY_NS>
+const char* Session_ServerThread<MY_NS>::_serverTypes[NB_SRV_TYP] = {"Container",
+                                                                      "ModuleCatalog",
+                                                                      "Registry",
+                                                                      "SALOMEDS",
+                                                                      "Session",
+                                                                      "ContainerManager"};
 
 /*! 
   default constructor not for use
 */
-Session_ServerThread::Session_ServerThread()
+template<class MY_NS>
+Session_ServerThread<MY_NS>::Session_ServerThread()
 {
   ASSERT(0); // must not be called
 }
@@ -67,7 +71,8 @@ Session_ServerThread::Session_ServerThread()
 /*! 
   constructor
 */
-Session_ServerThread::Session_ServerThread(int argc,
+template<class MY_NS>
+Session_ServerThread<MY_NS>::Session_ServerThread(int argc,
                                            char ** argv, 
                                            CORBA::ORB_ptr orb, 
                                            PortableServer::POA_ptr poa)
@@ -82,18 +87,17 @@ Session_ServerThread::Session_ServerThread(int argc,
   _orb = CORBA::ORB::_duplicate(orb);
   _root_poa = PortableServer::POA::_duplicate(poa);
   _servType =-1;
-  _NS = new SALOME_NamingService(_orb); // one instance per server to limit
-                                        // multi thread coherence problems
-  _container = 0;                       // embedded container
+  _NS.reset( new MY_NS(_orb) ); // one instance per server to limit
+                                               // multi thread coherence problems
+  _container = nullptr;                        // embedded container
 }
 
 /*! 
   destructor 
 */
-Session_ServerThread::~Session_ServerThread()
+template<class MY_NS>
+Session_ServerThread<MY_NS>::~Session_ServerThread()
 {
-  //MESSAGE("~Session_ServerThread "<< _argv[0]);
-  delete _NS;
   for (int i = 0; i <_argc ; i++ )
     free( _argv[i] );
   delete[] _argv;
@@ -103,7 +107,8 @@ Session_ServerThread::~Session_ServerThread()
   run the thread : activate one servant, the servant type is given by
   argument _argv[0]
 */
-void Session_ServerThread::Init()
+template<class MY_NS>
+void Session_ServerThread<MY_NS>::Init()
 {
   MESSAGE("Session_ServerThread::Init "<< _argv[0]); 
 
@@ -117,42 +122,42 @@ void Session_ServerThread::Init()
       switch (_servType) {
       case 0:  // Container
         {
-          NamingService_WaitForServerReadiness(_NS,"/Registry");
-          NamingService_WaitForServerReadiness(_NS,"/ContainerManager");
+          NamingService_WaitForServerReadiness(this->getNS(),"/Registry");
+          NamingService_WaitForServerReadiness(this->getNS(),"/ContainerManager");
           ActivateContainer(_argc, _argv);
           break;
         }
       case 1:  // ModuleCatalog
         {
-          NamingService_WaitForServerReadiness(_NS,"/Registry");
+          NamingService_WaitForServerReadiness(this->getNS(),"/Registry");
           ActivateModuleCatalog(_argc, _argv);
           break;
         }
       case 2:  // Registry
         {
-          NamingService_WaitForServerReadiness(_NS,"");
+          NamingService_WaitForServerReadiness(this->getNS(),"");
           ActivateRegistry(_argc, _argv);
           break;
         }
       case 3:  // SALOMEDS
         {
-          NamingService_WaitForServerReadiness(_NS,"/Kernel/ModulCatalog");
+          NamingService_WaitForServerReadiness(this->getNS(),"/Kernel/ModulCatalog");
           ActivateSALOMEDS(_argc, _argv);
           break;
         }
       case 4:  // Session
         {
-          NamingService_WaitForServerReadiness(_NS,"/Study");
+          NamingService_WaitForServerReadiness(this->getNS(),"/Study");
           std::string containerName = "/Containers/";
           containerName = containerName + Kernel_Utils::GetHostname();
           containerName = containerName + "/FactoryServer";
-          NamingService_WaitForServerReadiness(_NS,containerName);
+          NamingService_WaitForServerReadiness(this->getNS(),containerName);
           ActivateSession(_argc, _argv);
           break;
         }
       case 5: // Container Manager
         {
-          NamingService_WaitForServerReadiness(_NS,"");
+          NamingService_WaitForServerReadiness(this->getNS(),"");
           ActivateContainerManager(_argc, _argv);
           break;
         }
@@ -166,13 +171,14 @@ void Session_ServerThread::Init()
   }
 }
 
-void Session_ServerThread::Shutdown()
+template<class MY_NS>
+void Session_ServerThread<MY_NS>::Shutdown()
 {
   if ( _container ) _container->Shutdown();
 }
 
-void Session_ServerThread::ActivateModuleCatalog(int argc,
-                                                 char ** argv)
+template<class MY_NS>
+void Session_ServerThread<MY_NS>::ActivateModuleCatalog(int argc, char ** argv)
 {
   try {
     MESSAGE("ModuleCatalog thread started");
@@ -206,35 +212,14 @@ void Session_ServerThread::ActivateModuleCatalog(int argc,
   }
 }
 
-void Session_ServerThread::ActivateSALOMEDS(int /*argc*/, char** /*argv*/)
+template<class MY_NS>
+void Session_ServerThread<MY_NS>::ActivateSALOMEDS(int /*argc*/, char** /*argv*/)
 {
-  try {
-    MESSAGE("SALOMEDS thread started");
-    // We allocate the objects on the heap.  Since these are reference
-    // counted objects, they will be deleted by the POA when they are no
-    // longer needed.    
-    
-    ClientFactory::createStudy(_orb,_root_poa);
-  }
-  catch(CORBA::SystemException&) {
-    INFOS( "Caught CORBA::SystemException." );
-  }
-  catch(CORBA::Exception&) {
-    INFOS( "Caught CORBA::Exception." );
-  }
-  catch(omniORB::fatalException& fe) {
-    INFOS( "Caught omniORB::fatalException:" );
-    INFOS( "  file: " << fe.file() );
-    INFOS( "  line: " << fe.line() );
-    INFOS( "  mesg: " << fe.errmsg() );
-  }
-  catch(...) {
-    INFOS( "Caught unknown exception." );
-  }
+  this->_NS->activateSALOMEDS(this->_orb,this->_root_poa);
 }
 
-void Session_ServerThread::ActivateRegistry(int argc,
-                                            char ** argv)
+template<class MY_NS>
+void Session_ServerThread<MY_NS>::ActivateRegistry(int argc, char ** argv)
 {
   MESSAGE("Registry thread started");
   SCRUTE(argc); 
@@ -292,153 +277,59 @@ void Session_ServerThread::ActivateRegistry(int argc,
   }
 }
 
-void Session_ServerThread::ActivateContainerManager(int /*argc*/, char** /*argv*/)
+template<class MY_NS>
+void Session_ServerThread<MY_NS>::ActivateContainerManager(int /*argc*/, char** /*argv*/)
 {
-  try {
-    PortableServer::POA_var root_poa=PortableServer::POA::_the_root_poa();
-    std::cout << "Activate SalomeLauncher ......!!!! " << std::endl;
-    new SALOME_Launcher(_orb,root_poa);
-  }
-  catch(CORBA::SystemException&) {
-    INFOS("Caught CORBA::SystemException.");
-  }
-  catch(PortableServer::POA::WrongPolicy&) {
-    INFOS("Caught CORBA::WrongPolicyException.");
-  }
-  catch(PortableServer::POA::ServantAlreadyActive&) {
-    INFOS("Caught CORBA::ServantAlreadyActiveException");
-  }
-  catch(CORBA::Exception&) {
-    INFOS("Caught CORBA::Exception.");
-  }
-  catch(...) {
-    INFOS("Caught unknown exception.");
-  }
+  this->_NS->activateContainerManager(this->_orb);
 }
 
-void Session_ServerThread::ActivateContainer(int argc, char** argv)
+template<class MY_NS>
+typename MY_NS::RealNS *Session_ServerThread<MY_NS>::getNS()
 {
-  try {
-    MESSAGE("Container thread started");
-    
-    // get or create the child POA
-    
-    PortableServer::POA_var factory_poa;
-    try {
-      factory_poa = _root_poa->find_POA("factory_poa",0);
-      // 0 = no activation (already done if exists)
-    }
-    catch (PortableServer::POA::AdapterNonExistent&) {
-      MESSAGE("factory_poa does not exists, create...");
-      // define policy objects     
-      PortableServer::ImplicitActivationPolicy_var implicitActivation =
-        _root_poa->create_implicit_activation_policy(PortableServer::NO_IMPLICIT_ACTIVATION);
-      // default = NO_IMPLICIT_ACTIVATION
-      PortableServer::ThreadPolicy_var threadPolicy =
-        _root_poa->create_thread_policy(PortableServer::ORB_CTRL_MODEL);
-      // default = ORB_CTRL_MODEL, other choice SINGLE_THREAD_MODEL
-      
-      // create policy list
-      CORBA::PolicyList policyList;
-      policyList.length(2);
-      policyList[0] = PortableServer::ImplicitActivationPolicy::
-        _duplicate(implicitActivation);
-      policyList[1] = PortableServer::ThreadPolicy::
-        _duplicate(threadPolicy);
-      
-      PortableServer::POAManager_var nil_mgr
-        = PortableServer::POAManager::_nil();
-      factory_poa = _root_poa->create_POA("factory_poa",
-                                          nil_mgr,
-                                          policyList);
-      //with nil_mgr instead of pman,
-      //a new POA manager is created with the new POA
-      
-      // destroy policy objects
-      implicitActivation->destroy();
-      threadPolicy->destroy();
-      
-      // obtain the factory poa manager
-      PortableServer::POAManager_var pmanfac = factory_poa->the_POAManager();
-      pmanfac->activate();
-      MESSAGE("pmanfac->activate()");
-    }
-    
-    char *containerName = (char*)"";
-    if (argc >1) {
-      containerName = argv[1];
-    }
-    
-    _container = new Engines_Container_i(_orb, _root_poa, containerName, argc, argv, true, false);
-  }
-  catch(CORBA::SystemException&) {
-    INFOS("Caught CORBA::SystemException.");
-  }
-  catch(PortableServer::POA::WrongPolicy&) {
-    INFOS("Caught CORBA::WrongPolicyException.");
-  }
-  catch(PortableServer::POA::ServantAlreadyActive&) {
-    INFOS("Caught CORBA::ServantAlreadyActiveException");
-  }
-  catch(CORBA::Exception&) {
-    INFOS("Caught CORBA::Exception.");
-  }
-  catch(...) {
-    INFOS("Caught unknown exception.");
-  }
+  MY_NS *pt(_NS.get());
+  if(!pt)
+     THROW_SALOME_EXCEPTION("Session_ServerThread<MY_NS>::getNS : null pointer !");
+  return pt->getNS();
+}
+
+template<class MY_NS>
+void Session_ServerThread<MY_NS>::ActivateContainer(int argc, char** argv)
+{
+  _container = this->_NS->activateContainer(this->_orb,this->_root_poa,argc,argv);
 }
 
-void Session_ServerThread::ActivateSession(int /*argc*/, char** /*argv*/)
+template<class MY_NS>
+void Session_ServerThread<MY_NS>::ActivateSession(int /*argc*/, char** /*argv*/)
 {
   MESSAGE("Session_ServerThread::ActivateSession() not implemented!");
 }
 
-/*! 
-  constructor 
-*/
-Session_SessionThread::Session_SessionThread(int argc,
+template<class MY_NS>
+Session_SessionThread<MY_NS>::Session_SessionThread(int argc,
                                              char** argv, 
                                              CORBA::ORB_ptr orb, 
                                              PortableServer::POA_ptr poa,
                                              QMutex* GUIMutex,
                                              QWaitCondition* GUILauncher)
-: Session_ServerThread(argc, argv, orb, poa),
+: Session_ServerThread<MY_NS>(argc, argv, orb, poa),
   _GUIMutex( GUIMutex ),
   _GUILauncher( GUILauncher )
 {
 }
 
-/*! 
-  destructor 
-*/
-Session_SessionThread::~Session_SessionThread()
+template<class MY_NS>
+Session_SessionThread<MY_NS>::~Session_SessionThread()
 {
 }
 
-void Session_SessionThread::ActivateSession(int argc,
-                                            char ** argv)
+template<class MY_NS>
+void Session_SessionThread<MY_NS>::ActivateSession(int argc, char ** argv)
 {
-  try {
-    MESSAGE("Session thread started");
-    SALOME_Session_i * mySALOME_Session
-      = new SALOME_Session_i(argc, argv, _orb, _root_poa, _GUIMutex, _GUILauncher) ;
-    PortableServer::ObjectId_var mySALOME_Sessionid
-      = _root_poa->activate_object(mySALOME_Session);
-    MESSAGE("poa->activate_object(mySALOME_Session)");
-    
-    CORBA::Object_var obj = mySALOME_Session->_this();
-    CORBA::String_var sior(_orb->object_to_string(obj));
-    mySALOME_Session->_remove_ref();
-    
-    mySALOME_Session->NSregister();
-  }
-  catch (CORBA::SystemException&) {
-    INFOS("Caught CORBA::SystemException.");
-  }
-  catch (CORBA::Exception&) {
-    INFOS("Caught CORBA::Exception.");
-  }
-  catch (...) {
-    INFOS("Caught unknown exception.");
-  }
+  this->_NS->activateSession(this->_orb,this->_root_poa,_GUIMutex,_GUILauncher,argc,argv);
 }
+
+template class Session_ServerThread<OldStyleNS>;
+template class Session_SessionThread<OldStyleNS>;
+
+template class Session_ServerThread<NewStyleNS>;
+template class Session_SessionThread<NewStyleNS>;
index 1ea0db34aae4322ce0f6d54b0c5df08d3f787b61..a10aca6dc54dbf3ca47a3fa57a8dce7b975ef70e 100644 (file)
 #ifndef _SESSION_SERVERTHREAD_HXX_
 #define _SESSION_SERVERTHREAD_HXX_
 
+#include "Session_NS_wrapper.hxx"
 #include "SALOME_Session.hxx"
 
 #include <omniORB4/CORBA.h> 
 #include <string>
+#include <memory>
 
 void WaitForServerReadiness(std::string serverName);
 
 class SALOME_NamingService;
 class Engines_Container_i;
 
+template<class MY_NS>
 class SESSION_EXPORT Session_ServerThread
 {
+public:
+  using RealNS = typename MY_NS::RealNS;
 public:
   static const int NB_SRV_TYP;
   static const char* _serverTypes[];
@@ -59,20 +64,22 @@ protected:
   virtual void ActivateSession         ( int argc, char ** argv );
   void         ActivateEngine          ( int argc, char ** argv );
   void         ActivateContainerManager( int argc, char ** argv );
+  RealNS *getNS();
 protected:
   int                     _argc;
   char **                 _argv;
   int                     _servType;
   CORBA::ORB_var          _orb;
   PortableServer::POA_var _root_poa;
-  SALOME_NamingService *  _NS;
+  std::unique_ptr<MY_NS>  _NS;
   Engines_Container_i*    _container;
 };
 
 class QMutex;
 class QWaitCondition;
 
-class SESSION_EXPORT Session_SessionThread : public Session_ServerThread
+template<class MY_NS>
+class SESSION_EXPORT Session_SessionThread : public Session_ServerThread<MY_NS>
 {
 public:
   Session_SessionThread() {}
@@ -85,11 +92,10 @@ public:
   virtual ~Session_SessionThread();  
 
 protected:
-  virtual void ActivateSession       ( int argc, char ** argv );
+  void ActivateSession       ( int argc, char ** argv ) override;
 private:
   QMutex*                 _GUIMutex;
   QWaitCondition*         _GUILauncher;
 };
 
 #endif
-
index 2cb7cacf6d9664b7d34804cca7d1b17a4ef073f1..60ddf437e9f7e14c5007200487a8f6c28fab233e 100644 (file)
 #include <unistd.h>
 #endif
 
-/*!
-  constructor
-*/
-SALOME_Session_i::SALOME_Session_i(int argc,
-                                   char ** argv,
-                                   CORBA::ORB_ptr orb,
-                                   PortableServer::POA_ptr poa,
-                                   QMutex* GUIMutex,
-                                   QWaitCondition* GUILauncher)
+SALOME_Session_i::SALOME_Session_i(int argc, char ** argv, CORBA::ORB_ptr orb, PortableServer::POA_ptr poa, QMutex* GUIMutex, QWaitCondition* GUILauncher):
+_argc(argc),_argv(argv),_isGUI(false),_GUIMutex(GUIMutex),_GUILauncher(GUILauncher),
+_orb(CORBA::ORB::_duplicate(orb)),_poa(PortableServer::POA::_duplicate(poa)),_isShuttingDown(false)
 {
-  _argc = argc ;
-  _argv = argv ;
-  _isGUI = false ;
-  _orb = CORBA::ORB::_duplicate(orb) ;
-  _poa = PortableServer::POA::_duplicate(poa) ;
-  _GUIMutex = GUIMutex;
-  _GUILauncher = GUILauncher;
-  _NS = new SALOME_NamingService(_orb);
-  _isShuttingDown = false;
-  //MESSAGE("constructor end");
+  _NS.reset(new SALOME_NamingService(_orb));
+}
+
+SALOME_Session_i::SALOME_Session_i(int argc, char ** argv, CORBA::ORB_ptr orb, PortableServer::POA_ptr poa, QMutex* GUIMutex, QWaitCondition* GUILauncher, SALOME_NamingService_Abstract *NS):
+_argc(argc),_argv(argv),_isGUI(false),_GUIMutex(GUIMutex),_GUILauncher(GUILauncher),
+_orb(CORBA::ORB::_duplicate(orb)),_poa(PortableServer::POA::_duplicate(poa)),_isShuttingDown(false)
+{
+  _NS.reset(NS);
 }
 
 /*!
@@ -79,13 +71,14 @@ SALOME_Session_i::SALOME_Session_i(int argc,
 */
 Engines::EngineComponent_ptr SALOME_Session_i::GetComponent(const char* theLibraryName)
 {
-  typedef Engines::EngineComponent_ptr TGetImpl(CORBA::ORB_ptr,
-                                                PortableServer::POA_ptr,
-                                                SALOME_NamingService*,QMutex*);
+  using TGetImpl = Engines::EngineComponent_ptr (*)(CORBA::ORB_ptr, PortableServer::POA_ptr, SALOME_NamingService*,QMutex*);
   OSD_SharedLibrary aSharedLibrary(const_cast<char*>(theLibraryName));
   if (aSharedLibrary.DlOpen(OSD_RTLD_LAZY)) {
     if (OSD_Function anOSDFun = aSharedLibrary.DlSymb("GetImpl"))
-      return ((TGetImpl (*)) anOSDFun)(_orb,_poa,_NS,_GUIMutex);
+    {
+      Engines::EngineComponent_ptr ret = ((TGetImpl) anOSDFun)(_orb,_poa,dynamic_cast<SALOME_NamingService*>(_NS.get()),_GUIMutex);
+      return ret;
+    }
   }
   CORBA::Object_var obj = SalomeApp_Engine_i::EngineForComponent(theLibraryName, true);
   if (!CORBA::is_nil(obj)){
@@ -100,7 +93,6 @@ Engines::EngineComponent_ptr SALOME_Session_i::GetComponent(const char* theLibra
 */
 SALOME_Session_i::~SALOME_Session_i()
 {
-  delete _NS;
   //MESSAGE("destructor end");
 }
 
index a61fe7c334c1461dceac20f439bf7371895e1bdc..1d9d5e850dcba56a9834dba4f1b10a0f0b245dc0 100644 (file)
 #include <SALOMEconfig.h>
 #include CORBA_SERVER_HEADER(SALOME_Component)
 #include CORBA_SERVER_HEADER(SALOME_Session)
-class SALOME_NamingService;
+
+#include <memory>
 
 class QMutex;
 class QWaitCondition;
+class SALOME_NamingService_Abstract;
 
-class SESSION_EXPORT SALOME_Session_i:  public virtual POA_SALOME::Session,
-                         public virtual PortableServer::ServantBase
+class SESSION_EXPORT SALOME_Session_i :  public virtual POA_SALOME::Session, public virtual PortableServer::ServantBase
 {
 public:
-  SALOME_Session_i(int argc, 
-                   char ** argv, 
-                   CORBA::ORB_ptr orb, 
-                   PortableServer::POA_ptr poa, 
-                   QMutex* GUIMutex,
-                   QWaitCondition* GUILauncher);
+  SALOME_Session_i(int argc, char ** argv, CORBA::ORB_ptr orb, PortableServer::POA_ptr poa, QMutex* GUIMutex, QWaitCondition* GUILauncher);
+  SALOME_Session_i(int argc, char ** argv, CORBA::ORB_ptr orb, PortableServer::POA_ptr poa, QMutex* GUIMutex, QWaitCondition* GUILauncher, SALOME_NamingService_Abstract *NS);
   ~SALOME_Session_i();
 
   //! Launch Graphical User Interface
@@ -85,7 +82,7 @@ public:
 protected:
 
   //! Naming service interface
-  SALOME_NamingService *_NS;
+  std::unique_ptr<SALOME_NamingService_Abstract> _NS;
 
   int _argc ;
   char **_argv;
diff --git a/src/Session/salome2810.cxx b/src/Session/salome2810.cxx
new file mode 100644 (file)
index 0000000..76f831f
--- /dev/null
@@ -0,0 +1,96 @@
+// Copyright (C) 2021  CEA/DEN,EDF R&D
+//
+// 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, or (at your option) any later version.
+//
+// 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include <QProcessEnvironment>
+#include <QDir>
+#include <QProcess>
+
+#include <iostream>
+
+int main(int argc, char *argv[])
+{
+  constexpr char MAIN_PROGRAM[] = "SALOME_Session_Server_No_Server";
+  constexpr char NO_SERVER_ENV_VAR[] = "SALOME_EMB_SERVANT";
+  const char *MODULES[]={"SHAPERSTUDY","GEOM","SMESH","HYBRIDPLUGIN","GHS3DPLUGIN","BLSURFPLUGIN","GMSHPLUGIN","HEXABLOCKPLUGIN","HEXOTICPLUGIN","GHS3DPRLPLUGIN","NETGENPLUGIN"};
+  const char *MODULES_PATH[]={"GUI","SHAPER","SHAPERSTUDY","GEOM","SMESH","HYBRIDPLUGIN","GHS3DPLUGIN","BLSURFPLUGIN","GMSHPLUGIN","HEXABLOCKPLUGIN","GHS3DPRLPLUGIN","NETGENPLUGIN"};
+  constexpr char APPCONFIG[]="SalomeAppSLConfig";
+  QProcessEnvironment pe(QProcessEnvironment::systemEnvironment());
+  QStringList modulesPaths;
+  for(auto elt : MODULES_PATH)
+  {
+    QString elt_root_dir( QString("%1_ROOT_DIR").arg(elt) );
+    if( !pe.contains(elt_root_dir) || pe.value(elt_root_dir).isEmpty() )
+    {
+      std::cerr << elt_root_dir.toStdString() << " is not defined in your environment !" << std::endl;
+      return 1;
+    }
+    modulesPaths << QDir::fromNativeSeparators( QString("%1/share/salome/resources/%2").arg( pe.value(elt_root_dir) ).arg( QString(elt).toLower() ) );
+  }
+  // fill LightAppConfig env var
+  QString appconfig_val( modulesPaths.join(":"));
+  pe.insert(APPCONFIG,appconfig_val);
+  //tells shutup to salome.salome_init invoked at shaper engine ignition
+  pe.insert(NO_SERVER_ENV_VAR,"1");
+  //resource file retrieve
+  QString resfile;
+  {
+    QProcess proc;
+    proc.setProcessEnvironment(pe);
+    proc.setProgram("python3");
+    proc.setArguments({"-c","from launchConfigureParser import userFile ; import sys ; sys.stdout.write(userFile(\"SalomeApp\",\"salome\"))"});
+    proc.start();
+    proc.waitForFinished(-1);
+    if(proc.exitStatus() != QProcess::NormalExit)
+    {
+      std::cerr << "Fail to retrieve resource file from launchConfigureParser python module !" << std::endl;
+      return 1;
+    }
+    QByteArray val(proc.readAllStandardOutput());
+    resfile = QString::fromUtf8(val);
+  }
+  //
+  QProcess proc;
+  proc.setProcessEnvironment(pe);
+  proc.setProgram(MAIN_PROGRAM);
+
+  QStringList args({"--with","Registry","(","--salome_session","theSession",")","--with","ModuleCatalog","(","-common"});
+  QStringList catalogs;
+  for(std::size_t im = 0 ; im < sizeof(MODULES)/sizeof(decltype(MODULES[0])) ; ++im )
+  {
+    QString root_dir = pe.value( QString("%1_ROOT_DIR").arg(MODULES[im]) );
+    catalogs << QDir::toNativeSeparators( QString("%1/share/salome/resources/%2/%3Catalog.xml").arg(root_dir).arg(QString(MODULES[im]).toLower()).arg(MODULES[im]) );
+  }
+  args << catalogs.join("::");
+  args << ")";
+  args << "--with" << "SALOMEDS" <<  "(" << ")" << "--with" << "Container" << "(" << "FactoryServer" << ")" << "--with" << "SalomeAppEngine" << "(" << ")" << "CPP";
+  args << QString("--resources=%1").arg(resfile) << "--modules" << "(SHAPER:GEOM:SMESH)";
+  if( pe.contains("VERBOSE") )
+  {
+    std::cout << "Overloaded env var :" << std::endl;
+    std::cout << " - " << NO_SERVER_ENV_VAR << std::endl;
+    std::cout << " - " << APPCONFIG << " = " << appconfig_val.toStdString() << std::endl;
+    std::cout << "Command launched :" << std::endl;
+    std::cout << MAIN_PROGRAM << " " << args.join(" ").toStdString() << std::endl;
+  }
+  proc.setArguments(args);
+  proc.setProcessChannelMode( QProcess::ForwardedErrorChannel );
+  proc.start();
+  proc.waitForFinished(-1);
+  return proc.exitCode();
+}