4 * Copyright 2005 Develer S.r.l. (http://www.develer.com/)
9 * \brief Notifier obj (interface).
12 * \author Bernardo Innocenti <bernie@develer.com>
13 * \author Francesco Sacchi <batt@develer.com>
18 *#* Revision 1.2 2006/07/19 12:56:26 bernie
19 *#* Convert to new Doxygen style.
21 *#* Revision 1.1 2005/11/04 18:26:38 bernie
22 *#* Import into DevLib.
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 :)
37 #ifndef DT_DNOTIFIER_H
38 #define DT_DNOTIFIER_H
40 #include <cfg/debug.h>
42 #include <mware/list.h>
48 typedef void (* update_func_ptr)(struct DNotifier *, dtag_t, dval_t);
49 typedef void (* update_filter_ptr)(struct DFilter *, dtag_t, dval_t);
52 * Base object for receive and forward messages.
53 * It contains an update function used to update itslef and a list to
54 * notify other DNotifer eventually connected.
56 typedef struct DNotifier
58 /// Receive new attributes from other notifiers.
59 update_func_ptr update;
61 /// List of target notifiers to set new attributes to.
67 * Used to translate src message to dst message.
69 typedef struct DFilterMap
77 * A filter is an interface between two notifier.
78 * It can translate messages between them through a map (if it is not null).
80 typedef struct DFilter
82 /// Allow creating a list of dfilter objects.
85 /// Target of the filter
88 /// Update function called by the source dnotifier
89 update_filter_ptr update;
91 ///Map for translating messages for target
92 const DFilterMap *map;
94 ///Used in debug to prevent inserting this filter in more than one list
98 /// Type for filter-mask checking
99 typedef uint16_t dfilter_mask_t;
102 void filter_init(DFilter *f, const DFilterMap *map, bool masked, DNotifier *source, DNotifier *target);
104 /// Filter update function without masking capabilities.
105 void filter_update(DFilter *f, dtag_t tag, dval_t val);
107 /// Filter update function with masking capabilities.
108 void filter_mask_update(DFilter *f, dtag_t tag, dval_t val);
111 void notifier_init(DNotifier *n);
115 * Macro to notify the target object.
117 INLINE void dnotify(DNotifier *target, dtag_t tag, dval_t val)
120 target->update(target, tag, val);
124 * Macro to notify all the targets of \a target object.
126 INLINE void dnotify_targets(DNotifier *target, dtag_t tag, dval_t val)
129 if (!ISLISTEMPTY(&target->targets))
130 FOREACHNODE(f, &target->targets)
131 f->update(f, tag, val);
136 * Macro that connect \a src notifier to \a tgt using \a map and passing \a opt for filtering option.
137 * It declares a static filter to achieve connection and messages translation.
138 * \note Due its static filter declaration, DCONNECT MUST NOT be used inside loops or in functions called multiple times.
139 * Failing to do so will lead to unpredictable connections between notifiers.
141 #define DCONNECT(src, tgt, map, opt) \
143 static DFilter _filter_; /* Declare a filter */ \
144 filter_init(&(_filter_), map, opt, src, tgt); /* Init it. */ \
148 #endif /* DT_DNOTIFIER_H */