From 9ee7121c89dee1b85745c54ffef953855c6b8041 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Thu, 18 Feb 2021 10:13:14 +0100 Subject: [PATCH] GUI evolutions for salome gui without neither NS nor other servers. --- CMakeLists.txt | 2 +- SalomeGUIConfig.cmake.in | 2 + src/STD/STD_Application.cxx | 2 +- src/SalomeApp/CMakeLists.txt | 18 +- src/SalomeApp/SalomeApp_Application.cxx | 22 +- src/SalomeApp/SalomeApp_Application.h | 8 +- src/SalomeApp/SalomeApp_Application_Entry.cxx | 26 + src/SalomeApp/SalomeApp_Application_SL.cxx | 26 + src/SalomeApp/SalomeApp_Application_SL.h | 28 + .../SalomeApp_Application_SL_Entry.cxx | 26 + src/SalomeApp/SalomeApp_Engine_i.cxx | 5 +- src/SalomeApp/SalomeApp_Engine_i.h | 4 +- src/Session/CMakeLists.txt | 14 +- src/Session/SALOME_Session_Server.cxx | 530 ++++++++++-------- .../SALOME_Session_Server_No_Server.cxx | 26 + .../SALOME_Session_Server_With_Server.cxx | 25 + src/Session/Session_NS_wrapper.cxx | 264 +++++++++ src/Session/Session_NS_wrapper.hxx | 73 +++ src/Session/Session_Promises.cxx | 26 + src/Session/Session_Promises.hxx | 27 + src/Session/Session_ServerCheck.cxx | 92 ++- src/Session/Session_ServerCheck.hxx | 1 + src/Session/Session_ServerLauncher.cxx | 67 ++- src/Session/Session_ServerLauncher.hxx | 6 +- src/Session/Session_ServerThread.cxx | 249 +++----- src/Session/Session_ServerThread.hxx | 14 +- src/Session/Session_Session_i.cxx | 40 +- src/Session/Session_Session_i.hxx | 17 +- src/Session/salome2810.cxx | 96 ++++ 29 files changed, 1180 insertions(+), 556 deletions(-) create mode 100644 src/SalomeApp/SalomeApp_Application_Entry.cxx create mode 100644 src/SalomeApp/SalomeApp_Application_SL.cxx create mode 100644 src/SalomeApp/SalomeApp_Application_SL.h create mode 100644 src/SalomeApp/SalomeApp_Application_SL_Entry.cxx create mode 100644 src/Session/SALOME_Session_Server_No_Server.cxx create mode 100644 src/Session/SALOME_Session_Server_With_Server.cxx create mode 100644 src/Session/Session_NS_wrapper.cxx create mode 100644 src/Session/Session_NS_wrapper.hxx create mode 100644 src/Session/Session_Promises.cxx create mode 100644 src/Session/Session_Promises.hxx create mode 100644 src/Session/salome2810.cxx diff --git a/CMakeLists.txt b/CMakeLists.txt index 9d401f948..8f67a2d97 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/SalomeGUIConfig.cmake.in b/SalomeGUIConfig.cmake.in index d24b44d3b..925c10c24 100644 --- a/SalomeGUIConfig.cmake.in +++ b/SalomeGUIConfig.cmake.in @@ -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) diff --git a/src/STD/STD_Application.cxx b/src/STD/STD_Application.cxx index 4a391e348..fab945969 100644 --- a/src/STD/STD_Application.cxx +++ b/src/STD/STD_Application.cxx @@ -114,7 +114,7 @@ void STD_Application::closeApplication() study->closeDocument(); emit appClosed(); setActiveStudy( 0 ); - delete study; + //delete study; afterCloseDoc(); } diff --git a/src/SalomeApp/CMakeLists.txt b/src/SalomeApp/CMakeLists.txt index 10ae94a81..ed06db29b 100644 --- a/src/SalomeApp/CMakeLists.txt +++ b/src/SalomeApp/CMakeLists.txt @@ -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}) diff --git a/src/SalomeApp/SalomeApp_Application.cxx b/src/SalomeApp/SalomeApp_Application.cxx index bfb209efa..d5cc4fb44 100644 --- a/src/SalomeApp/SalomeApp_Application.cxx +++ b/src/SalomeApp/SalomeApp_Application.cxx @@ -110,6 +110,8 @@ #include +std::unique_ptr 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_NamingService* SalomeApp_Application::namingService() +SALOME_NamingService_Abstract *SalomeApp_Application::namingService() { - static SALOME_NamingService _ns(orb()); - return &_ns; + return _ns.get(); } /*!Create and return SALOME_LifeCycleCORBA.*/ diff --git a/src/SalomeApp/SalomeApp_Application.h b/src/SalomeApp/SalomeApp_Application.h index 5f4da65f0..a29b67c21 100644 --- a/src/SalomeApp/SalomeApp_Application.h +++ b/src/SalomeApp/SalomeApp_Application.h @@ -44,6 +44,8 @@ #include +#include + 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 _ns; }; #ifdef WIN32 diff --git a/src/SalomeApp/SalomeApp_Application_Entry.cxx b/src/SalomeApp/SalomeApp_Application_Entry.cxx new file mode 100644 index 000000000..4af758f7c --- /dev/null +++ b/src/SalomeApp/SalomeApp_Application_Entry.cxx @@ -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 index 000000000..def6831ad --- /dev/null +++ b/src/SalomeApp/SalomeApp_Application_SL.cxx @@ -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 index 000000000..9d9b735ac --- /dev/null +++ b/src/SalomeApp/SalomeApp_Application_SL.h @@ -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 index 000000000..9094003cd --- /dev/null +++ b/src/SalomeApp/SalomeApp_Application_SL_Entry.cxx @@ -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; +} diff --git a/src/SalomeApp/SalomeApp_Engine_i.cxx b/src/SalomeApp/SalomeApp_Engine_i.cxx index 4f5a82f00..cc3742d7c 100644 --- a/src/SalomeApp/SalomeApp_Engine_i.cxx +++ b/src/SalomeApp/SalomeApp_Engine_i.cxx @@ -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(); } /*! diff --git a/src/SalomeApp/SalomeApp_Engine_i.h b/src/SalomeApp/SalomeApp_Engine_i.h index 2b4137a52..9de78b810 100644 --- a/src/SalomeApp/SalomeApp_Engine_i.h +++ b/src/SalomeApp/SalomeApp_Engine_i.h @@ -38,7 +38,7 @@ #include #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; diff --git a/src/Session/CMakeLists.txt b/src/Session/CMakeLists.txt index 50358adae..8e525a27b 100644 --- a/src/Session/CMakeLists.txt +++ b/src/Session/CMakeLists.txt @@ -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}") diff --git a/src/Session/SALOME_Session_Server.cxx b/src/Session/SALOME_Session_Server.cxx index 0bf8344fd..13271628d 100644 --- a/src/Session/SALOME_Session_Server.cxx +++ b/src/Session/SALOME_Session_Server.cxx @@ -21,7 +21,7 @@ // #include // this include must be the first one as it includes Python.h -#include +#include #include #include #include @@ -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 #endif #include +#include #include #include @@ -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/ 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_ExceptionHandler* handler() 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_ExceptionHandler* myHandler; + 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 +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 _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_::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 +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 /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 *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_::Instance(); - ASSERT( SINGLETON_::IsAlreadyExisting() ); + ASSERT(SINGLETON_::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(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(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 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( poa->reference_to_servant( session.in() ) ); - if ( sessionServant ) + SALOME_Session_i *sessionServant = + dynamic_cast(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_::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 index 000000000..596f9ad05 --- /dev/null +++ b/src/Session/SALOME_Session_Server_No_Server.cxx @@ -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(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 index 000000000..1479f7549 --- /dev/null +++ b/src/Session/SALOME_Session_Server_With_Server.cxx @@ -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(argc, argv); +} diff --git a/src/Session/Session_NS_wrapper.cxx b/src/Session/Session_NS_wrapper.cxx new file mode 100644 index 000000000..a5dd110a7 --- /dev/null +++ b/src/Session/Session_NS_wrapper.cxx @@ -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_::Instance(); + CORBA::ORB_var orb = init( argc, argv ); + SALOME_NamingService &NS = *SINGLETON_::Instance(); + ASSERT( SINGLETON_::IsAlreadyExisting() ); + NS.init_orb( orb ); + CORBA::Object_var obj = NS.Resolve( NSName ); + return obj; +} + +CosNaming::NamingContext_var OldStyleNS::checkTrueNamingServiceIfExpected(int argc, char **argv, bool& forceOK) +{ + forceOK = false;//tell checker : do as before + ORB_INIT& init = *SINGLETON_::Instance(); + CORBA::ORB_var orb = init( argc, argv ); + CORBA::Object_var obj = orb->resolve_initial_references( "NameService" ); + CosNaming::NamingContext_var _root_context = CosNaming::NamingContext::_narrow( obj ); + return _root_context; +} + +#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 index 000000000..85518aff0 --- /dev/null +++ b/src/Session/Session_NS_wrapper.hxx @@ -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 index 000000000..b3a8d7dce --- /dev/null +++ b/src/Session/Session_Promises.cxx @@ -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 *GetSessionRefSingleton() +{ + static std::promise _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 index 000000000..be471593e --- /dev/null +++ b/src/Session/Session_Promises.hxx @@ -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 + +std::promise *GetSessionRefSingleton(); diff --git a/src/Session/Session_ServerCheck.cxx b/src/Session/Session_ServerCheck.cxx index 1a1e6a94b..f43a218c8 100644 --- a/src/Session/Session_ServerCheck.cxx +++ b/src/Session/Session_ServerCheck.cxx @@ -87,7 +87,8 @@ const int __DEFAULT__DELAY__ = 50000; \internal */ -class Session_ServerCheck::Locker +template +class Session_ServerCheck::Locker { public: /*! @@ -135,7 +136,8 @@ private: \param mutex a mutex used to serialize progress operations (splash) \param wc a wait condition used in combination with \a mutex */ -Session_ServerCheck::Session_ServerCheck( QMutex* mutex, QWaitCondition* wc ) +template +Session_ServerCheck::Session_ServerCheck( QMutex* mutex, QWaitCondition* wc ) : QThread(), myMutex( mutex ), myWC( wc ), @@ -169,7 +171,8 @@ Session_ServerCheck::Session_ServerCheck( QMutex* mutex, QWaitCondition* wc ) /*! \brief Destructor */ -Session_ServerCheck::~Session_ServerCheck() +template +Session_ServerCheck::~Session_ServerCheck() { terminate(); while( isRunning() ); @@ -179,7 +182,8 @@ Session_ServerCheck::~Session_ServerCheck() \brief Get current information message. \return current message */ -QString Session_ServerCheck::currentMessage() +template +QString Session_ServerCheck::currentMessage() { static QStringList messages; if ( messages.isEmpty() ) { @@ -204,7 +208,8 @@ QString Session_ServerCheck::currentMessage() \brief Get error message. \return error message or null string of there was no any error */ -QString Session_ServerCheck::error() +template +QString Session_ServerCheck::error() { QMutexLocker locker( &myDataMutex ); return myError; @@ -214,7 +219,8 @@ QString Session_ServerCheck::error() \brief Get current step. \return current step */ -int Session_ServerCheck::currentStep() +template +int Session_ServerCheck::currentStep() { QMutexLocker locker( &myDataMutex ); return myCurrentStep; @@ -224,7 +230,8 @@ int Session_ServerCheck::currentStep() \brief Get total number of check steps. \return total number of steps */ -int Session_ServerCheck::totalSteps() +template +int Session_ServerCheck::totalSteps() { QMutexLocker locker( &myDataMutex ); int cnt = 5; // base servers @@ -238,7 +245,8 @@ int Session_ServerCheck::totalSteps() \brief Modify current step. \param step new current step value */ -void Session_ServerCheck::setStep( const int step ) +template +void Session_ServerCheck::setStep( const int step ) { QMutexLocker locker( &myDataMutex ); myCurrentStep = step; @@ -248,7 +256,8 @@ void Session_ServerCheck::setStep( const int step ) \brief Set error message. \param msg error message */ -void Session_ServerCheck::setError( const QString& msg ) +template +void Session_ServerCheck::setError( const QString& msg ) { QMutexLocker locker( &myDataMutex ); myError = msg; @@ -257,7 +266,8 @@ void Session_ServerCheck::setError( const QString& msg ) /*! \brief Thread loop function. Performs SALOME servers check. */ -void Session_ServerCheck::run() +template +void Session_ServerCheck::run() { // start check servers int current = 0; @@ -271,11 +281,9 @@ void Session_ServerCheck::run() setStep( current * myAttempts + i ); try { - ORB_INIT& init = *SINGLETON_::Instance(); - CORBA::ORB_var orb = init( args.argc(), args.argv() ); - CORBA::Object_var obj = orb->resolve_initial_references( "NameService" ); - CosNaming::NamingContext_var _root_context = CosNaming::NamingContext::_narrow( obj ); - if ( !CORBA::is_nil( _root_context ) ) { + bool forceOK = false; + CosNaming::NamingContext_var _root_context = MY_NS::checkTrueNamingServiceIfExpected(args.argc(), args.argv(),forceOK); + if ( forceOK || !CORBA::is_nil( _root_context ) ) { setStep( ++current * myAttempts ); break; } @@ -302,12 +310,7 @@ void Session_ServerCheck::run() setStep( current * myAttempts + i ); try { - ORB_INIT& init = *SINGLETON_::Instance(); - CORBA::ORB_var orb = init( args.argc(), args.argv() ); - SALOME_NamingService &NS = *SINGLETON_::Instance(); - ASSERT( SINGLETON_::IsAlreadyExisting() ); - NS.init_orb( orb ); - CORBA::Object_var obj = NS.Resolve( "/Registry" ); + CORBA::Object_var obj = MY_NS::forServerChecker("/Registry", args.argc(), args.argv()); Registry::Components_var registry = Registry::Components::_narrow( obj ); if ( !CORBA::is_nil( registry ) ) { MESSAGE( "/Registry is found" ); @@ -351,12 +354,7 @@ void Session_ServerCheck::run() setStep( current * myAttempts + i ); try { - ORB_INIT& init = *SINGLETON_::Instance(); - CORBA::ORB_var orb = init( args.argc(), args.argv() ); - SALOME_NamingService &NS = *SINGLETON_::Instance(); - ASSERT( SINGLETON_::IsAlreadyExisting() ); - NS.init_orb( orb ); - CORBA::Object_var obj = NS.Resolve( "/Study" ); + CORBA::Object_var obj = MY_NS::forServerChecker("/Study", args.argc(), args.argv()); SALOMEDS::Study_var study = SALOMEDS::Study::_narrow( obj ); if ( !CORBA::is_nil( study ) ) { MESSAGE( "/Study is found" ); @@ -400,12 +398,7 @@ void Session_ServerCheck::run() setStep( current * myAttempts + i ); try { - ORB_INIT& init = *SINGLETON_::Instance(); - CORBA::ORB_var orb = init( args.argc(), args.argv() ); - SALOME_NamingService &NS = *SINGLETON_::Instance(); - ASSERT( SINGLETON_::IsAlreadyExisting() ); - NS.init_orb( orb ); - CORBA::Object_var obj = NS.Resolve( "/Kernel/ModulCatalog" ); + CORBA::Object_var obj = MY_NS::forServerChecker("/Kernel/ModulCatalog", args.argc(), args.argv()); SALOME_ModuleCatalog::ModuleCatalog_var catalog = SALOME_ModuleCatalog::ModuleCatalog::_narrow( obj ); if ( !CORBA::is_nil( catalog ) ){ MESSAGE( "/Kernel/ModulCatalog is found" ); @@ -449,12 +442,7 @@ void Session_ServerCheck::run() setStep( current * myAttempts + i ); try { - ORB_INIT& init = *SINGLETON_::Instance(); - CORBA::ORB_var orb = init( args.argc(), args.argv() ); - SALOME_NamingService &NS = *SINGLETON_::Instance(); - ASSERT( SINGLETON_::IsAlreadyExisting() ); - NS.init_orb( orb ); - CORBA::Object_var obj = NS.Resolve( "/Kernel/Session" ); + CORBA::Object_var obj = MY_NS::forServerChecker("/Kernel/Session", args.argc(), args.argv()); SALOME::Session_var session = SALOME::Session::_narrow( obj ); if ( !CORBA::is_nil( session ) ) { MESSAGE( "/Kernel/Session is found" ); @@ -499,13 +487,8 @@ void Session_ServerCheck::run() setStep( current * myAttempts + i ); try { - ORB_INIT& init = *SINGLETON_::Instance(); - CORBA::ORB_var orb = init( args.argc(), args.argv() ); - SALOME_NamingService &NS = *SINGLETON_::Instance(); - ASSERT( SINGLETON_::IsAlreadyExisting() ); - NS.init_orb( orb ); QString containerName = QString( "/Containers/%1/FactoryServer" ).arg( Kernel_Utils::GetHostname().c_str() ); - CORBA::Object_var obj = NS.Resolve( containerName.toLatin1() ); + CORBA::Object_var obj = MY_NS::forServerChecker(containerName.toLatin1(), args.argc(), args.argv()); Engines::Container_var FScontainer = Engines::Container::_narrow( obj ); if ( !CORBA::is_nil( FScontainer ) ) { MESSAGE( containerName.toLatin1().constData() << " is found" ); @@ -551,13 +534,8 @@ void Session_ServerCheck::run() setStep( current * myAttempts + i ); try { - ORB_INIT& init = *SINGLETON_::Instance(); - CORBA::ORB_var orb = init( args.argc(), args.argv() ); - SALOME_NamingService &NS = *SINGLETON_::Instance(); - ASSERT( SINGLETON_::IsAlreadyExisting() ); - NS.init_orb( orb ); QString containerName = QString( "/Containers/%1/FactoryServerPy" ).arg( Kernel_Utils::GetHostname().c_str() ); - CORBA::Object_var obj = NS.Resolve( containerName.toLatin1() ); + CORBA::Object_var obj = MY_NS::forServerChecker(containerName.toLatin1(), args.argc(), args.argv()); Engines::Container_var FSPcontainer = Engines::Container::_narrow( obj ); if ( !CORBA::is_nil( FSPcontainer ) ) { MESSAGE( containerName.toLatin1().constData() << " is found" ); @@ -603,13 +581,8 @@ void Session_ServerCheck::run() setStep( current * myAttempts + i ); try { - ORB_INIT& init = *SINGLETON_::Instance(); - CORBA::ORB_var orb = init( args.argc(), args.argv() ); - SALOME_NamingService &NS = *SINGLETON_::Instance(); - ASSERT( SINGLETON_::IsAlreadyExisting() ); - NS.init_orb( orb ); QString containerName = QString( "/Containers/%1/SuperVisionContainer" ).arg( Kernel_Utils::GetHostname().c_str() ); - CORBA::Object_var obj = NS.Resolve( containerName.toLatin1() ); + CORBA::Object_var obj = MY_NS::forServerChecker(containerName.toLatin1(), args.argc(), args.argv()); Engines::Container_var SVcontainer = Engines::Container::_narrow( obj ); if ( !CORBA::is_nil( SVcontainer ) ) { MESSAGE( containerName.toLatin1().constData() << " is found" ); @@ -647,3 +620,8 @@ void Session_ServerCheck::run() } } } + +#include "Session_NS_wrapper.hxx" + +template class Session_ServerCheck; +template class Session_ServerCheck; diff --git a/src/Session/Session_ServerCheck.hxx b/src/Session/Session_ServerCheck.hxx index d6733f7d4..e6aedc60b 100644 --- a/src/Session/Session_ServerCheck.hxx +++ b/src/Session/Session_ServerCheck.hxx @@ -33,6 +33,7 @@ class QWaitCondition; +template class SESSION_EXPORT Session_ServerCheck : public QThread { class Locker; diff --git a/src/Session/Session_ServerLauncher.cxx b/src/Session/Session_ServerLauncher.cxx index 6471c26bc..fd8f638db 100644 --- a/src/Session/Session_ServerLauncher.cxx +++ b/src/Session/Session_ServerLauncher.cxx @@ -36,7 +36,8 @@ /*! default constructor not for use */ -Session_ServerLauncher::Session_ServerLauncher() +template +Session_ServerLauncher::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 +Session_ServerLauncher::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 +Session_ServerLauncher::~Session_ServerLauncher() { } /*! Check args and activate servers */ -void Session_ServerLauncher::run() +template +void Session_ServerLauncher::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 +void Session_ServerLauncher::CheckArgs() { int argState = 0; ServArg aServArg(0,0,0); @@ -135,8 +140,8 @@ void Session_ServerLauncher::CheckArgs() } // Temporary solution - for (int i=0; i::NB_SRV_TYP; i++) + if (strcmp(_argv[iarg],Session_ServerThread::_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::_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 +void Session_ServerLauncher::ActivateAll() { std::list::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::_serverTypes[servType]); if (argc>1) { for (int i=0; i* aServerThread = new Session_ServerThread(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* aServerThread + = new Session_SessionThread(argc, argv, _orb,_root_poa,_SessionMutex,_SessionStarted); _serverThreads.push_front(aServerThread); aServerThread->Init(); delete[] argv; } -void Session_ServerLauncher::ShutdownAll() +template +void Session_ServerLauncher::ShutdownAll() { MESSAGE("Session_ServerLauncher::ShutdownAll()"); - std::list::reverse_iterator itServ; + using Session_ServerThreadT = Session_ServerThread; + typename std::list::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 +void Session_ServerLauncher::KillAll() { MESSAGE("Session_ServerLauncher::KillAll()"); - std::list::reverse_iterator itServ; + using Session_ServerThreadT = Session_ServerThread; + typename std::list::reverse_iterator itServ; for (itServ = _serverThreads.rbegin(); itServ !=_serverThreads.rend(); itServ++) { delete (*itServ); } } + +#include "Session_NS_wrapper.hxx" + +template class Session_ServerLauncher; + +template class Session_ServerLauncher; diff --git a/src/Session/Session_ServerLauncher.hxx b/src/Session/Session_ServerLauncher.hxx index 33e8187a6..719157e40 100644 --- a/src/Session/Session_ServerLauncher.hxx +++ b/src/Session/Session_ServerLauncher.hxx @@ -48,12 +48,14 @@ inline ServArg::ServArg(int servType, int firstArg, int lastArg): _servType(servType),_firstArg(firstArg),_lastArg(lastArg) {} +template class Session_ServerThread; class QMutex; class QWaitCondition; -class SESSION_EXPORT Session_ServerLauncher: public QThread +template +class SESSION_EXPORT Session_ServerLauncher : public QThread { public: Session_ServerLauncher(); @@ -85,7 +87,7 @@ private: QWaitCondition* _SessionStarted; std::list _argServToLaunch; std::vector _argCopy; - std::list _serverThreads; + std::list< Session_ServerThread* > _serverThreads; }; #endif diff --git a/src/Session/Session_ServerThread.cxx b/src/Session/Session_ServerThread.cxx index 0d042a042..84eb438fa 100644 --- a/src/Session/Session_ServerThread.cxx +++ b/src/Session/Session_ServerThread.cxx @@ -25,11 +25,11 @@ // Author : Paul RASCLE, EDF #include "Session_ServerThread.hxx" +#include "Session_Promises.hxx" #include #include #include -#include #include #include @@ -48,18 +48,22 @@ #include #include -const int Session_ServerThread::NB_SRV_TYP = 6; -const char* Session_ServerThread::_serverTypes[NB_SRV_TYP] = {"Container", - "ModuleCatalog", - "Registry", - "SALOMEDS", - "Session", - "ContainerManager"}; +template +const int Session_ServerThread::NB_SRV_TYP = 6; + +template +const char* Session_ServerThread::_serverTypes[NB_SRV_TYP] = {"Container", + "ModuleCatalog", + "Registry", + "SALOMEDS", + "Session", + "ContainerManager"}; /*! default constructor not for use */ -Session_ServerThread::Session_ServerThread() +template +Session_ServerThread::Session_ServerThread() { ASSERT(0); // must not be called } @@ -67,7 +71,8 @@ Session_ServerThread::Session_ServerThread() /*! constructor */ -Session_ServerThread::Session_ServerThread(int argc, +template +Session_ServerThread::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 +Session_ServerThread::~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 +void Session_ServerThread::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 +void Session_ServerThread::Shutdown() { if ( _container ) _container->Shutdown(); } -void Session_ServerThread::ActivateModuleCatalog(int argc, - char ** argv) +template +void Session_ServerThread::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 +void Session_ServerThread::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 +void Session_ServerThread::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 +void Session_ServerThread::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 +typename MY_NS::RealNS *Session_ServerThread::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::getNS : null pointer !"); + return pt->getNS(); +} + +template +void Session_ServerThread::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 +void Session_ServerThread::ActivateSession(int /*argc*/, char** /*argv*/) { MESSAGE("Session_ServerThread::ActivateSession() not implemented!"); } -/*! - constructor -*/ -Session_SessionThread::Session_SessionThread(int argc, +template +Session_SessionThread::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(argc, argv, orb, poa), _GUIMutex( GUIMutex ), _GUILauncher( GUILauncher ) { } -/*! - destructor -*/ -Session_SessionThread::~Session_SessionThread() +template +Session_SessionThread::~Session_SessionThread() { } -void Session_SessionThread::ActivateSession(int argc, - char ** argv) +template +void Session_SessionThread::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; +template class Session_SessionThread; + +template class Session_ServerThread; +template class Session_SessionThread; diff --git a/src/Session/Session_ServerThread.hxx b/src/Session/Session_ServerThread.hxx index 1ea0db34a..a10aca6dc 100644 --- a/src/Session/Session_ServerThread.hxx +++ b/src/Session/Session_ServerThread.hxx @@ -27,18 +27,23 @@ #ifndef _SESSION_SERVERTHREAD_HXX_ #define _SESSION_SERVERTHREAD_HXX_ +#include "Session_NS_wrapper.hxx" #include "SALOME_Session.hxx" #include #include +#include void WaitForServerReadiness(std::string serverName); class SALOME_NamingService; class Engines_Container_i; +template 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 _NS; Engines_Container_i* _container; }; class QMutex; class QWaitCondition; -class SESSION_EXPORT Session_SessionThread : public Session_ServerThread +template +class SESSION_EXPORT Session_SessionThread : public Session_ServerThread { 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 - diff --git a/src/Session/Session_Session_i.cxx b/src/Session/Session_Session_i.cxx index 2cb7cacf6..60ddf437e 100644 --- a/src/Session/Session_Session_i.cxx +++ b/src/Session/Session_Session_i.cxx @@ -52,26 +52,18 @@ #include #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(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(_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"); } diff --git a/src/Session/Session_Session_i.hxx b/src/Session/Session_Session_i.hxx index a61fe7c33..1d9d5e850 100644 --- a/src/Session/Session_Session_i.hxx +++ b/src/Session/Session_Session_i.hxx @@ -31,21 +31,18 @@ #include #include CORBA_SERVER_HEADER(SALOME_Component) #include CORBA_SERVER_HEADER(SALOME_Session) -class SALOME_NamingService; + +#include 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 _NS; int _argc ; char **_argv; diff --git a/src/Session/salome2810.cxx b/src/Session/salome2810.cxx new file mode 100644 index 000000000..76f831f1e --- /dev/null +++ b/src/Session/salome2810.cxx @@ -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 +#include +#include + +#include + +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(); +} -- 2.39.2