Remove obsolete names.
[bertos.git] / kern / event.h
1 /*!
2  * \file
3  * <!--
4  * Copyright 2003,2004 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 devlib/README for information.
7  * -->
8  *
9  * \brief Events handling
10  *
11  * This module implements a common system for executing
12  * a user defined action calling a hook function.
13  *
14  * \version $Id$
15  *
16  * \author Bernardo Innocenti <bernie@develer.com>
17  */
18
19 /*#*
20  *#* $Log$
21  *#* Revision 1.9  2005/01/24 04:19:55  bernie
22  *#* Remove obsolete names.
23  *#*
24  *#* Revision 1.8  2005/01/24 04:19:05  bernie
25  *#* Function pointer based event dispatching.
26  *#*
27  *#* Revision 1.7  2004/08/25 14:12:09  rasky
28  *#* Aggiornato il comment block dei log RCS
29  *#*
30  *#* Revision 1.6  2004/08/14 19:37:57  rasky
31  *#* Merge da SC: macros.h, pool.h, BIT_CHANGE, nome dei processi, etc.
32  *#*
33  *#* Revision 1.5  2004/07/30 14:30:27  rasky
34  *#* Resa la sig_signal interrupt safe (con il nuovo scheduler IRQ-safe)
35  *#* Rimossa event_doIntr (ora inutile) e semplificata la logica delle macro con funzioni inline
36  *#*
37  *#* Revision 1.4  2004/06/07 15:58:00  aleph
38  *#* Add function prototypes
39  *#*
40  *#* Revision 1.3  2004/06/06 18:25:44  bernie
41  *#* Rename event macros to look like regular functions.
42  *#*
43  *#* Revision 1.2  2004/06/03 11:27:09  bernie
44  *#* Add dual-license information.
45  *#*
46  *#* Revision 1.1  2004/05/23 17:27:00  bernie
47  *#* Import kern/ subdirectory.
48  *#*
49  *#*/
50 #ifndef KERN_EVENT_H
51 #define KERN_EVENT_H
52
53 #include <config.h>
54
55 #if CONFIG_KERNEL
56         #include "config_kern.h"
57         #if defined(CONFIG_KERN_SIGNALS) && CONFIG_KERN_SIGNALS
58                 #include "signal.h"
59         #endif
60 #endif
61
62
63 /* Forward decl */
64 struct Process;
65
66 //! User defined callback type
67 typedef void (*Hook)(void *);
68
69 typedef struct Event
70 {
71         void (*action)(struct Event *);
72         union
73         {
74 #if defined(CONFIG_KERN_SIGNALS) && CONFIG_KERN_SIGNALS
75                 struct
76                 {
77                         struct Process *sig_proc;  /* Process to be signalled */
78                         sig_t           sig_bit;   /* Signal to send */
79                 } Sig;
80 #endif
81                 struct
82                 {
83                         Hook  func;         /* Pointer to softint hook */
84                         void *user_data;    /* Data to be passed back to user hook */
85                 } Int;
86         } Ev;
87 } Event;
88
89 void event_hook_ignore(Event *event);
90 void event_hook_signal(Event *event);
91 void event_hook_softint(Event *event);
92
93 /*! Initialize the event \a e as a no-op */
94 #define event_initNone(e) \
95         ((e)->action = event_hook_ignore)
96
97 /*! Same as event_initNone(), but returns the initialized event */
98 INLINE Event event_createNone(void);
99 INLINE Event event_createNone(void)
100 {
101         Event e;
102         e.action = event_hook_ignore;
103         return e;
104 }
105
106 /*! Initialize the event \a e with a software interrupt (call function \a f, with parameter \a u) */
107 #define event_initSoftInt(e,f,u) \
108         ((e)->action = event_hook_softint,(e)->Ev.Int.func = (f), (e)->Ev.Int.user_data = (u))
109
110 /*! Same as event_initSoftInt(), but returns the initialized event */
111 INLINE Event event_createSoftInt(Hook func, void* user_data)
112 {
113         Event e;
114         e.action = event_hook_softint;
115         e.Ev.Int.func = func;
116         e.Ev.Int.user_data = user_data;
117         return e;
118 }
119
120
121 #if defined(CONFIG_KERN_SIGNALS) && CONFIG_KERN_SIGNALS
122
123 /*! Initialize the event \a e with a signal (send signal \a s to process \a p) */
124 #define event_initSignal(e,p,s) \
125         ((e)->action = event_hook_signal,(e)->Ev.Sig.sig_proc = (p), (e)->Ev.Sig.sig_bit = (s))
126
127 /*! Same as event_initSignal(), but returns the initialized event */
128 INLINE Event event_createSignal(struct Process* proc, sig_t bit)
129 {
130         Event e;
131         e.action = event_hook_signal;
132         e.Ev.Sig.sig_proc = proc;
133         e.Ev.Sig.sig_bit = bit;
134         return e;
135 }
136
137 #endif
138
139 /*! Trigger an event */
140 INLINE void event_do(struct Event* e)
141 {
142         e->action(e);
143 }
144
145 #endif /* KERN_EVENT_H */