]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
DataServerManager is now available in SSL mode
authorAnthony Geay <anthony.geay@edf.fr>
Tue, 17 Aug 2021 12:58:01 +0000 (14:58 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Tue, 17 Aug 2021 12:58:01 +0000 (14:58 +0200)
src/SALOMESDS/CMakeLists.txt
src/SALOMESDS/KernelSDS.cxx [new file with mode: 0644]
src/SALOMESDS/KernelSDS.hxx [new file with mode: 0644]
src/SALOMESDS/KernelSDS.i [new file with mode: 0644]
src/SALOMESDS/SALOMESDS_DataScopeServer.cxx
src/SALOMESDS/SALOMESDS_DataScopeServer.hxx
src/SALOMESDS/SALOMESDS_DataServerManager.cxx
src/SALOMESDS/SALOMESDS_DataServerManager.hxx
src/SALOMESDS/SALOME_DataScopeServer.cxx

index 8c2f7c5b9c020362ccdd648c0f650af3b97c9b52..c3195be20c88ca131cb7dfc7d9dad9f2ea43006b 100644 (file)
@@ -18,6 +18,8 @@
 #
 # Author : Anthony GEAY (EDF R&D)
 
+include(${SWIG_USE_FILE})
+
 INCLUDE_DIRECTORIES(
   ${OMNIORB_INCLUDE_DIR}
   ${PTHREAD_INCLUDE_DIR}
@@ -29,6 +31,8 @@ INCLUDE_DIRECTORIES(
   ${CMAKE_CURRENT_SOURCE_DIR}/../Launcher
   ${CMAKE_CURRENT_SOURCE_DIR}/../Container
   ${CMAKE_CURRENT_SOURCE_DIR}/../ResourcesManager
+  ${CMAKE_CURRENT_SOURCE_DIR}/../KernelHelpers
+  ${CMAKE_CURRENT_SOURCE_DIR}
 )
 
 ADD_DEFINITIONS(${OMNIORB_DEFINITIONS} ${PYTHON_DEFINITIONS})
@@ -62,6 +66,28 @@ INSTALL(TARGETS SALOME_DataScopeServer DESTINATION ${SALOME_INSTALL_BINS})
 INSTALL(FILES SalomeSDSClt.py SALOMEWrappedStdType.py DESTINATION ${SALOME_INSTALL_BINS})
 FILE(GLOB COMMON_HEADERS_HXX "${CMAKE_CURRENT_SOURCE_DIR}/*.hxx")
 INSTALL(FILES ${COMMON_HEADERS_HXX} DESTINATION ${SALOME_INSTALL_HEADERS})
+
+#
+
+SET(KernelSDS_HEADERS KernelSDS.hxx KernelSDS.i)
+SET(KernelSDS_SOURCES KernelSDS.cxx ${KernelSDS_HEADERS})
+SET_SOURCE_FILES_PROPERTIES(KernelSDS.i PROPERTIES CPLUSPLUS ON)
+SET_SOURCE_FILES_PROPERTIES(KernelSDS.i PROPERTIES SWIG_FLAGS "-py3")
+SET_SOURCE_FILES_PROPERTIES(KernelSDS_wrap.cpp PROPERTIES COMPILE_FLAGS "-DHAVE_CONFIG_H")
+SET(_swig_SCRIPTS ${CMAKE_CURRENT_BINARY_DIR}/KernelSDS.py )
+IF(${CMAKE_VERSION} VERSION_LESS "3.8.0") 
+  SWIG_ADD_MODULE(KernelSDS python ${KernelSDS_SOURCES})
+ELSE()
+  SWIG_ADD_LIBRARY(KernelSDS LANGUAGE python SOURCES ${KernelSDS_SOURCES})
+ENDIF()
+IF(${MACHINE} STREQUAL WINDOWS)
+  SET_TARGET_PROPERTIES(_KernelSDS PROPERTIES DEBUG_OUTPUT_NAME _KernelSDS_d)
+ENDIF(${MACHINE} STREQUAL WINDOWS)
+SWIG_LINK_LIBRARIES(KernelSDS ${PYTHON_LIBRARIES} ${PLATFORM_LIBS} SalomeSDS)
+install(TARGETS _KernelSDS DESTINATION ${SALOME_INSTALL_LIBS})
+install(FILES ${KernelSDS_HEADERS} DESTINATION ${SALOME_INSTALL_HEADERS})
+SALOME_INSTALL_SCRIPTS("${_swig_SCRIPTS}"  ${SALOME_INSTALL_BINS} EXTRA_DPYS "${SWIG_MODULE_KernelSDS_REAL_NAME}")
+
 # tests part
 SET(LOCAL_TEST_DIR ${KERNEL_TEST_DIR}/SALOMESDS)
 INSTALL(FILES TestSalomeSDS.py TestSalomeSDSHelper0.py DESTINATION ${LOCAL_TEST_DIR})
diff --git a/src/SALOMESDS/KernelSDS.cxx b/src/SALOMESDS/KernelSDS.cxx
new file mode 100644 (file)
index 0000000..3c21b26
--- /dev/null
@@ -0,0 +1,50 @@
+// 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 "KernelSDS.hxx"
+#include "SALOMESDS_DataServerManager.hxx"
+#include "SALOME_Fake_NamingService.hxx"
+#include "SALOME_KernelORB.hxx"
+
+static SALOME::DataServerManager_var _dsm_singleton;
+
+std::string GetDSMInstanceInternal()
+{
+  CORBA::ORB_ptr orb = KERNEL::getORB();
+  if( CORBA::is_nil(_dsm_singleton) )
+  {
+    PortableServer::POA_var root_poa;
+    CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
+    if(!CORBA::is_nil(obj))
+      root_poa = PortableServer::POA::_narrow(obj);
+    SALOME_CPythonHelper cPyh;
+    {
+      int argc(1);
+      char *argv[2] = {"oops",nullptr};
+      cPyh.initializePython(argc,argv);
+    }
+    SALOME_Fake_NamingService *ns(new SALOME_Fake_NamingService);
+    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);
+  }
+  CORBA::String_var ior = orb->object_to_string(_dsm_singleton);
+  return std::string(ior.in());
+}
diff --git a/src/SALOMESDS/KernelSDS.hxx b/src/SALOMESDS/KernelSDS.hxx
new file mode 100644 (file)
index 0000000..3f1eb04
--- /dev/null
@@ -0,0 +1,24 @@
+// 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 <string>
+
+std::string GetDSMInstanceInternal();
diff --git a/src/SALOMESDS/KernelSDS.i b/src/SALOMESDS/KernelSDS.i
new file mode 100644 (file)
index 0000000..cc1e46e
--- /dev/null
@@ -0,0 +1,39 @@
+// 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
+//
+
+%module KernelSDS
+
+%include "std_string.i"
+
+%{
+#include "KernelSDS.hxx"
+%}
+
+%inline
+{
+  std::string GetDSMInstanceInternal();
+}
+
+%pythoncode %{
+def GetDSMInstance():
+  import SALOME
+  import CORBA
+  orb=CORBA.ORB_init([''])
+  return orb.string_to_object(GetDSMInstanceInternal())
+%}
index 3fdd6924f9e8550c40be976af7148d7700fb62aa..b6c961a275d57acf4381a826027fe2a65c974646 100644 (file)
@@ -27,7 +27,7 @@
 #include "SALOMESDS_TrustTransaction.hxx"
 #include "SALOMESDS_KeyWaiter.hxx"
 #include "SALOMESDS_Transaction.hxx"
-#include "SALOME_NamingService.hxx"
+#include "SALOME_NamingService_Abstract.hxx"
 #include "SALOMESDS_Exception.hxx"
 
 #include <sstream>
@@ -71,11 +71,11 @@ void RequestSwitcher::fetchAndGetAccessOfVar(const char *varName, CORBA::String_
   return _ds->fetchAndGetAccessOfVar(varName,access,data);
 }
 
-DataScopeServerBase::DataScopeServerBase(const SALOME_CPythonHelper *pyHelper, CORBA::ORB_ptr orb, SALOME::DataScopeKiller_var killer, const std::string& scopeName):_pyHelper(pyHelper),_orb(CORBA::ORB::_duplicate(orb)),_name(scopeName),_killer(killer)
+DataScopeServerBase::DataScopeServerBase(const SALOME_CPythonHelper *pyHelper, CORBA::ORB_ptr orb, SALOME::DataScopeKiller_var killer, const std::string& scopeName, SALOME_NamingService_Abstract *ns):_ns(ns),_pyHelper(pyHelper),_orb(CORBA::ORB::_duplicate(orb)),_name(scopeName),_killer(killer)
 {
 }
 
-DataScopeServerBase::DataScopeServerBase(const DataScopeServerBase& other):omniServant(other),ServantBase(other),_pyHelper(other._pyHelper),_name(other._name),_vars(other._vars),_killer(other._killer)
+DataScopeServerBase::DataScopeServerBase(const DataScopeServerBase& other):omniServant(other),ServantBase(other),_ns(other._ns->cloneCoVar()),_pyHelper(other._pyHelper),_name(other._name),_vars(other._vars),_killer(other._killer)
 {
 }
 
@@ -89,6 +89,7 @@ DataScopeServerBase::~DataScopeServerBase()
            obj->decrRef();
          }
     }
