1 #ifndef __SIGNAL_H
2 #define __SIGNAL_H
3 
4 #define SIGNAL_PRIORITY_LOW    	100
5 #define SIGNAL_PRIORITY_DEFAULT	0
6 #define SIGNAL_PRIORITY_HIGH	-100
7 
8 #define SIGNAL_MAX_ARGUMENTS 6
9 typedef void (*SIGNAL_FUNC) (const void *, const void *,
10 			     const void *, const void *,
11 			     const void *, const void *);
12 
13 extern void *signal_user_data; /* use signal_get_user_data() macro to access */
14 
15 /* bind a signal */
16 void signal_add_full(const char *module, int priority,
17 		     const char *signal, SIGNAL_FUNC func, void *user_data);
18 void signal_add_full_id(const char *module, int priority,
19 			int signal, SIGNAL_FUNC func, void *user_data);
20 #define signal_add(signal, func) \
21 	signal_add_full(MODULE_NAME, SIGNAL_PRIORITY_DEFAULT, (signal), (SIGNAL_FUNC) (func), NULL)
22 #define signal_add_first(signal, func) \
23 	signal_add_full(MODULE_NAME, SIGNAL_PRIORITY_HIGH, (signal), (SIGNAL_FUNC) (func), NULL)
24 #define signal_add_last(signal, func) \
25 	signal_add_full(MODULE_NAME, SIGNAL_PRIORITY_LOW, (signal), (SIGNAL_FUNC) (func), NULL)
26 
27 #define signal_add_data(signal, func, data) \
28 	signal_add_full(MODULE_NAME, SIGNAL_PRIORITY_DEFAULT, (signal), (SIGNAL_FUNC) (func), data)
29 #define signal_add_first_data(signal, func, data) \
30 	signal_add_full(MODULE_NAME, SIGNAL_PRIORITY_HIGH, (signal), (SIGNAL_FUNC) (func), data)
31 #define signal_add_last_data(signal, func, data) \
32 	signal_add_full(MODULE_NAME, SIGNAL_PRIORITY_LOW, (signal), (SIGNAL_FUNC) (func), data)
33 
34 /* unbind signal */
35 void signal_remove_full(const char *signal, SIGNAL_FUNC func, void *user_data);
36 #define signal_remove(signal, func) \
37         signal_remove_full((signal), (SIGNAL_FUNC) (func), NULL)
38 #define signal_remove_data(signal, func, data) \
39         signal_remove_full((signal), (SIGNAL_FUNC) (func), data)
40 void signal_remove_id(int signal_id, SIGNAL_FUNC func, void *user_data);
41 
42 /* emit signal */
43 int signal_emit(const char *signal, int params, ...);
44 int signal_emit_id(int signal_id, int params, ...);
45 
46 /* continue currently emitted signal with different parameters */
47 void signal_continue(int params, ...);
48 
49 /* stop the current ongoing signal emission */
50 void signal_stop(void);
51 /* stop ongoing signal emission by signal name */
52 void signal_stop_by_name(const char *signal);
53 
54 /* return the name of the signal that is currently being emitted */
55 const char *signal_get_emitted(void);
56 /* return the ID of the signal that is currently being emitted */
57 int signal_get_emitted_id(void);
58 /* return TRUE if specified signal was stopped */
59 int signal_is_stopped(int signal_id);
60 /* return the user data of the signal function currently being emitted */
61 #define signal_get_user_data() signal_user_data
62 
63 /* remove all signals that belong to `module' */
64 void signals_remove_module(const char *module);
65 
66 /* signal name -> ID */
67 #define signal_get_uniq_id(signal) \
68         module_get_uniq_id_str("signals", signal)
69 /* signal ID -> name */
70 #define signal_get_id_str(signal_id) \
71 	module_find_id_str("signals", signal_id)
72 
73 void signals_init(void);
74 void signals_deinit(void);
75 
76 #endif
77