From: Anthony Geay Date: Tue, 17 Aug 2021 14:31:23 +0000 (+0200) Subject: WIP X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=745f3b71db5bb27926f3a60cdca2936c8ba119af;p=modules%2Fkernel.git WIP --- diff --git a/src/KERNEL_PY/__init__.py b/src/KERNEL_PY/__init__.py index 5c0900e62..bf37b0b8f 100644 --- a/src/KERNEL_PY/__init__.py +++ b/src/KERNEL_PY/__init__.py @@ -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,8 @@ def salome_init_without_session(): sg = SalomeOutsideGUI() salome_study_init_without_session() naming_service = NamingService() + from KernelSDS import GetDSMInstance + dsm = GetDSMInstance() def salome_init_with_session(path=None, embedded=False): """ diff --git a/src/SALOMESDS/CMakeLists.txt b/src/SALOMESDS/CMakeLists.txt index c3195be20..14a3f7d9f 100644 --- a/src/SALOMESDS/CMakeLists.txt +++ b/src/SALOMESDS/CMakeLists.txt @@ -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}) diff --git a/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx b/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx index b6c961a27..fa7d04a9e 100644 --- a/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx +++ b/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx @@ -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)); diff --git a/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx b/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx index a705946a1..e6e466f7b 100644 --- a/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx +++ b/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx @@ -38,7 +38,7 @@ #include #include -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); diff --git a/src/SALOMESDS/SALOMESDS_DataServerManager.cxx b/src/SALOMESDS/SALOMESDS_DataServerManager.cxx index 2c2d9b277..55a6c0236 100644 --- a/src/SALOMESDS/SALOMESDS_DataServerManager.cxx +++ b/src/SALOMESDS/SALOMESDS_DataServerManager.cxx @@ -23,6 +23,8 @@ #include "SALOME_ContainerManager.hxx" #include "SALOME_NamingService.hxx" +#include "SALOME_Embedded_NamingService.hxx" +#include "KernelBasis.hxx" #include #include @@ -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())); diff --git a/src/SALOMESDS/SALOME_DataScopeServer.cxx b/src/SALOMESDS/SALOME_DataScopeServer.cxx index e2daee44a..5f265ad30 100644 --- a/src/SALOMESDS/SALOME_DataScopeServer.cxx +++ b/src/SALOMESDS/SALOME_DataScopeServer.cxx @@ -18,18 +18,13 @@ // // 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 -#include - 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 index 000000000..cf77e09b2 --- /dev/null +++ b/src/SALOMESDS/SALOME_DataScopeServer_Common.cxx @@ -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 +#include +#include + +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 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 index 000000000..ebd8f1e86 --- /dev/null +++ b/src/SALOMESDS/SALOME_DataScopeServer_SSL.cxx @@ -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); }); +}