Observer.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2005 Palmsource, Inc.
00003  * 
00004  * This software is licensed as described in the file LICENSE, which
00005  * you should have received as part of this distribution. The terms
00006  * are also available at http://www.openbinder.org/license.html.
00007  * 
00008  * This software consists of voluntary contributions made by many
00009  * individuals. For the exact contribution history, see the revision
00010  * history and logs, available at http://www.openbinder.org
00011  */
00012 
00013 #ifndef _SUPPORT__OBSERVER_H
00014 #define _SUPPORT__OBSERVER_H
00015 
00021 #include <support/Binder.h>
00022 #include <support/Handler.h>
00023 #include <support/Locker.h>
00024 
00025 #if _SUPPORTS_NAMESPACE
00026 namespace palmos {
00027 namespace support {
00028 #endif
00029 
00034 
00035 class BObserver : public BBinder
00036 {
00037 public:
00038                         BObserver(const SContext& context);
00039 
00040 protected:
00041     virtual             ~BObserver();
00042 
00044     virtual void        Observed(const SValue& key, const SValue& value) = 0;
00045 
00047     virtual status_t    HandleEffect(   const SValue &in,
00048                                         const SValue &inBindings,
00049                                         const SValue &outBindings,
00050                                         SValue *out);
00052     virtual status_t    DispatchEffect(const SValue& told);
00053 };
00054 
00055 enum {
00056     B_SERIAL_OBSERVER_MSG = 'sero'
00057 };
00058 
00060 class BSerialObserver : public BObserver, public SHandler
00061 {
00062 public:
00063                         BSerialObserver(const SContext& context);
00064 
00065     virtual status_t    HandleMessage(const SMessage &msg);
00066 
00068 
00069             void        SetPriority(int32_t priority);
00070             int32_t     Priority() const;
00071 
00072 protected:
00073     virtual             ~BSerialObserver();
00074     virtual void        InitAtom();
00075 
00076     virtual status_t    DispatchEffect(const SValue& told);
00077 
00079 
00082     SLocker&            SerialLock() const  { return m_lock; }
00083 
00084 private:
00085     mutable SLocker     m_lock;
00086             int32_t     m_priority;
00087 };
00088 
00091 #if _SUPPORTS_NAMESPACE
00092 } } // palmos::support
00093 #endif
00094 
00095 #endif // _SUPPORT__OBSERVER_H