dnotifier.h
Go to the documentation of this file.00001
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
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
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_; \
00169 filter_init(&(_filter_), map, opt, src, tgt); \
00170 } while (0)
00171
00172
00173 #endif