# 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
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)
study->closeDocument();
emit appClosed();
setActiveStudy( 0 );
- delete study;
+ //delete study;
afterCloseDoc();
}
# --- 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
# sources / static
SET(_other_SOURCES
+ SalomeApp_Application_SL.cxx
SalomeApp_Application.cxx
SalomeApp_CheckFileDlg.cxx
SalomeApp_DataModel.cxx
# --- 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}")
#include <SALOMEDS_Tool.hxx>
+std::unique_ptr<SALOME_NamingService_Abstract> SalomeApp_Application::_ns;
+
/*!Internal class that updates object browser item properties */
// temporary commented
/*class SalomeApp_Updater : public OB_Updater
};
}
-/*!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.
}
/*!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.*/
#include <QPointer>
+#include <memory>
+
class LightApp_Preferences;
class SalomeApp_Study;
#ifndef DISABLE_PYCONSOLE
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 );
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&);
bool theIsStudySaved );
void notebookVarUpdated( QString theVarName );
void objectDoubleClicked( SUIT_DataObject* );
+protected:
+ static std::unique_ptr<SALOME_NamingService_Abstract> _ns;
};
#ifdef WIN32
--- /dev/null
+// 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;
+}
--- /dev/null
+// 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 )
+{
+}
--- /dev/null
+// 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();
+};
--- /dev/null
+// 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;
+}
/*!
\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();
}
/*!
#include <SALOMEconfig.h>
#include CORBA_SERVER_HEADER(SalomeApp_Engine)
-class SALOME_NamingService;
+class SALOME_NamingService_Abstract;
class SALOMEAPP_EXPORT SalomeApp_Engine_i: public POA_SalomeApp::Engine,
public Engines_Component_i
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;
Session_ServerLauncher.hxx
Session_ServerThread.hxx
Session_Session_i.hxx
+ Session_Promises.hxx
+ Session_NS_wrapper.hxx
)
# --- resources ---
Session_ServerLauncher.cxx
Session_ServerThread.cxx
Session_Session_i.cxx
+ Session_Promises.cxx
+ Session_NS_wrapper.cxx
)
# --- rules ---
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}")
//
#include <Container_init_python.hxx> // this include must be the first one as it includes Python.h
-#include <Basics_Utils.hxx>
+#include <Basics_Utils.hxx>
#include <ConnectionManager_i.hxx>
#include <OpUtil.hxx>
#include <RegistryService.hxx>
#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"
#include <shellapi.h>
#endif
#include <time.h>
+#include <memory>
#include <QApplication>
#include <QDir>
namespace
{
- std::string handleCorbaException( const CORBA::Exception& e )
+ std::string handleCorbaException(const CORBA::Exception &e)
{
std::string message;
CORBA::Any tmp;
}
//! 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;
}
}
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; }
// 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
// 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.
//////////////////////////////////////////////////////////////////////////////////////////////
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)
// VSR 24/09/2012: issue 0021781: since version 6.6.0 user filename is not prepended with "."
// when it is stored in the ~/.config/<appname> directory;
// for backward compatibility we also check files prepended with "." with lower priority
- QRegExp exp( QString( "\\.?%1rc\\.([a-zA-Z0-9.]+)" ).arg( myCustomAppName ) );
+ QRegExp exp(QString("\\.?%1rc\\.([a-zA-Z0-9.]+)").arg(myCustomAppName));
#endif
- QString fname = QFileInfo( _fname ).fileName();
- if ( exp.exactMatch( fname ) ) {
- long fid = Qtx::versionToId( exp.cap( 1 ) );
- if ( fid > 0 ) id = fid;
+ QString fname = QFileInfo(_fname).fileName();
+ if (exp.exactMatch(fname))
+ {
+ long fid = Qtx::versionToId(exp.cap(1));
+ if (fid > 0)
+ id = fid;
}
}
return id;
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);
}
};
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;
};
class GetInterfaceThread : public QThread
{
public:
- GetInterfaceThread( SALOME::Session_var s ) : session ( s )
+ GetInterfaceThread(SALOME::Session_var s) : session(s)
{
start();
}
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;
// Option that results to \c true is specified via \a trueOption parameter.
// Option that results to \c false is specified via \a falseOption parameter (empty for default).
// Default value for the result (returned if both \a trueOption \a falseOption are not given) is specified via \c defValue parameter.
- bool boolCmdOption( const QString trueOption, const QString falseOption = QString(), bool defValue = false )
+ bool boolCmdOption(const QString trueOption, const QString falseOption = QString(), bool defValue = false)
{
bool value = defValue;
QStringList args = QApplication::arguments();
- foreach ( QString arg, args )
+ foreach (QString arg, args)
{
- if ( arg == trueOption )
+ if (arg == trueOption)
value = true;
- else if ( arg == falseOption )
+ else if (arg == falseOption)
value = false;
}
return value;
}
- // Kill omniNames process
- void killOmniNames()
+ // Shutdown standalone servers
+ void shutdownServers(SALOME_NamingService *theNS, bool remoteLauncher)
{
- SALOME_LifeCycleCORBA::killOmniNames();
+ SALOME_LifeCycleCORBA lcc(theNS);
+ lcc.shutdownServers(!remoteLauncher);
}
+} // end of anonymous namespace
- // Shutdown standalone servers
- void shutdownServers( SALOME_NamingService* theNS, bool remoteLauncher )
+template<class GUI_APP_STYLE>
+int AbstractGUIAppMain(int argc, char **argv);
+
+class GUIAppOldStyle
+{
+public:
+ using NamingServiceImplementation = OldStyleNS;
+ void connectToNSIfNeeded(CORBA::ORB_ptr orb) { _NS.reset(new SALOME_NamingService(orb)); }
+ void shutdownCORBAStufIfNeeded(bool shutdownAll, CORBA::ORB_ptr orb);
+ void killOtherServersIfNeeded() { SALOME_LifeCycleCORBA::killOmniNames(); }
+ SALOME::Session_var getSession();
+ void shutdownRemoteServersIfNeeded(bool remoteLauncher);
+private:
+ std::unique_ptr<SALOME_NamingService> _NS;
+};
+
+class GUIAppNewStyle
+{
+public:
+ using NamingServiceImplementation = NewStyleNS;
+ void connectToNSIfNeeded(CORBA::ORB_ptr orb) { /*! nothing */ }
+ void shutdownCORBAStufIfNeeded(bool shutdownAll, CORBA::ORB_ptr orb) { /*! nothing */ }
+ void killOtherServersIfNeeded() { /*! nothing */ }
+ SALOME::Session_var getSession();
+ void shutdownRemoteServersIfNeeded(bool remoteLauncher) { /*! nothing */ }
+};
+
+void GUIAppOldStyle::shutdownCORBAStufIfNeeded(bool shutdownAll, CORBA::ORB_ptr orb)
+{
+ try
{
- SALOME_LifeCycleCORBA lcc( theNS );
- lcc.shutdownServers( !remoteLauncher );
+ orb->shutdown(0);
}
-} // end of anonymous namespace
+ catch (...)
+ {
+ //////////////////////////////////////////////////////////////
+ // VSR: silently skip exception:
+ // CORBA.BAD_INV_ORDER.BAD_INV_ORDER_ORBHasShutdown
+ // exception is raised when orb->destroy() is called and
+ // cpp continer is launched in the embedded mode
+ //////////////////////////////////////////////////////////////
+ if (shutdownAll)
+ SALOME_LifeCycleCORBA::killOmniNames();
+ abort(); //abort program to avoid deadlock in destructors or atexit when shutdown has been interrupted
+ }
+ // Destroy ORB
+ sleep(2);
+ ORB_INIT *init = SINGLETON_<ORB_INIT>::Instance();
+ if (init)
+ init->explicit_destroy();
+}
+
+SALOME::Session_var GUIAppOldStyle::getSession()
+{
+ CORBA::Object_var obj = _NS->Resolve("/Kernel/Session");
+ SALOME::Session_var session = SALOME::Session::_narrow(obj);
+ return session;
+}
+void GUIAppOldStyle::shutdownRemoteServersIfNeeded(bool remoteLauncher)
+{
+ shutdownServers(_NS.get(), remoteLauncher);
+}
+
+SALOME::Session_var GUIAppNewStyle::getSession()
+{
+ SALOME::Session_var session = GetSessionRefSingleton()->get_future().get();
+ return session;
+}
// ---------------------------- MAIN -----------------------
-int main( int argc, char **argv )
+template<class GUI_APP_STYLE>
+int AbstractGUIAppMain(int argc, char **argv)
{
+ using NamingServiceImplementation = typename GUI_APP_STYLE::NamingServiceImplementation;
+ GUI_APP_STYLE self;
// Set-up application settings configuration (as for QSettings)
// Note: these are default settings which can be customized (see below)
- QApplication::setOrganizationName( "salome" );
- QApplication::setApplicationName( "salome" );
- QApplication::setApplicationVersion( salomeVersion() );
+ QApplication::setOrganizationName("salome");
+ QApplication::setApplicationName("salome");
+ QApplication::setApplicationVersion(salomeVersion());
// Install Qt debug messages handler
MsgHandler msgHandler;
- qInstallMessageHandler( QtxMsgHandler );
+ qInstallMessageHandler(QtxMsgHandler);
// Add <qtdir>/plugins dir to the pluins search path for image plugins
- QString qtdir = Qtx::qtDir( "plugins" );
- if ( !qtdir.isEmpty() )
- QApplication::addLibraryPath( qtdir );
+ QString qtdir = Qtx::qtDir("plugins");
+ if (!qtdir.isEmpty())
+ QApplication::addLibraryPath(qtdir);
// Add application library path (to search style plugin etc...)
- QString path = SUIT_Tools::addSlash( Qtx::getenv( "GUI_ROOT_DIR" ) ) + "bin/salome";
- QApplication::addLibraryPath( QDir::toNativeSeparators( path ) );
+ QString path = SUIT_Tools::addSlash(Qtx::getenv("GUI_ROOT_DIR")) + "bin/salome";
+ QApplication::addLibraryPath(QDir::toNativeSeparators(path));
- // QSurfaceFormat should be set before creation of QApplication,
+ // QSurfaceFormat should be set before creation of QApplication,
// so to avoid conflicts beetween SALOME and ParaView QSurfaceFormats we should merge theirs formats
// (see void Qtx::initDefaultSurfaceFormat()) and set the resultant format here.
- Qtx::initDefaultSurfaceFormat();
+ Qtx::initDefaultSurfaceFormat();
// Create Qt application instance: this should be done as early as possible!
// Note: QApplication forces setting locale LC_ALL to system one: setlocale(LC_ALL, "").
- Application app( argc, argv );
+ Application app(argc, argv);
// Initialize Python (only once)
// Note: Python forces setting locale LC_CTYPE to system one: setlocale(LC_CTYPE, "").
- char* py_argv[] = {(char*)""};
- KERNEL_PYTHON::init_python( 1, py_argv );
+ char *py_argv[] = {(char *)""};
+ KERNEL_PYTHON::init_python(1, py_argv);
// Create auxiliary resource manager to access application settings
ResourceMgr resMgr;
- resMgr.setWorkingMode( ResourceMgr::IgnoreUserValues );
- resMgr.loadLanguage( "LightApp", "en" );
- resMgr.loadLanguage( "SalomeApp", "en" );
- resMgr.loadLanguage( "Session" );
+ resMgr.setWorkingMode(ResourceMgr::IgnoreUserValues);
+ resMgr.loadLanguage("LightApp", "en");
+ resMgr.loadLanguage("SalomeApp", "en");
+ resMgr.loadLanguage("Session");
// Set-up application settings configuration possible customized via resources
- if ( resMgr.customName() != "SalomeApp" ) {
- QApplication::setApplicationName( resMgr.customName() );
- QApplication::setApplicationVersion( resMgr.version() );
+ if (resMgr.customName() != "SalomeApp")
+ {
+ QApplication::setApplicationName(resMgr.customName());
+ QApplication::setApplicationVersion(resMgr.version());
}
// Force default "C" locale if requested via user's preferences
// Note: this does not change whole application locale (changed via setlocale() function),
// but only affects GUI behavior
- resMgr.setWorkingMode( ResourceMgr::AllowUserValues ); // we must take into account user preferences
- if ( resMgr.booleanValue( "language", "locale", true ) )
- QLocale::setDefault( QLocale::c() );
- resMgr.setWorkingMode( ResourceMgr::IgnoreUserValues );
+ resMgr.setWorkingMode(ResourceMgr::AllowUserValues); // we must take into account user preferences
+ if (resMgr.booleanValue("language", "locale", true))
+ QLocale::setDefault(QLocale::c());
+ resMgr.setWorkingMode(ResourceMgr::IgnoreUserValues);
- bool isGUI = boolCmdOption( "--show-desktop", "--hide-desktop", true ); // true by default
- bool isSplash = boolCmdOption( "--show-splash", "--hide-splash", true ); // true by default
+ bool isGUI = boolCmdOption("--show-desktop", "--hide-desktop", true); // true by default
+ bool isSplash = boolCmdOption("--show-splash", "--hide-splash", true); // true by default
// Show splash screen (only if both the "GUI" and "SPLASH" options are true)
- QtxSplash* splash = 0;
- if ( isGUI && isSplash ) {
- splash = QtxSplash::splash( QPixmap() );
- splash->readSettings( &resMgr );
- if ( splash->pixmap().isNull() )
- splash->setPixmap( resMgr.loadPixmap( "LightApp", QObject::tr( "ABOUT_SPLASH" ) ) );
- if ( splash->pixmap().isNull() ) {
+ QtxSplash *splash = 0;
+ if (isGUI && isSplash)
+ {
+ splash = QtxSplash::splash(QPixmap());
+ splash->readSettings(&resMgr);
+ if (splash->pixmap().isNull())
+ splash->setPixmap(resMgr.loadPixmap("LightApp", QObject::tr("ABOUT_SPLASH")));
+ if (splash->pixmap().isNull())
+ {
delete splash;
splash = 0;
}
- else {
- splash->setOption( "%A", QObject::tr( "APP_NAME" ) );
- splash->setOption( "%V", QObject::tr( "ABOUT_VERSION" ).arg( resMgr.version() ) );
- splash->setOption( "%L", QObject::tr( "ABOUT_LICENSE" ) );
- splash->setOption( "%C", QObject::tr( "ABOUT_COPYRIGHT" ) );
+ else
+ {
+ splash->setOption("%A", QObject::tr("APP_NAME"));
+ splash->setOption("%V", QObject::tr("ABOUT_VERSION").arg(resMgr.version()));
+ splash->setOption("%L", QObject::tr("ABOUT_LICENSE"));
+ splash->setOption("%C", QObject::tr("ABOUT_COPYRIGHT"));
splash->show();
QApplication::instance()->processEvents();
}
CORBA::ORB_var orb;
PortableServer::POA_var poa;
- SUIT_Session* aGUISession = 0;
- SALOME_NamingService* _NS = 0;
- GetInterfaceThread* guiThread = 0;
- Session_ServerLauncher* myServerLauncher = 0;
+ SUIT_Session *aGUISession = 0;
+ GetInterfaceThread *guiThread = 0;
+ Session_ServerLauncher<NamingServiceImplementation> *myServerLauncher = nullptr;
#if defined(WIN32) && defined(UNICODE)
- char** new_argv = NULL;
+ char **new_argv = NULL;
#endif
bool remoteLauncher = false;
- try {
+ try
+ {
// ...create ORB, get RootPOA object, NamingService, etc.
ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance();
- ASSERT( SINGLETON_<ORB_INIT>::IsAlreadyExisting() );
+ ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
int orbArgc = 1;
- if( std::string(argv[1]).find("-ORBInitRef") != std::string::npos ){
+ if (std::string(argv[1]).find("-ORBInitRef") != std::string::npos)
+ {
orbArgc = 3;
remoteLauncher = true;
}
- orb = init( orbArgc, argv );
+ orb = init(orbArgc, argv);
- CORBA::Object_var obj = orb->resolve_initial_references( "RootPOA" );
- poa = PortableServer::POA::_narrow( obj );
+ CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
+ poa = PortableServer::POA::_narrow(obj);
PortableServer::POAManager_var pman = poa->the_POAManager();
- pman->activate() ;
- MESSAGE( "POA manager activated" );
+ pman->activate();
+ MESSAGE("POA manager activated");
- _NS = new SALOME_NamingService( orb );
+ self.connectToNSIfNeeded(orb);
result = 0;
}
- catch ( SALOME_Exception& e ) {
- INFOS( "run(): Caught SALOME_Exception : " << e.what() );
+ catch (SALOME_Exception &e)
+ {
+ INFOS("run(): Caught SALOME_Exception : " << e.what());
}
- catch ( CORBA::SystemException& e ) {
- INFOS( "run(): Caught CORBA::SystemException : " << handleCorbaException( e ) );
+ catch (CORBA::SystemException &e)
+ {
+ INFOS("run(): Caught CORBA::SystemException : " << handleCorbaException(e));
}
- catch ( CORBA::Exception& e ) {
- INFOS( "run(): Caught CORBA::Exception : " << handleCorbaException( e ) );
+ catch (CORBA::Exception &e)
+ {
+ INFOS("run(): Caught CORBA::Exception : " << handleCorbaException(e));
}
- catch ( std::exception& e ) {
- INFOS( "run(): Caught exception : " << e.what() );
+ catch (std::exception &e)
+ {
+ INFOS("run(): Caught exception : " << e.what());
}
- catch (...) {
- INFOS( "run(): Caught unknown exception" );
+ catch (...)
+ {
+ INFOS("run(): Caught unknown exception");
}
QMutex _GUIMutex, _SessionMutex, _SplashMutex;
// until all initialization is done
_SessionMutex.lock();
- if ( !result ) {
+ if (!result)
+ {
// Start embedded servers launcher (Registry, SALOMEDS, etc.)
// ...lock mutex to block embedded servers launching thread until wait( mutex )
- _GUIMutex.lock();
+ _GUIMutex.lock();
// ...create launcher
#if defined(WIN32) && defined(UNICODE)
- LPWSTR *szArglist = NULL;
- int nArgs;
- int i;
- szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);
- new_argv = new char*[nArgs];
- for (i = 0; i < nArgs; i++) {
- new_argv[i] = (char*) Kernel_Utils::utf8_encode(szArglist[i]);
- }
- // Free memory allocated for CommandLineToArgvW arguments.
- LocalFree(szArglist);
- myServerLauncher = new Session_ServerLauncher(nArgs, new_argv, orb, poa, &_GUIMutex, &_ServerLaunch, &_SessionMutex, &_SessionStarted);
+ LPWSTR *szArglist = NULL;
+ int nArgs;
+ int i;
+ szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);
+ new_argv = new char *[nArgs];
+ for (i = 0; i < nArgs; i++)
+ {
+ new_argv[i] = (char *)Kernel_Utils::utf8_encode(szArglist[i]);
+ }
+ // Free memory allocated for CommandLineToArgvW arguments.
+ LocalFree(szArglist);
+ myServerLauncher = new Session_ServerLauncher<NamingServiceImplementation>(nArgs, new_argv, orb, poa, &_GUIMutex, &_ServerLaunch, &_SessionMutex, &_SessionStarted);
#else
- myServerLauncher = new Session_ServerLauncher( argc, argv, orb, poa, &_GUIMutex, &_ServerLaunch, &_SessionMutex, &_SessionStarted );
+ myServerLauncher = new Session_ServerLauncher<NamingServiceImplementation>(argc, argv, orb, poa, &_GUIMutex, &_ServerLaunch, &_SessionMutex, &_SessionStarted);
#endif
// ...block this thread until launcher is ready
- _ServerLaunch.wait( &_GUIMutex );
+ _ServerLaunch.wait(&_GUIMutex);
// Start servers check thread (splash)
- if ( splash ) {
+ if (splash)
+ {
// ...lock mutex to block splash thread until wait( mutex )
_SplashMutex.lock();
// ...create servers checking thread
- Session_ServerCheck sc( &_SplashMutex, &_SplashStarted );
+ Session_ServerCheck<NamingServiceImplementation> sc(&_SplashMutex, &_SplashStarted);
// ... set initial progress
- splash->setProgress( 0, sc.totalSteps() );
- // start check loop
- while ( true ) {
- int step = sc.currentStep();
- int total = sc.totalSteps();
+ splash->setProgress(0, sc.totalSteps());
+ // start check loop
+ while (true)
+ {
+ int step = sc.currentStep();
+ int total = sc.totalSteps();
QString msg = sc.currentMessage();
QString err = sc.error();
- if ( !err.isEmpty() ) {
- QtxSplash::setError( err );
+ if (!err.isEmpty())
+ {
+ QtxSplash::setError(err);
QApplication::instance()->processEvents();
result = -1;
break;
}
- QtxSplash::setStatus( msg, step );
+ QtxSplash::setStatus(msg, step);
QApplication::instance()->processEvents();
- if ( step >= total )
+ if (step >= total)
break;
// ...block this thread until servers checking is finished
- _SplashStarted.wait( &_SplashMutex );
+ _SplashStarted.wait(&_SplashMutex);
}
// ...unlock mutex 'cause it is no more needed
_SplashMutex.unlock();
}
- // Finalize embedded servers launcher
+ // Finalize embedded servers launcher
// ...block this thread until launcher is finished
- _ServerLaunch.wait( &_GUIMutex );
+ _ServerLaunch.wait(&_GUIMutex);
// ...unlock mutex 'cause it is no more needed
_GUIMutex.unlock();
}
// Obtain Session interface reference
- CORBA::Object_var obj = _NS->Resolve( "/Kernel/Session" );
- SALOME::Session_var session = SALOME::Session::_narrow( obj ) ;
+ SALOME::Session_var session = self.getSession();
bool shutdownAll = false;
bool shutdownSession = false;
- bool debugExceptions = boolCmdOption( "--no-exception-handler" ) ||
- resMgr.booleanValue( "launch", "noexcepthandler", false );
+ bool debugExceptions = boolCmdOption("--no-exception-handler") ||
+ resMgr.booleanValue("launch", "noexcepthandler", false);
- if ( !result ) {
+ if (!result)
+ {
// Launch GUI activator
- if ( isGUI ) {
- if ( splash )
- splash->setStatus( QObject::tr( "Activating desktop..." ) );
+ if (isGUI)
+ {
+ if (splash)
+ splash->setStatus(QObject::tr("Activating desktop..."));
// ...create GUI launcher
- MESSAGE( "Session activated, Launch IAPP..." );
- guiThread = new GetInterfaceThread( session );
+ MESSAGE("Session activated, Launch IAPP...");
+ guiThread = new GetInterfaceThread(session);
}
// GUI activation
// Allow multiple activation/deactivation of GUI
- while ( true ) {
- MESSAGE( "waiting wakeAll()" );
- _SessionStarted.wait( &_SessionMutex ); // to be reseased by Launch server thread when ready:
+ while (true)
+ {
+ MESSAGE("waiting wakeAll()");
+ _SessionStarted.wait(&_SessionMutex); // to be reseased by Launch server thread when ready:
// atomic operation lock - unlock on mutex
// unlock mutex: serverThread runs, calls _ServerLaunch->wakeAll()
// this thread wakes up, and lock mutex
// 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;
}
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)
// 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;
}
_SessionMutex.unlock();
// Shutdown embedded servers
- if ( myServerLauncher )
+ if (myServerLauncher)
myServerLauncher->ShutdownAll();
// Shutdown standalone servers
- if ( shutdownAll )
- shutdownServers( _NS, remoteLauncher );
+ if (shutdownAll)
+ self.shutdownRemoteServersIfNeeded(remoteLauncher);
// Kill embedded servers
- if ( myServerLauncher )
+ if (myServerLauncher)
myServerLauncher->KillAll();
// Unregister session server
- SALOME_Session_i* sessionServant =
- dynamic_cast<SALOME_Session_i*>( poa->reference_to_servant( session.in() ) );
- if ( sessionServant )
+ SALOME_Session_i *sessionServant =
+ dynamic_cast<SALOME_Session_i *>(poa->reference_to_servant(session.in()));
+ if (sessionServant)
sessionServant->NSunregister();
delete aGUISession;
delete guiThread;
delete myServerLauncher;
- delete _NS;
#if defined(WIN32) && defined(UNICODE)
delete[] new_argv;
#endif
-
- try {
- orb->shutdown(0);
- }
- catch (...) {
- //////////////////////////////////////////////////////////////
- // VSR: silently skip exception:
- // CORBA.BAD_INV_ORDER.BAD_INV_ORDER_ORBHasShutdown
- // exception is raised when orb->destroy() is called and
- // cpp continer is launched in the embedded mode
- //////////////////////////////////////////////////////////////
- if ( shutdownAll )
- killOmniNames();
- abort(); //abort program to avoid deadlock in destructors or atexit when shutdown has been interrupted
- }
-
- // Destroy ORB
- sleep(2);
- ORB_INIT* init = SINGLETON_<ORB_INIT>::Instance();
- if ( init )
- init->explicit_destroy();
-
+ self.shutdownCORBAStufIfNeeded(shutdownAll,orb);
// Finalize Python
- if ( Py_IsInitialized() )
+ if (Py_IsInitialized())
{
PyGILState_Ensure();
Py_Finalize();
}
-
// Kill omniNames process
- if ( shutdownAll )
- {
- killOmniNames();
- }
+ if (shutdownAll)
+ self.killOtherServersIfNeeded();
- MESSAGE( "Salome_Session_Server:endofserver" );
+ MESSAGE("Salome_Session_Server:endofserver");
return result;
}
--- /dev/null
+// Copyright (C) 2021 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "SALOME_Session_Server.cxx"
+
+
+int main(int argc, char **argv)
+{
+ return AbstractGUIAppMain<GUIAppNewStyle>(argc, argv);
+}
--- /dev/null
+// Copyright (C) 2021 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "SALOME_Session_Server.cxx"
+
+int main(int argc, char **argv)
+{
+ return AbstractGUIAppMain<GUIAppOldStyle>(argc, argv);
+}
--- /dev/null
+// Copyright (C) 2021 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "Session_NS_wrapper.hxx"
+
+#include "SALOME_Fake_NamingService.hxx"
+#include "SALOME_Container_i.hxx"
+#include "SALOME_Launcher.hxx"
+#include "SALOMEDSClient_ClientFactory.hxx"
+
+#include "Session_Session_i.hxx"
+#include "Session_Promises.hxx"
+#include "utilities.h"
+
+const char OldStyleNS::LibName[]="SalomeApp";
+const char NewStyleNS::LibName[]="SalomeAppSL";
+
+void CommonActivateSession(CORBA::ORB_var orb, PortableServer::POA_var poa, QMutex *GUIMutex, QWaitCondition *GUILauncher, SALOME_NamingService_Abstract *ns, int argc, char ** argv)
+{
+ try {
+ MESSAGE("Session thread started");
+ SALOME_Session_i * mySALOME_Session = nullptr;
+ if(!ns)
+ mySALOME_Session = new SALOME_Session_i(argc, argv, orb, poa, GUIMutex, GUILauncher);
+ else
+ mySALOME_Session = new SALOME_Session_i(argc, argv, orb, poa, GUIMutex, GUILauncher,ns);
+ PortableServer::ObjectId_var mySALOME_Sessionid = poa->activate_object(mySALOME_Session);
+ MESSAGE("poa->activate_object(mySALOME_Session)");
+
+ CORBA::Object_var obj = mySALOME_Session->_this();
+ SALOME::Session_var objC = SALOME::Session::_narrow(obj);
+ GetSessionRefSingleton()->set_value(objC);
+ CORBA::String_var sior(orb->object_to_string(obj));
+ mySALOME_Session->_remove_ref();
+
+ mySALOME_Session->NSregister();
+ }
+ catch (CORBA::SystemException&) {
+ INFOS("Caught CORBA::SystemException.");
+ }
+ catch (CORBA::Exception&) {
+ INFOS("Caught CORBA::Exception.");
+ }
+ catch (...) {
+ INFOS("Caught unknown exception.");
+ }
+}
+
+Engines_Container_i *OldStyleNS::activateContainer(CORBA::ORB_var orb, PortableServer::POA_var poa, int argc, char **argv)
+{
+ Engines_Container_i *_container = nullptr;
+ try
+ {
+ MESSAGE("Container thread started");
+
+ // get or create the child POA
+
+ PortableServer::POA_var factory_poa;
+ try
+ {
+ factory_poa = poa->find_POA("factory_poa", 0);
+ // 0 = no activation (already done if exists)
+ }
+ catch (PortableServer::POA::AdapterNonExistent &)
+ {
+ MESSAGE("factory_poa does not exists, create...");
+ // define policy objects
+ PortableServer::ImplicitActivationPolicy_var implicitActivation =
+ poa->create_implicit_activation_policy(PortableServer::NO_IMPLICIT_ACTIVATION);
+ // default = NO_IMPLICIT_ACTIVATION
+ PortableServer::ThreadPolicy_var threadPolicy =
+ poa->create_thread_policy(PortableServer::ORB_CTRL_MODEL);
+ // default = ORB_CTRL_MODEL, other choice SINGLE_THREAD_MODEL
+
+ // create policy list
+ CORBA::PolicyList policyList;
+ policyList.length(2);
+ policyList[0] = PortableServer::ImplicitActivationPolicy::
+ _duplicate(implicitActivation);
+ policyList[1] = PortableServer::ThreadPolicy::
+ _duplicate(threadPolicy);
+
+ PortableServer::POAManager_var nil_mgr = PortableServer::POAManager::_nil();
+ factory_poa = poa->create_POA("factory_poa",
+ nil_mgr,
+ policyList);
+ //with nil_mgr instead of pman,
+ //a new POA manager is created with the new POA
+
+ // destroy policy objects
+ implicitActivation->destroy();
+ threadPolicy->destroy();
+
+ // obtain the factory poa manager
+ PortableServer::POAManager_var pmanfac = factory_poa->the_POAManager();
+ pmanfac->activate();
+ MESSAGE("pmanfac->activate()");
+ }
+
+ char *containerName = (char *)"";
+ if (argc > 1)
+ {
+ containerName = argv[1];
+ }
+ _container = new Engines_Container_i(orb, poa, containerName, argc, argv, nullptr, false);
+ }
+ catch (CORBA::SystemException &)
+ {
+ INFOS("Caught CORBA::SystemException.");
+ }
+ catch (PortableServer::POA::WrongPolicy &)
+ {
+ INFOS("Caught CORBA::WrongPolicyException.");
+ }
+ catch (PortableServer::POA::ServantAlreadyActive &)
+ {
+ INFOS("Caught CORBA::ServantAlreadyActiveException");
+ }
+ catch (CORBA::Exception &)
+ {
+ INFOS("Caught CORBA::Exception.");
+ }
+ catch (...)
+ {
+ INFOS("Caught unknown exception.");
+ }
+ return _container;
+}
+
+void OldStyleNS::activateContainerManager(CORBA::ORB_var orb)
+{
+ try {
+ PortableServer::POA_var root_poa=PortableServer::POA::_the_root_poa();
+ std::cout << "Activate SalomeLauncher ......!!!! " << std::endl;
+ new SALOME_Launcher(orb,root_poa);
+ }
+ catch(CORBA::SystemException&) {
+ INFOS("Caught CORBA::SystemException.");
+ }
+ catch(PortableServer::POA::WrongPolicy&) {
+ INFOS("Caught CORBA::WrongPolicyException.");
+ }
+ catch(PortableServer::POA::ServantAlreadyActive&) {
+ INFOS("Caught CORBA::ServantAlreadyActiveException");
+ }
+ catch(CORBA::Exception&) {
+ INFOS("Caught CORBA::Exception.");
+ }
+ catch(...) {
+ INFOS("Caught unknown exception.");
+ }
+}
+
+void OldStyleNS::activateSession(CORBA::ORB_var orb, PortableServer::POA_var poa, QMutex *GUIMutex, QWaitCondition *GUILauncher, int argc, char ** argv)
+{
+ CommonActivateSession(orb,poa,GUIMutex,GUILauncher,nullptr,argc,argv);
+}
+
+void OldStyleNS::activateSALOMEDS(CORBA::ORB_var orb, PortableServer::POA_var poa)
+{
+ try {
+ MESSAGE("SALOMEDS thread started");
+ // We allocate the objects on the heap. Since these are reference
+ // counted objects, they will be deleted by the POA when they are no
+ // longer needed.
+
+ ClientFactory::createStudy(orb,poa);
+ }
+ catch(CORBA::SystemException&) {
+ INFOS( "Caught CORBA::SystemException." );
+ }
+ catch(CORBA::Exception&) {
+ INFOS( "Caught CORBA::Exception." );
+ }
+ catch(omniORB::fatalException& fe) {
+ INFOS( "Caught omniORB::fatalException:" );
+ INFOS( " file: " << fe.file() );
+ INFOS( " line: " << fe.line() );
+ INFOS( " mesg: " << fe.errmsg() );
+ }
+ catch(...) {
+ INFOS( "Caught unknown exception." );
+ }
+}
+
+#include "Utils_ORB_INIT.hxx"
+#include "Utils_SINGLETON.hxx"
+
+CORBA::Object_var OldStyleNS::forServerChecker(const char *NSName, int argc, char **argv)
+{
+ ORB_INIT& init = *SINGLETON_<ORB_INIT>::Instance();
+ CORBA::ORB_var orb = init( argc, argv );
+ SALOME_NamingService &NS = *SINGLETON_<SALOME_NamingService>::Instance();
+ ASSERT( SINGLETON_<SALOME_NamingService>::IsAlreadyExisting() );
+ NS.init_orb( orb );
+ CORBA::Object_var obj = NS.Resolve( NSName );
+ return obj;
+}
+
+CosNaming::NamingContext_var OldStyleNS::checkTrueNamingServiceIfExpected(int argc, char **argv, bool& forceOK)
+{
+ forceOK = false;//tell checker : do as before
+ ORB_INIT& init = *SINGLETON_<ORB_INIT>::Instance();
+ CORBA::ORB_var orb = init( argc, argv );
+ CORBA::Object_var obj = orb->resolve_initial_references( "NameService" );
+ CosNaming::NamingContext_var _root_context = CosNaming::NamingContext::_narrow( obj );
+ return _root_context;
+}
+
+#include "SALOME_KernelServices.hxx"
+
+void NewStyleNS::defineDefaultSALOMEKERNELNamingService()
+{
+ KERNEL::assignNamingServiceSL();
+}
+
+Engines_Container_i *NewStyleNS::activateContainer(CORBA::ORB_var orb, PortableServer::POA_var poa, int argc, char **argv)
+{
+ return KERNEL::getContainerSA();
+}
+
+void NewStyleNS::activateContainerManager(CORBA::ORB_var orb)
+{
+ KERNEL::getLauncherSA();
+}
+
+void NewStyleNS::activateSession(CORBA::ORB_var orb, PortableServer::POA_var poa, QMutex *GUIMutex, QWaitCondition *GUILauncher, int argc, char ** argv)
+{
+ SALOME_Fake_NamingService *ns=new SALOME_Fake_NamingService;
+ CommonActivateSession(orb,poa,GUIMutex,GUILauncher,ns,argc,argv);
+}
+
+void NewStyleNS::activateSALOMEDS(CORBA::ORB_var orb, PortableServer::POA_var poa)
+{
+ ClientFactory::createStudyWithoutNS(orb,poa);
+}
+
+CORBA::Object_var NewStyleNS::forServerChecker(const char *NSName, int argc, char **argv)
+{
+ SALOME_Fake_NamingService ns;
+ return ns.Resolve(NSName);
+}
+
+CosNaming::NamingContext_var NewStyleNS::checkTrueNamingServiceIfExpected(int argc, char **argv, bool& forceOK)
+{
+ forceOK = true;//tell checker : forget it's always OK
+ return CosNaming::NamingContext::_nil();
+}
--- /dev/null
+// 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;
+};
--- /dev/null
+// Copyright (C) 2021 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "Session_Promises.hxx"
+
+std::promise<SALOME::Session_var> *GetSessionRefSingleton()
+{
+ static std::promise<SALOME::Session_var> _my_unique_study_ref;
+ return &_my_unique_study_ref;
+}
--- /dev/null
+// Copyright (C) 2021 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#pragma once
+
+#include "SALOMEconfig.h"
+#include CORBA_SERVER_HEADER(SALOME_Session)
+
+#include <future>
+
+std::promise<SALOME::Session_var> *GetSessionRefSingleton();
\internal
*/
-class Session_ServerCheck::Locker
+template<class MY_CLS>
+class Session_ServerCheck<MY_CLS>::Locker
{
public:
/*!
\param mutex a mutex used to serialize progress operations (splash)
\param wc a wait condition used in combination with \a mutex
*/
-Session_ServerCheck::Session_ServerCheck( QMutex* mutex, QWaitCondition* wc )
+template<class MY_NS>
+Session_ServerCheck<MY_NS>::Session_ServerCheck( QMutex* mutex, QWaitCondition* wc )
: QThread(),
myMutex( mutex ),
myWC( wc ),
/*!
\brief Destructor
*/
-Session_ServerCheck::~Session_ServerCheck()
+template<class MY_NS>
+Session_ServerCheck<MY_NS>::~Session_ServerCheck()
{
terminate();
while( isRunning() );
\brief Get current information message.
\return current message
*/
-QString Session_ServerCheck::currentMessage()
+template<class MY_NS>
+QString Session_ServerCheck<MY_NS>::currentMessage()
{
static QStringList messages;
if ( messages.isEmpty() ) {
\brief Get error message.
\return error message or null string of there was no any error
*/
-QString Session_ServerCheck::error()
+template<class MY_NS>
+QString Session_ServerCheck<MY_NS>::error()
{
QMutexLocker locker( &myDataMutex );
return myError;
\brief Get current step.
\return current step
*/
-int Session_ServerCheck::currentStep()
+template<class MY_NS>
+int Session_ServerCheck<MY_NS>::currentStep()
{
QMutexLocker locker( &myDataMutex );
return myCurrentStep;
\brief Get total number of check steps.
\return total number of steps
*/
-int Session_ServerCheck::totalSteps()
+template<class MY_NS>
+int Session_ServerCheck<MY_NS>::totalSteps()
{
QMutexLocker locker( &myDataMutex );
int cnt = 5; // base servers
\brief Modify current step.
\param step new current step value
*/
-void Session_ServerCheck::setStep( const int step )
+template<class MY_NS>
+void Session_ServerCheck<MY_NS>::setStep( const int step )
{
QMutexLocker locker( &myDataMutex );
myCurrentStep = step;
\brief Set error message.
\param msg error message
*/
-void Session_ServerCheck::setError( const QString& msg )
+template<class MY_NS>
+void Session_ServerCheck<MY_NS>::setError( const QString& msg )
{
QMutexLocker locker( &myDataMutex );
myError = msg;
/*!
\brief Thread loop function. Performs SALOME servers check.
*/
-void Session_ServerCheck::run()
+template<class MY_NS>
+void Session_ServerCheck<MY_NS>::run()
{
// start check servers
int current = 0;
setStep( current * myAttempts + i );
try {
- ORB_INIT& init = *SINGLETON_<ORB_INIT>::Instance();
- CORBA::ORB_var orb = init( args.argc(), args.argv() );
- CORBA::Object_var obj = orb->resolve_initial_references( "NameService" );
- CosNaming::NamingContext_var _root_context = CosNaming::NamingContext::_narrow( obj );
- if ( !CORBA::is_nil( _root_context ) ) {
+ bool forceOK = false;
+ CosNaming::NamingContext_var _root_context = MY_NS::checkTrueNamingServiceIfExpected(args.argc(), args.argv(),forceOK);
+ if ( forceOK || !CORBA::is_nil( _root_context ) ) {
setStep( ++current * myAttempts );
break;
}
setStep( current * myAttempts + i );
try {
- ORB_INIT& init = *SINGLETON_<ORB_INIT>::Instance();
- CORBA::ORB_var orb = init( args.argc(), args.argv() );
- SALOME_NamingService &NS = *SINGLETON_<SALOME_NamingService>::Instance();
- ASSERT( SINGLETON_<SALOME_NamingService>::IsAlreadyExisting() );
- NS.init_orb( orb );
- CORBA::Object_var obj = NS.Resolve( "/Registry" );
+ CORBA::Object_var obj = MY_NS::forServerChecker("/Registry", args.argc(), args.argv());
Registry::Components_var registry = Registry::Components::_narrow( obj );
if ( !CORBA::is_nil( registry ) ) {
MESSAGE( "/Registry is found" );
setStep( current * myAttempts + i );
try {
- ORB_INIT& init = *SINGLETON_<ORB_INIT>::Instance();
- CORBA::ORB_var orb = init( args.argc(), args.argv() );
- SALOME_NamingService &NS = *SINGLETON_<SALOME_NamingService>::Instance();
- ASSERT( SINGLETON_<SALOME_NamingService>::IsAlreadyExisting() );
- NS.init_orb( orb );
- CORBA::Object_var obj = NS.Resolve( "/Study" );
+ CORBA::Object_var obj = MY_NS::forServerChecker("/Study", args.argc(), args.argv());
SALOMEDS::Study_var study = SALOMEDS::Study::_narrow( obj );
if ( !CORBA::is_nil( study ) ) {
MESSAGE( "/Study is found" );
setStep( current * myAttempts + i );
try {
- ORB_INIT& init = *SINGLETON_<ORB_INIT>::Instance();
- CORBA::ORB_var orb = init( args.argc(), args.argv() );
- SALOME_NamingService &NS = *SINGLETON_<SALOME_NamingService>::Instance();
- ASSERT( SINGLETON_<SALOME_NamingService>::IsAlreadyExisting() );
- NS.init_orb( orb );
- CORBA::Object_var obj = NS.Resolve( "/Kernel/ModulCatalog" );
+ CORBA::Object_var obj = MY_NS::forServerChecker("/Kernel/ModulCatalog", args.argc(), args.argv());
SALOME_ModuleCatalog::ModuleCatalog_var catalog = SALOME_ModuleCatalog::ModuleCatalog::_narrow( obj );
if ( !CORBA::is_nil( catalog ) ){
MESSAGE( "/Kernel/ModulCatalog is found" );
setStep( current * myAttempts + i );
try {
- ORB_INIT& init = *SINGLETON_<ORB_INIT>::Instance();
- CORBA::ORB_var orb = init( args.argc(), args.argv() );
- SALOME_NamingService &NS = *SINGLETON_<SALOME_NamingService>::Instance();
- ASSERT( SINGLETON_<SALOME_NamingService>::IsAlreadyExisting() );
- NS.init_orb( orb );
- CORBA::Object_var obj = NS.Resolve( "/Kernel/Session" );
+ CORBA::Object_var obj = MY_NS::forServerChecker("/Kernel/Session", args.argc(), args.argv());
SALOME::Session_var session = SALOME::Session::_narrow( obj );
if ( !CORBA::is_nil( session ) ) {
MESSAGE( "/Kernel/Session is found" );
setStep( current * myAttempts + i );
try {
- ORB_INIT& init = *SINGLETON_<ORB_INIT>::Instance();
- CORBA::ORB_var orb = init( args.argc(), args.argv() );
- SALOME_NamingService &NS = *SINGLETON_<SALOME_NamingService>::Instance();
- ASSERT( SINGLETON_<SALOME_NamingService>::IsAlreadyExisting() );
- NS.init_orb( orb );
QString containerName = QString( "/Containers/%1/FactoryServer" ).arg( Kernel_Utils::GetHostname().c_str() );
- CORBA::Object_var obj = NS.Resolve( containerName.toLatin1() );
+ CORBA::Object_var obj = MY_NS::forServerChecker(containerName.toLatin1(), args.argc(), args.argv());
Engines::Container_var FScontainer = Engines::Container::_narrow( obj );
if ( !CORBA::is_nil( FScontainer ) ) {
MESSAGE( containerName.toLatin1().constData() << " is found" );
setStep( current * myAttempts + i );
try {
- ORB_INIT& init = *SINGLETON_<ORB_INIT>::Instance();
- CORBA::ORB_var orb = init( args.argc(), args.argv() );
- SALOME_NamingService &NS = *SINGLETON_<SALOME_NamingService>::Instance();
- ASSERT( SINGLETON_<SALOME_NamingService>::IsAlreadyExisting() );
- NS.init_orb( orb );
QString containerName = QString( "/Containers/%1/FactoryServerPy" ).arg( Kernel_Utils::GetHostname().c_str() );
- CORBA::Object_var obj = NS.Resolve( containerName.toLatin1() );
+ CORBA::Object_var obj = MY_NS::forServerChecker(containerName.toLatin1(), args.argc(), args.argv());
Engines::Container_var FSPcontainer = Engines::Container::_narrow( obj );
if ( !CORBA::is_nil( FSPcontainer ) ) {
MESSAGE( containerName.toLatin1().constData() << " is found" );
setStep( current * myAttempts + i );
try {
- ORB_INIT& init = *SINGLETON_<ORB_INIT>::Instance();
- CORBA::ORB_var orb = init( args.argc(), args.argv() );
- SALOME_NamingService &NS = *SINGLETON_<SALOME_NamingService>::Instance();
- ASSERT( SINGLETON_<SALOME_NamingService>::IsAlreadyExisting() );
- NS.init_orb( orb );
QString containerName = QString( "/Containers/%1/SuperVisionContainer" ).arg( Kernel_Utils::GetHostname().c_str() );
- CORBA::Object_var obj = NS.Resolve( containerName.toLatin1() );
+ CORBA::Object_var obj = MY_NS::forServerChecker(containerName.toLatin1(), args.argc(), args.argv());
Engines::Container_var SVcontainer = Engines::Container::_narrow( obj );
if ( !CORBA::is_nil( SVcontainer ) ) {
MESSAGE( containerName.toLatin1().constData() << " is found" );
}
}
}
+
+#include "Session_NS_wrapper.hxx"
+
+template class Session_ServerCheck<OldStyleNS>;
+template class Session_ServerCheck<NewStyleNS>;
class QWaitCondition;
+template<class MY_NS>
class SESSION_EXPORT Session_ServerCheck : public QThread
{
class Locker;
/*!
default constructor not for use
*/
-Session_ServerLauncher::Session_ServerLauncher()
+template<class MY_NS>
+Session_ServerLauncher<MY_NS>::Session_ServerLauncher()
{
ASSERT(0); // must not be called
}
/*!
constructor
*/
-Session_ServerLauncher::Session_ServerLauncher(int argc,
- char ** argv,
- CORBA::ORB_ptr orb,
- PortableServer::POA_ptr poa,
- QMutex *GUIMutex,
- QWaitCondition *ServerLaunch,
- QMutex *SessionMutex,
- QWaitCondition *SessionStarted)
+template<class MY_NS>
+Session_ServerLauncher<MY_NS>::Session_ServerLauncher(int argc,
+ char ** argv,
+ CORBA::ORB_ptr orb,
+ PortableServer::POA_ptr poa,
+ QMutex *GUIMutex,
+ QWaitCondition *ServerLaunch,
+ QMutex *SessionMutex,
+ QWaitCondition *SessionStarted)
{
_argc = argc;
_argv = argv;
_ServerLaunch = ServerLaunch;
_SessionMutex = SessionMutex;
_SessionStarted = SessionStarted;
-
+ MY_NS::defineDefaultSALOMEKERNELNamingService();
// start thread
start();
}
/*!
destructor
*/
-Session_ServerLauncher::~Session_ServerLauncher()
+template<class MY_NS>
+Session_ServerLauncher<MY_NS>::~Session_ServerLauncher()
{
}
/*!
Check args and activate servers
*/
-void Session_ServerLauncher::run()
+template<class MY_NS>
+void Session_ServerLauncher<MY_NS>::run()
{
// wait until main thread is ready
_GUIMutex->lock(); // ... lock mutex (it is unlocked my calling thread
/*!
controls and dispatchs arguments given with command
*/
-void Session_ServerLauncher::CheckArgs()
+template<class MY_NS>
+void Session_ServerLauncher<MY_NS>::CheckArgs()
{
int argState = 0;
ServArg aServArg(0,0,0);
}
// Temporary solution
- for (int i=0; i<Session_ServerThread::NB_SRV_TYP; i++)
- if (strcmp(_argv[iarg],Session_ServerThread::_serverTypes[i])==0)
+ for (int i=0; i<Session_ServerThread<MY_NS>::NB_SRV_TYP; i++)
+ if (strcmp(_argv[iarg],Session_ServerThread<MY_NS>::_serverTypes[i])==0)
{
aServArg._servType = i;
argState = 2;
if (strcmp(_argv[iarg],")")==0) // end of arguments = ')'
{
aServArg._lastArg=iarg-1; // arg before ')'
- MESSAGE("server : "<< Session_ServerThread::_serverTypes[aServArg._servType]);
+ MESSAGE("server : "<< Session_ServerThread<MY_NS>::_serverTypes[aServArg._servType]);
for (int i=aServArg._firstArg; i<=aServArg._lastArg; i++)
MESSAGE(" arg : " << _argCopy[i]);
_argServToLaunch.push_back(aServArg);
throw SALOME_Exception(LOCALIZED("Error in command arguments, missing parenthesis ')'"));
}
-void Session_ServerLauncher::ActivateAll()
+template<class MY_NS>
+void Session_ServerLauncher<MY_NS>::ActivateAll()
{
std::list<ServArg>::iterator itServ;
for (itServ = _argServToLaunch.begin(); itServ !=_argServToLaunch.end(); itServ++)
char** argv = new char*[argc+1];
argv[argc]=0; // for Engines_Container_i constructor...
int servType = (*itServ)._servType;
- argv[0]=strdup(Session_ServerThread::_serverTypes[servType]);
+ argv[0]=strdup(Session_ServerThread<MY_NS>::_serverTypes[servType]);
if (argc>1)
{
for (int i=0; i<argc-1; i++)
MESSAGE("*** activating [" << argc << "] : " << argv[0]);
- Session_ServerThread* aServerThread
- = new Session_ServerThread(argc, argv, _orb,_root_poa);
+ Session_ServerThread<MY_NS>* aServerThread = new Session_ServerThread<MY_NS>(argc, argv, _orb,_root_poa);
_serverThreads.push_front(aServerThread);
aServerThread->Init();
int argc=1;
char** argv = new char*[argc];
argv[0] = (char*)"Session";
- Session_SessionThread* aServerThread
- = new Session_SessionThread(argc, argv, _orb,_root_poa,_SessionMutex,_SessionStarted);
+ Session_SessionThread<MY_NS>* aServerThread
+ = new Session_SessionThread<MY_NS>(argc, argv, _orb,_root_poa,_SessionMutex,_SessionStarted);
_serverThreads.push_front(aServerThread);
aServerThread->Init();
delete[] argv;
}
-void Session_ServerLauncher::ShutdownAll()
+template <class MY_NS>
+void Session_ServerLauncher<MY_NS>::ShutdownAll()
{
MESSAGE("Session_ServerLauncher::ShutdownAll()");
- std::list<Session_ServerThread*>::reverse_iterator itServ;
+ using Session_ServerThreadT = Session_ServerThread<MY_NS>;
+ typename std::list<Session_ServerThreadT*>::reverse_iterator itServ;
for (itServ = _serverThreads.rbegin(); itServ !=_serverThreads.rend(); itServ++)
{
(*itServ)->Shutdown();
/*!
Destruction des classes serveur dans l'ordre inverse de creation
*/
-void Session_ServerLauncher::KillAll()
+template <class MY_NS>
+void Session_ServerLauncher<MY_NS>::KillAll()
{
MESSAGE("Session_ServerLauncher::KillAll()");
- std::list<Session_ServerThread*>::reverse_iterator itServ;
+ using Session_ServerThreadT = Session_ServerThread<MY_NS>;
+ typename std::list<Session_ServerThreadT*>::reverse_iterator itServ;
for (itServ = _serverThreads.rbegin(); itServ !=_serverThreads.rend(); itServ++)
{
delete (*itServ);
}
}
+
+#include "Session_NS_wrapper.hxx"
+
+template class Session_ServerLauncher<OldStyleNS>;
+
+template class Session_ServerLauncher<NewStyleNS>;
_servType(servType),_firstArg(firstArg),_lastArg(lastArg)
{}
+template <class MY_NS>
class Session_ServerThread;
class QMutex;
class QWaitCondition;
-class SESSION_EXPORT Session_ServerLauncher: public QThread
+template<class MY_NS>
+class SESSION_EXPORT Session_ServerLauncher : public QThread
{
public:
Session_ServerLauncher();
QWaitCondition* _SessionStarted;
std::list<ServArg> _argServToLaunch;
std::vector<std::string> _argCopy;
- std::list<Session_ServerThread*> _serverThreads;
+ std::list< Session_ServerThread<MY_NS>* > _serverThreads;
};
#endif
// Author : Paul RASCLE, EDF
#include "Session_ServerThread.hxx"
+#include "Session_Promises.hxx"
#include <SALOME_NamingService.hxx>
#include <SALOME_Container_i.hxx>
#include <SALOME_Launcher.hxx>
-#include <SALOMEDSClient_ClientFactory.hxx>
#include <SALOME_ModuleCatalog_impl.hxx>
#include <RegistryService.hxx>
#include <QMutex>
#include <QWaitCondition>
-const int Session_ServerThread::NB_SRV_TYP = 6;
-const char* Session_ServerThread::_serverTypes[NB_SRV_TYP] = {"Container",
- "ModuleCatalog",
- "Registry",
- "SALOMEDS",
- "Session",
- "ContainerManager"};
+template<class MY_NS>
+const int Session_ServerThread<MY_NS>::NB_SRV_TYP = 6;
+
+template<class MY_NS>
+const char* Session_ServerThread<MY_NS>::_serverTypes[NB_SRV_TYP] = {"Container",
+ "ModuleCatalog",
+ "Registry",
+ "SALOMEDS",
+ "Session",
+ "ContainerManager"};
/*!
default constructor not for use
*/
-Session_ServerThread::Session_ServerThread()
+template<class MY_NS>
+Session_ServerThread<MY_NS>::Session_ServerThread()
{
ASSERT(0); // must not be called
}
/*!
constructor
*/
-Session_ServerThread::Session_ServerThread(int argc,
+template<class MY_NS>
+Session_ServerThread<MY_NS>::Session_ServerThread(int argc,
char ** argv,
CORBA::ORB_ptr orb,
PortableServer::POA_ptr poa)
_orb = CORBA::ORB::_duplicate(orb);
_root_poa = PortableServer::POA::_duplicate(poa);
_servType =-1;
- _NS = new SALOME_NamingService(_orb); // one instance per server to limit
- // multi thread coherence problems
- _container = 0; // embedded container
+ _NS.reset( new MY_NS(_orb) ); // one instance per server to limit
+ // multi thread coherence problems
+ _container = nullptr; // embedded container
}
/*!
destructor
*/
-Session_ServerThread::~Session_ServerThread()
+template<class MY_NS>
+Session_ServerThread<MY_NS>::~Session_ServerThread()
{
- //MESSAGE("~Session_ServerThread "<< _argv[0]);
- delete _NS;
for (int i = 0; i <_argc ; i++ )
free( _argv[i] );
delete[] _argv;
run the thread : activate one servant, the servant type is given by
argument _argv[0]
*/
-void Session_ServerThread::Init()
+template<class MY_NS>
+void Session_ServerThread<MY_NS>::Init()
{
MESSAGE("Session_ServerThread::Init "<< _argv[0]);
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;
}
}
}
-void Session_ServerThread::Shutdown()
+template<class MY_NS>
+void Session_ServerThread<MY_NS>::Shutdown()
{
if ( _container ) _container->Shutdown();
}
-void Session_ServerThread::ActivateModuleCatalog(int argc,
- char ** argv)
+template<class MY_NS>
+void Session_ServerThread<MY_NS>::ActivateModuleCatalog(int argc, char ** argv)
{
try {
MESSAGE("ModuleCatalog thread started");
}
}
-void Session_ServerThread::ActivateSALOMEDS(int /*argc*/, char** /*argv*/)
+template<class MY_NS>
+void Session_ServerThread<MY_NS>::ActivateSALOMEDS(int /*argc*/, char** /*argv*/)
{
- try {
- MESSAGE("SALOMEDS thread started");
- // We allocate the objects on the heap. Since these are reference
- // counted objects, they will be deleted by the POA when they are no
- // longer needed.
-
- ClientFactory::createStudy(_orb,_root_poa);
- }
- catch(CORBA::SystemException&) {
- INFOS( "Caught CORBA::SystemException." );
- }
- catch(CORBA::Exception&) {
- INFOS( "Caught CORBA::Exception." );
- }
- catch(omniORB::fatalException& fe) {
- INFOS( "Caught omniORB::fatalException:" );
- INFOS( " file: " << fe.file() );
- INFOS( " line: " << fe.line() );
- INFOS( " mesg: " << fe.errmsg() );
- }
- catch(...) {
- INFOS( "Caught unknown exception." );
- }
+ this->_NS->activateSALOMEDS(this->_orb,this->_root_poa);
}
-void Session_ServerThread::ActivateRegistry(int argc,
- char ** argv)
+template<class MY_NS>
+void Session_ServerThread<MY_NS>::ActivateRegistry(int argc, char ** argv)
{
MESSAGE("Registry thread started");
SCRUTE(argc);
}
}
-void Session_ServerThread::ActivateContainerManager(int /*argc*/, char** /*argv*/)
+template<class MY_NS>
+void Session_ServerThread<MY_NS>::ActivateContainerManager(int /*argc*/, char** /*argv*/)
{
- try {
- PortableServer::POA_var root_poa=PortableServer::POA::_the_root_poa();
- std::cout << "Activate SalomeLauncher ......!!!! " << std::endl;
- new SALOME_Launcher(_orb,root_poa);
- }
- catch(CORBA::SystemException&) {
- INFOS("Caught CORBA::SystemException.");
- }
- catch(PortableServer::POA::WrongPolicy&) {
- INFOS("Caught CORBA::WrongPolicyException.");
- }
- catch(PortableServer::POA::ServantAlreadyActive&) {
- INFOS("Caught CORBA::ServantAlreadyActiveException");
- }
- catch(CORBA::Exception&) {
- INFOS("Caught CORBA::Exception.");
- }
- catch(...) {
- INFOS("Caught unknown exception.");
- }
+ this->_NS->activateContainerManager(this->_orb);
}
-void Session_ServerThread::ActivateContainer(int argc, char** argv)
+template<class MY_NS>
+typename MY_NS::RealNS *Session_ServerThread<MY_NS>::getNS()
{
- try {
- MESSAGE("Container thread started");
-
- // get or create the child POA
-
- PortableServer::POA_var factory_poa;
- try {
- factory_poa = _root_poa->find_POA("factory_poa",0);
- // 0 = no activation (already done if exists)
- }
- catch (PortableServer::POA::AdapterNonExistent&) {
- MESSAGE("factory_poa does not exists, create...");
- // define policy objects
- PortableServer::ImplicitActivationPolicy_var implicitActivation =
- _root_poa->create_implicit_activation_policy(PortableServer::NO_IMPLICIT_ACTIVATION);
- // default = NO_IMPLICIT_ACTIVATION
- PortableServer::ThreadPolicy_var threadPolicy =
- _root_poa->create_thread_policy(PortableServer::ORB_CTRL_MODEL);
- // default = ORB_CTRL_MODEL, other choice SINGLE_THREAD_MODEL
-
- // create policy list
- CORBA::PolicyList policyList;
- policyList.length(2);
- policyList[0] = PortableServer::ImplicitActivationPolicy::
- _duplicate(implicitActivation);
- policyList[1] = PortableServer::ThreadPolicy::
- _duplicate(threadPolicy);
-
- PortableServer::POAManager_var nil_mgr
- = PortableServer::POAManager::_nil();
- factory_poa = _root_poa->create_POA("factory_poa",
- nil_mgr,
- policyList);
- //with nil_mgr instead of pman,
- //a new POA manager is created with the new POA
-
- // destroy policy objects
- implicitActivation->destroy();
- threadPolicy->destroy();
-
- // obtain the factory poa manager
- PortableServer::POAManager_var pmanfac = factory_poa->the_POAManager();
- pmanfac->activate();
- MESSAGE("pmanfac->activate()");
- }
-
- char *containerName = (char*)"";
- if (argc >1) {
- containerName = argv[1];
- }
-
- _container = new Engines_Container_i(_orb, _root_poa, containerName, argc, argv, true, false);
- }
- catch(CORBA::SystemException&) {
- INFOS("Caught CORBA::SystemException.");
- }
- catch(PortableServer::POA::WrongPolicy&) {
- INFOS("Caught CORBA::WrongPolicyException.");
- }
- catch(PortableServer::POA::ServantAlreadyActive&) {
- INFOS("Caught CORBA::ServantAlreadyActiveException");
- }
- catch(CORBA::Exception&) {
- INFOS("Caught CORBA::Exception.");
- }
- catch(...) {
- INFOS("Caught unknown exception.");
- }
+ MY_NS *pt(_NS.get());
+ if(!pt)
+ THROW_SALOME_EXCEPTION("Session_ServerThread<MY_NS>::getNS : null pointer !");
+ return pt->getNS();
+}
+
+template<class MY_NS>
+void Session_ServerThread<MY_NS>::ActivateContainer(int argc, char** argv)
+{
+ _container = this->_NS->activateContainer(this->_orb,this->_root_poa,argc,argv);
}
-void Session_ServerThread::ActivateSession(int /*argc*/, char** /*argv*/)
+template<class MY_NS>
+void Session_ServerThread<MY_NS>::ActivateSession(int /*argc*/, char** /*argv*/)
{
MESSAGE("Session_ServerThread::ActivateSession() not implemented!");
}
-/*!
- constructor
-*/
-Session_SessionThread::Session_SessionThread(int argc,
+template<class MY_NS>
+Session_SessionThread<MY_NS>::Session_SessionThread(int argc,
char** argv,
CORBA::ORB_ptr orb,
PortableServer::POA_ptr poa,
QMutex* GUIMutex,
QWaitCondition* GUILauncher)
-: Session_ServerThread(argc, argv, orb, poa),
+: Session_ServerThread<MY_NS>(argc, argv, orb, poa),
_GUIMutex( GUIMutex ),
_GUILauncher( GUILauncher )
{
}
-/*!
- destructor
-*/
-Session_SessionThread::~Session_SessionThread()
+template<class MY_NS>
+Session_SessionThread<MY_NS>::~Session_SessionThread()
{
}
-void Session_SessionThread::ActivateSession(int argc,
- char ** argv)
+template<class MY_NS>
+void Session_SessionThread<MY_NS>::ActivateSession(int argc, char ** argv)
{
- try {
- MESSAGE("Session thread started");
- SALOME_Session_i * mySALOME_Session
- = new SALOME_Session_i(argc, argv, _orb, _root_poa, _GUIMutex, _GUILauncher) ;
- PortableServer::ObjectId_var mySALOME_Sessionid
- = _root_poa->activate_object(mySALOME_Session);
- MESSAGE("poa->activate_object(mySALOME_Session)");
-
- CORBA::Object_var obj = mySALOME_Session->_this();
- CORBA::String_var sior(_orb->object_to_string(obj));
- mySALOME_Session->_remove_ref();
-
- mySALOME_Session->NSregister();
- }
- catch (CORBA::SystemException&) {
- INFOS("Caught CORBA::SystemException.");
- }
- catch (CORBA::Exception&) {
- INFOS("Caught CORBA::Exception.");
- }
- catch (...) {
- INFOS("Caught unknown exception.");
- }
+ this->_NS->activateSession(this->_orb,this->_root_poa,_GUIMutex,_GUILauncher,argc,argv);
}
+
+template class Session_ServerThread<OldStyleNS>;
+template class Session_SessionThread<OldStyleNS>;
+
+template class Session_ServerThread<NewStyleNS>;
+template class Session_SessionThread<NewStyleNS>;
#ifndef _SESSION_SERVERTHREAD_HXX_
#define _SESSION_SERVERTHREAD_HXX_
+#include "Session_NS_wrapper.hxx"
#include "SALOME_Session.hxx"
#include <omniORB4/CORBA.h>
#include <string>
+#include <memory>
void WaitForServerReadiness(std::string serverName);
class SALOME_NamingService;
class Engines_Container_i;
+template<class MY_NS>
class SESSION_EXPORT Session_ServerThread
{
+public:
+ using RealNS = typename MY_NS::RealNS;
public:
static const int NB_SRV_TYP;
static const char* _serverTypes[];
virtual void ActivateSession ( int argc, char ** argv );
void ActivateEngine ( int argc, char ** argv );
void ActivateContainerManager( int argc, char ** argv );
+ RealNS *getNS();
protected:
int _argc;
char ** _argv;
int _servType;
CORBA::ORB_var _orb;
PortableServer::POA_var _root_poa;
- SALOME_NamingService * _NS;
+ std::unique_ptr<MY_NS> _NS;
Engines_Container_i* _container;
};
class QMutex;
class QWaitCondition;
-class SESSION_EXPORT Session_SessionThread : public Session_ServerThread
+template<class MY_NS>
+class SESSION_EXPORT Session_SessionThread : public Session_ServerThread<MY_NS>
{
public:
Session_SessionThread() {}
virtual ~Session_SessionThread();
protected:
- virtual void ActivateSession ( int argc, char ** argv );
+ void ActivateSession ( int argc, char ** argv ) override;
private:
QMutex* _GUIMutex;
QWaitCondition* _GUILauncher;
};
#endif
-
#include <unistd.h>
#endif
-/*!
- constructor
-*/
-SALOME_Session_i::SALOME_Session_i(int argc,
- char ** argv,
- CORBA::ORB_ptr orb,
- PortableServer::POA_ptr poa,
- QMutex* GUIMutex,
- QWaitCondition* GUILauncher)
+SALOME_Session_i::SALOME_Session_i(int argc, char ** argv, CORBA::ORB_ptr orb, PortableServer::POA_ptr poa, QMutex* GUIMutex, QWaitCondition* GUILauncher):
+_argc(argc),_argv(argv),_isGUI(false),_GUIMutex(GUIMutex),_GUILauncher(GUILauncher),
+_orb(CORBA::ORB::_duplicate(orb)),_poa(PortableServer::POA::_duplicate(poa)),_isShuttingDown(false)
{
- _argc = argc ;
- _argv = argv ;
- _isGUI = false ;
- _orb = CORBA::ORB::_duplicate(orb) ;
- _poa = PortableServer::POA::_duplicate(poa) ;
- _GUIMutex = GUIMutex;
- _GUILauncher = GUILauncher;
- _NS = new SALOME_NamingService(_orb);
- _isShuttingDown = false;
- //MESSAGE("constructor end");
+ _NS.reset(new SALOME_NamingService(_orb));
+}
+
+SALOME_Session_i::SALOME_Session_i(int argc, char ** argv, CORBA::ORB_ptr orb, PortableServer::POA_ptr poa, QMutex* GUIMutex, QWaitCondition* GUILauncher, SALOME_NamingService_Abstract *NS):
+_argc(argc),_argv(argv),_isGUI(false),_GUIMutex(GUIMutex),_GUILauncher(GUILauncher),
+_orb(CORBA::ORB::_duplicate(orb)),_poa(PortableServer::POA::_duplicate(poa)),_isShuttingDown(false)
+{
+ _NS.reset(NS);
}
/*!
*/
Engines::EngineComponent_ptr SALOME_Session_i::GetComponent(const char* theLibraryName)
{
- typedef Engines::EngineComponent_ptr TGetImpl(CORBA::ORB_ptr,
- PortableServer::POA_ptr,
- SALOME_NamingService*,QMutex*);
+ using TGetImpl = Engines::EngineComponent_ptr (*)(CORBA::ORB_ptr, PortableServer::POA_ptr, SALOME_NamingService*,QMutex*);
OSD_SharedLibrary aSharedLibrary(const_cast<char*>(theLibraryName));
if (aSharedLibrary.DlOpen(OSD_RTLD_LAZY)) {
if (OSD_Function anOSDFun = aSharedLibrary.DlSymb("GetImpl"))
- return ((TGetImpl (*)) anOSDFun)(_orb,_poa,_NS,_GUIMutex);
+ {
+ Engines::EngineComponent_ptr ret = ((TGetImpl) anOSDFun)(_orb,_poa,dynamic_cast<SALOME_NamingService*>(_NS.get()),_GUIMutex);
+ return ret;
+ }
}
CORBA::Object_var obj = SalomeApp_Engine_i::EngineForComponent(theLibraryName, true);
if (!CORBA::is_nil(obj)){
*/
SALOME_Session_i::~SALOME_Session_i()
{
- delete _NS;
//MESSAGE("destructor end");
}
#include <SALOMEconfig.h>
#include CORBA_SERVER_HEADER(SALOME_Component)
#include CORBA_SERVER_HEADER(SALOME_Session)
-class SALOME_NamingService;
+
+#include <memory>
class QMutex;
class QWaitCondition;
+class SALOME_NamingService_Abstract;
-class SESSION_EXPORT SALOME_Session_i: public virtual POA_SALOME::Session,
- public virtual PortableServer::ServantBase
+class SESSION_EXPORT SALOME_Session_i : public virtual POA_SALOME::Session, public virtual PortableServer::ServantBase
{
public:
- SALOME_Session_i(int argc,
- char ** argv,
- CORBA::ORB_ptr orb,
- PortableServer::POA_ptr poa,
- QMutex* GUIMutex,
- QWaitCondition* GUILauncher);
+ SALOME_Session_i(int argc, char ** argv, CORBA::ORB_ptr orb, PortableServer::POA_ptr poa, QMutex* GUIMutex, QWaitCondition* GUILauncher);
+ SALOME_Session_i(int argc, char ** argv, CORBA::ORB_ptr orb, PortableServer::POA_ptr poa, QMutex* GUIMutex, QWaitCondition* GUILauncher, SALOME_NamingService_Abstract *NS);
~SALOME_Session_i();
//! Launch Graphical User Interface
protected:
//! Naming service interface
- SALOME_NamingService *_NS;
+ std::unique_ptr<SALOME_NamingService_Abstract> _NS;
int _argc ;
char **_argv;
--- /dev/null
+// Copyright (C) 2021 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include <QProcessEnvironment>
+#include <QDir>
+#include <QProcess>
+
+#include <iostream>
+
+int main(int argc, char *argv[])
+{
+ constexpr char MAIN_PROGRAM[] = "SALOME_Session_Server_No_Server";
+ constexpr char NO_SERVER_ENV_VAR[] = "SALOME_EMB_SERVANT";
+ const char *MODULES[]={"SHAPERSTUDY","GEOM","SMESH"};
+ constexpr char GUI_ROOT_DIR[]="GUI_ROOT_DIR";
+ constexpr char GEOM_ROOT_DIR[]="GEOM_ROOT_DIR";
+ constexpr char SMESH_ROOT_DIR[]="SMESH_ROOT_DIR";
+ constexpr char SHAPER_ROOT_DIR[]="SHAPER_ROOT_DIR";
+ constexpr char SHAPERSTUDY_ROOT_DIR[]="SHAPERSTUDY_ROOT_DIR";
+ constexpr char APPCONFIG[]="SalomeAppSLConfig";
+ QProcessEnvironment pe(QProcessEnvironment::systemEnvironment());
+ for(auto elt : {GUI_ROOT_DIR,GEOM_ROOT_DIR,SMESH_ROOT_DIR,SHAPER_ROOT_DIR,SHAPERSTUDY_ROOT_DIR} )
+ {
+ if( !pe.contains(elt) || pe.value(elt).isEmpty() )
+ {
+ std::cerr << elt << " is not defined in your environment !" << std::endl;
+ return 1;
+ }
+ }
+ // fill LightAppConfig env var
+ QString gui_root_dir( QDir::fromNativeSeparators(pe.value(GUI_ROOT_DIR)) );
+ QString shaper_root_dir( QDir::fromNativeSeparators(pe.value(SHAPER_ROOT_DIR)) );
+ QString shaperstudy_root_dir( QDir::fromNativeSeparators(pe.value(SHAPERSTUDY_ROOT_DIR)) );
+ QString geom_root_dir( QDir::fromNativeSeparators(pe.value(GEOM_ROOT_DIR)) );
+ QString smesh_root_dir( QDir::fromNativeSeparators(pe.value(SMESH_ROOT_DIR)) );
+ QString appconfig_val( QString("%1:%2:%3:%4:%5")
+ .arg( QDir::toNativeSeparators( QString("%1/share/salome/resources/gui").arg(gui_root_dir) ) )
+ .arg( QDir::toNativeSeparators( QString("%1/share/salome/resources/shaper").arg(shaper_root_dir) ) )
+ .arg( QDir::toNativeSeparators( QString("%1/share/salome/resources/shaperstudy").arg(shaperstudy_root_dir) ) )
+ .arg( QDir::toNativeSeparators( QString("%1/share/salome/resources/geom").arg(geom_root_dir) ) )
+ .arg( QDir::toNativeSeparators( QString("%1/share/salome/resources/smesh").arg(smesh_root_dir) ) ) );
+ 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();
+}