From 726f961b8a9446eeb85744183ffc80b67d221677 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Tue, 17 Aug 2021 09:41:34 +0200 Subject: [PATCH] Make the EDF non reg test work in SSL mode : Bug14551_reloadStudy.py --- src/KERNEL_PY/__init__.py | 2 + src/KERNEL_PY/salome_study.py | 8 ++++ src/SALOMEDS/KernelDS.cxx | 22 ++++++++-- src/SALOMEDS/KernelDS.hxx | 3 ++ src/SALOMEDS/KernelDS.i | 10 ++++- src/SALOMEDS/SALOMEDS_Study_i.cxx | 71 ++++++++++++++++++++----------- src/SALOMEDS/SALOMEDS_Study_i.hxx | 5 +++ 7 files changed, 92 insertions(+), 29 deletions(-) diff --git a/src/KERNEL_PY/__init__.py b/src/KERNEL_PY/__init__.py index 8a62c4a42..7b99a03e4 100644 --- a/src/KERNEL_PY/__init__.py +++ b/src/KERNEL_PY/__init__.py @@ -280,6 +280,8 @@ def salome_close(): salome_iapp_close() salome_study_close() myStudy, myStudyName = None, None + import KernelDS + KernelDS.KillGlobalSessionInstance() pass def salome_NS(): diff --git a/src/KERNEL_PY/salome_study.py b/src/KERNEL_PY/salome_study.py index 57d2d7127..c8fab2542 100644 --- a/src/KERNEL_PY/salome_study.py +++ b/src/KERNEL_PY/salome_study.py @@ -302,6 +302,14 @@ def salome_study_init_without_session(theStudyPath=None): if verbose(): print("Study found") pass + import types + if theStudyPath and isinstance(theStudyPath, (str, bytes)): + if isinstance(theStudyPath, bytes): + theStudyPath = str(theStudyPath, 'UTF8') + openStudy(theStudyPath) + else: + myStudy.Init() + myStudyName = myStudy._get_Name() return myStudy, myStudyName diff --git a/src/SALOMEDS/KernelDS.cxx b/src/SALOMEDS/KernelDS.cxx index 82fe2aefb..ef6ca4e24 100644 --- a/src/SALOMEDS/KernelDS.cxx +++ b/src/SALOMEDS/KernelDS.cxx @@ -26,8 +26,22 @@ std::string GetSessionInstance() { - SALOMEDS::Study_var study = KERNEL::getStudyServantSA(); - CORBA::ORB_ptr orb = KERNEL::getORB(); - CORBA::String_var ior = orb->object_to_string(study); - return std::string(ior.in()); + SALOMEDS::Study_var study = KERNEL::getStudyServantSA(); + CORBA::ORB_ptr orb = KERNEL::getORB(); + CORBA::String_var ior = orb->object_to_string(study); + return std::string(ior.in()); } + +std::string GetNewSessionInstance() +{ + SALOMEDS::Study_var study = KERNEL::retrieveNewStudyServantSA(); + KERNEL::setStudyServantSA(study); + CORBA::ORB_ptr orb = KERNEL::getORB(); + CORBA::String_var ior = orb->object_to_string(study); + return std::string(ior.in()); +} + +void KillGlobalSessionInstance() +{ + KERNEL::killStudyServantSA(); +} \ No newline at end of file diff --git a/src/SALOMEDS/KernelDS.hxx b/src/SALOMEDS/KernelDS.hxx index c60e72ee7..53af1598d 100644 --- a/src/SALOMEDS/KernelDS.hxx +++ b/src/SALOMEDS/KernelDS.hxx @@ -21,4 +21,7 @@ #include std::string GetSessionInstance(); +std::string GetNewSessionInstance(); +void KillGlobalSessionInstance(); + #endif diff --git a/src/SALOMEDS/KernelDS.i b/src/SALOMEDS/KernelDS.i index 278870731..663c32a36 100644 --- a/src/SALOMEDS/KernelDS.i +++ b/src/SALOMEDS/KernelDS.i @@ -27,7 +27,9 @@ %inline { - std::string GetSessionInstance(); + std::string GetSessionInstance(); + std::string GetNewSessionInstance(); + void KillGlobalSessionInstance(); } %pythoncode %{ @@ -36,4 +38,10 @@ def myStudy(): import CORBA orb=CORBA.ORB_init(['']) return orb.string_to_object(GetSessionInstance()) + +def myNewStudy(): + import SALOMEDS + import CORBA + orb=CORBA.ORB_init(['']) + return orb.string_to_object(GetNewSessionInstance()) %} diff --git a/src/SALOMEDS/SALOMEDS_Study_i.cxx b/src/SALOMEDS/SALOMEDS_Study_i.cxx index 96a37ba1d..42da7d8c6 100644 --- a/src/SALOMEDS/SALOMEDS_Study_i.cxx +++ b/src/SALOMEDS/SALOMEDS_Study_i.cxx @@ -76,24 +76,28 @@ static SALOMEDS::Study_var _study; */ SALOMEDS::Study_ptr KERNEL::getStudyServantSA() { - if(CORBA::is_nil(_study)) { - CORBA::ORB_ptr orb = KERNEL::getORB(); - CORBA::Object_var obj = orb->resolve_initial_references("RootPOA"); - PortableServer::POA_var poa = PortableServer::POA::_narrow(obj); - _poa = PortableServer::POA::_duplicate(poa); - SALOME_Fake_NamingService ns; - SALOMEDS_Study_i *servant = new SALOMEDS_Study_i(orb,&ns); - _study = servant->_this(); + _study = retrieveNewStudyServantSA(); } return SALOMEDS::Study::_duplicate(_study); } -/** - * If a study is already built and activated elsewhere (for example in GUI context) - */ -void KERNEL::setStudyServantSA(SALOMEDS::Study_var study, PortableServer::POA_var poa) +SALOMEDS::Study_var KERNEL::retrieveNewStudyServantSA() +{ + CORBA::ORB_ptr orb = KERNEL::getORB(); + CORBA::Object_var obj = orb->resolve_initial_references("RootPOA"); + PortableServer::POA_var poa = PortableServer::POA::_narrow(obj); + if(CORBA::is_nil(_poa)) + _poa = poa; + SALOME_Fake_NamingService *ns = new SALOME_Fake_NamingService; + SALOMEDS_Study_i *servant = new SALOMEDS_Study_i(orb,ns); + SALOMEDS::Study_var study = servant->_this(); + servant->_remove_ref(); + return study; +} + +void KERNEL::killStudyServantSA() { if( ! CORBA::is_nil(_study) ) { @@ -101,12 +105,29 @@ void KERNEL::setStudyServantSA(SALOMEDS::Study_var study, PortableServer::POA_va try { serv = _poa->reference_to_servant(_study); + PortableServer::ObjectId_var anObjectId = _poa->servant_to_id(serv); + _poa->deactivate_object(anObjectId); } catch(...) { } if(serv) serv->_remove_ref(); } - _study = study; _poa = poa; + _study = SALOMEDS::Study::_nil(); +} + +/** + * If a study is already built and activated elsewhere (for example in GUI context) + */ +void KERNEL::setStudyServantSA(SALOMEDS::Study_var study, PortableServer::POA_var poa) +{ + _poa = poa; + setStudyServantSA(study); +} + +void KERNEL::setStudyServantSA(SALOMEDS::Study_var study) +{ + killStudyServantSA(); + _study = study; } namespace SALOMEDS @@ -290,9 +311,8 @@ namespace SALOMEDS */ //================================================================================ - void sendMessageToGUI(const char* msg ) + void sendMessageToGUI(SALOME_NamingService_Abstract *aNamingService, const char* msg) { - SALOME_NamingService_Abstract *aNamingService = KERNEL::getNamingService(); CORBA::Object_var obj = aNamingService->Resolve("/Kernel/Session"); SALOME::Session_var aSession = SALOME::Session::_narrow(obj); sendMessageToGUIGivenSession(aSession,msg); @@ -302,12 +322,12 @@ namespace SALOMEDS SALOMEDS_Study_i::SALOMEDS_Study_i(CORBA::ORB_ptr orb, SALOME_NamingService_Abstract *ns) { - SALOME_NamingService_Abstract *aNamingService = ns==nullptr?KERNEL::getNamingService():ns; + _ns = ns==nullptr?KERNEL::getNamingService():ns; _orb = CORBA::ORB::_duplicate(orb); _impl = new SALOMEDSImpl_Study(); - _factory = new SALOMEDS_DriverFactory_i(_orb,aNamingService); + _factory = new SALOMEDS_DriverFactory_i(_orb,_ns); _closed = true; - CORBA::Object_var obj = aNamingService->Resolve("/Kernel/Session"); + CORBA::Object_var obj = _ns->Resolve("/Kernel/Session"); SALOME::Session_var aSession = SALOME::Session::_narrow(obj); Init(aSession); } @@ -319,6 +339,7 @@ SALOMEDS_Study_i::SALOMEDS_Study_i(CORBA::ORB_ptr orb, SALOME_NamingService_Abst //============================================================================ SALOMEDS_Study_i::SALOMEDS_Study_i(CORBA::ORB_ptr orb, SALOME::Session_ptr session) { + _ns = KERNEL::getNamingService(); _orb = CORBA::ORB::_duplicate(orb); _impl = new SALOMEDSImpl_Study(); _factory = new SALOMEDS_DriverFactory_i(_orb,!CORBA::is_nil(session)); @@ -337,12 +358,15 @@ SALOMEDS_Study_i::~SALOMEDS_Study_i() Clear(); delete _factory; delete _impl; + //_ns is owned by SALOMEDS_Study_i only if IsTrueNS() returns false + if(_ns) + if(!_ns->IsTrueNS()) + delete _ns; } void SALOMEDS_Study_i::Init() { - SALOME_NamingService_Abstract *aNamingService = KERNEL::getNamingService(); - CORBA::Object_var obj = aNamingService->Resolve("/Kernel/Session"); + CORBA::Object_var obj = _ns->Resolve("/Kernel/Session"); SALOME::Session_var aSession = SALOME::Session::_narrow(obj); Init(aSession); } @@ -432,7 +456,7 @@ void SALOMEDS_Study_i::Clear() } // Notify GUI that study is cleared - SALOMEDS::sendMessageToGUI( "studyCleared" ); + SALOMEDS::sendMessageToGUI( _ns, "studyCleared" ); _impl->Clear(); _impl->setNotifier(0); @@ -480,7 +504,7 @@ bool SALOMEDS_Study_i::Open(const wchar_t* aWUrl) // update desktop title with new study name //NameChanged(); - SALOMEDS::sendMessageToGUI( "connect_to_study" ); + SALOMEDS::sendMessageToGUI( _ns, "connect_to_study" ); if ( !res ) THROW_SALOME_CORBA_EXCEPTION("Impossible to Open study from file", SALOME::BAD_PARAM) @@ -1051,8 +1075,7 @@ void SALOMEDS_Study_i::URL(const wchar_t* wurl) _impl->URL(Kernel_Utils::encode_s(wurl)); // update desktop title with new study name - SALOME_NamingService_Abstract *aNamingService = KERNEL::getNamingService(); - CORBA::Object_var obj = aNamingService->Resolve("/Kernel/Session"); + CORBA::Object_var obj = _ns->Resolve("/Kernel/Session"); SALOME::Session_var aSession = SALOME::Session::_narrow(obj); NameChanged(aSession); } diff --git a/src/SALOMEDS/SALOMEDS_Study_i.hxx b/src/SALOMEDS/SALOMEDS_Study_i.hxx index 50a69af13..8de709f17 100644 --- a/src/SALOMEDS/SALOMEDS_Study_i.hxx +++ b/src/SALOMEDS/SALOMEDS_Study_i.hxx @@ -51,6 +51,9 @@ class SALOME_NamingService_Abstract; namespace KERNEL { Standard_EXPORT SALOMEDS::Study_ptr getStudyServantSA(); + Standard_EXPORT SALOMEDS::Study_var retrieveNewStudyServantSA(); + Standard_EXPORT void killStudyServantSA(); + Standard_EXPORT void setStudyServantSA(SALOMEDS::Study_var study); Standard_EXPORT void setStudyServantSA(SALOMEDS::Study_var study, PortableServer::POA_var poa); } @@ -66,6 +69,8 @@ private: SALOMEDSImpl_AbstractCallback* _genObjRegister; SALOMEDS_DriverFactory_i* _factory; bool _closed; + //! naming service object to retrieve session. _ns is owned by SALOMEDS_Study_i only if IsTrueNS() returns false + SALOME_NamingService_Abstract *_ns = nullptr; public: //! standard constructor -- 2.39.2