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);
}
#include "SALOMEDSImpl_AttributeParameter.hxx"
#include "SALOMEDSImpl_ChildIterator.hxx"
#include "SALOMEDSImpl_IParameters.hxx"
+#include "SALOMEDSImpl_Callback.hxx"
#include "DF_Label.hxx"
#include "DF_Attribute.hxx"
#include <unistd.h>
#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<SALOME::Observer_var> ObsList;
+ typedef ObsList::iterator ObsListIter;
+ ObsList myObservers;
+};
+
+
std::map<SALOMEDSImpl_Study* , SALOMEDS_Study_i*> SALOMEDS_Study_i::_mapOfStudies;
//============================================================================
{
_orb = CORBA::ORB::_duplicate(orb);
_impl = theImpl;
+ _notifier = new Notifier;
+ theImpl->setNotifier(_notifier);
_builder = new SALOMEDS_StudyBuilder_i(_impl->NewBuilder(), _orb);
}
* 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);
}
//===========================================================================
#include "SALOMEDSImpl_Study.hxx"
#include "SALOMEDSImpl_AttributeIOR.hxx"
+class Notifier;
+
class Standard_EXPORT SALOMEDS_Study_i: public POA_SALOMEDS::Study
{
private:
SALOMEDSImpl_Study* _impl;
SALOMEDS_StudyBuilder_i* _builder;
static std::map<SALOMEDSImpl_Study*, SALOMEDS_Study_i*> _mapOfStudies;
- typedef std::list<SALOME::Observer_var> ObsList;
- typedef ObsList::iterator ObsListIter;
- ObsList myObservers;
+ Notifier* _notifier;
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
#include <fstream>
#include <sstream>
-#include "utilities.h"
-
#define DIRECTORYID 16661
#define FILELOCALID 26662
#define FILEID "FILE: "
* 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);
}
//============================================================================
* 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);
}
//============================================================================
* 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;
}
#include <string>
#include <vector>
#include <map>
-#include <list>
#include "DF_Document.hxx"
#include "DF_Label.hxx"
#include "SALOMEDSImpl_Driver.hxx"
#include "SALOMEDSImpl_ChildIterator.hxx"
#include "SALOMEDSImpl_GenericVariable.hxx"
-#include "SALOME_Observer.hh"
class SALOMEDSImpl_StudyManager;
class SALOMEDSImpl_GenericAttribute;
SALOMEDSImpl_Callback* _cb;
SALOMEDSImpl_StudyBuilder* _builder;
SALOMEDSImpl_UseCaseBuilder* _useCaseBuilder;
+ SALOMEDSImpl_AbstractCallback* _notifier;
std::map<std::string, SALOMEDSImpl_SObject> _mapOfSO;
std::map<std::string, SALOMEDSImpl_SComponent> _mapOfSCO;
std::map<std::string, DF_Label> myIORLabels;
std::vector<SALOMEDSImpl_GenericVariable*> myNoteBookVars;
- typedef std::list<SALOME::Observer_var> ObsList;
- typedef ObsList::iterator ObsListIter;
- ObsList myObservers;
-
SALOMEDSImpl_SObject _FindObject(const SALOMEDSImpl_SObject& SO,
const std::string& anObjectName,
bool& _find);
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;
//============================================================================
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();
//============================================================================
SALOMEDSImpl_SObject SALOMEDSImpl_StudyBuilder::NewObject(const SALOMEDSImpl_SObject& theFatherObject)
{
- std::cerr << "I'm here newObject " << std::endl;
_errorCode = "";
CheckLocked();
SALOMEDSImpl_AttributeTarget::Set(RefLab)->Add(SALOMEDSImpl_Study::SObject(Lab));
if(_callbackOnRemove && Lab.IsDescendant(_doc->Main())) _callbackOnRemove->OnRemoveSObject(me);
- _study->removeSO_Notification(me);
return true;
}