bb_blackboard.h

Go to the documentation of this file.
00001 #ifndef __bb_blackboard_h__
00002 #define __bb_blackboard_h__
00003 
00004 // This component is really just a glorified callback mechanism, a way
00005 // for internal components to invoke callbacks without the target
00006 // components actually having to expose an API for that purpose. Many
00007 // frameworks (such as Qt), provide such a mechanism. An added benefit
00008 // of sending callbacks via this component is that the communicating
00009 // parties do not need to know who they're talking to, leading to
00010 // decoupling.
00011 
00012 #include <glib.h>
00013 
00014 #ifdef __cplusplus
00015 extern "C" {
00016 #endif
00017 
00018   typedef struct _bb_Blackboard bb_Blackboard;
00019 
00020   bb_Blackboard* bb_Blackboard_new(GError** error);
00021 
00022   void bb_Blackboard_destroy(bb_Blackboard* self);
00023 
00024   // This structure may be used to store data that the notifications
00025   // point to, for any datatype as desired. Note that no automatic
00026   // allocation or freeing is performed; this memory is simply
00027   // zero-initialized.
00028   typedef struct {
00029     gboolean flightmode;
00030     gboolean uploads_allowed;
00031     gboolean netpos_allowed;
00032   } bb_Board;
00033 
00034   bb_Board* bb_Blackboard_board(bb_Blackboard* self);
00035 
00036   enum bb_DataType {
00037     bb_dt_flightmode,      /* gboolean */
00038     bb_dt_network_info,    /* CTelephony::TNetworkInfoV1 */
00039     bb_dt_cell_id,         /* CTelephony::TNetworkInfoV1 */
00040     bb_dt_uploads_allowed, /* gboolean */
00041     bb_dt_netpos_allowed   /* gboolean, by value */
00042   };
00043 
00044   typedef void (*bb_Func)(bb_Blackboard* self, enum bb_DataType dt,
00045         gpointer data, int len, gpointer arg);
00046 
00047   typedef struct {
00048     bb_Func changed;
00049     gpointer arg;
00050   } bb_Closure;
00051 
00052   // The value of the closure is used as a unique ID for the
00053   // registrant. This function does not check for duplicates.
00054   gboolean bb_Blackboard_register(bb_Blackboard* self,
00055           enum bb_DataType dt,
00056           bb_Closure cb,
00057           GError** error);
00058 
00059   // Unregisters all entries for the specified closure.
00060   // Does nothing if not registered.
00061   void bb_Blackboard_unregister(bb_Blackboard* self,
00062         bb_Closure cb);
00063 
00064   // Note that the delivery is synchronous, and usual caveats apply.
00065   // However, the good thing is that the data you pass (probably) will
00066   // not have time to change by the time the event has been received
00067   // by each observer. We suggest you always pass a pointer to the
00068   // data as "data"; the receiver can make a copy as required. If you
00069   // want to pass a value directly, at least consider using
00070   // GINT_TO_POINTER and GPOINTER_TO_INT to make this safe. The "len"
00071   // argument is not required for data with fixed, known size.
00072   void bb_Blackboard_notify(bb_Blackboard* self,
00073           enum bb_DataType dt,
00074           gpointer data, int len);
00075 
00076 #ifdef __cplusplus
00077 } /* extern "C" */
00078 #endif
00079 
00080 // Symbian C++ convenience API for observing.
00081 #if defined(__cplusplus) && defined(__SYMBIAN32__)
00082 namespace bb {
00083   class RHandle;
00084 
00085   class MObserver
00086   {
00087   public:
00088     virtual void BbChangedL(bb::RHandle* self, enum bb_DataType dt,
00089           gpointer data, int len) = 0;
00090 
00091     // Override if you do not consider leave in BbChangedL fatal.
00092     virtual void BbLeave(TInt errCode);
00093   };
00094 
00095   // Only one property may be observed per handle.
00096   class RHandle
00097   {
00098   private:
00099     bb_Blackboard* iBoard;
00100     bb_Closure iClosure;
00101     MObserver* iObserver;
00102 
00103   public:
00104     RHandle();
00105 
00106     ~RHandle();
00107 
00108     void Register(bb_Blackboard* aBoard,
00109       enum bb_DataType dt, 
00110       MObserver* observer);
00111     
00112     void Unregister();
00113 
00114     MObserver* Observer() const { return iObserver; }
00115   };
00116 };
00117 #endif // end Symbian C++
00118 
00119 #endif /* __bb_blackboard_h__ */
00120 
00121 /**
00122 
00123 Copyright 2010 Helsinki Institute for Information Technology (HIIT)
00124 and the authors. All rights reserved.
00125 
00126 Authors: Tero Hasu <tero.hasu@hut.fi>
00127 
00128 Permission is hereby granted, free of charge, to any person
00129 obtaining a copy of this software and associated documentation files
00130 (the "Software"), to deal in the Software without restriction,
00131 including without limitation the rights to use, copy, modify, merge,
00132 publish, distribute, sublicense, and/or sell copies of the Software,
00133 and to permit persons to whom the Software is furnished to do so,
00134 subject to the following conditions:
00135 
00136 The above copyright notice and this permission notice shall be
00137 included in all copies or substantial portions of the Software.
00138 
00139 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00140 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00141 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00142 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
00143 BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
00144 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00145 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
00146 SOFTWARE.
00147 
00148  **/

ContextLogger2—ContextLogger2 Logger Daemon Internals—Generated on Mon May 2 13:49:51 2011 by Doxygen 1.6.1