]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
[EDF30382] : Synchro mecanism to ease test of extreme situations V9_13_BR agy/30382_913 V9_13_0 V9_13_0rc1 V9_13_0rc2 V9_13_0rc3
authorAnthony Geay <anthony.geay@edf.fr>
Fri, 28 Jun 2024 15:07:32 +0000 (17:07 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Mon, 8 Jul 2024 12:47:57 +0000 (14:47 +0200)
13 files changed:
idl/CMakeLists.txt
idl/SALOME_Locker.idl [new file with mode: 0644]
src/Container/CMakeLists.txt
src/Container/SALOME_Container_i.hxx
src/Container/SALOME_LockMasterImpl.cxx [new file with mode: 0644]
src/Container/SALOME_LockMasterImpl.hxx [new file with mode: 0644]
src/Container/SALOME_LockServantImpl.cxx [new file with mode: 0644]
src/Container/SALOME_LockServantImpl.hxx [new file with mode: 0644]
src/Container/Test/testProxy.py
src/KERNEL_PY/__init__.py
src/Launcher/KernelLauncher.cxx
src/Launcher/KernelLauncher.hxx
src/Launcher/KernelLauncher.i

index 236b9b9544f649d115032012f7c86d25c723790a..fc044fdbbae43554695a0a9a65abb48db80bf193 100644 (file)
@@ -57,6 +57,7 @@ SET(SalomeIDLKernel_IDLSOURCES
   SALOME_ExternalServerLauncher.idl
   SALOME_LogManager.idl
   SALOME_Embedded_NamingService.idl
+  SALOME_Locker.idl
   ${CMAKE_CURRENT_BINARY_DIR}/Calcium_Ports.idl
 )
 
diff --git a/idl/SALOME_Locker.idl b/idl/SALOME_Locker.idl
new file mode 100644 (file)
index 0000000..956a60b
--- /dev/null
@@ -0,0 +1,43 @@
+// Copyright (C) 2024  CEA, EDF
+//
+// 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
+//
+
+#ifndef __SALOME_LOCKER_IDL__
+#define __SALOME_LOCKER_IDL__
+
+module Engines
+{
+  interface LockServant
+  {
+    void acquire();
+    void release();
+  };
+
+  interface RendezVousServant
+  {
+    void acquire();
+  };
+
+  interface LockMaster
+  {
+    LockServant getLockerFor(in string key);
+    RendezVousServant buildRendezVous(in long nbClients);
+  };
+};
+
+#endif
index e61ebbb214b8e43b66372bf7fd77df45086d34ba..616b4e348bc092f210dbe1f60cbcdc174f713af4 100644 (file)
@@ -89,6 +89,8 @@ SET(SalomeContainer_SOURCES
   SALOME_ContainerManager.cxx
   Salome_file_i.cxx
   SALOME_CPythonHelper.cxx
+  SALOME_LockMasterImpl.cxx
+  SALOME_LockServantImpl.cxx
 )
 
 ADD_LIBRARY(SalomeContainer ${SalomeContainer_SOURCES})
index 758082ffa1325122e6c0899caafd31d86ab0f036..ae96b0544c168b94037ca2b244b5ca4a83b0ddc2 100644 (file)
@@ -35,6 +35,7 @@
 #include <SALOMEconfig.h>
 #include CORBA_SERVER_HEADER(SALOME_Component)
 #include CORBA_SERVER_HEADER(SALOME_PyNode)
+#include CORBA_SERVER_HEADER(SALOME_Locker)
 
 #include <iostream>
 #include <signal.h>
diff --git a/src/Container/SALOME_LockMasterImpl.cxx b/src/Container/SALOME_LockMasterImpl.cxx
new file mode 100644 (file)
index 0000000..f1649a8
--- /dev/null
@@ -0,0 +1,53 @@
+// Copyright (C) 2024  CEA, EDF
+//
+// 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_LockMasterImpl.hxx"
+#include "SALOME_LockServantImpl.hxx"
+
+#include "SALOME_KernelORB.hxx"
+
+#include <string>
+#include <map>
+
+static std::map<std::string,Engines::LockServant_var> _uniqueLockObj;
+
+Engines::LockServant_ptr SALOME::LockMasterImpl::getLockerFor(const char *key)
+{
+  std::string keyCpp(key);
+  auto it = _uniqueLockObj.find( keyCpp );
+  Engines::LockServant_var ret;
+  if( it != _uniqueLockObj.end() )
+    ret = it->second;
+  else
+  {
+    SALOME::LockServantImpl *serv = new SALOME::LockServantImpl;
+    ret = serv->_this();
+    serv->_remove_ref();
+    _uniqueLockObj[keyCpp] = ret;
+  }
+  return Engines::LockServant::_duplicate( ret );
+}
+
+Engines::RendezVousServant_ptr SALOME::LockMasterImpl::buildRendezVous(CORBA::Long nbClients)
+{
+  SALOME::RendezVousServantImpl *serv = new SALOME::RendezVousServantImpl(nbClients);
+  Engines::RendezVousServant_var ret = serv->_this();
+  serv->_remove_ref();
+  return Engines::RendezVousServant::_duplicate( ret );
+}
diff --git a/src/Container/SALOME_LockMasterImpl.hxx b/src/Container/SALOME_LockMasterImpl.hxx
new file mode 100644 (file)
index 0000000..e1b9843
--- /dev/null
@@ -0,0 +1,37 @@
+// Copyright (C) 2024  CEA, EDF
+//
+// 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_Container.hxx"
+
+#include <SALOMEconfig.h>
+
+#include CORBA_SERVER_HEADER(SALOME_Locker)
+
+namespace SALOME
+{
+  class CONTAINER_EXPORT LockMasterImpl : public virtual POA_Engines::LockMaster
+  {
+  public:
+    LockMasterImpl() = default;
+    Engines::LockServant_ptr getLockerFor(const char *key) override;
+    Engines::RendezVousServant_ptr buildRendezVous(CORBA::Long nbClients) override;
+  };
+}
diff --git a/src/Container/SALOME_LockServantImpl.cxx b/src/Container/SALOME_LockServantImpl.cxx
new file mode 100644 (file)
index 0000000..09e8450
--- /dev/null
@@ -0,0 +1,59 @@
+// Copyright (C) 2024  CEA, EDF
+//
+// 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_LockServantImpl.hxx"
+
+#include <stdexcept>
+
+#include <iostream>
+
+void SALOME::LockServantImpl::acquire()
+{
+  _mutex.lock();
+}
+
+void SALOME::LockServantImpl::release()
+{
+  _mutex.unlock();
+}
+
+SALOME::RendezVousServantImpl::RendezVousServantImpl(unsigned int nbOfClientsToWait):_nb_clients(nbOfClientsToWait)
+{
+  if( _nb_clients == 0 )
+    throw std::runtime_error("RendezVousServantImpl is supposed to be >= 1!");
+  _promise.resize( _nb_clients-1 );
+}
+
+void SALOME::RendezVousServantImpl::acquire()
+{
+  bool waitOrRelease = false;
+  {
+    std::lock_guard<std::mutex> lock(_mutex);
+    waitOrRelease = _nb_clients <= 1;
+    if( _nb_clients != 0)
+      _nb_clients--;
+  }
+  if( !waitOrRelease )//wait
+    _promise[_nb_clients-1].get_future().wait();
+  else//relase
+  {
+    for(auto& it : _promise)
+      it.set_value();
+  }
+}
diff --git a/src/Container/SALOME_LockServantImpl.hxx b/src/Container/SALOME_LockServantImpl.hxx
new file mode 100644 (file)
index 0000000..3db5d50
--- /dev/null
@@ -0,0 +1,54 @@
+// Copyright (C) 2024  CEA, EDF
+//
+// 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_Container.hxx"
+
+#include <SALOMEconfig.h>
+
+#include CORBA_SERVER_HEADER(SALOME_Locker)
+
+#include <mutex>
+#include <future>
+#include <vector>
+
+namespace SALOME
+{
+  class CONTAINER_EXPORT LockServantImpl : public virtual POA_Engines::LockServant
+  {
+  public:
+    LockServantImpl() = default;
+    void acquire() override;
+    void release() override;
+  private:
+    std::mutex _mutex;
+  };
+  
+  class CONTAINER_EXPORT RendezVousServantImpl : public virtual POA_Engines::RendezVousServant
+  {
+  public:
+    RendezVousServantImpl(unsigned int nbOfClientsToWait);
+    void acquire() override;
+  private:
+    std::vector< std::promise<void> > _promise;
+    std::mutex _mutex;
+    unsigned int _nb_clients;
+  };
+}
index 4637e895a9815e8e9b627274a22ebd6d1f3fa8d3..b79e8e021e9d884979f070603a3228233b978522 100644 (file)
@@ -182,38 +182,108 @@ ret = os.getcwd()
         ### end of check effectivity of manipulation locally
 
         cp = pylauncher.GetRequestForGiveContainer("localhost","gg")
-        cont = salome.cm.GiveContainer(cp)
-        pyscript = cont.createPyScriptNode("testScript","""
+        with salome.ContainerLauncherCM(cp) as cont:
+            pyscript = cont.createPyScriptNode("testScript","""
 import salome
 salome.salome_init()
 machines = salome.rm.ListAllResourceEntriesInCatalog()
 structure = { machine : salome.rm.GetResourceDefinition( machine ) for machine in machines }
 """) # retrieve the content remotely and then return it back to current process
+            import SALOME_PyNode
+            import pickle
+            poa = salome.orb.resolve_initial_references("RootPOA")
+            obj = SALOME_PyNode.SenderByte_i(poa,pickle.dumps( ([],{}) ))
+            id_o = poa.activate_object(obj)
+            refPtr = poa.id_to_reference(id_o)
+            #
+            pyscript.executeFirst(refPtr)
+            ret = pyscript.executeSecond(["structure"])
+            ret = ret[0]
+            retPy = pickle.loads( SALOME_PyNode.SeqByteReceiver(ret).data() )
+
+            self.assertTrue( len(localStructure) == len(retPy) )
+            self.assertTrue( "zFakeHost" in [elt for elt in localStructure])
+            self.assertTrue( localStructure["zFakeHost"].applipath == "/home/appli/fakeappli")
+            self.assertTrue( "zzFakeHost" in [elt for elt in localStructure])
+            self.assertTrue( localStructure["zzFakeHost"].applipath == "/home/appli/zzfakeappli")
+            for k in localStructure:
+                a = pylauncher.FromEngineResourceDefinitionToCPP( localStructure[k] )
+                self.assertTrue( isinstance(a,pylauncher.ResourceDefinition_cpp) )
+                b = pylauncher.FromEngineResourceDefinitionToCPP( retPy[k] )
+                self.assertTrue( isinstance(b,pylauncher.ResourceDefinition_cpp) )
+                self.assertTrue( a==b ) #<- key point is here
+                a1 = pylauncher.ToEngineResourceDefinitionFromCPP( a )
+                b1 = pylauncher.ToEngineResourceDefinitionFromCPP( b )
+                a2 = pylauncher.FromEngineResourceDefinitionToCPP( a1 )
+                b2 = pylauncher.FromEngineResourceDefinitionToCPP( b1 )
+                self.assertTrue( a2==b2 )
+
+    def testMultiProcessCriticalSection0(self):
+        """
+        [EDF30382] : Synchro mecanism to ease test of extreme situations
+        """
+        from datetime import datetime
+        from threading import Thread
+        import contextlib
         import SALOME_PyNode
-        import pickle
-        poa = salome.orb.resolve_initial_references("RootPOA")
-        obj = SALOME_PyNode.SenderByte_i(poa,pickle.dumps( ([],{}) ))
-        id_o = poa.activate_object(obj)
-        refPtr = poa.id_to_reference(id_o)
-        #
-        pyscript.executeFirst(refPtr)
-        ret = pyscript.executeSecond(["structure"])
-        ret = ret[0]
-        retPy = pickle.loads( SALOME_PyNode.SeqByteReceiver(ret).data() )
-
-        assert( len(localStructure) == len(retPy) )
-        for k in localStructure:
-            a = pylauncher.FromEngineResourceDefinitionToCPP( localStructure[k] )
-            self.assertTrue( isinstance(a,pylauncher.ResourceDefinition_cpp) )
-            b = pylauncher.FromEngineResourceDefinitionToCPP( retPy[k] )
-            self.assertTrue( isinstance(b,pylauncher.ResourceDefinition_cpp) )
-            self.assertTrue( a==b ) #<- key point is here
-            a1 = pylauncher.ToEngineResourceDefinitionFromCPP( a )
-            b1 = pylauncher.ToEngineResourceDefinitionFromCPP( b )
-            a2 = pylauncher.FromEngineResourceDefinitionToCPP( a1 )
-            b2 = pylauncher.FromEngineResourceDefinitionToCPP( b1 )
-            self.assertTrue( a2==b2 )
-        cont.Shutdown()
+        import time
+
+        def func(pyscript,b):
+            poa = salome.orb.resolve_initial_references("RootPOA")
+            obj = SALOME_PyNode.SenderByte_i(poa,pickle.dumps( (["b"],{"b":b} ) )) ; id_o = poa.activate_object(obj) ; refPtr = poa.id_to_reference(id_o)
+            pyscript.executeFirst(refPtr)
+            ret = pyscript.executeSecond([])
+            retPy = [ pickle.loads( SALOME_PyNode.SeqByteReceiver( elt ).data() ) for elt in ret]
+            return retPy
+
+        salome.salome_init()
+        rmcpp = pylauncher.RetrieveRMCppSingleton()
+        hostname = "localhost"
+        cps = [ pylauncher.GetRequestForGiveContainer(hostname,contName) for contName in ["container_test_lock","container_test_lock_2"]]
+        with contextlib.ExitStack() as stack:
+            conts = [stack.enter_context(salome.ContainerLauncherCM(cp)) for cp in cps] # Context Manager to automatically cleanup launched containers
+            b = salome.Barrier(3)
+            pyscript = conts[0].createPyScriptNode("testScript","""
+from datetime import datetime
+import salome
+import time
+time.sleep( 2.0 )
+b.barrier()
+print("go barrier")
+print("after barrier T0 : {}".format(datetime.now()))
+with salome.LockGuardCM("SSD"):
+    print("Start CS T0 : {}".format(datetime.now()))
+    time.sleep(5)
+    print("End CS T0 : {}".format(datetime.now()))
+""")
+            pyscript2 = conts[1].createPyScriptNode("testScript","""
+from datetime import datetime
+import salome
+import time
+time.sleep( 4.0 )
+b.barrier()
+print("go barrier")
+print("after barrier T1 : {}".format(datetime.now()))
+with salome.LockGuardCM("SSD"):
+    print("Start CS T1 : {}".format(datetime.now()))
+    time.sleep(5)
+    print("End CS T1 : {}".format(datetime.now()))
+""")
+            ts = [Thread( target=func, args=(ps,b) ) for ps in [pyscript,pyscript2]]
+            [t.start() for t in ts]
+            st0 = datetime.now()
+            time.sleep( 1.0 )
+            b.barrier() # wait everybody
+            print("go barrier")
+            print("after barrier Master : {}".format(datetime.now()))
+            with salome.LockGuardCM("SSD"):
+                print("In critical section")
+            [t.join() for t in ts]
+            zedelt = datetime.now() - st0
+            assert( zedelt.total_seconds() > 14.0 ) # expected max(1,2,4)+5+5 = 14s
+            pass
+    pass
+
 
 if __name__ == '__main__':
     salome.standalone()
index 6d7d73211f837fd94006e9254f551918d94eb4b7..822df2c6a38962f0109bf7492b9a646488bb590d 100644 (file)
@@ -161,7 +161,7 @@ if not flags:
 #    sys.setdlopenflags(flags)
 #    pass
 
-orb, lcc, naming_service, cm, sg, esm, dsm, logm, modulcat, rm = None,None,None,None,None,None,None,None,None,None
+orb, lcc, naming_service, cm, sg, esm, dsm, logm, modulcat, rm, lm = None,None,None,None,None,None,None,None,None,None,None
 myStudy, myStudyName = None,None
 
 salome_initial=True
@@ -245,7 +245,7 @@ def salome_init_without_session(path=None, embedded=False, iorfakensfile=None):
     A Fake NamingService is created storing reference of all servants in the current process.
     """
     salome_init_without_session_common(path,embedded)
-    global lcc,cm,dsm,esm,rm,logm
+    global lcc,cm,dsm,esm,rm,logm,lm
     import KernelLauncher
     cm = KernelLauncher.myContainerManager()
     type(cm).SetOverrideEnvForContainersSimple = ContainerManagerSetOverrideEnvForContainersSimple
@@ -255,6 +255,7 @@ def salome_init_without_session(path=None, embedded=False, iorfakensfile=None):
     # create a FactoryServer Container servant
     import KernelContainer
     KernelContainer.myContainer()
+    lm = KernelLauncher.myLockMaster()
     # activate poaManager to accept co-localized CORBA calls.
     from KernelSDS import GetDSMInstance
     import sys
@@ -297,11 +298,12 @@ def salome_init_without_session_attached(path=None, embedded=False):
     lcc is pointing to the FakeNamingService above.
     """
     salome_init_without_session_common(path,embedded)
-    global lcc,cm,dsm,esm,rm,logm
+    global lcc,cm,dsm,esm,rm,logm,lm
     import CORBA
     orb=CORBA.ORB_init([''])
     import Engines
     import KernelBasis
+    import KernelLauncher
     nsAbroad = orb.string_to_object( KernelBasis.getIOROfEmbeddedNS() )
     import SALOME
     cm = orb.string_to_object( nsAbroad.Resolve(CM_NAME_IN_NS).decode() )
@@ -320,6 +322,9 @@ def salome_init_without_session_attached(path=None, embedded=False):
     #
     logm = orb.string_to_object( nsAbroad.Resolve(LOGM_NAME_IN_NS).decode() )
     naming_service.Register(logm,LOGM_NAME_IN_NS)
+    #
+    lm = orb.string_to_object( nsAbroad.Resolve(KernelLauncher.GetLockMasterEntryInNS()).decode() )
+    naming_service.Register(lm,KernelLauncher.GetLockMasterEntryInNS())
 
 def salome_init_with_session(path=None, embedded=False):
     """
@@ -601,5 +606,47 @@ def LogManagerGetLatestMonitoringDumpFile(self):
     logging.warning("in LogManagerGetLatestMonitoringDumpFile an unexpected situation araises.")
     return ""
 
+class Barrier:
+  def __init__(self, nbClients):
+    import CORBA
+    orb=CORBA.ORB_init([''])
+    self._ior = orb.object_to_string( lm.buildRendezVous( nbClients ) )
+  def barrier(self):
+    import CORBA
+    import Engines
+    orb=CORBA.ORB_init([''])
+    rvPtr = orb.string_to_object( self._ior )
+    rvPtr.acquire()
+
+class LockGuardCM:
+  def __init__(self, key):
+    if lm is None:
+        raise RuntimeError("SALOME has not been initialized !")
+    self._lock = lm.getLockerFor( key )
+  def __enter__(self):
+    self._lock.acquire()
+  def __exit__(self,exctype, exc, tb):
+    self._lock.release()
+
+class ContainerLauncherCM:
+  def __init__(self, cp, aggressiveShutdown = False):
+    """
+    :param cp: Engines.ContainerParameters instance specifying the request where the container will be launched
+    :param aggressiveShutdown:
+    """
+    self._cp = cp
+    self.aggressiveShutdown = aggressiveShutdown
+  def __enter__(self):
+    self._cont = cm.GiveContainer(self._cp)
+    return self._cont
+  def __exit__(self,exctype, exc, tb):
+    if not self.aggressiveShutdown:
+      self._cont.Shutdown()
+    else:
+      try:# we are in aggressive situation the following call is not expected to return normally
+        self._cont.ShutdownNow()
+      except:
+        pass
+
 #to expose all objects to pydoc
 __all__ = dir()
index 94da678585a0edb7bb4fc0e77c6e42037daf9b51..2d60f5a10d4d32c967c6bb46509dcaff9d009362 100644 (file)
 #include "SALOME_ExternalServerLauncher.hxx"
 #include "SALOME_LogManager.hxx"
 #include "SALOME_CPythonHelper.hxx"
+#include "SALOME_LockMasterImpl.hxx"
 
 #include <cstring>
 #include <sstream>
 
 static Engines::LogManager_var LogManagerInstanceSingleton;
 static SALOME::ExternalServerLauncher_var ExternalServerLauncherSingleton;
+static Engines::LockMaster_var LockMasterSingleton;
+static const char LockMasterEntryInNS[] = "/LockMaster";
 
 std::string RetrieveInternalInstanceOfLocalCppResourcesManager()
 {
@@ -118,3 +121,38 @@ std::string GetLogManagerInstance()
   CORBA::String_var ior = orb->object_to_string(LogManagerInstanceSingleton);
   return std::string(ior.in());
 }
+
+std::string GetLockMasterEntryInNS()
+{
+  return std::string( LockMasterEntryInNS );
+}
+
+std::string GetLockMasterInstance()
+{
+  CORBA::ORB_ptr orb = KERNEL::getORB();
+  if( CORBA::is_nil(LockMasterSingleton) )
+  {
+    SALOME_Fake_NamingService ns;
+    SALOME::LockMasterImpl *serv = new SALOME::LockMasterImpl;
+    {
+      CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
+      PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj);
+      //
+      CORBA::PolicyList policies;
+      policies.length(1);
+      PortableServer::POAManager_var pman = root_poa->the_POAManager();
+      PortableServer::ThreadPolicy_var threadPol(root_poa->create_thread_policy(PortableServer::SINGLE_THREAD_MODEL));
+      policies[0] = PortableServer::ThreadPolicy::_duplicate(threadPol);
+      PortableServer::POA_var safePOA = root_poa->create_POA("SingleThreadPOAForLockMaster",pman,policies);
+      threadPol->destroy();
+      //
+      PortableServer::ObjectId_var id(safePOA->activate_object(serv));
+      CORBA::Object_var lmPtr(safePOA->id_to_reference(id));
+      LockMasterSingleton = Engines::LockMaster::_narrow( lmPtr );
+    }
+    serv->_remove_ref();
+    ns.Register(LockMasterSingleton,LockMasterEntryInNS);
+  }
+  CORBA::String_var ior = orb->object_to_string( LockMasterSingleton );
+  return std::string(ior.in());
+}
index a9f418fd25e5afed2de89dc276cab497e046cdce..dd50894484acacf0f4a5ab6636abbcce69a5d8c7 100644 (file)
@@ -25,4 +25,6 @@ std::string RetrieveInternalInstanceOfLocalCppResourcesManager();
 std::string GetContainerManagerInstance();
 std::string GetResourcesManagerInstance();
 std::string GetExternalServerInstance();
-std::string GetLogManagerInstance();
\ No newline at end of file
+std::string GetLogManagerInstance();
+std::string GetLockMasterEntryInNS();
+std::string GetLockMasterInstance();
index e88dd8ad62d6edf8868cf39994e56701ffdd67f0..a4faa305bffa42d98fad6c4e034d8cda9fed287e 100644 (file)
@@ -32,6 +32,8 @@
   std::string GetResourcesManagerInstance();
   std::string GetExternalServerInstance();
   std::string GetLogManagerInstance();
+  std::string GetLockMasterEntryInNS();
+  std::string GetLockMasterInstance();
 }
 
 %pythoncode %{
@@ -58,4 +60,10 @@ def myLogManager():
   import CORBA
   orb=CORBA.ORB_init([''])
   return orb.string_to_object(GetLogManagerInstance())
+
+def myLockMaster():
+  import Engines
+  import CORBA
+  orb=CORBA.ORB_init([''])
+  return orb.string_to_object(GetLockMasterInstance())
 %}