1 // IObservable.h 2 // * PURPOSE 3 // Defines a general observable-object interface. 4 // * HISTORY 5 // e.moon 19aug99 Begun 6 7 #ifndef __IObservable_H__ 8 #define __IObservable_H__ 9 10 class BMessenger; 11 12 #include "cortex_defs.h" 13 __BEGIN_CORTEX_NAMESPACE 14 15 class IObservable { 16 17 public: 18 IObservable() { } 19 virtual ~IObservable() { } 20 public: // *** deletion 21 // clients must call release() rather than deleting, 22 // to ensure that all observers are notified of the 23 // object's demise. if the object has already been 24 // released, return an error. 25 virtual status_t release()=0; 26 27 public: // *** accessors 28 // return true if release() has been called, false otherwise. 29 virtual bool isReleased() const=0; 30 31 protected: // *** hooks 32 // must be called after an observer has been added (this is a good 33 // place to send an acknowledgement) 34 virtual void observerAdded( 35 const BMessenger& observer) {TOUCH(observer);} 36 37 // must be called after an observer has been removed 38 virtual void observerRemoved( 39 const BMessenger& observer) {TOUCH(observer);} 40 41 // must be called once all observers have been removed 42 virtual void releaseComplete() {} 43 44 protected: // *** operations 45 // call to send the given message to all observers. 46 // Responsibility for deletion of the message remains with 47 // the caller. 48 virtual status_t notify( 49 BMessage* message)=0; 50 51 // must be called by release() if targets remain to be 52 // released. should notify all targets with an appropriate 53 // release-notification message (such as M_RELEASE_OBSERVABLE). 54 virtual void notifyRelease()=0; 55 }; 56 57 __END_CORTEX_NAMESPACE 58 #endif /*__IObservable_H__*/ 59