glitch in the license text detected by hyazinthe, thank you!
[oweals/gnunet.git] / src / include / gnunet_signal_lib.h
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009 GNUnet e.V.
4
5      GNUnet is free software: you can redistribute it and/or modify it
6      under the terms of the GNU Affero General Public License as published
7      by the Free Software Foundation, either version 3 of the License,
8      or (at your option) any later version.
9
10      GNUnet is distributed in the hope that it will be useful, but
11      WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13      Affero General Public License for more details.
14 */
15
16 /**
17  * @author Christian Grothoff
18  *
19  * @file
20  * Functions related to signals
21  *
22  * @defgroup signal  Signal library
23  * Manage signal handlers.
24  * @{
25  */
26
27 #ifndef GNUNET_SIGNAL_LIB_H
28 #define GNUNET_SIGNAL_LIB_H
29
30 #ifdef __cplusplus
31 extern "C"
32 {
33 #if 0                           /* keep Emacsens' auto-indent happy */
34 }
35 #endif
36 #endif
37
38 /**
39  * Context created when a signal handler is installed;
40  * can be used to restore it to the previous state later.
41  */
42 struct GNUNET_SIGNAL_Context;
43
44
45 /**
46  * A signal handler.  Since different OSes have different signatures
47  * for their handlers, the API only gives the most restrictive
48  * signature -- no arguments, no return value.  Note that this will
49  * work even if the OS expects a function with arguments.  However,
50  * the implementation must guarantee that this handler is not called
51  * for signals other than the one that it has been registered for.
52  */
53 typedef void
54 (*GNUNET_SIGNAL_Handler) (void);
55
56
57 /**
58  * Install a signal handler that will be run if the
59  * given signal is received.
60  *
61  * @param signal the number of the signal
62  * @param handler the function to call
63  * @return context that can be used to restore, NULL on error
64  */
65 struct GNUNET_SIGNAL_Context *
66 GNUNET_SIGNAL_handler_install (int signal,
67                                GNUNET_SIGNAL_Handler handler);
68
69
70 /**
71  * Uninstall a previously installed signal hander.
72  *
73  * @param ctx context that was returned when the
74  *            signal handler was installed
75  */
76 void
77 GNUNET_SIGNAL_handler_uninstall (struct GNUNET_SIGNAL_Context *ctx);
78
79
80 /**
81  * Raise the given signal by calling the installed signal handlers.  This will
82  * not use the @em raise() system call but only calls the handlers registered
83  * through GNUNET_SIGNAL_handler_install().
84  *
85  * @param sig the signal to raise
86  */
87 void
88 GNUNET_SIGNAL_raise (const int sig);
89
90
91 #if 0                           /* keep Emacsens' auto-indent happy */
92 {
93 #endif
94 #ifdef __cplusplus
95 }
96 #endif
97
98 /* ifndef GNUNET_SIGNAL_LIB_H */
99 #endif
100
101 /** @} */  /* end of group */
102
103 /* end of gnunet_signal_lib.h */