2 This file is part of GNUnet.
3 (C) 2009-2013 Christian Grothoff (and other contributing authors)
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.
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.
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.
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
29 #ifndef GNUNET_SERVICE_LIB_H
30 #define GNUNET_SERVICE_LIB_H
35 #if 0 /* keep Emacsens' auto-indent happy */
40 #include "gnunet_configuration_lib.h"
41 #include "gnunet_server_lib.h"
45 * Get the list of addresses that a server for the given service
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
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
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);
72 * Function called by the service's run
73 * method to run service-specific setup code.
76 * @param server the initialized server
77 * @param cfg configuration to use
79 typedef void (*GNUNET_SERVICE_Main) (void *cls,
80 struct GNUNET_SERVER_Handle *server,
81 const struct GNUNET_CONFIGURATION_Handle *cfg);
85 * Options for the service (bitmask).
87 enum GNUNET_SERVICE_Options
92 GNUNET_SERVICE_OPTION_NONE = 0,
95 * Do not trigger server shutdown on signals, allow for the user
96 * to terminate the server explicitly when needed.
98 GNUNET_SERVICE_OPTION_MANUAL_SHUTDOWN = 1,
101 * Trigger a SOFT server shutdown on signals, allowing active
102 * non-monitor clients to complete their transactions.
104 GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN = 2
109 * Run a standard GNUnet service startup sequence (initialize loggers
110 * and configuration, parse options).
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
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,
130 * Opaque handle for a service.
132 struct GNUNET_SERVICE_Context;
136 * Run a service startup sequence within an existing
137 * initialized system.
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
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);
151 * Obtain the server used by a service. Note that the server must NOT
152 * be destroyed by the caller.
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
157 struct GNUNET_SERVER_Handle *
158 GNUNET_SERVICE_get_server (struct GNUNET_SERVICE_Context *ctx);
162 * Stop a service that was started with #GNUNET_SERVICE_start.
164 * @param sctx the service context returned from the start function
167 GNUNET_SERVICE_stop (struct GNUNET_SERVICE_Context *sctx);
170 #if 0 /* keep Emacsens' auto-indent happy */
178 /** @} */ /* end of group service */
181 /* ifndef GNUNET_SERVICE_LIB_H */
183 /* end of gnunet_service_lib.h */