From 162c7f607b5fd41903c1e0c010630e36dad7b411 Mon Sep 17 00:00:00 2001 From: caremoli Date: Thu, 17 Jun 2010 17:22:51 +0000 Subject: [PATCH] CCAR: add a notifier object in SALOMEDS so that CORBA is no more called in SALOMEDSImpl --- src/SALOMEDS/SALOMEDS_Study.cxx | 9 +- src/SALOMEDS/SALOMEDS_Study_i.cxx | 84 ++++++++++++++++++- src/SALOMEDS/SALOMEDS_Study_i.hxx | 6 +- src/SALOMEDSImpl/SALOMEDSImpl_Callback.hxx | 7 ++ src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx | 46 +++------- src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx | 9 +- .../SALOMEDSImpl_StudyBuilder.cxx | 4 +- 7 files changed, 109 insertions(+), 56 deletions(-) diff --git a/src/SALOMEDS/SALOMEDS_Study.cxx b/src/SALOMEDS/SALOMEDS_Study.cxx index de2f8bba4..43c7932a1 100644 --- a/src/SALOMEDS/SALOMEDS_Study.cxx +++ b/src/SALOMEDS/SALOMEDS_Study.cxx @@ -1002,12 +1002,7 @@ _PTR(AttributeParameter) SALOMEDS_Study::GetModuleParameters(const std::string& void SALOMEDS_Study::attach(SALOME::Observer_ptr theObserver) { - if (_isLocal) { - SALOMEDS::Locker lock; - _local_impl->attach(theObserver); - } - else { - _corba_impl->attach(theObserver); - } + if(CORBA::is_nil(_corba_impl)) GetStudy(); //If CORBA implementation is null then retrieve it + _corba_impl->attach(theObserver); } diff --git a/src/SALOMEDS/SALOMEDS_Study_i.cxx b/src/SALOMEDS/SALOMEDS_Study_i.cxx index 8f8975116..0bb71eb4f 100644 --- a/src/SALOMEDS/SALOMEDS_Study_i.cxx +++ b/src/SALOMEDS/SALOMEDS_Study_i.cxx @@ -42,6 +42,7 @@ #include "SALOMEDSImpl_AttributeParameter.hxx" #include "SALOMEDSImpl_ChildIterator.hxx" #include "SALOMEDSImpl_IParameters.hxx" +#include "SALOMEDSImpl_Callback.hxx" #include "DF_Label.hxx" #include "DF_Attribute.hxx" @@ -55,6 +56,81 @@ #include #endif +class Notifier: public SALOMEDSImpl_AbstractCallback +{ +public: +//============================================================================ +/*! Function : addSO_Notification + * Purpose : This function tells all the observers that a SO has been added + */ +//============================================================================ + + virtual bool addSO_Notification(const SALOMEDSImpl_SObject& theSObject) + { + //MESSAGE("Notification ADD called") + CORBA::String_var event="ADD"; + CORBA::String_var anID=theSObject.GetID().c_str(); + for (ObsListIter it (myObservers.begin()); it != myObservers.end(); ++it) + { + (*it)->notifyObserver(anID,event); + } + return true; // NGE return always true but can be modified if needed + } + +//============================================================================ +/*! Function : removeSO_Notification + * Purpose : This function tells all the observers that a SO has been removed + */ +//============================================================================ + + virtual bool removeSO_Notification(const SALOMEDSImpl_SObject& theSObject) + { + //MESSAGE("Notification REMOVE called") + CORBA::String_var event="REMOVE"; + CORBA::String_var anID=theSObject.GetID().c_str(); + for (ObsListIter it (myObservers.begin()); it != myObservers.end(); ++it) + { + (*it)->notifyObserver(anID,event); + } + return true; // NGE return always true but can be modified if needed + } + +//============================================================================ +/*! Function : modifySO_Notification + * Purpose : This function tells all the observers that a SO has been modified + */ +//============================================================================ + + virtual bool modifySO_Notification(const SALOMEDSImpl_SObject& theSObject) + { + //MESSAGE("Notification MODIFY called") + CORBA::String_var event="MODIFY"; + CORBA::String_var anID=theSObject.GetID().c_str(); + for (ObsListIter it (myObservers.begin()); it != myObservers.end(); ++it) + { + (*it)->notifyObserver(anID,event); + } + return true; // NGE return always true but can be modified if needed + } + +//============================================================================ +/*! Function : attach + * Purpose : register an Observer + */ +//============================================================================ + + virtual void attach(SALOME::Observer_ptr theObs) + { + myObservers.push_back(SALOME::Observer::_duplicate(theObs)); + } + +private: + typedef std::list ObsList; + typedef ObsList::iterator ObsListIter; + ObsList myObservers; +}; + + std::map SALOMEDS_Study_i::_mapOfStudies; //============================================================================ @@ -67,6 +143,8 @@ SALOMEDS_Study_i::SALOMEDS_Study_i(SALOMEDSImpl_Study* theImpl, { _orb = CORBA::ORB::_duplicate(orb); _impl = theImpl; + _notifier = new Notifier; + theImpl->setNotifier(_notifier); _builder = new SALOMEDS_StudyBuilder_i(_impl->NewBuilder(), _orb); } @@ -1154,9 +1232,9 @@ void SALOMEDS_Study_i::EnableUseCaseAutoFilling(CORBA::Boolean isEnabled) * Purpose : This function attach an observer to the study */ //============================================================================ -void SALOMEDS_Study_i::attach(SALOME::Observer_ptr theObs){ - SALOMEDS::Locker lock; - _impl->attach(theObs); +void SALOMEDS_Study_i::attach(SALOME::Observer_ptr theObs) +{ + _notifier->attach(theObs); } //=========================================================================== diff --git a/src/SALOMEDS/SALOMEDS_Study_i.hxx b/src/SALOMEDS/SALOMEDS_Study_i.hxx index 9daf7f15e..b2df91f87 100644 --- a/src/SALOMEDS/SALOMEDS_Study_i.hxx +++ b/src/SALOMEDS/SALOMEDS_Study_i.hxx @@ -47,6 +47,8 @@ #include "SALOMEDSImpl_Study.hxx" #include "SALOMEDSImpl_AttributeIOR.hxx" +class Notifier; + class Standard_EXPORT SALOMEDS_Study_i: public POA_SALOMEDS::Study { private: @@ -54,9 +56,7 @@ private: SALOMEDSImpl_Study* _impl; SALOMEDS_StudyBuilder_i* _builder; static std::map _mapOfStudies; - typedef std::list ObsList; - typedef ObsList::iterator ObsListIter; - ObsList myObservers; + Notifier* _notifier; public: diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_Callback.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_Callback.hxx index 91cef20ef..906403c97 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_Callback.hxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_Callback.hxx @@ -54,4 +54,11 @@ public: }; +class SALOMEDSIMPL_EXPORT SALOMEDSImpl_AbstractCallback +{ +public: + virtual bool addSO_Notification(const SALOMEDSImpl_SObject& theSObject){return false;}; + virtual bool removeSO_Notification(const SALOMEDSImpl_SObject& theSObject){return false;}; + virtual bool modifySO_Notification(const SALOMEDSImpl_SObject& theSObject){return false;}; +}; #endif diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx index c8abc7e5a..3e18369b1 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx @@ -45,8 +45,6 @@ #include #include -#include "utilities.h" - #define DIRECTORYID 16661 #define FILELOCALID 26662 #define FILEID "FILE: " @@ -1991,15 +1989,9 @@ std::vector SALOMEDSImpl_Study::GetIORs() * Purpose : This function tells all the observers that a SO has been added */ //============================================================================ -bool SALOMEDSImpl_Study::addSO_Notification (const SALOMEDSImpl_SObject& theSObject) { - MESSAGE("Notification ADD called") - CORBA::String_var event="ADD"; - CORBA::String_var anID=theSObject.GetID().c_str(); - for (ObsListIter it (myObservers.begin()); it != myObservers.end(); ++it) - { - (*it)->notifyObserver(anID,event); - } - return true; // NGE return always true but can be modified if needed +bool SALOMEDSImpl_Study::addSO_Notification (const SALOMEDSImpl_SObject& theSObject) +{ + return _notifier->addSO_Notification(theSObject); } //============================================================================ @@ -2007,15 +1999,9 @@ bool SALOMEDSImpl_Study::addSO_Notification (const SALOMEDSImpl_SObject& theSObj * Purpose : This function tells all the observers that a SO has been removed */ //============================================================================ -bool SALOMEDSImpl_Study::removeSO_Notification (const SALOMEDSImpl_SObject& theSObject) { - MESSAGE("Notification REMOVE called") - CORBA::String_var event="REMOVE"; - CORBA::String_var anID=theSObject.GetID().c_str(); - for (ObsListIter it (myObservers.begin()); it != myObservers.end(); ++it) - { - (*it)->notifyObserver(anID,event); - } - return true; // NGE return always true but can be modified if needed +bool SALOMEDSImpl_Study::removeSO_Notification (const SALOMEDSImpl_SObject& theSObject) +{ + return _notifier->removeSO_Notification(theSObject); } //============================================================================ @@ -2023,23 +2009,17 @@ bool SALOMEDSImpl_Study::removeSO_Notification (const SALOMEDSImpl_SObject& theS * Purpose : This function tells all the observers that a SO has been modified */ //============================================================================ -bool SALOMEDSImpl_Study::modifySO_Notification (const SALOMEDSImpl_SObject& theSObject) { - MESSAGE("Notification MODIFY called") - CORBA::String_var event="MODIFY"; - CORBA::String_var anID=theSObject.GetID().c_str(); - for (ObsListIter it (myObservers.begin()); it != myObservers.end(); ++it) - { - (*it)->notifyObserver(anID,event); - } - return true; // NGE return always true but can be modified if needed +bool SALOMEDSImpl_Study::modifySO_Notification (const SALOMEDSImpl_SObject& theSObject) +{ + return _notifier->modifySO_Notification(theSObject); } //============================================================================ -/*! Function : attach - * Purpose : register an Observer +/*! Function : setNotifier + * Purpose : register a notifier */ //============================================================================ -void SALOMEDSImpl_Study::attach(SALOME::Observer_ptr theObs) +void SALOMEDSImpl_Study::setNotifier(SALOMEDSImpl_AbstractCallback* notifier) { - myObservers.push_back(SALOME::Observer::_duplicate(theObs)); + _notifier=notifier; } diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx index a4f6b0910..0731d3ab3 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx @@ -32,7 +32,6 @@ #include #include #include -#include #include "DF_Document.hxx" #include "DF_Label.hxx" @@ -51,7 +50,6 @@ #include "SALOMEDSImpl_Driver.hxx" #include "SALOMEDSImpl_ChildIterator.hxx" #include "SALOMEDSImpl_GenericVariable.hxx" -#include "SALOME_Observer.hh" class SALOMEDSImpl_StudyManager; class SALOMEDSImpl_GenericAttribute; @@ -72,16 +70,13 @@ private: SALOMEDSImpl_Callback* _cb; SALOMEDSImpl_StudyBuilder* _builder; SALOMEDSImpl_UseCaseBuilder* _useCaseBuilder; + SALOMEDSImpl_AbstractCallback* _notifier; std::map _mapOfSO; std::map _mapOfSCO; std::map myIORLabels; std::vector myNoteBookVars; - typedef std::list ObsList; - typedef ObsList::iterator ObsListIter; - ObsList myObservers; - SALOMEDSImpl_SObject _FindObject(const SALOMEDSImpl_SObject& SO, const std::string& anObjectName, bool& _find); @@ -323,7 +318,7 @@ public: virtual bool addSO_Notification(const SALOMEDSImpl_SObject& theSObject); virtual bool removeSO_Notification(const SALOMEDSImpl_SObject& theSObject); virtual bool modifySO_Notification(const SALOMEDSImpl_SObject& theSObject); - virtual void attach(SALOME::Observer_ptr theObs); + virtual void setNotifier(SALOMEDSImpl_AbstractCallback* notifier); friend class SALOMEDSImpl_StudyManager; diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_StudyBuilder.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_StudyBuilder.cxx index 804d5e307..f49c7d0c6 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_StudyBuilder.cxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_StudyBuilder.cxx @@ -74,7 +74,7 @@ SALOMEDSImpl_StudyBuilder::~SALOMEDSImpl_StudyBuilder() //============================================================================ SALOMEDSImpl_SComponent SALOMEDSImpl_StudyBuilder::NewComponent(const std::string& DataType) { - std::cerr << "I'm here newComponent " << std::endl; + //std::cerr << "I'm here newComponent " << std::endl; _errorCode = ""; CheckLocked(); @@ -139,7 +139,6 @@ bool SALOMEDSImpl_StudyBuilder::RemoveComponent(const SALOMEDSImpl_SComponent& a //============================================================================ SALOMEDSImpl_SObject SALOMEDSImpl_StudyBuilder::NewObject(const SALOMEDSImpl_SObject& theFatherObject) { - std::cerr << "I'm here newObject " << std::endl; _errorCode = ""; CheckLocked(); @@ -575,7 +574,6 @@ bool SALOMEDSImpl_StudyBuilder::Addreference(const SALOMEDSImpl_SObject& me, SALOMEDSImpl_AttributeTarget::Set(RefLab)->Add(SALOMEDSImpl_Study::SObject(Lab)); if(_callbackOnRemove && Lab.IsDescendant(_doc->Main())) _callbackOnRemove->OnRemoveSObject(me); - _study->removeSO_Notification(me); return true; } -- 2.39.2