#
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)
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
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):
"""
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)
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>();
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()
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;
};
${CMAKE_CURRENT_SOURCE_DIR}/../Container
${CMAKE_CURRENT_SOURCE_DIR}/../ResourcesManager
${CMAKE_CURRENT_SOURCE_DIR}/../KernelHelpers
+ ${CMAKE_CURRENT_SOURCE_DIR}/../Basics
${CMAKE_CURRENT_SOURCE_DIR}
)
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})
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)
#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) )
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));
#pragma once
#include <string>
+#include <vector>
-std::string GetDSMInstanceInternal();
+std::string GetDSMInstanceInternal(const std::vector<std::string>& argv);
%{
#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))
%}
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)
{
}
///////
-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)
{
}
////////
-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));
#include <vector>
#include <list>
-class SALOME_NamingService_Abstract;
+class SALOME_NamingService_Container_Abstract;
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();
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;
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);
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);
#include "SALOME_ContainerManager.hxx"
#include "SALOME_NamingService.hxx"
+#include "SALOME_Embedded_NamingService.hxx"
+#include "KernelBasis.hxx"
#include <sstream>
#include <algorithm>
}
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())
}
//
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()));
}
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
{
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);
}
}
}
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)
//
// 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 !");
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); });
}
-
--- /dev/null
+// 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;
+}
--- /dev/null
+// 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); });
+}
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
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 -----------")
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])
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]
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"
#
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)
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"
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"
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. """
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"""
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):
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):
t1.addKeyValueInVarErrorIfAlreadyExistingNow(obj2Str("c"),obj2Str(3))
dss.atomicApply([t1])
self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),value2)
+ dsm.removeDataScope(scopeName)
pass
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
import salome
import sys
-salome.salome_init()
+salome.salome_init_without_session()
scopeName="Scope1"
varName="a"
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"))
return str2Obj(dss.waitForMonoThrRev(wk))==[11,14,100]
if __name__=="__main__":
- sys.exit(not waitKey())
+ IORNS = sys.argv[-1]
+ sys.exit(not waitKey(IORNS))