diff options
Diffstat (limited to 'src/include/gnunet_service_lib.h')
-rw-r--r-- | src/include/gnunet_service_lib.h | 103 |
1 files changed, 83 insertions, 20 deletions
diff --git a/src/include/gnunet_service_lib.h b/src/include/gnunet_service_lib.h index 3ebfae581..6109d6e5e 100644 --- a/src/include/gnunet_service_lib.h +++ b/src/include/gnunet_service_lib.h | |||
@@ -19,7 +19,7 @@ | |||
19 | */ | 19 | */ |
20 | 20 | ||
21 | 21 | ||
22 | #if !defined (__GNUNET_UTIL_LIB_H_INSIDE__) | 22 | #if ! defined (__GNUNET_UTIL_LIB_H_INSIDE__) |
23 | #error "Only <gnunet_util_lib.h> can be included directly." | 23 | #error "Only <gnunet_util_lib.h> can be included directly." |
24 | #endif | 24 | #endif |
25 | 25 | ||
@@ -203,7 +203,6 @@ GNUNET_SERVICE_start (const char *service_name, | |||
203 | void | 203 | void |
204 | GNUNET_SERVICE_stop (struct GNUNET_SERVICE_Handle *srv); | 204 | GNUNET_SERVICE_stop (struct GNUNET_SERVICE_Handle *srv); |
205 | 205 | ||
206 | |||
207 | /** | 206 | /** |
208 | * Creates the "main" function for a GNUnet service. You | 207 | * Creates the "main" function for a GNUnet service. You |
209 | * should almost always use the #GNUNET_SERVICE_MAIN macro | 208 | * should almost always use the #GNUNET_SERVICE_MAIN macro |
@@ -258,6 +257,56 @@ GNUNET_SERVICE_run_ (int argc, | |||
258 | 257 | ||
259 | 258 | ||
260 | /** | 259 | /** |
260 | * Registers the GNUnet service to be scheduled as part of a monilithic | ||
261 | * libgnunet. | ||
262 | * You should almost always use the #GNUNET_SERVICE_MAIN macro | ||
263 | * instead of calling this function directly. | ||
264 | * | ||
265 | * The function will launch the service with the name @a service_name | ||
266 | * using the @a service_options to configure its shutdown | ||
267 | * behavior. Once the service is ready, the @a init_cb will be called | ||
268 | * for service-specific initialization. @a init_cb will be given the | ||
269 | * service handler which can be used to control the service's | ||
270 | * availability. When clients connect or disconnect, the respective | ||
271 | * @a connect_cb or @a disconnect_cb functions will be called. For | ||
272 | * messages received from the clients, the respective @a handlers will | ||
273 | * be invoked; for the closure of the handlers we use the return value | ||
274 | * from the @a connect_cb invocation of the respective client. | ||
275 | * | ||
276 | * Each handler MUST call #GNUNET_SERVICE_client_continue() after each | ||
277 | * message to receive further messages from this client. If | ||
278 | * #GNUNET_SERVICE_client_continue() is not called within a short | ||
279 | * time, a warning will be logged. If delays are expected, services | ||
280 | * should call #GNUNET_SERVICE_client_disable_continue_warning() to | ||
281 | * disable the warning. | ||
282 | * | ||
283 | * Clients sending invalid messages (based on @a handlers) will be | ||
284 | * dropped. Additionally, clients can be dropped at any time using | ||
285 | * #GNUNET_SERVICE_client_drop(). | ||
286 | * | ||
287 | * @param service_name name of the service to run | ||
288 | * @param options options controlling shutdown of the service | ||
289 | * @param service_init_cb function to call once the service is ready | ||
290 | * @param connect_cb function to call whenever a client connects | ||
291 | * @param disconnect_cb function to call whenever a client disconnects | ||
292 | * @param cls closure argument for @a service_init_cb, @a connect_cb and @a disconnect_cb | ||
293 | * @param handlers NULL-terminated array of message handlers for the service, | ||
294 | * the closure will be set to the value returned by | ||
295 | * the @a connect_cb for the respective connection | ||
296 | * @return 0 on success, non-zero on error | ||
297 | */ | ||
298 | int | ||
299 | GNUNET_SERVICE_register_ ( | ||
300 | const char *service_name, | ||
301 | enum GNUNET_SERVICE_Options options, | ||
302 | GNUNET_SERVICE_InitCallback service_init_cb, | ||
303 | GNUNET_SERVICE_ConnectHandler connect_cb, | ||
304 | GNUNET_SERVICE_DisconnectHandler disconnect_cb, | ||
305 | void *cls, | ||
306 | const struct GNUNET_MQ_MessageHandler *handlers); | ||
307 | |||
308 | |||
309 | /** | ||
261 | * Creates the "main" function for a GNUnet service. You | 310 | * Creates the "main" function for a GNUnet service. You |
262 | * MUST use this macro to define GNUnet services (except | 311 | * MUST use this macro to define GNUnet services (except |
263 | * for ARM, which MUST NOT use the macro). The reason is | 312 | * for ARM, which MUST NOT use the macro). The reason is |
@@ -317,26 +366,40 @@ GNUNET_SERVICE_run_ (int argc, | |||
317 | #ifndef HAVE_GNUNET_MONOLITH | 366 | #ifndef HAVE_GNUNET_MONOLITH |
318 | #define GNUNET_SERVICE_MAIN(service_name, service_options, init_cb, connect_cb, \ | 367 | #define GNUNET_SERVICE_MAIN(service_name, service_options, init_cb, connect_cb, \ |
319 | disconnect_cb, cls, ...) \ | 368 | disconnect_cb, cls, ...) \ |
320 | int \ | 369 | int \ |
321 | main (int argc, \ | 370 | main (int argc, \ |
322 | char *const *argv) \ | 371 | char *const *argv) \ |
323 | { \ | 372 | { \ |
324 | struct GNUNET_MQ_MessageHandler mh[] = { \ | 373 | struct GNUNET_MQ_MessageHandler mh[] = { \ |
325 | __VA_ARGS__ \ | 374 | __VA_ARGS__ \ |
326 | }; \ | 375 | }; \ |
327 | return GNUNET_SERVICE_run_ (argc, \ | 376 | return GNUNET_SERVICE_run_ (argc, \ |
328 | argv, \ | 377 | argv, \ |
329 | service_name, \ | 378 | service_name, \ |
330 | service_options, \ | 379 | service_options, \ |
331 | init_cb, \ | 380 | init_cb, \ |
332 | connect_cb, \ | 381 | connect_cb, \ |
333 | disconnect_cb, \ | 382 | disconnect_cb, \ |
334 | cls, \ | 383 | cls, \ |
335 | mh); \ | 384 | mh); \ |
336 | } | 385 | } |
337 | #else | 386 | #else |
338 | #define GNUNET_SERVICE_MAIN(service_name, service_options, init_cb, connect_cb, \ | 387 | #define GNUNET_SERVICE_MAIN(service_name, service_options, init_cb, connect_cb, \ |
339 | disconnect_cb, cls, ...) | 388 | disconnect_cb, cls, ...) \ |
389 | static int __attribute__ ((constructor)) \ | ||
390 | init (void) \ | ||
391 | { \ | ||
392 | struct GNUNET_MQ_MessageHandler mh[] = { \ | ||
393 | __VA_ARGS__ \ | ||
394 | }; \ | ||
395 | return GNUNET_SERVICE_register_ (service_name, \ | ||
396 | service_options, \ | ||
397 | init_cb, \ | ||
398 | connect_cb, \ | ||
399 | disconnect_cb, \ | ||
400 | cls, \ | ||
401 | mh); \ | ||
402 | } | ||
340 | #endif | 403 | #endif |
341 | 404 | ||
342 | /** | 405 | /** |