event.h

Go to the documentation of this file.
00001 
00044 #ifndef KERN_EVENT_H
00045 #define KERN_EVENT_H
00046 
00047 #include <cfg/compiler.h>
00048 #include <appconfig.h>
00049 
00050 #if CONFIG_KERNEL
00051     #include <config_kern.h>
00052     #if defined(CONFIG_KERN_SIGNALS) && CONFIG_KERN_SIGNALS
00053         #include <kern/signal.h>
00054     #endif
00055 
00056     /* Forward decl */
00057     struct Process;
00058 #endif
00059 
00060 
00062 typedef void (*Hook)(void *);
00063 
00064 typedef struct Event
00065 {
00066     void (*action)(struct Event *);
00067     union
00068     {
00069 #if defined(CONFIG_KERN_SIGNALS) && CONFIG_KERN_SIGNALS
00070         struct
00071         {
00072             struct Process *sig_proc;  /* Process to be signalled */
00073             sigbit_t        sig_bit;   /* Signal to send */
00074         } Sig;
00075 #endif
00076         struct
00077         {
00078             Hook  func;         /* Pointer to softint hook */
00079             void *user_data;    /* Data to be passed back to user hook */
00080         } Int;
00081     } Ev;
00082 } Event;
00083 
00084 void event_hook_ignore(Event *event);
00085 void event_hook_signal(Event *event);
00086 void event_hook_softint(Event *event);
00087 
00089 #define event_initNone(e) \
00090     ((e)->action = event_hook_ignore)
00091 
00093 INLINE Event event_createNone(void);
00094 INLINE Event event_createNone(void)
00095 {
00096     Event e;
00097     e.action = event_hook_ignore;
00098     return e;
00099 }
00100 
00102 #define event_initSoftInt(e,f,u) \
00103     ((e)->action = event_hook_softint,(e)->Ev.Int.func = (f), (e)->Ev.Int.user_data = (u))
00104 
00106 INLINE Event event_createSoftInt(Hook func, void *user_data)
00107 {
00108     Event e;
00109     e.action = event_hook_softint;
00110     e.Ev.Int.func = func;
00111     e.Ev.Int.user_data = user_data;
00112     return e;
00113 }
00114 
00115 
00116 #if defined(CONFIG_KERN_SIGNALS) && CONFIG_KERN_SIGNALS
00117 
00119 #define event_initSignal(e,p,s) \
00120     ((e)->action = event_hook_signal,(e)->Ev.Sig.sig_proc = (p), (e)->Ev.Sig.sig_bit = (s))
00121 
00123 INLINE Event event_createSignal(struct Process *proc, sigbit_t bit)
00124 {
00125     Event e;
00126     e.action = event_hook_signal;
00127     e.Ev.Sig.sig_proc = proc;
00128     e.Ev.Sig.sig_bit = bit;
00129     return e;
00130 }
00131 
00132 #endif
00133 
00135 INLINE void event_do(struct Event *e)
00136 {
00137     e->action(e);
00138 }
00139 
00140 #endif /* KERN_EVENT_H */