2 This file is part of GNUnet.
3 (C) 2009 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 2, 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
27 #ifndef GNUNET_SERVICE_LIB_H
28 #define GNUNET_SERVICE_LIB_H
33 #if 0 /* keep Emacsens' auto-indent happy */
38 #include "gnunet_configuration_lib.h"
39 #include "gnunet_server_lib.h"
43 * Get the list of addresses that a server for the given service
46 * @param serviceName name of the service
47 * @param cfg configuration (which specifies the addresses)
48 * @param addrs set (call by reference) to an array of pointers to the
49 * addresses the server should bind to and listen on; the
50 * array will be NULL-terminated (on success)
51 * @param addr_lens set (call by reference) to an array of the lengths
52 * of the respective 'struct sockaddr' struct in the 'addrs'
54 * @return number of addresses found on success,
55 * GNUNET_SYSERR if the configuration
56 * did not specify reasonable finding information or
57 * if it specified a hostname that could not be resolved;
58 * GNUNET_NO if the number of addresses configured is
59 * zero (in this case, '*addrs' and '*addr_lens' will be
63 GNUNET_SERVICE_get_server_addresses (const char *serviceName,
64 const struct GNUNET_CONFIGURATION_Handle *cfg,
65 struct sockaddr ***addrs,
66 socklen_t **addr_lens);
70 * Function called by the service's run
71 * method to run service-specific setup code.
74 * @param sched scheduler to use
75 * @param server the initialized server
76 * @param cfg configuration to use
78 typedef void (*GNUNET_SERVICE_Main) (void *cls,
79 struct GNUNET_SCHEDULER_Handle * sched,
80 struct GNUNET_SERVER_Handle * server,
81 const struct GNUNET_CONFIGURATION_Handle *
86 * Options for the service (bitmask).
88 enum GNUNET_SERVICE_Options
93 GNUNET_SERVICE_OPTION_NONE = 0,
96 * Do not trigger server shutdown on signals, allow for the user
97 * to terminate the server explicitly when needed.
99 GNUNET_SERVICE_OPTION_MANUAL_SHUTDOWN = 1
104 * Run a standard GNUnet service startup sequence (initialize loggers
105 * and configuration, parse options).
107 * @param argc number of command line arguments
108 * @param argv command line arguments
109 * @param serviceName our service name
110 * @param opt service options
111 * @param task main task of the service
112 * @param task_cls closure for task
113 * @return GNUNET_SYSERR on error, GNUNET_OK
114 * if we shutdown nicely
116 int GNUNET_SERVICE_run (int argc,
118 const char *serviceName,
119 enum GNUNET_SERVICE_Options opt,
120 GNUNET_SERVICE_Main task,
124 struct GNUNET_SERVICE_Context;
127 * Run a service startup sequence within an existing
128 * initialized system.
130 * @param serviceName our service name
131 * @param sched scheduler to use
132 * @param cfg configuration to use
133 * @return NULL on error, service handle
135 struct GNUNET_SERVICE_Context *GNUNET_SERVICE_start (const char *serviceName,
137 GNUNET_SCHEDULER_Handle
140 GNUNET_CONFIGURATION_Handle
145 * Obtain the server used by a service. Note that the server must NOT
146 * be destroyed by the caller.
148 * @param ctx the service context returned from the start function
149 * @return handle to the server for this service, NULL if there is none
151 struct GNUNET_SERVER_Handle *GNUNET_SERVICE_get_server (struct
152 GNUNET_SERVICE_Context
157 * Stop a service that was started with "GNUNET_SERVICE_start".
159 * @param sctx the service context returned from the start function
161 void GNUNET_SERVICE_stop (struct GNUNET_SERVICE_Context *sctx);
164 #if 0 /* keep Emacsens' auto-indent happy */
171 /* ifndef GNUNET_SERVICE_LIB_H */
173 /* end of gnunet_service_lib.h */