From 90466a608cf8d858007cb509cc797b5e4d6b9910 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Wed, 24 Feb 2021 15:09:07 +0100 Subject: [PATCH] Fix problem of multiple study servant in GUI case generating empty notifiers list in SALOMEDSImpl_Study aggregated instance --- src/SALOMEDS/SALOMEDS.cxx | 1 + src/SALOMEDS/SALOMEDS_Study_i.cxx | 30 +++++++++++++++++++++++++----- src/SALOMEDS/SALOMEDS_Study_i.hxx | 1 + 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/SALOMEDS/SALOMEDS.cxx b/src/SALOMEDS/SALOMEDS.cxx index 0ce9dc1f4..bd1c112b6 100644 --- a/src/SALOMEDS/SALOMEDS.cxx +++ b/src/SALOMEDS/SALOMEDS.cxx @@ -129,6 +129,7 @@ extern "C" // Activate the objects. This tells the POA that the objects are ready to accept requests. PortableServer::ObjectId_var aStudy_iid = root_poa->activate_object(aStudy_i); aStudy = aStudy_i->_this(); + KERNEL::setStudyServantSA(aStudy,poa); namingService.Register(aStudy, "/Study"); aStudy_i->GetImpl()->GetDocument()->SetModified(false); aStudy_i->_remove_ref(); diff --git a/src/SALOMEDS/SALOMEDS_Study_i.cxx b/src/SALOMEDS/SALOMEDS_Study_i.cxx index 79ad8c553..60961b891 100644 --- a/src/SALOMEDS/SALOMEDS_Study_i.cxx +++ b/src/SALOMEDS/SALOMEDS_Study_i.cxx @@ -64,7 +64,8 @@ UNEXPECT_CATCH(LockProtection, SALOMEDS::StudyBuilder::LockProtection) static SALOMEDS_Driver_i* GetDriver(const SALOMEDSImpl_SObject& theObject, CORBA::ORB_ptr orb); -static PortableServer::POA_ptr _poa; +static PortableServer::POA_var _poa; +static SALOMEDS::Study_var _study; /** * Return a unique study obj but servant is embeded here. @@ -72,17 +73,36 @@ static PortableServer::POA_ptr _poa; */ SALOMEDS::Study_ptr KERNEL::getStudyServantSA() { - static SALOMEDS::Study_ptr aStudy; - if(CORBA::is_nil(aStudy)) + + 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); SALOMEDS_Study_i *servant = new SALOMEDS_Study_i(orb,SALOME::Session::_nil()); - aStudy = servant->_this(); + _study = servant->_this(); + } + 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) +{ + if( ! CORBA::is_nil(_study) ) + { + PortableServer::ServantBase *serv = nullptr; + try + { + serv = _poa->reference_to_servant(_study); + } + catch(...) { } + if(serv) + serv->_remove_ref(); } - return SALOMEDS::Study::_duplicate(aStudy); + _study = study; _poa = poa; } namespace SALOMEDS diff --git a/src/SALOMEDS/SALOMEDS_Study_i.hxx b/src/SALOMEDS/SALOMEDS_Study_i.hxx index 8f3b34ef7..37a44de5f 100644 --- a/src/SALOMEDS/SALOMEDS_Study_i.hxx +++ b/src/SALOMEDS/SALOMEDS_Study_i.hxx @@ -51,6 +51,7 @@ class SALOME_NamingService_Abstract; namespace KERNEL { Standard_EXPORT SALOMEDS::Study_ptr getStudyServantSA(); + Standard_EXPORT void setStudyServantSA(SALOMEDS::Study_var study, PortableServer::POA_var poa); } class Standard_EXPORT SALOMEDS_Study_i: public POA_SALOMEDS::Study -- 2.39.2