- fix compilation
[oweals/gnunet.git] / src / include / gnunet_service_lib.h
1 /*
2      This file is part of GNUnet.
3      (C) 2009-2013 Christian Grothoff (and other contributing authors)
4
5      GNUnet is free software; you can redistribute it and/or modify
6      it under the terms of the GNU General Public License as published
7      by the Free Software Foundation; either version 3, or (at your
8      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      General Public License for more details.
14
15      You should have received a copy of the GNU General Public License
16      along with GNUnet; see the file COPYING.  If not, write to the
17      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18      Boston, MA 02111-1307, USA.
19 */
20
21 /**
22  * @file include/gnunet_service_lib.h
23  * @brief functions related to starting services
24  * @author Christian Grothoff
25  * @defgroup service generic functions for implementing service processes
26  * @{
27  */
28
29 #ifndef GNUNET_SERVICE_LIB_H
30 #define GNUNET_SERVICE_LIB_H
31
32 #ifdef __cplusplus
33 extern "C"
34 {
35 #if 0                           /* keep Emacsens' auto-indent happy */
36 }
37 #endif
38 #endif
39
40 #include "gnunet_configuration_lib.h"
41 #include "gnunet_server_lib.h"
42
43
44 /**
45  * Get the list of addresses that a server for the given service
46  * should bind to.
47  *
48  * @param service_name name of the service
49  * @param cfg configuration (which specifies the addresses)
50  * @param addrs set (call by reference) to an array of pointers to the
51  *              addresses the server should bind to and listen on; the
52  *              array will be NULL-terminated (on success)
53  * @param addr_lens set (call by reference) to an array of the lengths
54  *              of the respective 'struct sockaddr' struct in the @a addrs
55  *              array (on success)
56  * @return number of addresses found on success,
57  *              #GNUNET_SYSERR if the configuration
58  *              did not specify reasonable finding information or
59  *              if it specified a hostname that could not be resolved;
60  *              #GNUNET_NO if the number of addresses configured is
61  *              zero (in this case, '* @a addrs' and '* @a addr_lens' will be
62  *              set to NULL).
63  */
64 int
65 GNUNET_SERVICE_get_server_addresses (const char *service_name,
66                                      const struct GNUNET_CONFIGURATION_Handle
67                                      *cfg, struct sockaddr ***addrs,
68                                      socklen_t **addr_lens);
69
70
71 /**
72  * Function called by the service's run
73  * method to run service-specific setup code.
74  *
75  * @param cls closure
76  * @param server the initialized server
77  * @param cfg configuration to use
78  */
79 typedef void (*GNUNET_SERVICE_Main) (void *cls,
80                                      struct GNUNET_SERVER_Handle *server,
81                                      const struct GNUNET_CONFIGURATION_Handle *cfg);
82
83
84 /**
85  * Options for the service (bitmask).
86  */
87 enum GNUNET_SERVICE_Options
88 {
89   /**
90    * Use defaults.
91    */
92   GNUNET_SERVICE_OPTION_NONE = 0,
93
94   /**
95    * Do not trigger server shutdown on signals, allow for the user
96    * to terminate the server explicitly when needed.
97    */
98   GNUNET_SERVICE_OPTION_MANUAL_SHUTDOWN = 1,
99
100   /**
101    * Trigger a SOFT server shutdown on signals, allowing active
102    * non-monitor clients to complete their transactions.
103    */
104   GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN = 2
105 };
106
107
108 /**
109  * Run a standard GNUnet service startup sequence (initialize loggers
110  * and configuration, parse options).
111  *
112  * @param argc number of command line arguments in @a argv
113  * @param argv command line arguments
114  * @param service_name our service name
115  * @param options service options
116  * @param task main task of the service
117  * @param task_cls closure for @a task
118  * @return #GNUNET_SYSERR on error, #GNUNET_OK
119  *         if we shutdown nicely
120  */
121 int
122 GNUNET_SERVICE_run (int argc, char *const *argv,
123                     const char *service_name,
124                     enum GNUNET_SERVICE_Options options,
125                     GNUNET_SERVICE_Main task,
126                     void *task_cls);
127
128
129 /**
130  * Opaque handle for a service.
131  */
132 struct GNUNET_SERVICE_Context;
133
134
135 /**
136  * Run a service startup sequence within an existing
137  * initialized system.
138  *
139  * @param service_name our service name
140  * @param cfg configuration to use
141  * @param options service options
142  * @return NULL on error, service handle
143  */
144 struct GNUNET_SERVICE_Context *
145 GNUNET_SERVICE_start (const char *service_name,
146                       const struct GNUNET_CONFIGURATION_Handle *cfg,
147                       enum GNUNET_SERVICE_Options options);
148
149
150 /**
151  * Obtain the server used by a service.  Note that the server must NOT
152  * be destroyed by the caller.
153  *
154  * @param ctx the service context returned from the start function
155  * @return handle to the server for this service, NULL if there is none
156  */
157 struct GNUNET_SERVER_Handle *
158 GNUNET_SERVICE_get_server (struct GNUNET_SERVICE_Context *ctx);
159
160
161 /**
162  * Stop a service that was started with #GNUNET_SERVICE_start.
163  *
164  * @param sctx the service context returned from the start function
165  */
166 void
167 GNUNET_SERVICE_stop (struct GNUNET_SERVICE_Context *sctx);
168
169
170 #if 0                           /* keep Emacsens' auto-indent happy */
171 {
172 #endif
173 #ifdef __cplusplus
174 }
175 #endif
176
177
178 /** @} */ /* end of group service */
179
180
181 /* ifndef GNUNET_SERVICE_LIB_H */
182 #endif
183 /* end of gnunet_service_lib.h */