dnotifier.h

Go to the documentation of this file.
00001 
00041 /*#*
00042  *#* $Log$
00043  *#* Revision 1.2  2006/07/19 12:56:26  bernie
00044  *#* Convert to new Doxygen style.
00045  *#*
00046  *#* Revision 1.1  2005/11/04 18:26:38  bernie
00047  *#* Import into DevLib.
00048  *#*
00049  *#* Revision 1.4  2005/06/09 13:23:58  batt
00050  *#* Add some comments.
00051  *#*
00052  *#* Revision 1.3  2005/06/08 17:32:33  batt
00053  *#* Switch to new messaging system.
00054  *#*
00055  *#* Revision 1.2  2005/06/06 11:04:12  batt
00056  *#* Add some comments.
00057  *#*
00058  *#* Revision 1.1  2005/05/26 08:32:53  batt
00059  *#* Add new Develer widget system :)
00060  *#*
00061  *#*/
00062 #ifndef DT_DNOTIFIER_H
00063 #define DT_DNOTIFIER_H
00064 
00065 #include <cfg/debug.h>
00066 #include <dt/dtag.h>
00067 #include <mware/list.h>
00068 
00069 //Fwd declaretion.
00070 struct DNotifier;
00071 struct DFilter;
00072 
00073 typedef void (* update_func_ptr)(struct DNotifier *, dtag_t, dval_t);
00074 typedef void (* update_filter_ptr)(struct DFilter *, dtag_t, dval_t);
00075 
00081 typedef struct DNotifier
00082 {
00084     update_func_ptr update;
00085 
00087     List targets;
00088 } DNotifier;
00089 
00094 typedef struct DFilterMap
00095 {
00096     DTagItem src;
00097     DTagItem dst;
00098 } DFilterMap;
00099 
00100 
00105 typedef struct DFilter
00106 {
00108     Node link;
00109 
00111     DNotifier *target;
00112 
00114     update_filter_ptr update;
00115 
00117     const DFilterMap *map;
00118 
00120     DB(uint8_t magic;)
00121 } DFilter;
00122 
00124 typedef uint16_t dfilter_mask_t;
00125 
00127 void filter_init(DFilter *f, const DFilterMap *map, bool masked, DNotifier *source, DNotifier *target);
00128 
00130 void filter_update(DFilter *f, dtag_t tag, dval_t val);
00131 
00133 void filter_mask_update(DFilter *f, dtag_t tag, dval_t val);
00134 
00136 void notifier_init(DNotifier *n);
00137 
00138 
00142 INLINE void dnotify(DNotifier *target, dtag_t tag, dval_t val)
00143 {
00144     if (target)
00145         target->update(target, tag, val);
00146 }
00147 
00151 INLINE void dnotify_targets(DNotifier *target, dtag_t tag, dval_t val)
00152 {
00153     DFilter *f;
00154     if (!ISLISTEMPTY(&target->targets))
00155         FOREACHNODE(f, &target->targets)
00156             f->update(f, tag, val);
00157 }
00158 
00159 
00166 #define DCONNECT(src, tgt, map, opt) \
00167     do { \
00168         static DFilter _filter_; /* Declare a filter */ \
00169         filter_init(&(_filter_), map, opt, src, tgt); /* Init it. */ \
00170     } while (0)
00171 
00172 
00173 #endif /* DT_DNOTIFIER_H */