From: Anthony Geay Date: Thu, 18 Feb 2021 12:43:41 +0000 (+0100) Subject: Communicate Session servant created into Session_ServerLauncher thread to the main... X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=a879b12f6b864f54cc6ca79b3abe075ecf242af2;p=modules%2Fgui.git Communicate Session servant created into Session_ServerLauncher thread to the main thread to avoid use of NS --- diff --git a/src/Session/CMakeLists.txt b/src/Session/CMakeLists.txt index 50358adae..77038452f 100644 --- a/src/Session/CMakeLists.txt +++ b/src/Session/CMakeLists.txt @@ -81,6 +81,7 @@ SET(SalomeSession_HEADERS Session_ServerLauncher.hxx Session_ServerThread.hxx Session_Session_i.hxx + Session_Promises.hxx ) # --- resources --- @@ -98,6 +99,7 @@ SET(SalomeSession_SOURCES Session_ServerLauncher.cxx Session_ServerThread.cxx Session_Session_i.cxx + Session_Promises.cxx ) # --- rules --- diff --git a/src/Session/SALOME_Session_Server.cxx b/src/Session/SALOME_Session_Server.cxx index 38417eed6..8c516411a 100644 --- a/src/Session/SALOME_Session_Server.cxx +++ b/src/Session/SALOME_Session_Server.cxx @@ -37,6 +37,7 @@ #include "Session_Session_i.hxx" #include "Session_ServerCheck.hxx" #include "Session_ServerLauncher.hxx" +#include "Session_Promises.hxx" #include "GUI_version.h" #include "Qtx.h" @@ -449,8 +450,9 @@ void GUIAppOldStyle::shutdownRemoteServersIfNeeded(bool remoteLauncher) SALOME::Session_var GUIAppNewStyle::getSession() { - /*SALOMEDS::Study_var session = KERNEL::getStudyServantSA(); - return session;*/ + GetSessionRefSingleton()->get_future().wait(); + SALOME::Session_var session = GetSessionRefSingleton()->get_future().get(); + return session; } // ---------------------------- MAIN ----------------------- 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_ServerThread.cxx b/src/Session/Session_ServerThread.cxx index 7e4b67473..4e7e65f54 100644 --- a/src/Session/Session_ServerThread.cxx +++ b/src/Session/Session_ServerThread.cxx @@ -25,6 +25,7 @@ // Author : Paul RASCLE, EDF #include "Session_ServerThread.hxx" +#include "Session_Promises.hxx" #include #include @@ -426,6 +427,8 @@ void Session_SessionThread::ActivateSession(int argc, char ** argv) 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();