4 * This file is part of BeRTOS.
6 * Bertos is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * As a special exception, you may use this file as part of a free software
21 * library without restriction. Specifically, if other files instantiate
22 * templates or use macros or inline functions from this file, or you compile
23 * this file and link it with other files to produce an executable, this
24 * file does not by itself cause the resulting executable to be covered by
25 * the GNU General Public License. This exception does not however
26 * invalidate any other reasons why the executable file might be covered by
27 * the GNU General Public License.
29 * Copyright 2005 Develer S.r.l. (http://www.develer.com/)
34 * \brief Notifier obj (implementation).
37 * \author Bernie Innocenti <bernie@codewiz.org>
38 * \author Francesco Sacchi <batt@develer.com>
41 #include <cfg/debug.h>
44 #include <dt/dnotifier.h>
45 #include <struct/list.h>
48 * Default update used to notify target: notify all trasparently all
49 * targets in the list.
51 static void notifier_update(DNotifier *n, dtag_t tag, dval_t val)
53 dnotify_targets(n, tag, val);
59 void notifier_init(DNotifier *n)
62 n->update = notifier_update;
63 LIST_INIT(&n->targets);
67 * Search in the map a tag and a val corresponding to the ones supplied.
68 * If a match is found change them to the corresponding ones in the map.
69 * If map is NULL the filter is trasparent and all messages sent to filter
70 * will be forwarded to its target.
72 void filter_update(DFilter *f, dtag_t tag, dval_t val)
75 const DFilterMap *map = f->map;
79 while (map->src.tag != TAG_END)
81 if ((map->src.tag == tag) && (map->src.val == val))
87 /* TAG_ANY matches anything */
88 if (map->src.tag == TAG_ANY)
93 if (map->src.tag != TAG_END)
94 dnotify(f->target, tag, val);
97 dnotify(f->target, tag, val);
102 * Search in the table a tag corresponding to the one supplied and a val
103 * that has at least the mask map supplied bits to one.
104 * If a match is found change them to the corresponding ones in the map.
105 * If map is NULL the filter is trasparent and all messages sent to filter
106 * will be forwarded to its target.
108 void filter_mask_update(DFilter *f, dtag_t tag, dval_t val)
111 const DFilterMap *map = f->map;
116 while (map->src.tag != TAG_END)
118 mask = (dfilter_mask_t) map->src.val;
119 if ((map->src.tag == tag) && ((mask & (dfilter_mask_t)val) == mask))
125 /* TAG_ANY matches anything */
126 if (map->src.tag == TAG_ANY)
132 if (map->src.tag != TAG_END)
133 dnotify(f->target, tag, val);
136 dnotify(f->target, tag, val);
140 #define FILTER_MAGIC_ACTIVE 0xAA
143 * If \a masked is true, all the fields value in \a map must be interpreted as a mask of bits.
145 void filter_init(DFilter *f, const DFilterMap *map, bool masked, DNotifier *source, DNotifier *target)
149 f->update = (update_filter_ptr)filter_mask_update;
151 f->update = (update_filter_ptr)filter_update;
153 /* set filter map and target */
157 /* these ensure that the filter is not inserted in more than one list */
158 ASSERT(f->magic != FILTER_MAGIC_ACTIVE);
159 DB(f->magic = FILTER_MAGIC_ACTIVE;)
161 /* Add the filter to source filter list */
162 ADDTAIL(&source->targets, &f->link);