+  delete _ns;
 }
 
 /*!
@@ -165,14 +166,13 @@ void DataScopeServerBase::deleteVar(const char *varName)
 
 CORBA::Boolean DataScopeServerBase::shutdownIfNotHostedByDSM(SALOME::DataScopeKiller_out killer)
 {
-  SALOME_NamingService ns(_orb);
-  CORBA::Object_var obj(ns.Resolve(DataServerManager::NAME_IN_NS));
+  CORBA::Object_var obj(_ns->Resolve(DataServerManager::NAME_IN_NS));
   SALOME::DataServerManager_var dsm(SALOME::DataServerManager::_narrow(obj));
   if(CORBA::is_nil(dsm))
     throw Exception("Unable to reach in the NS the unique DataServerManager instance of the Session !");
   // destroy ref in the naming service
   std::string fullScopeName(SALOMESDS::DataServerManager::CreateAbsNameInNSFromScopeName(_name));
-  ns.Destroy_Name(fullScopeName.c_str());
+  _ns->Destroy_Name(fullScopeName.c_str());
   // establish if dsm and this shared the same POA. If yes dsm and this are collocated !
   PortableServer::ServantBase *ret(0);
   try
@@ -302,8 +302,7 @@ void DataScopeServerBase::setPOA(PortableServer::POA_var poa)
 void DataScopeServerBase::registerInNS(SALOME::DataScopeServerBase_ptr ptr)
 {
   std::string fullScopeName(SALOMESDS::DataServerManager::CreateAbsNameInNSFromScopeName(_name));
-  SALOME_NamingService ns(_orb);
-  ns.Register(ptr,fullScopeName.c_str());
+  _ns->Register(ptr,fullScopeName.c_str());
 }
 
 std::string DataScopeServerBase::BuildTmpVarNameFrom(const std::string& varName)
@@ -474,7 +473,7 @@ std::list< std::pair< SALOME::BasicDataServer_var, BasicDataServer * > >::iterat
 
 ///////
 
-DataScopeServer::DataScopeServer(const SALOME_CPythonHelper *pyHelper, CORBA::ORB_ptr orb, SALOME::DataScopeKiller_var killer, const std::string& scopeName):DataScopeServerBase(pyHelper,orb,killer,scopeName)
+DataScopeServer::DataScopeServer(const SALOME_CPythonHelper *pyHelper, CORBA::ORB_ptr orb, SALOME::DataScopeKiller_var killer, const std::string& scopeName, SALOME_NamingService_Abstract *ns):DataScopeServerBase(pyHelper,orb,killer,scopeName,ns)
 {
 }
 
@@ -521,7 +520,7 @@ DataScopeServer::~DataScopeServer()
 
 ////////
 
-DataScopeServerTransaction::DataScopeServerTransaction(const SALOME_CPythonHelper *pyHelper, CORBA::ORB_ptr orb, SALOME::DataScopeKiller_var killer, const std::string& scopeName):DataScopeServerBase(pyHelper,orb,killer,scopeName)
+DataScopeServerTransaction::DataScopeServerTransaction(const SALOME_CPythonHelper *pyHelper, CORBA::ORB_ptr orb, SALOME::DataScopeKiller_var killer, const std::string& scopeName, SALOME_NamingService_Abstract *ns):DataScopeServerBase(pyHelper,orb,killer,scopeName,ns)
 {
   CORBA::Object_var obj(_orb->resolve_initial_references("RootPOA"));
   PortableServer::POA_var poa(PortableServer::POA::_narrow(obj));
index 6119cc9814f779db8c9d5c2dca24fb671dd20457..a705946a1d1cd10eb4e295d298ac03e6ef5eb861 100644 (file)
@@ -38,6 +38,8 @@
 #include <vector>
 #include <list>
 
+class SALOME_NamingService_Abstract;
+
 namespace SALOMESDS
 {
   class SALOMESDS_EXPORT DataScopeKiller : public POA_SALOME::DataScopeKiller
@@ -73,7 +75,7 @@ namespace SALOMESDS
   class SALOMESDS_EXPORT DataScopeServerBase : public virtual POA_SALOME::DataScopeServerBase, public POAHolder
   {
   public:
-    DataScopeServerBase(const SALOME_CPythonHelper *pyHelper, CORBA::ORB_ptr orb, SALOME::DataScopeKiller_var killer, const std::string& scopeName);
+    DataScopeServerBase(const SALOME_CPythonHelper *pyHelper, CORBA::ORB_ptr orb, SALOME::DataScopeKiller_var killer, const std::string& scopeName, SALOME_NamingService_Abstract *ns);
     DataScopeServerBase(const DataScopeServerBase& other);
   public: // remote access methods
     void ping();
@@ -115,6 +117,7 @@ namespace SALOMESDS
     std::list< std::pair< SALOME::BasicDataServer_var, BasicDataServer * > >::const_iterator retrieveVarInternal3(const std::string& varName) const;
     std::list< std::pair< SALOME::BasicDataServer_var, BasicDataServer * > >::iterator retrieveVarInternal4(const std::string& varName);
   protected:
+    SALOME_NamingService_Abstract *_ns = nullptr;
     const SALOME_CPythonHelper *_pyHelper = nullptr;
     PortableServer::POA_var _poa;
     CORBA::ORB_var _orb;
@@ -127,7 +130,7 @@ namespace SALOMESDS
   class SALOMESDS_EXPORT DataScopeServer : public DataScopeServerBase, public virtual POA_SALOME::DataScopeServer
   {
   public:
-    DataScopeServer(const SALOME_CPythonHelper *pyHelper, CORBA::ORB_ptr orb, SALOME::DataScopeKiller_var killer, const std::string& scopeName);
+    DataScopeServer(const SALOME_CPythonHelper *pyHelper, CORBA::ORB_ptr orb, SALOME::DataScopeKiller_var killer, const std::string& scopeName, SALOME_NamingService_Abstract *ns);
     DataScopeServer(const DataScopeServer& other);
     SALOME::BasicDataServer_ptr retrieveVar(const char *varName) { return retrieveVarInternal(varName); }
     SALOME::PickelizedPyObjRdOnlyServer_ptr createRdOnlyVar(const char *varName, const SALOME::ByteVec& constValue);
@@ -139,7 +142,7 @@ namespace SALOMESDS
   class SALOMESDS_EXPORT DataScopeServerTransaction : public DataScopeServerBase, public virtual POA_SALOME::DataScopeServerTransaction
   {
   public://not remotely callable
-    DataScopeServerTransaction(const SALOME_CPythonHelper *pyHelper, CORBA::ORB_ptr orb, SALOME::DataScopeKiller_var killer, const std::string& scopeName);
+    DataScopeServerTransaction(const SALOME_CPythonHelper *pyHelper, CORBA::ORB_ptr orb, SALOME::DataScopeKiller_var killer, const std::string& scopeName, SALOME_NamingService_Abstract *ns);
     DataScopeServerTransaction(const DataScopeServerTransaction& other);
     ~DataScopeServerTransaction();
     void createRdOnlyVarInternal(const std::string& varName, const SALOME::ByteVec& constValue);
index 4f2a0d0fee233d24d4951d5a29b8d045630971b1..2c2d9b277ff75d117f8dd570e2bf62a1fee1778d 100644 (file)
@@ -43,9 +43,10 @@ SALOME::DataScopeServerTransaction_ptr RequestSwitcherDSM::giveADataScopeTransac
   return _dsm->giveADataScopeTransactionCalled(scopeName,isCreated);
 }
 
-DataServerManager::DataServerManager(const SALOME_CPythonHelper *pyHelper, CORBA::ORB_ptr orb, PortableServer::POA_ptr poa):_orb(CORBA::ORB::_duplicate(orb))
+DataServerManager::DataServerManager(const SALOME_CPythonHelper *pyHelper, CORBA::ORB_ptr orb, PortableServer::POA_ptr poa, SALOME_NamingService_Abstract *ns):_orb(CORBA::ORB::_duplicate(orb))
 {
-  DataScopeServer *dftScope(new DataScopeServer(pyHelper,orb,SALOME::DataScopeKiller::_nil(),DFT_SCOPE_NAME_IN_NS));//_remove_ref will be call by DataScopeServer::shutdownIfNotHostedByDSM
+  _ns = ns==nullptr?new SALOME_NamingService(_orb):ns;
+  DataScopeServer *dftScope(new DataScopeServer(pyHelper,orb,SALOME::DataScopeKiller::_nil(),DFT_SCOPE_NAME_IN_NS,_ns->cloneCoVar()));//_remove_ref will be call by DataScopeServer::shutdownIfNotHostedByDSM
   PortableServer::POAManager_var pman(poa->the_POAManager());
   CORBA::PolicyList policies;
   policies.length(1);
@@ -58,8 +59,7 @@ DataServerManager::DataServerManager(const SALOME_CPythonHelper *pyHelper, CORBA
   CORBA::Object_var obj(_poa->id_to_reference(id));
   SALOME::DataServerManager_var obj2(SALOME::DataServerManager::_narrow(obj));
   // publish Data server manager in NS
-  SALOME_NamingService ns(orb);
-  ns.Register(obj2,NAME_IN_NS);
+  _ns->Register(obj2,NAME_IN_NS);
   // the default DataScopeServer object is the only one hosted by the current process
   dftScope->setPOA(_poa);
   obj=dftScope->activate();
@@ -67,6 +67,12 @@ DataServerManager::DataServerManager(const SALOME_CPythonHelper *pyHelper, CORBA
   dftScope->registerInNS(dftScopePtr);// agy : Very important ! invoke this method BEFORE activation ! Because this method initializes Python !
 }
 
+DataServerManager::~DataServerManager()
+{
+  //_ns is owned by DataServerManager
+  delete _ns;
+}
+
 SALOME::StringVec *DataServerManager::listScopes()
 {
   std::vector<std::string> scopes(listOfScopesCpp());
@@ -115,7 +121,7 @@ CORBA::Boolean DataServerManager::isAliveAndKicking(const char *scopeName)
 }
 
 template<class T>
-typename T::PtrType CreateDataScope(const std::string& scopeName, const std::vector<std::string>& scopes, SALOME_NamingService& ns)
+typename T::PtrType CreateDataScope(const std::string& scopeName, const std::vector<std::string>& scopes, SALOME_NamingService_Abstract& ns)
 {
   int isTransactionInt(T::IsTransaction);
   if(std::find(scopes.begin(),scopes.end(),scopeName)!=scopes.end())
@@ -148,7 +154,7 @@ typename T::PtrType CreateDataScope(const std::string& scopeName, const std::vec
 }
 
 template<class T>
-typename T::PtrType GiveADataScopeCalled(const std::string& scopeName, const std::vector<std::string>& scopes, SALOME_NamingService& ns, CORBA::Boolean& isCreated)
+typename T::PtrType GiveADataScopeCalled(const std::string& scopeName, const std::vector<std::string>& scopes, SALOME_NamingService_Abstract& ns, CORBA::Boolean& isCreated)
 {
   if(std::find(scopes.begin(),scopes.end(),scopeName)==scopes.end())
     {
@@ -157,7 +163,7 @@ typename T::PtrType GiveADataScopeCalled(const std::string& scopeName, const std
     }
   else
     {
-      SALOME::DataScopeServerBase_var ret(SALOMESDS::DataServerManager::GetScopePtrGivenName(scopeName,scopes,ns));
+      SALOME::DataScopeServerBase_var ret(SALOMESDS::DataServerManager::GetScopePtrGivenName(scopeName,scopes,&ns));
       if(SALOMESDS::DataServerManager::IsAliveAndKicking(ret))
         {
           isCreated=false;
@@ -207,26 +213,22 @@ public:
 
 SALOME::DataScopeServer_ptr DataServerManager::createDataScope(const char *scopeName)
 {
-  SALOME_NamingService ns(_orb);
-  return CreateDataScope<NormalFunctor>(scopeName,listOfScopesCpp(),ns);
+  return CreateDataScope<NormalFunctor>(scopeName,listOfScopesCpp(),*_ns);
 }
 
 SALOME::DataScopeServer_ptr DataServerManager::giveADataScopeCalled(const char *scopeName, CORBA::Boolean& isCreated)
 {
-  SALOME_NamingService ns(_orb);
-  return GiveADataScopeCalled<NormalFunctor>(scopeName,listOfScopesCpp(),ns,isCreated);
+  return GiveADataScopeCalled<NormalFunctor>(scopeName,listOfScopesCpp(),*_ns,isCreated);
 }
 
 SALOME::DataScopeServerTransaction_ptr DataServerManager::createDataScopeTransaction(const char *scopeName)
 {
-  SALOME_NamingService ns(_orb);
-  return CreateDataScope<TransactionFunctor>(scopeName,listOfScopesCpp(),ns);
+  return CreateDataScope<TransactionFunctor>(scopeName,listOfScopesCpp(),*_ns);
 }
 
 SALOME::DataScopeServerTransaction_ptr DataServerManager::giveADataScopeTransactionCalled(const char *scopeName, CORBA::Boolean& isCreated)
 {
-  SALOME_NamingService ns(_orb);
-  return GiveADataScopeCalled<TransactionFunctor>(scopeName,listOfScopesCpp(),ns,isCreated);
+  return GiveADataScopeCalled<TransactionFunctor>(scopeName,listOfScopesCpp(),*_ns,isCreated);
 }
 
 SALOME::DataScopeServerBase_ptr DataServerManager::retriveDataScope(const char *scopeName)
@@ -246,14 +248,13 @@ void DataServerManager::removeDataScope(const char *scopeName)
 
 void DataServerManager::cleanScopesInNS()
 {
-  SALOME_NamingService ns(_orb);
   std::vector<std::string> scopes(listOfScopesCpp());
   for(std::vector<std::string>::const_iterator it=scopes.begin();it!=scopes.end();it++)
     {
       if(!isAliveAndKicking((*it).c_str()))
         {
           std::string fullScopeName(SALOMESDS::DataServerManager::CreateAbsNameInNSFromScopeName(*it));
-          ns.Destroy_Name(fullScopeName.c_str());
+          _ns->Destroy_Name(fullScopeName.c_str());
         }
     }
 }
@@ -291,13 +292,12 @@ CORBA::Boolean DataServerManager::IsAliveAndKicking(SALOME::DataScopeServerBase_
 
 std::vector<std::string> DataServerManager::listOfScopesCpp()
 {
-  SALOME_NamingService ns(_orb);
-  ns.Change_Directory(NAME_IN_NS);
-  std::vector<std::string> ret(ns.list_directory());
+  _ns->Change_Directory(NAME_IN_NS);
+  std::vector<std::string> ret(_ns->list_directory());
   return ret;
 }
 
-SALOME::DataScopeServerBase_var DataServerManager::GetScopePtrGivenName(const std::string& scopeName, const std::vector<std::string>& scopes, SALOME_NamingServicens)
+SALOME::DataScopeServerBase_var DataServerManager::GetScopePtrGivenName(const std::string& scopeName, const std::vector<std::string>& scopes, SALOME_NamingService_Abstract *ns)
 {
   if(std::find(scopes.begin(),scopes.end(),scopeName)==scopes.end())
     {
@@ -305,15 +305,14 @@ SALOME::DataScopeServerBase_var DataServerManager::GetScopePtrGivenName(const st
       throw Exception(oss.str());
     }
   std::string fullScopeName(CreateAbsNameInNSFromScopeName(scopeName));
-  CORBA::Object_var obj(ns.Resolve(fullScopeName.c_str()));
+  CORBA::Object_var obj(ns->Resolve(fullScopeName.c_str()));
   SALOME::DataScopeServerBase_var ret(SALOME::DataScopeServerBase::_narrow(obj));
   return ret;
 }
 
 SALOME::DataScopeServerBase_var DataServerManager::getScopePtrGivenName(const std::string& scopeName)
 {
-  SALOME_NamingService ns(_orb);
-  return GetScopePtrGivenName(scopeName,listOfScopesCpp(),ns);
+  return GetScopePtrGivenName(scopeName,listOfScopesCpp(),_ns);
 }
 
 SALOME::RequestSwitcherDSM_ptr DataServerManager::getRequestSwitcher()
index 0f2429c93ff3e468e27fd2ec0d41a1b2a55cff52..b7594e94478be007c25539fb68fe66b2731338a8 100644 (file)
@@ -32,7 +32,7 @@
 
 #include <string>
 
-class SALOME_NamingService;
+class SALOME_NamingService_Abstract;
 
 namespace SALOMESDS
 {
@@ -53,7 +53,8 @@ namespace SALOMESDS
   class SALOMESDS_EXPORT DataServerManager : public virtual POA_SALOME::DataServerManager
   {
   public:
-    DataServerManager(const SALOME_CPythonHelper *pyHelper, CORBA::ORB_ptr orb, PortableServer::POA_ptr poa);
+    DataServerManager(const SALOME_CPythonHelper *pyHelper, CORBA::ORB_ptr orb, PortableServer::POA_ptr poa, SALOME_NamingService_Abstract *ns = nullptr);
+    ~DataServerManager();
     SALOME::StringVec *listScopes();
     SALOME::StringVec *listAliveAndKickingScopes();
     SALOME::DataScopeServer_ptr getDefaultScope();
@@ -74,7 +75,7 @@ namespace SALOMESDS
     CORBA::ORB_var getORB() { return _orb; }
     static std::string CreateAbsNameInNSFromScopeName(const std::string& scopeName);
     static CORBA::Boolean IsAliveAndKicking(SALOME::DataScopeServerBase_ptr scopePtr);
-    static SALOME::DataScopeServerBase_var GetScopePtrGivenName(const std::string& scopeName, const std::vector<std::string>& scopes, SALOME_NamingServicens);
+    static SALOME::DataScopeServerBase_var GetScopePtrGivenName(const std::string& scopeName, const std::vector<std::string>& scopes, SALOME_NamingService_Abstract *ns);
   public:
     static const char NAME_IN_NS[];
     static const char DFT_SCOPE_NAME_IN_NS[];
@@ -82,6 +83,8 @@ namespace SALOMESDS
     std::vector<std::string> listOfScopesCpp();
     SALOME::DataScopeServerBase_var getScopePtrGivenName(const std::string& scopeName);
   private:
+    //! naming service object is owned
+    SALOME_NamingService_Abstract *_ns = nullptr;
     CORBA::ORB_var _orb;
     //! single thread poa
     PortableServer::POA_var _poa;
index 3c6a1f6e6876105ee9a9e51f1e0a858be85a342f..e2daee44aff68148ee33d85b1bc979aceda7a9f1 100644 (file)
@@ -62,9 +62,9 @@ int main(int argc, char *argv[])
   //
   SALOMESDS::DataScopeServerBase *server(nullptr);
   if(!isTransac)
-    server=new SALOMESDS::DataScopeServer(&cPyHelper,orb,killerObj,scopeName);
+    server=new SALOMESDS::DataScopeServer(&cPyHelper,orb,killerObj,scopeName,new SALOME_NamingService(orb));
   else
-    server=new SALOMESDS::DataScopeServerTransaction(&cPyHelper,orb,killerObj,scopeName);
+    server=new SALOMESDS::DataScopeServerTransaction(&cPyHelper,orb,killerObj,scopeName,new SALOME_NamingService(orb));
   //
   CORBA::PolicyList policies;
   policies.length(3);