From cd5265c03df3fa45b5c15edd02c06d2e0efb2b2e Mon Sep 17 00:00:00 2001 From: vsr Date: Mon, 17 Mar 2014 11:30:36 +0400 Subject: [PATCH] Fix bug of the observer: detach an observer when study is unloaded from GUI --- idl/SALOMEDS.idl | 10 ++++++- src/SALOMEDS/SALOMEDS_Study.cxx | 6 +++++ src/SALOMEDS/SALOMEDS_Study.hxx | 1 + src/SALOMEDS/SALOMEDS_Study_i.cxx | 29 +++++++++++++++++++++ src/SALOMEDS/SALOMEDS_Study_i.hxx | 2 +- src/SALOMEDSClient/SALOMEDSClient_Study.hxx | 2 +- 6 files changed, 47 insertions(+), 3 deletions(-) diff --git a/idl/SALOMEDS.idl b/idl/SALOMEDS.idl index 1e73daad5..d911ea1ad 100644 --- a/idl/SALOMEDS.idl +++ b/idl/SALOMEDS.idl @@ -552,9 +552,17 @@ during each working session. /*! Attach an observer to the Study - \param theObserver + \param theObserver observer being attached + \param modify when \c true, observer receives any object's modification events; + otherwise observer receives object's creation events only */ void attach(in SALOMEDS::Observer theObserver, in boolean modify); +/*! + Detach an observer from the Study + + \param theObserver observer to be detached +*/ + void detach(in SALOMEDS::Observer theObserver); }; //=========================================================================== diff --git a/src/SALOMEDS/SALOMEDS_Study.cxx b/src/SALOMEDS/SALOMEDS_Study.cxx index 4dc66de3f..1834ca349 100644 --- a/src/SALOMEDS/SALOMEDS_Study.cxx +++ b/src/SALOMEDS/SALOMEDS_Study.cxx @@ -1008,3 +1008,9 @@ void SALOMEDS_Study::attach(SALOMEDS::Observer_ptr theObserver,bool modify) if(CORBA::is_nil(_corba_impl)) GetStudy(); //If CORBA implementation is null then retrieve it _corba_impl->attach(theObserver,modify); } + +void SALOMEDS_Study::detach(SALOMEDS::Observer_ptr theObserver) +{ + if(CORBA::is_nil(_corba_impl)) GetStudy(); //If CORBA implementation is null then retrieve it + _corba_impl->detach(theObserver); +} diff --git a/src/SALOMEDS/SALOMEDS_Study.hxx b/src/SALOMEDS/SALOMEDS_Study.hxx index deae52fe4..5732761f5 100644 --- a/src/SALOMEDS/SALOMEDS_Study.hxx +++ b/src/SALOMEDS/SALOMEDS_Study.hxx @@ -123,6 +123,7 @@ public: virtual bool IsVariableUsed(const std::string& theVarName); virtual std::vector< std::vector > ParseVariables(const std::string& theVars); virtual void attach(SALOMEDS::Observer_ptr theObserver,bool modify); + virtual void detach(SALOMEDS::Observer_ptr theObserver); std::string ConvertObjectToIOR(CORBA::Object_ptr theObject); CORBA::Object_ptr ConvertIORToObject(const std::string& theIOR); diff --git a/src/SALOMEDS/SALOMEDS_Study_i.cxx b/src/SALOMEDS/SALOMEDS_Study_i.cxx index 3dec698bc..5bbc01b31 100644 --- a/src/SALOMEDS/SALOMEDS_Study_i.cxx +++ b/src/SALOMEDS/SALOMEDS_Study_i.cxx @@ -147,6 +147,23 @@ namespace SALOMEDS myObservers.push_back(std::make_pair(SALOMEDS::Observer::_duplicate(theObs),modify)); } + //============================================================================ + /*! Function : detach + * Purpose : unregister an Observer + */ + //============================================================================ + + virtual void detach(SALOMEDS::Observer_ptr theObs) + { + for (ObsListIter it (myObservers.begin()); it != myObservers.end(); ++it) + { + if ( it->first->_is_equivalent(theObs) ) { + myObservers.erase( it ); + break; + } + } + } + private: typedef std::list< std::pair< SALOMEDS::Observer_var, bool > > ObsList; typedef ObsList::iterator ObsListIter; @@ -1330,6 +1347,18 @@ void SALOMEDS_Study_i::attach(SALOMEDS::Observer_ptr theObs,CORBA::Boolean modif static_cast(_notifier)->attach(theObs,modify); } + +//============================================================================ +/*! Function : detach + * Purpose : This function detaches an observer from the study + */ +//============================================================================ +void SALOMEDS_Study_i::detach(SALOMEDS::Observer_ptr theObs) +{ + if(_notifier) + static_cast(_notifier)->detach(theObs); +} + //=========================================================================== // PRIVATE FUNCTIONS //=========================================================================== diff --git a/src/SALOMEDS/SALOMEDS_Study_i.hxx b/src/SALOMEDS/SALOMEDS_Study_i.hxx index fc10f36f2..d988daa48 100644 --- a/src/SALOMEDS/SALOMEDS_Study_i.hxx +++ b/src/SALOMEDS/SALOMEDS_Study_i.hxx @@ -351,6 +351,6 @@ public: virtual CORBA::LongLong GetLocalImpl(const char* theHostname, CORBA::Long thePID, CORBA::Boolean& isLocal); virtual void attach(SALOMEDS::Observer_ptr theObs, CORBA::Boolean modify); - + virtual void detach(SALOMEDS::Observer_ptr theObs); }; #endif diff --git a/src/SALOMEDSClient/SALOMEDSClient_Study.hxx b/src/SALOMEDSClient/SALOMEDSClient_Study.hxx index 92d681b08..5492ffd4a 100644 --- a/src/SALOMEDSClient/SALOMEDSClient_Study.hxx +++ b/src/SALOMEDSClient/SALOMEDSClient_Study.hxx @@ -126,7 +126,7 @@ public: virtual std::vector< std::vector > ParseVariables(const std::string& theVars) = 0; virtual void attach(SALOMEDS::Observer_ptr theObserver,bool modify) = 0; - + virtual void detach(SALOMEDS::Observer_ptr theObserver) = 0; }; -- 2.39.2