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.1 2005/11/04 18:26:38 bernie
19 *#* Import into DevLib.
21 *#* Revision 1.4 2005/06/09 13:23:58 batt
22 *#* Add some comments.
24 *#* Revision 1.3 2005/06/08 17:32:33 batt
25 *#* Switch to new messaging system.
27 *#* Revision 1.2 2005/06/06 11:04:12 batt
28 *#* Add some comments.
30 *#* Revision 1.1 2005/05/26 08:32:53 batt
31 *#* Add new Develer widget system :)
34 #ifndef DT_DNOTIFIER_H
35 #define DT_DNOTIFIER_H
37 #include <cfg/debug.h>
39 #include <mware/list.h>
45 typedef void (* update_func_ptr)(struct DNotifier *, dtag_t, dval_t);
46 typedef void (* update_filter_ptr)(struct DFilter *, dtag_t, dval_t);
49 * Base object for receive and forward messages.
50 * It contains an update function used to update itslef and a list to
51 * notify other DNotifer eventually connected.
53 typedef struct DNotifier
55 //! Receive new attributes from other notifiers.
56 update_func_ptr update;
58 //! List of target notifiers to set new attributes to.
64 * Used to translate src message to dst message.
66 typedef struct DFilterMap
74 * A filter is an interface between two notifier.
75 * It can translate messages between them through a map (if it is not null).
77 typedef struct DFilter
79 //! Allow creating a list of dfilter objects.
82 //! Target of the filter
85 //! Update function called by the source dnotifier
86 update_filter_ptr update;
88 //!Map for translating messages for target
89 const DFilterMap *map;
91 //!Used in debug to prevent inserting this filter in more than one list
95 //! Type for filter-mask checking
96 typedef uint16_t dfilter_mask_t;
99 void filter_init(DFilter *f, const DFilterMap *map, bool masked, DNotifier *source, DNotifier *target);
101 //! Filter update function without masking capabilities.
102 void filter_update(DFilter *f, dtag_t tag, dval_t val);
104 //! Filter update function with masking capabilities.
105 void filter_mask_update(DFilter *f, dtag_t tag, dval_t val);
108 void notifier_init(DNotifier *n);
112 * Macro to notify the target object.
114 INLINE void dnotify(DNotifier *target, dtag_t tag, dval_t val)
117 target->update(target, tag, val);
121 * Macro to notify all the targets of \a target object.
123 INLINE void dnotify_targets(DNotifier *target, dtag_t tag, dval_t val)
126 if (!ISLISTEMPTY(&target->targets))
127 FOREACHNODE(f, &target->targets)
128 f->update(f, tag, val);
133 * Macro that connect \a src notifier to \a tgt using \a map and passing \a opt for filtering option.
134 * It declares a static filter to achieve connection and messages translation.
135 * \note Due its static filter declaration, DCONNECT MUST NOT be used inside loops or in functions called multiple times.
136 * Failing to do so will lead to unpredictable connections between notifiers.
138 #define DCONNECT(src, tgt, map, opt) \
140 static DFilter _filter_; /* Declare a filter */ \
141 filter_init(&(_filter_), map, opt, src, tgt); /* Init it. */ \
145 #endif /* DT_DNOTIFIER_H */