]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
WIP
authorAnthony Geay <anthony.geay@edf.fr>
Thu, 19 Aug 2021 07:56:36 +0000 (09:56 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Thu, 19 Aug 2021 07:56:36 +0000 (09:56 +0200)
src/Container/SALOME_CPythonHelper.cxx
src/Container/SALOME_CPythonHelper.hxx
src/KERNEL_PY/__init__.py
src/Launcher/KernelLauncher.cxx
src/Launcher/KernelLauncher.hxx
src/Launcher/KernelLauncher.i
src/Launcher/SALOME_ExternalServerHandler.cxx
src/Launcher/SALOME_ExternalServerHandler.hxx
src/Launcher/SALOME_ExternalServerLauncher.cxx
src/Launcher/SALOME_ExternalServerLauncher.hxx
src/SALOMESDS/KernelSDS.cxx

index d6b5585e9ae31ef3f9adf36f9f0a225ac059c5a7..3aca93ee837ba35a617434a94a0148f2876a9333 100644 (file)
@@ -20,6 +20,8 @@
 
 #include "SALOME_CPythonHelper.hxx"
 
+SALOME_CPythonHelper SALOME_CPythonHelper::_CPYTHONHELPER_INSTANCE;
+
 #if PY_VERSION_HEX < 0x03050000
 static char*
 Py_EncodeLocale(const wchar_t *arg, size_t *size)
index e267f64b5d2dd55acd347b26abf113eb835ff435..c89d5ee27596c0441733cbce86dead32ec346fb2 100644 (file)
@@ -38,6 +38,9 @@ class CONTAINER_EXPORT SALOME_CPythonHelper
   PyObject *getGlobals() const { return _globals; }
   PyObject *getLocals() const { return _locals; }
   PyObject *getPickler() const  { return _pickler; }
+  static SALOME_CPythonHelper& Singleton() { return _CPYTHONHELPER_INSTANCE; }
+ private:
+  static SALOME_CPythonHelper _CPYTHONHELPER_INSTANCE;
  private:
   PyObject *_globals = nullptr;
   PyObject *_locals = nullptr;
index 8e78458d28ada9842164057fcbcdebccfb5947be..02452948ada2234c6c338f79906e5d9e2c92d3b4 100644 (file)
@@ -204,7 +204,7 @@ class StandAloneLifecyle:
       return self._rm
 
 def salome_init_without_session():
-    global lcc,naming_service,myStudy,orb,modulcat,sg,cm,dsm
+    global lcc,naming_service,myStudy,orb,modulcat,sg,cm,dsm,esm
     import KernelBasis
     KernelBasis.setSSLMode(True)
     import KernelDS
@@ -229,6 +229,9 @@ def salome_init_without_session():
     from KernelSDS import GetDSMInstance
     import sys
     dsm = GetDSMInstance(sys.argv)
+    # esm inherits from SALOME_CPythonHelper singleton already initialized by GetDSMInstance
+    # esm inherits also from SALOME_ResourcesManager creation/initialization (concerning SingleThreadPOA POA) when KernelLauncher.GetContainerManager() has been called
+    esm = KernelLauncher.GetExternalServer()
 
 def salome_init_with_session(path=None, embedded=False):
     """
index 5eaaae9f9942cf932a17c641ff4792372296a373..4df0eecb5c635e2f7a8936b917caf365a7fc0fc9 100644 (file)
@@ -24,6 +24,8 @@
 #include "SALOME_Fake_NamingService.hxx"
 #include "SALOME_KernelServices.hxx"
 #include "SALOME_ResourcesManager.hxx"
+#include "SALOME_ExternalServerLauncher.hxx"
+#include "SALOME_CPythonHelper.hxx"
 
 #include <cstring>
 
@@ -46,3 +48,23 @@ std::string GetResourcesManagerInstance()
   CORBA::String_var ior = orb->object_to_string(cm);
   return std::string(ior.in());
 }
+
+std::string GetExternalServerInstance()
+{
+  CORBA::ORB_ptr orb = KERNEL::getORB();
+  CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
+  PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj);
+  //
+  PortableServer::POA_var safePOA = root_poa->find_POA("SingleThreadPOA",true);
+  //
+  SALOME_CPythonHelper *cPyh(&SALOME_CPythonHelper::Singleton());
+  SALOME_Fake_NamingService *ns = new SALOME_Fake_NamingService;
+  SALOME_ExternalServerLauncher *esm(new SALOME_ExternalServerLauncher(cPyh,orb,safePOA,ns));
+  esm->_remove_ref();
+  //
+  CORBA::Object_var esmPtr = safePOA->servant_to_reference(esm);
+  SALOME::ExternalServerLauncher_var esmCPtr = SALOME::ExternalServerLauncher::_narrow(esmPtr);
+  //
+  CORBA::String_var ior = orb->object_to_string(esmCPtr);
+  return std::string(ior.in());
+}
index 567f5e581758f9f0310999e23783189d75042640..575c8101c4d9679b6431fcd52b36a305f0db0af4 100644 (file)
@@ -23,3 +23,4 @@
 
 std::string GetContainerManagerInstance();
 std::string GetResourcesManagerInstance();
+std::string GetExternalServerInstance();
index d67ef54f542e51713d54b32eb8e4ebf09aff1d89..11dc719e6ab5e46278c7b823d9efccde1fd9d8d5 100644 (file)
@@ -29,6 +29,7 @@
 {
   std::string GetContainerManagerInstance();
   std::string GetResourcesManagerInstance();
+  std::string GetExternalServerInstance();
 }
 
 %pythoncode %{
@@ -43,4 +44,10 @@ def myResourcesManager():
   import CORBA
   orb=CORBA.ORB_init([''])
   return orb.string_to_object(GetResourcesManagerInstance())
+
+def GetExternalServer():
+  import SALOME
+  import CORBA
+  orb=CORBA.ORB_init([''])
+  return orb.string_to_object(GetExternalServerInstance())
 %}
index fb2c2106d83fc198b3d2958abb17f65d3f093905..7f8c7466580c7ce6cdafe22edc70c8aaebf57d59 100644 (file)
@@ -36,7 +36,7 @@
 
 unsigned SALOME_ExternalServerHandler::CNT = 0;
 
-SALOME_ExternalServerHandler::SALOME_ExternalServerHandler(SALOME_ExternalServerLauncher *boss, const std::string& name, SALOME_NamingService *ns, long pid):_name(name),_pid(pid),_NS(ns),_boss(boss)
+SALOME_ExternalServerHandler::SALOME_ExternalServerHandler(SALOME_ExternalServerLauncher *boss, const std::string& name, SALOME_NamingService_Abstract *ns, long pid):_name(name),_pid(pid),_NS(ns),_boss(boss)
 {
 }
 
index 39b28df4fcdd14a6d73c87c50f4024f1cd33a768..542315706c904426032401db74837fe41db833e6 100644 (file)
 
 #include <string>
 
-class SALOME_NamingService;
+class SALOME_NamingService_Abstract;
 class SALOME_ExternalServerLauncher;
 class SALOME_CPythonHelper;
 
 class SALOMELAUNCHER_EXPORT SALOME_ExternalServerHandler : public POA_SALOME::ExternalServerHandler
 {
  public:
-  SALOME_ExternalServerHandler(SALOME_ExternalServerLauncher *boss, const std::string& name, SALOME_NamingService *ns, long pid);
+  SALOME_ExternalServerHandler(SALOME_ExternalServerLauncher *boss, const std::string& name, SALOME_NamingService_Abstract *ns, long pid);
   virtual ~SALOME_ExternalServerHandler();
   void registerToKill(const SALOME_CPythonHelper *pyHelper) const;
   static void KillPID(long pid);
@@ -49,7 +49,7 @@ class SALOMELAUNCHER_EXPORT SALOME_ExternalServerHandler : public POA_SALOME::Ex
  private:
   std::string _name;
   long _pid;
-  SALOME_NamingService *_NS;
+  SALOME_NamingService_Abstract *_NS;
   SALOME_ExternalServerLauncher *_boss;
   static unsigned CNT;
 };
index 2fb3ab142a9dda213d8e84bf97ed13dd4869a01f..47df986605b0c142688a0827712105c40f3cf630 100644 (file)
@@ -44,9 +44,9 @@ const char SALOME_ExternalServerLauncher::NAME_IN_NS[]="/ExternalServers";
 
 unsigned SALOME_ExternalServerLauncher::CNT = 0;
 
-SALOME_ExternalServerLauncher::SALOME_ExternalServerLauncher(const SALOME_CPythonHelper *pyHelper, CORBA::ORB_ptr orb, PortableServer::POA_var poa):_pyHelper(pyHelper),_poa(poa)
+SALOME_ExternalServerLauncher::SALOME_ExternalServerLauncher(const SALOME_CPythonHelper *pyHelper, CORBA::ORB_ptr orb, PortableServer::POA_var poa,SALOME_NamingService_Abstract *ns):_pyHelper(pyHelper),_poa(poa)
 {
-  _NS = new SALOME_NamingService(orb);
+  _NS = ns == nullptr ? new SALOME_NamingService(orb) : ns;
   PortableServer::ObjectId_var id(_poa->activate_object(this));
   CORBA::Object_var obj(_poa->id_to_reference(id));
   SALOME::ExternalServerLauncher_var refPtr(SALOME::ExternalServerLauncher::_narrow(obj));
@@ -211,7 +211,7 @@ SALOME::ByteVec *SALOME_ExternalServerLauncher::fetchContentOfFileAndRm(const ch
   return ret.release();
 }
 
-std::vector<std::string> SALOME_ExternalServerLauncher::ListOfExternalServersCpp(SALOME_NamingService *ns)
+std::vector<std::string> SALOME_ExternalServerLauncher::ListOfExternalServersCpp(SALOME_NamingService_Abstract *ns)
 {
   ns->Change_Directory(NAME_IN_NS);
   std::vector<std::string> ret(ns->list_directory());
@@ -236,7 +236,7 @@ bool SALOME_ExternalServerLauncher::IsAliveAndKicking(SALOME::ExternalServerHand
   return ret;
 }
 
-bool SALOME_ExternalServerLauncher::IsAliveAndKicking(SALOME_NamingService *ns, const std::string& serverName)
+bool SALOME_ExternalServerLauncher::IsAliveAndKicking(SALOME_NamingService_Abstract *ns, const std::string& serverName)
 {
   SALOME::ExternalServerHandler_var pt(GetServerHandlerGivenName(ns, serverName));
   if( CORBA::is_nil(pt) )
@@ -244,7 +244,7 @@ bool SALOME_ExternalServerLauncher::IsAliveAndKicking(SALOME_NamingService *ns,
   return IsAliveAndKicking(pt);
 }
 
-SALOME::ExternalServerHandler_var SALOME_ExternalServerLauncher::GetServerHandlerGivenName(SALOME_NamingService *ns, const std::string& serverName)
+SALOME::ExternalServerHandler_var SALOME_ExternalServerLauncher::GetServerHandlerGivenName(SALOME_NamingService_Abstract *ns, const std::string& serverName)
 {
   std::vector<std::string> serverNames(ListOfExternalServersCpp(ns));
   if(std::find(serverNames.begin(),serverNames.end(),serverName)==serverNames.end())
index c69664e4b664fd059f553fd54c5bdc3f9bc56f96..d4c617ecb50d0de4ba67c53cb567b354b54ea670 100644 (file)
 #include <vector>
 #include <string>
 
-class SALOME_NamingService;
+class SALOME_NamingService_Abstract;
 class SALOME_CPythonHelper;
 
 class SALOMELAUNCHER_EXPORT SALOME_ExternalServerLauncher : public POA_SALOME::ExternalServerLauncher
 {
  public:
-  SALOME_ExternalServerLauncher(const SALOME_CPythonHelper *pyHelper, CORBA::ORB_ptr orb, PortableServer::POA_var poa);
+  SALOME_ExternalServerLauncher(const SALOME_CPythonHelper *pyHelper, CORBA::ORB_ptr orb, PortableServer::POA_var poa, SALOME_NamingService_Abstract *ns = nullptr);
   virtual ~SALOME_ExternalServerLauncher();
  public:
   SALOME::ExternalServerHandler_ptr launchServer(const char *server_name, const char *working_dir, const SALOME::CmdList& command_list ) override;
@@ -49,13 +49,13 @@ class SALOMELAUNCHER_EXPORT SALOME_ExternalServerLauncher : public POA_SALOME::E
   const SALOME_CPythonHelper *getPyHelper() const { return _pyHelper; }
  private:
   static std::string CreateAbsNameInNSFromServerName(const std::string& scopeName);
-  static std::vector<std::string> ListOfExternalServersCpp(SALOME_NamingService *ns);
+  static std::vector<std::string> ListOfExternalServersCpp(SALOME_NamingService_Abstract *ns);
   static bool IsAliveAndKicking(SALOME::ExternalServerHandler_ptr server);
-  static bool IsAliveAndKicking(SALOME_NamingService *ns, const std::string& serverName);
-  static SALOME::ExternalServerHandler_var GetServerHandlerGivenName(SALOME_NamingService *ns, const std::string& serverName);
+  static bool IsAliveAndKicking(SALOME_NamingService_Abstract *ns, const std::string& serverName);
+  static SALOME::ExternalServerHandler_var GetServerHandlerGivenName(SALOME_NamingService_Abstract *ns, const std::string& serverName);
  private:
   const SALOME_CPythonHelper *_pyHelper = nullptr;
-  SALOME_NamingService *_NS = nullptr;
+  SALOME_NamingService_Abstract *_NS = nullptr;
   PortableServer::POA_var _poa;
   static unsigned CNT;
   std::vector<long> _list_of_pids_to_kill;
index a76f99f14db60a7a8f72f3d4f9b1dcee10fce796..d9f50fc4e4fd429b327cb88bc32a5557edf4397e 100644 (file)
@@ -35,20 +35,20 @@ std::string GetDSMInstanceInternal(const std::vector<std::string>& argv)
     CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
     if(!CORBA::is_nil(obj))
       root_poa = PortableServer::POA::_narrow(obj);
-    SALOME_CPythonHelper cPyh;
+    SALOME_CPythonHelper* cPyh(&SALOME_CPythonHelper::Singleton());
     {
       int argcInit((int)argv.size());
       char **argvInit = new char *[argcInit+1];
       argvInit[argcInit] = nullptr;
       for(int i = 0 ; i < argcInit ; ++i)
         argvInit[i] = strdup(argv[i].c_str());
-      cPyh.initializePython(argcInit,argvInit);
+      cPyh->initializePython(argcInit,argvInit);
       for(int i = 0 ; i < argcInit ; ++i)
         free(argvInit[i]);
       delete [] argvInit;
     }
     SALOME_Fake_NamingService *ns(new SALOME_Fake_NamingService);
-    SALOMESDS::DataServerManager *dsm(new SALOMESDS::DataServerManager(&cPyh,orb,root_poa,ns));
+    SALOMESDS::DataServerManager *dsm(new SALOMESDS::DataServerManager(cPyh,orb,root_poa,ns));
     dsm->_remove_ref();
     CORBA::Object_var objRef = ns->Resolve(SALOMESDS::DataServerManager::NAME_IN_NS);
     _dsm_singleton = SALOME::DataServerManager::_narrow(objRef);