4 * Copyright 2005 Develer S.r.l. (http://www.develer.com/)
9 * \brief Notifier obj (implementation).
12 * \author Bernardo Innocenti <bernie@develer.com>
13 * \author Francesco Sacchi <batt@develer.com>
18 *#* Revision 1.1 2005/11/04 18:26:38 bernie
19 *#* Import into DevLib.
21 *#* Revision 1.5 2005/06/09 13:49:22 batt
22 *#* Reformat; correct some comments.
24 *#* Revision 1.4 2005/06/09 13:23:58 batt
25 *#* Add some comments.
27 *#* Revision 1.3 2005/06/08 17:32:33 batt
28 *#* Switch to new messaging system.
30 *#* Revision 1.2 2005/06/06 11:04:12 batt
31 *#* Add some comments.
33 *#* Revision 1.1 2005/05/26 08:32:53 batt
34 *#* Add new Develer widget system :)
38 #include <cfg/debug.h>
41 #include <dt/dnotifier.h>
42 #include <mware/list.h>
45 * Default update used to notify target: notify all trasparently all
46 * targets in the list.
48 static void notifier_update(DNotifier *n, dtag_t tag, dval_t val)
50 dnotify_targets(n, tag, val);
56 void notifier_init(DNotifier *n)
59 n->update = notifier_update;
60 LIST_INIT(&n->targets);
64 * Search in the map a tag and a val corresponding to the ones supplied.
65 * If a match is found change them to the corresponding ones in the map.
66 * If map is NULL the filter is trasparent and all messages sent to filter
67 * will be forwarded to its target.
69 void filter_update(DFilter *f, dtag_t tag, dval_t val)
72 const DFilterMap *map = f->map;
76 while (map->src.tag != TAG_END)
78 if ((map->src.tag == tag) && (map->src.val == val))
84 /* TAG_ANY matches anything */
85 if (map->src.tag == TAG_ANY)
90 if (map->src.tag != TAG_END)
91 dnotify(f->target, tag, val);
94 dnotify(f->target, tag, val);
99 * Search in the table a tag corresponding to the one supplied and a val
100 * that has at least the mask map supplied bits to one.
101 * If a match is found change them to the corresponding ones in the map.
102 * If map is NULL the filter is trasparent and all messages sent to filter
103 * will be forwarded to its target.
105 void filter_mask_update(DFilter *f, dtag_t tag, dval_t val)
108 const DFilterMap *map = f->map;
113 while (map->src.tag != TAG_END)
115 mask = (dfilter_mask_t) map->src.val;
116 if ((map->src.tag == tag) && ((mask & (dfilter_mask_t)val) == mask))
122 /* TAG_ANY matches anything */
123 if (map->src.tag == TAG_ANY)
129 if (map->src.tag != TAG_END)
130 dnotify(f->target, tag, val);
133 dnotify(f->target, tag, val);
137 #define FILTER_MAGIC_ACTIVE 0xAA
140 * If \a masked is true, all the fields value in \a map must be interpreted as a mask of bits.
142 void filter_init(DFilter *f, const DFilterMap *map, bool masked, DNotifier *source, DNotifier *target)
146 f->update = (update_filter_ptr)filter_mask_update;
148 f->update = (update_filter_ptr)filter_update;
150 /* set filter map and target */
154 /* these ensure that the filter is not inserted in more than one list */
155 ASSERT(f->magic != FILTER_MAGIC_ACTIVE);
156 DB(f->magic = FILTER_MAGIC_ACTIVE;)
158 /* Add the filter to source filter list */
159 ADDTAIL(&source->targets, &f->link);