dbfb2588bd629d51e4af8e87bb1bcab56c57cbe5
[oweals/gnunet.git] / src / include / gnunet_service_lib.h
1 /*
2      This file is part of GNUnet.
3      (C) 2009 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 2, 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  */
26
27 #ifndef GNUNET_SERVICE_LIB_H
28 #define GNUNET_SERVICE_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 #include "gnunet_configuration_lib.h"
39 #include "gnunet_server_lib.h"
40
41 /**
42  * Function called by the service's run
43  * method to run service-specific setup code.
44  *
45  * @param cls closure
46  * @param sched scheduler to use
47  * @param server the initialized server
48  * @param cfg configuration to use
49  */
50 typedef void (*GNUNET_SERVICE_Main) (void *cls,
51                                      struct GNUNET_SCHEDULER_Handle * sched,
52                                      struct GNUNET_SERVER_Handle * server,
53                                      struct GNUNET_CONFIGURATION_Handle *
54                                      cfg);
55
56
57 /**
58  * Function called when the service shuts
59  * down to run service-specific teardown code.
60  *
61  * @param cls closure
62  * @param cfg configuration to use
63  */
64 typedef void (*GNUNET_SERVICE_Term) (void *cls,
65                                      struct GNUNET_CONFIGURATION_Handle *
66                                      cfg);
67
68
69 /**
70  * Run a standard GNUnet service startup sequence (initialize loggers
71  * and configuration, parse options).
72  *
73  * @param argc number of command line arguments
74  * @param argv command line arguments
75  * @param serviceName our service name
76  * @param task main task of the service
77  * @param task_cls closure for task
78  * @param term termination task of the service
79  * @param term_cls closure for term
80  * @return GNUNET_SYSERR on error, GNUNET_OK
81  *         if we shutdown nicely
82  */
83 int GNUNET_SERVICE_run (int argc,
84                         char *const *argv,
85                         const char *serviceName,
86                         GNUNET_SERVICE_Main task,
87                         void *task_cls,
88                         GNUNET_SERVICE_Term term, void *term_cls);
89
90
91 struct GNUNET_SERVICE_Context;
92
93 /**
94  * Run a service startup sequence within an existing
95  * initialized system.
96  *
97  * @param serviceName our service name
98  * @param sched scheduler to use
99  * @param cfg configuration to use
100  * @return NULL on error, service handle
101  */
102 struct GNUNET_SERVICE_Context *GNUNET_SERVICE_start (const char *serviceName,
103                                                      struct
104                                                      GNUNET_SCHEDULER_Handle
105                                                      *sched,
106                                                      struct
107                                                      GNUNET_CONFIGURATION_Handle
108                                                      *cfg);
109
110
111 /**
112  * Obtain the server used by a service.  Note that the server must NOT
113  * be destroyed by the caller.
114  *
115  * @param ctx the service context returned from the start function
116  * @return handle to the server for this service, NULL if there is none
117  */
118 struct GNUNET_SERVER_Handle *GNUNET_SERVICE_get_server (struct
119                                                         GNUNET_SERVICE_Context
120                                                         *ctx);
121
122
123 /**
124  * Stop a service that was started with "GNUNET_SERVICE_start".
125  *
126  * @param ctx the service context returned from the start function
127  */
128 void GNUNET_SERVICE_stop (struct GNUNET_SERVICE_Context *ctx);
129
130
131 #if 0                           /* keep Emacsens' auto-indent happy */
132 {
133 #endif
134 #ifdef __cplusplus
135 }
136 #endif
137
138 /* ifndef GNUNET_SERVICE_LIB_H */
139 #endif
140 /* end of gnunet_service_lib.h */