+namespace SALOMEDS
+{
+ class Notifier: public SALOMEDSImpl_AbstractCallback
+ {
+ public:
+ Notifier(CORBA::ORB_ptr orb)
+ {
+ _orb = CORBA::ORB::_duplicate(orb);
+ }
+
+ //============================================================================
+ /*! Function : addSO_Notification
+ * Purpose : This function tells all the observers that a SO has been added
+ */
+ //============================================================================
+
+ virtual bool addSO_Notification(const SALOMEDSImpl_SObject& theSObject)
+ {
+ std::string anID=theSObject.GetID();
+ const char* cID=anID.c_str();
+ for (ObsListIter it (myObservers.begin()); it != myObservers.end(); ++it)
+ {
+ it->first->notifyObserverID(cID,1);
+ }
+ 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)
+ {
+ std::string anID=theSObject.GetID();
+ const char* cID=anID.c_str();
+ for (ObsListIter it (myObservers.begin()); it != myObservers.end(); ++it)
+ {
+ it->first->notifyObserverID(cID,2);
+ }
+ 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, int reason)
+ {
+ for (ObsListIter it (myObservers.begin()); it != myObservers.end(); ++it)
+ {
+ if(it->second)
+ {
+ std::string anID=theSObject.GetID();
+ const char* cID=anID.c_str();
+ it->first->notifyObserverID(cID,reason);
+ }
+ }
+ return true; // NGE return always true but can be modified if needed
+ }
+
+ //============================================================================
+ /*! Function : modifyNB_Notification
+ * Purpose : This function tells all the observers that
+ * a NoteBook variable has been added/modified/removed.
+ */
+ //============================================================================
+
+ virtual bool modifyNB_Notification(const char* theVarName)
+ {
+ for (ObsListIter it (myObservers.begin()); it != myObservers.end(); ++it)
+ {
+ it->first->notifyObserverID(theVarName,6);
+ }
+ return true; // NGE return always true but can be modified if needed
+ }
+
+ //============================================================================
+ /*! Function : attach
+ * Purpose : register an Observer
+ */
+ //============================================================================
+
+ virtual void attach(SALOMEDS::Observer_ptr theObs, bool modify)
+ {
+ 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;
+ ObsList myObservers;
+ CORBA::ORB_var _orb;
+ };
+
+ class GenObjRegister: public SALOMEDSImpl_AbstractCallback
+ {
+ public:
+ GenObjRegister(CORBA::ORB_ptr orb)
+ {
+ _orb = CORBA::ORB::_duplicate(orb);
+ }
+ virtual void RegisterGenObj (const std::string& theIOR)
+ {
+ try
+ {
+ CORBA::Object_var obj = _orb->string_to_object(theIOR.c_str());
+ if ( obj->_non_existent() ) return;
+ SALOME::GenericObj_var gobj = SALOME::GenericObj::_narrow(obj);
+ if(! CORBA::is_nil(gobj) )
+ {
+ gobj->Register();
+ }
+ }
+ catch(const CORBA::Exception& e)
+ {
+ }
+ }
+ virtual void UnRegisterGenObj(const std::string& theIOR)
+ {
+ try
+ {
+ CORBA::Object_var obj = _orb->string_to_object(theIOR.c_str());
+ if ( obj->_non_existent() ) return;
+ SALOME::GenericObj_var gobj = SALOME::GenericObj::_narrow(obj);
+ if(! CORBA::is_nil(gobj) )
+ {
+ gobj->UnRegister();
+ }
+ }
+ catch(const CORBA::Exception& e)
+ {
+ }
+ }
+
+ private:
+ CORBA::ORB_var _orb;
+ };
+
+} // namespace SALOMEDS
+
+std::map<SALOMEDSImpl_Study* , SALOMEDS_Study_i*> SALOMEDS_Study_i::_mapOfStudies;