]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
SDS in SSL mode.
authorAnthony Geay <anthony.geay@edf.fr>
Tue, 17 Aug 2021 14:31:23 +0000 (16:31 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Wed, 18 Aug 2021 15:14:02 +0000 (17:14 +0200)
17 files changed:
CTestTestfileInstall.cmake.in
src/KERNEL_PY/__init__.py
src/NamingService/SALOME_Fake_NamingService.cxx
src/NamingService/SALOME_Fake_NamingService.hxx
src/SALOMESDS/CMakeLists.txt
src/SALOMESDS/CTestTestfileInstall.cmake
src/SALOMESDS/KernelSDS.cxx
src/SALOMESDS/KernelSDS.hxx
src/SALOMESDS/KernelSDS.i
src/SALOMESDS/SALOMESDS_DataScopeServer.cxx
src/SALOMESDS/SALOMESDS_DataScopeServer.hxx
src/SALOMESDS/SALOMESDS_DataServerManager.cxx
src/SALOMESDS/SALOME_DataScopeServer.cxx
src/SALOMESDS/SALOME_DataScopeServer_Common.cxx [new file with mode: 0644]
src/SALOMESDS/SALOME_DataScopeServer_SSL.cxx [new file with mode: 0644]
src/SALOMESDS/TestSalomeSDS.py
src/SALOMESDS/TestSalomeSDSHelper0.py

index 3c6b54920b010b186686bb02d57c4dcc5f99d7c6..b6ee219e3b6e3b34921ba26aff41d33422195ae8 100644 (file)
@@ -18,6 +18,7 @@
 #
 
 SET(SALOME_TEST_DRIVER "$ENV{KERNEL_ROOT_DIR}/bin/salome/appliskel/salome_test_driver.py")
+SET(PYTHON_TEST_DRIVER "$ENV{KERNEL_ROOT_DIR}/bin/salome/appliskel/python_test_driver.py")
 
 SET(COMPONENT_NAME KERNEL)
 SET(TIMEOUT        200)
index 5c0900e62689a9a8faecc18f3c7453475faacbfa..8e78458d28ada9842164057fcbcdebccfb5947be 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
+    global lcc,naming_service,myStudy,orb,modulcat,sg,cm,dsm
     import KernelBasis
     KernelBasis.setSSLMode(True)
     import KernelDS
@@ -226,6 +226,9 @@ def salome_init_without_session():
     sg = SalomeOutsideGUI()
     salome_study_init_without_session()
     naming_service = NamingService()
+    from KernelSDS import GetDSMInstance
+    import sys
+    dsm = GetDSMInstance(sys.argv)
 
 def salome_init_with_session(path=None, embedded=False):
     """
index e9e19f30d489934edb247937cef95c1ffc612de8..a667cc03e5a9fdffe4ec7cb154da273bdb6eb27d 100644 (file)
@@ -60,6 +60,11 @@ void SALOME_Fake_NamingService::Register(CORBA::Object_ptr ObjRef, const char* P
 
 void SALOME_Fake_NamingService::Destroy_Name(const char* Path)
 {
+  std::lock_guard<std::mutex> g(_mutex);
+  std::string pathCpp(Path);
+  auto it = _map.find(pathCpp);
+  if(it!=_map.end())
+    _map.erase(it);
 }
 
 void SALOME_Fake_NamingService::Destroy_Directory(const char* Path)
@@ -72,9 +77,33 @@ void SALOME_Fake_NamingService::Destroy_FullDirectory(const char* Path)
 
 bool SALOME_Fake_NamingService::Change_Directory(const char* Path)
 {
+  std::lock_guard<std::mutex> g(_mutex);
+  _current_dir = Path;
   return true;
 }
 
+std::vector<std::string> SALOME_Fake_NamingService::SplitDir(const std::string& fullPath)
+{
+  constexpr char SEP = '/';
+  std::vector<std::string> ret;
+  if(fullPath.empty())
+    THROW_SALOME_EXCEPTION("Empty input string");
+  if(fullPath.at(0) != SEP)
+    THROW_SALOME_EXCEPTION("input string is expected to start with " << SEP);
+  auto len = fullPath.length();
+  if( len == 1 )
+    THROW_SALOME_EXCEPTION("input string is expected to be different from " << SEP);
+  std::size_t pos = 1;
+  while(pos < len)
+  {
+    std::size_t endPos = fullPath.find_first_of(SEP,pos);
+    std::string elt(fullPath.substr(pos,endPos==std::string::npos?std::string::npos:endPos-pos));
+    ret.push_back(elt);
+    pos = endPos==std::string::npos?std::string::npos:endPos+1;
+  }
+  return ret;
+}
+
 std::vector<std::string> SALOME_Fake_NamingService::list_subdirs()
 {
   return std::vector<std::string>();
@@ -82,7 +111,21 @@ std::vector<std::string> SALOME_Fake_NamingService::list_subdirs()
 
 std::vector<std::string> SALOME_Fake_NamingService::list_directory()
 {
-  return std::vector<std::string>();
+  std::lock_guard<std::mutex> g(_mutex);
+  std::vector<std::string> ret;
+  std::vector<std::string> splitCWD(SplitDir(_current_dir));
+  auto len = _current_dir.length();
+  for(auto it : _map)
+  {
+    std::vector<std::string> splitIt(SplitDir(it.first));
+    if(splitIt.size()<=splitCWD.size())
+      continue;
+    std::vector<std::string> partSplitIt(splitIt.cbegin(),splitIt.cbegin()+splitCWD.size());
+    if(partSplitIt!=splitCWD)
+      continue;
+    ret.push_back(splitIt.at(splitCWD.size()));
+  }
+  return ret;
 }
 
 std::vector<std::string> SALOME_Fake_NamingService::list_directory_recurs()
index 295433cfaa88471bb40c2a9b51055b1860880e3d..a4a10f96b84df82af176ad5ae293b9bc2c867c3b 100644 (file)
@@ -56,9 +56,12 @@ private:
   static std::string ReprOfContainersIORS();
   static std::vector< std::pair< std::string, Engines::Container_var> > ListOfContainersInNS_NoThreadSafe();
   static void FlushLogContainersFile_NoThreadSafe();
+  static std::vector<std::string> SplitDir(const std::string& fullPath);
 private:
   static std::mutex _mutex;
   static std::map<std::string,CORBA::Object_var> _map;
   static bool _log_container_file_thread_launched;
   static std::string _log_container_file_name;
+private:
+  mutable std::string _current_dir;
 };
index c3195be20c88ca131cb7dfc7d9dad9f2ea43006b..14a3f7d9f3f8993c0a303ce31bf0d79a12f16b02 100644 (file)
@@ -32,6 +32,7 @@ INCLUDE_DIRECTORIES(
   ${CMAKE_CURRENT_SOURCE_DIR}/../Container
   ${CMAKE_CURRENT_SOURCE_DIR}/../ResourcesManager
   ${CMAKE_CURRENT_SOURCE_DIR}/../KernelHelpers
+  ${CMAKE_CURRENT_SOURCE_DIR}/../Basics
   ${CMAKE_CURRENT_SOURCE_DIR}
 )
 
@@ -62,7 +63,9 @@ INSTALL(TARGETS SalomeSDS EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME
 
 ADD_EXECUTABLE(SALOME_DataScopeServer SALOME_DataScopeServer.cxx)
 TARGET_LINK_LIBRARIES(SALOME_DataScopeServer SalomeSDS)
-INSTALL(TARGETS SALOME_DataScopeServer DESTINATION ${SALOME_INSTALL_BINS})
+ADD_EXECUTABLE(SALOME_DataScopeServer_SSL SALOME_DataScopeServer_SSL.cxx)
+TARGET_LINK_LIBRARIES(SALOME_DataScopeServer_SSL SalomeSDS)
+INSTALL(TARGETS SALOME_DataScopeServer SALOME_DataScopeServer_SSL 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})
index aa7fecdbf59ef7008bff5d2df0681e6e986d894f..125496459bee84e6332bc0655fe49ca7a86b693f 100644 (file)
@@ -19,6 +19,6 @@
 
 IF(NOT WIN32)
   SET(TEST_NAME ${COMPONENT_NAME}_SalomeSDS)
-  ADD_TEST(${TEST_NAME} ${SALOME_TEST_DRIVER} ${TIMEOUT} TestSalomeSDS.py)
+  ADD_TEST(${TEST_NAME} ${PYTHON_TEST_DRIVER} ${TIMEOUT} TestSalomeSDS.py)
   SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES LABELS "${COMPONENT_NAME}" ENVIRONMENT "PYTHONPATH=${KERNEL_TEST_LIB}:$ENV{PYTHONPATH}")
 ENDIF(NOT WIN32)
index 3c21b267aefd23859dfb2d3dc989a2fcaa54bd5e..a76f99f14db60a7a8f72f3d4f9b1dcee10fce796 100644 (file)
 #include "SALOME_Fake_NamingService.hxx"
 #include "SALOME_KernelORB.hxx"
 
+#include <cstring>
+
 static SALOME::DataServerManager_var _dsm_singleton;
 
-std::string GetDSMInstanceInternal()
+std::string GetDSMInstanceInternal(const std::vector<std::string>& argv)
 {
   CORBA::ORB_ptr orb = KERNEL::getORB();
   if( CORBA::is_nil(_dsm_singleton) )
@@ -35,9 +37,15 @@ std::string GetDSMInstanceInternal()
       root_poa = PortableServer::POA::_narrow(obj);
     SALOME_CPythonHelper cPyh;
     {
-      int argc(1);
-      char *argv[2] = {"oops",nullptr};
-      cPyh.initializePython(argc,argv);
+      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);
+      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));
index 3f1eb0475eed707f053461c4041abe1493e71233..9782426a080ffc1afe65b5806d39d08806580410 100644 (file)
@@ -20,5 +20,6 @@
 #pragma once
 
 #include <string>
+#include <vector>
 
-std::string GetDSMInstanceInternal();
+std::string GetDSMInstanceInternal(const std::vector<std::string>& argv);
index cc1e46e09d9776aa23071a46da7e247b0ea3d0c5..74779d8b0fd6c87205f3f9d61aa0f5d85a984e81 100644 (file)
 
 %{
 #include "KernelSDS.hxx"
+#include "Utils_SALOME_Exception.hxx"
 %}
 
+
+class SALOME_Exception
+{
+  public:
+  SALOME_Exception(const std::string& text);
+  %extend
+  {
+    std::string __str__() const
+    {
+      return std::string(self->what());
+    }
+  }
+};
+
+%exception {
+  try {
+    $action
+  }
+  catch (SALOME_Exception& _e) {
+    // Reraise with SWIG_Python_Raise
+    SWIG_Python_Raise(SWIG_NewPointerObj((new SALOME_Exception(static_cast< const SALOME_Exception& >(_e.what()))),SWIGTYPE_p_SALOME_Exception,SWIG_POINTER_OWN), "SALOME_Exception", SWIGTYPE_p_SALOME_Exception);
+    SWIG_fail;
+  }
+}
+
 %inline
 {
-  std::string GetDSMInstanceInternal();
+  std::string GetDSMInstanceInternal(PyObject *argv)
+  {
+    if(!PyList_Check(argv))
+      THROW_SALOME_EXCEPTION("Not a pylist");
+    Py_ssize_t sz=PyList_Size(argv);
+    std::vector<std::string> argvCpp(sz);
+    for(Py_ssize_t i = 0 ; i < sz ; ++i)
+    {
+      PyObject *obj = PyList_GetItem(argv,i);
+      if(!PyUnicode_Check(obj))
+        THROW_SALOME_EXCEPTION("Not a pylist of strings");
+      {
+        Py_ssize_t dummy;
+        argvCpp[i] = PyUnicode_AsUTF8AndSize(obj,&dummy);
+      }
+    }
+    return GetDSMInstanceInternal(argvCpp);
+  }
 }
 
 %pythoncode %{
-def GetDSMInstance():
+def GetDSMInstance(argv):
   import SALOME
   import CORBA
   orb=CORBA.ORB_init([''])
-  return orb.string_to_object(GetDSMInstanceInternal())
+  return orb.string_to_object(GetDSMInstanceInternal(argv))
 %}
index b6c961a275d57acf4381a826027fe2a65c974646..fa7d04a9e3b6fba42781c7fb1d593ec2414affa7 100644 (file)
@@ -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, SALOME_NamingService_Abstract *ns):_ns(ns),_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_Container_Abstract *ns):_ns(ns),_pyHelper(pyHelper),_orb(CORBA::ORB::_duplicate(orb)),_name(scopeName),_killer(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)
+DataScopeServerBase::DataScopeServerBase(const DataScopeServerBase& other):omniServant(other),ServantBase(other),_ns(other._ns->clone()),_pyHelper(other._pyHelper),_name(other._name),_vars(other._vars),_killer(other._killer)
 {
 }
 
@@ -473,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, SALOME_NamingService_Abstract *ns):DataScopeServerBase(pyHelper,orb,killer,scopeName,ns)
+DataScopeServer::DataScopeServer(const SALOME_CPythonHelper *pyHelper, CORBA::ORB_ptr orb, SALOME::DataScopeKiller_var killer, const std::string& scopeName, SALOME_NamingService_Container_Abstract *ns):DataScopeServerBase(pyHelper,orb,killer,scopeName,ns)
 {
 }
 
@@ -520,7 +520,7 @@ DataScopeServer::~DataScopeServer()
 
 ////////
 
-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)
+DataScopeServerTransaction::DataScopeServerTransaction(const SALOME_CPythonHelper *pyHelper, CORBA::ORB_ptr orb, SALOME::DataScopeKiller_var killer, const std::string& scopeName, SALOME_NamingService_Container_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 a705946a1d1cd10eb4e295d298ac03e6ef5eb861..e6e466f7b67fc94df537a7a2723cc5662d10771a 100644 (file)
@@ -38,7 +38,7 @@
 #include <vector>
 #include <list>
 
-class SALOME_NamingService_Abstract;
+class SALOME_NamingService_Container_Abstract;
 
 namespace SALOMESDS
 {
@@ -75,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, SALOME_NamingService_Abstract *ns);
+    DataScopeServerBase(const SALOME_CPythonHelper *pyHelper, CORBA::ORB_ptr orb, SALOME::DataScopeKiller_var killer, const std::string& scopeName, SALOME_NamingService_Container_Abstract *ns);
     DataScopeServerBase(const DataScopeServerBase& other);
   public: // remote access methods
     void ping();
@@ -117,7 +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;
+    SALOME_NamingService_Container_Abstract *_ns = nullptr;
     const SALOME_CPythonHelper *_pyHelper = nullptr;
     PortableServer::POA_var _poa;
     CORBA::ORB_var _orb;
@@ -130,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, SALOME_NamingService_Abstract *ns);
+    DataScopeServer(const SALOME_CPythonHelper *pyHelper, CORBA::ORB_ptr orb, SALOME::DataScopeKiller_var killer, const std::string& scopeName, SALOME_NamingService_Container_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);
@@ -142,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, SALOME_NamingService_Abstract *ns);
+    DataScopeServerTransaction(const SALOME_CPythonHelper *pyHelper, CORBA::ORB_ptr orb, SALOME::DataScopeKiller_var killer, const std::string& scopeName, SALOME_NamingService_Container_Abstract *ns);
     DataScopeServerTransaction(const DataScopeServerTransaction& other);
     ~DataScopeServerTransaction();
     void createRdOnlyVarInternal(const std::string& varName, const SALOME::ByteVec& constValue);
index 2c2d9b277ff75d117f8dd570e2bf62a1fee1778d..80ba9319e67bffda9931258806a3344e9971e540 100644 (file)
@@ -23,6 +23,8 @@
 
 #include "SALOME_ContainerManager.hxx"
 #include "SALOME_NamingService.hxx"
+#include "SALOME_Embedded_NamingService.hxx"
+#include "KernelBasis.hxx"
 
 #include <sstream>
 #include <algorithm>
@@ -121,7 +123,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_Abstract& ns)
+typename T::PtrType CreateDataScope(CORBA::ORB_ptr orb, 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())
@@ -131,8 +133,19 @@ typename T::PtrType CreateDataScope(const std::string& scopeName, const std::vec
     }
   //
   std::string fullScopeName(DataServerManager::CreateAbsNameInNSFromScopeName(scopeName));
-  std::ostringstream oss; oss << "SALOME_DataScopeServer" << " " << scopeName << " " << isTransactionInt << " ";
-  SALOME_ContainerManager::AddOmninamesParams(oss,&ns);
+  std::ostringstream oss; 
+  if(!getSSLMode())
+  {
+    oss << "SALOME_DataScopeServer" << " " << scopeName << " " << isTransactionInt << " ";
+    SALOME_ContainerManager::AddOmninamesParams(oss,&ns);
+  }
+  else
+  {
+     oss << "SALOME_DataScopeServer_SSL" << " " << scopeName << " " << isTransactionInt << " ";
+     Engines::EmbeddedNamingService_var emb = GetEmbeddedNamingService();
+     CORBA::String_var ior = orb->object_to_string(emb);
+     oss << ior.in();
+  }
   std::string command(oss.str());
   SALOME_ContainerManager::MakeTheCommandToBeLaunchedASync(command);
   int status(SALOME_ContainerManager::SystemThreadSafe(command.c_str()));
@@ -154,12 +167,12 @@ 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_Abstract& ns, CORBA::Boolean& isCreated)
+typename T::PtrType GiveADataScopeCalled(CORBA::ORB_ptr orb, 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())
     {
       isCreated=true;
-      return CreateDataScope<T>(scopeName,scopes,ns);
+      return CreateDataScope<T>(orb,scopeName,scopes,ns);
     }
   else
     {
@@ -182,7 +195,7 @@ typename T::PtrType GiveADataScopeCalled(const std::string& scopeName, const std
           std::string fullScopeName(SALOMESDS::DataServerManager::CreateAbsNameInNSFromScopeName(scopeName));
           ns.Destroy_Name(fullScopeName.c_str());
           isCreated=true;
-          return CreateDataScope<T>(scopeName,scopes,ns);
+          return CreateDataScope<T>(orb,scopeName,scopes,ns);
         }
     }
 }
@@ -213,22 +226,22 @@ public:
 
 SALOME::DataScopeServer_ptr DataServerManager::createDataScope(const char *scopeName)
 {
-  return CreateDataScope<NormalFunctor>(scopeName,listOfScopesCpp(),*_ns);
+  return CreateDataScope<NormalFunctor>(_orb,scopeName,listOfScopesCpp(),*_ns);
 }
 
 SALOME::DataScopeServer_ptr DataServerManager::giveADataScopeCalled(const char *scopeName, CORBA::Boolean& isCreated)
 {
-  return GiveADataScopeCalled<NormalFunctor>(scopeName,listOfScopesCpp(),*_ns,isCreated);
+  return GiveADataScopeCalled<NormalFunctor>(_orb,scopeName,listOfScopesCpp(),*_ns,isCreated);
 }
 
 SALOME::DataScopeServerTransaction_ptr DataServerManager::createDataScopeTransaction(const char *scopeName)
 {
-  return CreateDataScope<TransactionFunctor>(scopeName,listOfScopesCpp(),*_ns);
+  return CreateDataScope<TransactionFunctor>(_orb,scopeName,listOfScopesCpp(),*_ns);
 }
 
 SALOME::DataScopeServerTransaction_ptr DataServerManager::giveADataScopeTransactionCalled(const char *scopeName, CORBA::Boolean& isCreated)
 {
-  return GiveADataScopeCalled<TransactionFunctor>(scopeName,listOfScopesCpp(),*_ns,isCreated);
+  return GiveADataScopeCalled<TransactionFunctor>(_orb,scopeName,listOfScopesCpp(),*_ns,isCreated);
 }
 
 SALOME::DataScopeServerBase_ptr DataServerManager::retriveDataScope(const char *scopeName)
index e2daee44aff68148ee33d85b1bc979aceda7a9f1..5f265ad3054103344883ca303e14340ddf594444 100644 (file)
 //
 // Author : Anthony GEAY (EDF R&D)
 
-#include "SALOMESDS_DataScopeServer.hxx"
-#include "SALOMESDS_DataServerManager.hxx"
-#include "SALOMESDS_Exception.hxx"
-#include "SALOME_CPythonHelper.hxx"
+#include "SALOME_DataScopeServer_Common.cxx"
 
 #include "SALOME_NamingService.hxx"
 
-#include <string>
-#include <sstream>
-
 int main(int argc, char *argv[])
 {
+  CORBA::ORB_var orb = GetCustomORB();
   std::string scopeName;
   if(argc<=1)
     throw SALOMESDS::Exception("In the main of SALOME_DataScopeServer.cxx !");
@@ -37,52 +32,5 @@ int main(int argc, char *argv[])
   std::istringstream isTransacSS(argv[2]);
   int isTransac(0);
   isTransacSS >> isTransac;
-  CORBA::ORB_var orb;
-  {
-    int argc(3);
-    char **argv=new char *[3];
-    char *p0(strdup("DTC")),*p1(strdup("-ORBsupportCurrent")),*p2(strdup("0"));
-    argv[0]=p0;
-    argv[1]=p1;// by disabling supportCurrent it make the POAManager::hold_requests work !
-    argv[2]=p2;
-    orb=CORBA::ORB_init(argc,argv);
-    free(p0); free(p1); free(p2);
-    delete [] argv;
-  }
-  CORBA::Object_var obj(orb->resolve_initial_references("RootPOA"));
-  PortableServer::POA_var poa(PortableServer::POA::_narrow(obj));
-  PortableServer::POAManager_var mgr(poa->the_POAManager());
-  mgr->activate();
-  //
-  SALOMESDS::DataScopeKiller *killer(new SALOMESDS::DataScopeKiller(orb));
-  SALOME::DataScopeKiller_var killerObj(killer->_this());
-  //
-  SALOME_CPythonHelper cPyHelper;
-  cPyHelper.initializePython(argc,argv);
-  //
-  SALOMESDS::DataScopeServerBase *server(nullptr);
-  if(!isTransac)
-    server=new SALOMESDS::DataScopeServer(&cPyHelper,orb,killerObj,scopeName,new SALOME_NamingService(orb));
-  else
-    server=new SALOMESDS::DataScopeServerTransaction(&cPyHelper,orb,killerObj,scopeName,new SALOME_NamingService(orb));
-  //
-  CORBA::PolicyList policies;
-  policies.length(3);
-  PortableServer::ThreadPolicy_var threadPol(poa->create_thread_policy(PortableServer::SINGLE_THREAD_MODEL));
-  policies[0]=PortableServer::ThreadPolicy::_duplicate(threadPol);
-  policies[1]=poa->create_implicit_activation_policy(PortableServer::NO_IMPLICIT_ACTIVATION);
-  policies[2]=poa->create_id_uniqueness_policy(PortableServer::UNIQUE_ID);
-  PortableServer::POA_var poa2(poa->create_POA("SingleThPOA4SDS",mgr,policies));
-  threadPol->destroy();
-  server->registerToSalomePiDict();
-  //
-  server->setPOA(poa2);
-  obj=server->activate();
-  SALOME::DataScopeServerBase_var serverPtr(SALOME::DataScopeServerBase::_narrow(obj));
-  server->registerInNS(serverPtr);
-  //
-  orb->run();
-  delete killer;
-  return 0;
+  return CommonDataScopeServerMain(argc,argv,orb,scopeName,isTransac,[](CORBA::ORB_ptr orb2) { return new SALOME_NamingService(orb2); });
 }
-
diff --git a/src/SALOMESDS/SALOME_DataScopeServer_Common.cxx b/src/SALOMESDS/SALOME_DataScopeServer_Common.cxx
new file mode 100644 (file)
index 0000000..cf77e09
--- /dev/null
@@ -0,0 +1,85 @@
+// 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
+//
+// Author : Anthony GEAY (EDF R&D)
+
+#include "SALOMESDS_DataScopeServer.hxx"
+#include "SALOMESDS_DataServerManager.hxx"
+#include "SALOMESDS_Exception.hxx"
+#include "SALOME_CPythonHelper.hxx"
+#include "SALOME_NamingService_Abstract.hxx"
+
+#include <string>
+#include <sstream>
+#include <functional>
+
+CORBA::ORB_var GetCustomORB()
+{
+  CORBA::ORB_var orb;
+  {
+    int argc(3);
+    char **argv=new char *[3];
+    char *p0(strdup("DTC")),*p1(strdup("-ORBsupportCurrent")),*p2(strdup("0"));
+    argv[0]=p0;
+    argv[1]=p1;// by disabling supportCurrent it make the POAManager::hold_requests work !
+    argv[2]=p2;
+    orb=CORBA::ORB_init(argc,argv);
+    free(p0); free(p1); free(p2);
+    delete [] argv;
+  }
+  return orb;
+}
+
+int CommonDataScopeServerMain(int argc, char *argv[], CORBA::ORB_var orb, const std::string& scopeName, int isTransac, std::function<SALOME_NamingService_Container_Abstract *(CORBA::ORB_ptr)> nsGenrator)
+{
+  CORBA::Object_var obj(orb->resolve_initial_references("RootPOA"));
+  PortableServer::POA_var poa(PortableServer::POA::_narrow(obj));
+  PortableServer::POAManager_var mgr(poa->the_POAManager());
+  mgr->activate();
+  //
+  SALOMESDS::DataScopeKiller *killer(new SALOMESDS::DataScopeKiller(orb));
+  SALOME::DataScopeKiller_var killerObj(killer->_this());
+  //
+  SALOME_CPythonHelper cPyHelper;
+  cPyHelper.initializePython(argc,argv);
+  //
+  SALOMESDS::DataScopeServerBase *server(nullptr);
+  if(!isTransac)
+    server=new SALOMESDS::DataScopeServer(&cPyHelper,orb,killerObj,scopeName,nsGenrator(orb));
+  else
+    server=new SALOMESDS::DataScopeServerTransaction(&cPyHelper,orb,killerObj,scopeName,nsGenrator(orb));
+  //
+  CORBA::PolicyList policies;
+  policies.length(3);
+  PortableServer::ThreadPolicy_var threadPol(poa->create_thread_policy(PortableServer::SINGLE_THREAD_MODEL));
+  policies[0]=PortableServer::ThreadPolicy::_duplicate(threadPol);
+  policies[1]=poa->create_implicit_activation_policy(PortableServer::NO_IMPLICIT_ACTIVATION);
+  policies[2]=poa->create_id_uniqueness_policy(PortableServer::UNIQUE_ID);
+  PortableServer::POA_var poa2(poa->create_POA("SingleThPOA4SDS",mgr,policies));
+  threadPol->destroy();
+  server->registerToSalomePiDict();
+  //
+  server->setPOA(poa2);
+  obj=server->activate();
+  SALOME::DataScopeServerBase_var serverPtr(SALOME::DataScopeServerBase::_narrow(obj));
+  server->registerInNS(serverPtr);
+  //
+  orb->run();
+  delete killer;
+  return 0;
+}
diff --git a/src/SALOMESDS/SALOME_DataScopeServer_SSL.cxx b/src/SALOMESDS/SALOME_DataScopeServer_SSL.cxx
new file mode 100644 (file)
index 0000000..ebd8f1e
--- /dev/null
@@ -0,0 +1,44 @@
+// Copyright (C) 2007-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
+//
+// Author : Anthony GEAY (EDF R&D)
+
+#include "SALOME_DataScopeServer_Common.cxx"
+
+#include "SALOME_Embedded_NamingService_Client.hxx"
+#include "Utils_SALOME_Exception.hxx"
+
+int main(int argc, char *argv[])
+{
+  CORBA::ORB_var orb = GetCustomORB();
+  std::string scopeName;
+  if(argc<=2)
+    throw SALOMESDS::Exception("In the main of SALOME_DataScopeServer.cxx !");
+  scopeName=argv[1];
+  std::istringstream isTransacSS(argv[2]);
+  int isTransac(0);
+  isTransacSS >> isTransac;
+  std::string IORFakeNS(argv[3]);
+  CORBA::Object_var ns_serv_obj_base = orb->string_to_object(IORFakeNS.c_str());
+  if( CORBA::is_nil(ns_serv_obj_base) )
+    THROW_SALOME_EXCEPTION( "SALOME_DataScopeServer_SSL : argument 3 is NOT a valid IOR" );
+  Engines::EmbeddedNamingService_var ns_serv_obj = Engines::EmbeddedNamingService::_narrow(ns_serv_obj_base);
+  if( CORBA::is_nil(ns_serv_obj) )
+    THROW_SALOME_EXCEPTION( "SALOME_DataScopeServer_SSL : argument 3 is NOT a valid IOR of Engines::EmbeddedNamingService" );
+  return CommonDataScopeServerMain(argc,argv,orb,scopeName,isTransac,[ns_serv_obj](CORBA::ORB_ptr orb) { return new SALOME_Embedded_NamingService_Client(ns_serv_obj); });
+}
index c509d74fbf309be5f42200fb26d4a32e797a0e4a..54d3c1947be98c6a7bdf268dc8f76557cb453063 100644 (file)
@@ -43,7 +43,7 @@ def generateKey(varName,scopeName):
   time.sleep(3)
   dss.atomicApply([t])
 def work(t):
-  i,varName,scopeName=t
+  IORNS,i,varName,scopeName=t
   if i==0:
     generateKey(varName,scopeName)
     return 0
@@ -51,7 +51,7 @@ def work(t):
     import TestSalomeSDSHelper0
     import os,subprocess
     fname=os.path.splitext(TestSalomeSDSHelper0.__file__)[0]+".py"
-    proc = subprocess.Popen(["python3", fname], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+    proc = subprocess.Popen(["python3", fname, IORNS], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
     out,err=proc.communicate()
     if proc.returncode!=0:
       print("-------------- work -----------")
@@ -96,7 +96,8 @@ def func_test7(scopeName,cv,cv2,cv3,sharedNum):
 class SalomeSDSTest(unittest.TestCase):
   
   def testList1(self):
-    a=SalomeSDSClt.CreateRdExtGlobalVar([],"a","Scope0")
+    scopeName = "Scope0"
+    a=SalomeSDSClt.CreateRdExtGlobalVar([],"a",scopeName)
     self.assertEqual(a.local_copy(),[])
     a.append(5)
     self.assertEqual(a.local_copy(),[5])
@@ -112,10 +113,15 @@ class SalomeSDSTest(unittest.TestCase):
     a[4].append(7)
     self.assertEqual(a.local_copy(),[5,["rt",8],5,["rt",8],["rt",8,7]])
     a.ptr().getMyDataScopeServer().deleteVar("a")
+    del a
+    import gc
+    gc.collect(0)
+    salome.dsm.removeDataScope(scopeName)
     pass
   
   def testDict1(self):
-    a=SalomeSDSClt.CreateRdExtGlobalVar({},"a","Scope0")
+    scopeName = "Scope0"
+    a=SalomeSDSClt.CreateRdExtGlobalVar({},"a",scopeName)
     a["ab"]=4
     self.assertEqual(a.local_copy(),{"ab":4})
     a["cd"]=[5]
@@ -133,13 +139,24 @@ class SalomeSDSTest(unittest.TestCase):
     a["gh"]["cd"].append(99) ; a["cd"].append(88)
     self.assertEqual(a.local_copy(),{"ab":4,"cd":[5,77,88],"ef":["a","bb","ccc"],"gh":{"ab":4,"cd":[5,77,99],"ef":["a","bb","ccc"]}})
     a.ptr().getMyDataScopeServer().deleteVar("a")
+    del a
+    import gc
+    gc.collect(0)
+    salome.dsm.removeDataScope(scopeName)
     pass
 
   def testReadOnly1(self):
-    a=SalomeSDSClt.CreateRdOnlyGlobalVar({"ab":4,"cd":[5,77]},"a","Scope0")
+    scopeName = "Scope0"
+    #
+    a=SalomeSDSClt.CreateRdOnlyGlobalVar({"ab":4,"cd":[5,77]},"a",scopeName)
     self.assertEqual(a.local_copy(),{"ab":4,"cd":[5,77]})
     self.assertRaises(Exception,a.__getitem__,"ab")
     a.ptr().getMyDataScopeServer().deleteVar("a")
+    del a
+    import gc
+    gc.collect(0)
+    #
+    salome.dsm.removeDataScope(scopeName)
 
   def testTransaction1(self):
     scopeName="Scope1"
@@ -166,7 +183,8 @@ class SalomeSDSTest(unittest.TestCase):
     #
     nbProc=8
     pool=mp.Pool(processes=nbProc)
-    asyncResult=pool.map_async(work,[(i,varName,scopeName) for i in range(nbProc)])
+    from NamingService import NamingService
+    asyncResult=pool.map_async(work,[(NamingService.IOROfNS(),i,varName,scopeName) for i in range(nbProc)])
     print("asyncResult=", asyncResult)
     self.assertEqual(asyncResult.get(),nbProc*[0]) # <- the big test is here !
     dsm.removeDataScope(scopeName)
@@ -194,6 +212,7 @@ class SalomeSDSTest(unittest.TestCase):
     wk=dss.waitForKeyInVar(varName,obj2Str("cd"))
     wk.waitFor()
     self.assertEqual(str2Obj(dss.waitForMonoThrRev(wk)),[7,8,9,10])
+    dsm.removeDataScope(scopeName)
 
   def testTransaction3(self):
     scopeName="Scope1"
@@ -216,6 +235,7 @@ class SalomeSDSTest(unittest.TestCase):
     t2=dss.removeKeyInVarErrorIfNotAlreadyExisting(varName,obj2Str("ab"))
     dss.atomicApply([t2])
     self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),{'cd':[7,8,9,10]})
+    dsm.removeDataScope(scopeName)
 
   def testTransaction4(self):
     scopeName="Scope1"
@@ -240,6 +260,7 @@ class SalomeSDSTest(unittest.TestCase):
     self.assertEqual(str2Obj(dss.waitForMonoThrRev(wk)),[7,8,9,10])
     dss.atomicApply([t2])
     self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),{'ab':[4,5,6]})
+    dsm.removeDataScope(scopeName)
 
   def testTransaction5(self):
     """ Like testTransaction2 but without transactions. """
@@ -274,6 +295,7 @@ class SalomeSDSTest(unittest.TestCase):
     self.assertEqual(str2Obj(dss.waitForMonoThrRev(wk)),[7,8,9,10])
     keys=[str2Obj(elt) for elt in dss.getAllKeysOfVarWithTypeDict(varName)]
     self.assertEqual(set(keys),set(['ab','cd']))
+    dsm.removeDataScope(scopeName)
 
   def testTransaction6(self):
     """ Test to test RdWr global vars with transaction"""
@@ -346,6 +368,7 @@ class SalomeSDSTest(unittest.TestCase):
     dss.atomicApply([t1])
     self.assertEqual(dss.getAccessOfVar(varName),"RdExt")
     self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),{'ab':[4,5,6],'cd':[7,8,9,10]})
+    dsm.removeDataScope(scopeName)
     pass
 
   def testTransaction8(self):
@@ -383,6 +406,7 @@ class SalomeSDSTest(unittest.TestCase):
     t4=dss.createRdExtVarFreeStyleTransac(varName,obj2Str(value),funcContent)
     self.assertRaises(SALOME.SALOME_Exception,dss.atomicApply,[t4]) # d is in dict pointed by var. Func returns false -> rejected
     self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),value3)
+    dsm.removeDataScope(scopeName)
     pass
   
   def testTransaction9(self):
@@ -412,6 +436,7 @@ class SalomeSDSTest(unittest.TestCase):
     t1.addKeyValueInVarErrorIfAlreadyExistingNow(obj2Str("c"),obj2Str(3))
     dss.atomicApply([t1])
     self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),value2)
+    dsm.removeDataScope(scopeName)
     pass
 
     
@@ -466,10 +491,11 @@ class SalomeSDSTest(unittest.TestCase):
       self.assertTrue(s>=0.99*nbOfSecWait and s<nbOfSecWait*1.01) # expect to be not locked
     # finishing
     p.join()
+    dsm.removeDataScope(scopeName)
     pass
 
   def setUp(self):
-    salome.salome_init()
+    salome.salome_init_without_session()
     pass
   
   pass
index be356d492ef2c6b0946f3f10d92ec8bc530f1677..7f44e3cd97a09298d4feb1a1adf5212335484370 100644 (file)
@@ -21,7 +21,7 @@ import pickle
 import salome
 import sys
 
-salome.salome_init()
+salome.salome_init_without_session()
 
 scopeName="Scope1"
 varName="a"
@@ -32,8 +32,13 @@ def obj2Str(obj):
 def str2Obj(strr):
     return pickle.loads(strr)
 
-def waitKey():
-    dsm=salome.naming_service.Resolve("/DataServerManager")
+def waitKey(IORNS):
+    import Engines
+    import CORBA
+    orb = CORBA.ORB_init([''])
+    ns = orb.string_to_object(IORNS)
+    import SALOME
+    dsm = orb.string_to_object(ns.Resolve("/DataServerManager").decode())
     dss,isCreated=dsm.giveADataScopeTransactionCalled(scopeName)
     assert(not isCreated)
     wk=dss.waitForKeyInVar(varName,obj2Str("ef"))
@@ -41,4 +46,5 @@ def waitKey():
     return str2Obj(dss.waitForMonoThrRev(wk))==[11,14,100]
 
 if __name__=="__main__":
-    sys.exit(not waitKey())
+    IORNS = sys.argv[-1]
+    sys.exit(not waitKey(IORNS))