1 /*
2 * Copyright (c) 2013 Hugh Bailey <obs.jim@gmail.com>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17 #pragma once
18
19 #include "../util/c99defs.h"
20
21 #include "calldata.h"
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26
27 /*
28 * Signal handler
29 *
30 * This is used to create a signal handler which can broadcast events
31 * to one or more callbacks connected to a signal.
32 */
33
34 struct signal_handler;
35 typedef struct signal_handler signal_handler_t;
36 typedef void (*global_signal_callback_t)(void *, const char *, calldata_t *);
37 typedef void (*signal_callback_t)(void *, calldata_t *);
38
39 EXPORT signal_handler_t *signal_handler_create(void);
40 EXPORT void signal_handler_destroy(signal_handler_t *handler);
41
42 EXPORT bool signal_handler_add(signal_handler_t *handler,
43 const char *signal_decl);
44
signal_handler_add_array(signal_handler_t * handler,const char ** signal_decls)45 static inline bool signal_handler_add_array(signal_handler_t *handler,
46 const char **signal_decls)
47 {
48 bool success = true;
49 if (!signal_decls)
50 return false;
51
52 while (*signal_decls)
53 if (!signal_handler_add(handler, *(signal_decls++)))
54 success = false;
55
56 return success;
57 }
58
59 EXPORT void signal_handler_connect(signal_handler_t *handler,
60 const char *signal,
61 signal_callback_t callback, void *data);
62 EXPORT void signal_handler_connect_ref(signal_handler_t *handler,
63 const char *signal,
64 signal_callback_t callback, void *data);
65 EXPORT void signal_handler_disconnect(signal_handler_t *handler,
66 const char *signal,
67 signal_callback_t callback, void *data);
68
69 EXPORT void signal_handler_connect_global(signal_handler_t *handler,
70 global_signal_callback_t callback,
71 void *data);
72 EXPORT void signal_handler_disconnect_global(signal_handler_t *handler,
73 global_signal_callback_t callback,
74 void *data);
75
76 EXPORT void signal_handler_remove_current(void);
77
78 EXPORT void signal_handler_signal(signal_handler_t *handler, const char *signal,
79 calldata_t *params);
80
81 #ifdef __cplusplus
82 }
83 #endif
84