4 * Copyright 2003,2004 Develer S.r.l. (http://www.develer.com/)
5 * Copyright 1999,2001,2003 Bernardo Innocenti <bernie@develer.com>
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.1 2004/05/23 17:27:00 bernie
22 * Import kern/ subdirectory.
31 #include "config_kern.h"
32 #if defined(CONFIG_KERN_SIGNALS) && CONFIG_KERN_SIGNALS
45 EVENT_IGNORE, /*!< No-op event */
46 #if defined(CONFIG_KERN_SIGNALS) && CONFIG_KERN_SIGNALS
47 EVENT_SIGNAL, /*!< Send a signal to a process */
49 EVENT_SOFTINT /*!< Trigger a software interrupt (i.e.: call user hook) */
52 //! User defined callback type
53 typedef void (*Hook)(void *);
57 enum EventAction action;
60 #if defined(CONFIG_KERN_SIGNALS) && CONFIG_KERN_SIGNALS
63 struct Process *sig_proc; /* Process to be signalled */
64 sig_t sig_bit; /* Signal to send */
69 Hook func; /* Pointer to softint hook */
70 void *user_data; /* Data to be passed back to user hook */
76 /*! Initialize an event with a softint */
77 #define INITEVENT_INT(e,f,u) \
78 ((e)->action = EVENT_SOFTINT,(e)->Ev.Int.func = (f), (e)->Ev.Int.user_data = (u))
81 #if defined(CONFIG_KERN_SIGNALS) && CONFIG_KERN_SIGNALS
83 /*! Initialize an event with a signal */
84 #define INITEVENT_SIG(e,p,s) \
85 ((e)->action = EVENT_SIGNAL,(e)->Ev.Sig.sig_proc = (p), (e)->Ev.Sig.sig_bit = (s))
87 /*! Trigger an event */
90 if ((e)->action == EVENT_SIGNAL) \
91 sig_signal((e)->Ev.Sig.sig_proc, (e)->Sig.sig_bit); \
92 else if ((e)->action == EVENT_SOFTINT) \
93 (e)->Ev.Int.func((e)->Ev.Int.user_data); \
96 /*! Trigger an event (to be used inside interrupts) */
97 #define DOEVENT_INTR(e) \
99 if ((e)->action == EVENT_SIGNAL) \
100 _sig_signal((e)->Ev.Sig.sig_proc, (e)->Ev.Sig.sig_bit); \
101 else if ((e)->action == EVENT_SOFTINT) \
102 (e)->Ev.Int.func((e)->Ev.Int.user_data); \
105 #else /* !CONFIG_KERN_SIGNALS */
107 /*! Trigger an event */
110 if ((e)->action == EVENT_SOFTINT) \
111 (e)->Ev.Int.func((e)->Ev.Int.user_data); \
114 /*! Trigger an event (to be used inside interrupts) */
115 #define DOEVENT_INTR(e) \
117 if ((e)->action == EVENT_SOFTINT) \
118 (e)->Ev.Int.func((e)->Ev.Int.user_data); \
123 #endif /* KERN_EVENT_H */