4 * Copyright 2003, 2004, 2005 Develer S.r.l. (http://www.develer.com/)
5 * Copyright 1999, 2001, 2003 Bernardo Innocenti <bernie@develer.com>
6 * This file is part of DevLib - See README.devlib for information.
9 * \brief Events handling
11 * This module implements a common system for executing
12 * a user defined action calling a hook function.
16 * \author Bernardo Innocenti <bernie@develer.com>
21 *#* Revision 1.11 2005/04/11 19:10:28 bernie
22 *#* Include top-level headers from cfg/ subdir.
24 *#* Revision 1.10 2005/01/24 04:22:02 bernie
25 *#* Update copyright information.
27 *#* Revision 1.9 2005/01/24 04:19:55 bernie
28 *#* Remove obsolete names.
30 *#* Revision 1.8 2005/01/24 04:19:05 bernie
31 *#* Function pointer based event dispatching.
33 *#* Revision 1.7 2004/08/25 14:12:09 rasky
34 *#* Aggiornato il comment block dei log RCS
36 *#* Revision 1.6 2004/08/14 19:37:57 rasky
37 *#* Merge da SC: macros.h, pool.h, BIT_CHANGE, nome dei processi, etc.
39 *#* Revision 1.5 2004/07/30 14:30:27 rasky
40 *#* Resa la sig_signal interrupt safe (con il nuovo scheduler IRQ-safe)
41 *#* Rimossa event_doIntr (ora inutile) e semplificata la logica delle macro con funzioni inline
43 *#* Revision 1.4 2004/06/07 15:58:00 aleph
44 *#* Add function prototypes
46 *#* Revision 1.3 2004/06/06 18:25:44 bernie
47 *#* Rename event macros to look like regular functions.
49 *#* Revision 1.2 2004/06/03 11:27:09 bernie
50 *#* Add dual-license information.
52 *#* Revision 1.1 2004/05/23 17:27:00 bernie
53 *#* Import kern/ subdirectory.
59 #include <cfg/config.h>
62 #include <cfg/config_kern.h>
63 #if defined(CONFIG_KERN_SIGNALS) && CONFIG_KERN_SIGNALS
72 //! User defined callback type
73 typedef void (*Hook)(void *);
77 void (*action)(struct Event *);
80 #if defined(CONFIG_KERN_SIGNALS) && CONFIG_KERN_SIGNALS
83 struct Process *sig_proc; /* Process to be signalled */
84 sig_t sig_bit; /* Signal to send */
89 Hook func; /* Pointer to softint hook */
90 void *user_data; /* Data to be passed back to user hook */
95 void event_hook_ignore(Event *event);
96 void event_hook_signal(Event *event);
97 void event_hook_softint(Event *event);
99 /*! Initialize the event \a e as a no-op */
100 #define event_initNone(e) \
101 ((e)->action = event_hook_ignore)
103 /*! Same as event_initNone(), but returns the initialized event */
104 INLINE Event event_createNone(void);
105 INLINE Event event_createNone(void)
108 e.action = event_hook_ignore;
112 /*! Initialize the event \a e with a software interrupt (call function \a f, with parameter \a u) */
113 #define event_initSoftInt(e,f,u) \
114 ((e)->action = event_hook_softint,(e)->Ev.Int.func = (f), (e)->Ev.Int.user_data = (u))
116 /*! Same as event_initSoftInt(), but returns the initialized event */
117 INLINE Event event_createSoftInt(Hook func, void* user_data)
120 e.action = event_hook_softint;
121 e.Ev.Int.func = func;
122 e.Ev.Int.user_data = user_data;
127 #if defined(CONFIG_KERN_SIGNALS) && CONFIG_KERN_SIGNALS
129 /*! Initialize the event \a e with a signal (send signal \a s to process \a p) */
130 #define event_initSignal(e,p,s) \
131 ((e)->action = event_hook_signal,(e)->Ev.Sig.sig_proc = (p), (e)->Ev.Sig.sig_bit = (s))
133 /*! Same as event_initSignal(), but returns the initialized event */
134 INLINE Event event_createSignal(struct Process* proc, sig_t bit)
137 e.action = event_hook_signal;
138 e.Ev.Sig.sig_proc = proc;
139 e.Ev.Sig.sig_bit = bit;
145 /*! Trigger an event */
146 INLINE void event_do(struct Event* e)
151 #endif /* KERN_EVENT_H */