From: Christian Grothoff Date: Fri, 21 Oct 2016 22:00:26 +0000 (+0000) Subject: migrate template to new service API X-Git-Tag: initial-import-from-subversion-38251~75 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=a7e626e2a613e86f3ebf6ff6f8cfec1cc2a9758b;p=oweals%2Fgnunet.git migrate template to new service API --- diff --git a/src/template/gnunet-service-template.c b/src/template/gnunet-service-template.c index 6ff63c073..815cc26d6 100644 --- a/src/template/gnunet-service-template.c +++ b/src/template/gnunet-service-template.c @@ -39,42 +39,68 @@ cleanup_task (void *cls) } +/** + * Callback called when a client connects to the service. + * + * @param cls closure for the service + * @param c the new client that connected to the service + * @param mq the message queue used to send messages to the client + * @return @a c + */ +static void * +client_connect_cb (void *cls, + struct GNUNET_SERVICE_Client *c, + struct GNUNET_MQ_Handle *mq) +{ + return c; +} + + +/** + * Callback called when a client disconnected from the service + * + * @param cls closure for the service + * @param c the client that disconnected + * @param internal_cls should be equal to @a c + */ +static void +client_disconnect_cb (void *cls, + struct GNUNET_SERVICE_Client *c, + void *internal_cls) +{ + GNUNET_assert (c == internal_cls); +} + + /** * Process template requests. * * @param cls closure - * @param server the initialized server * @param cfg configuration to use + * @param service the initialized service */ static void run (void *cls, - struct GNUNET_SERVER_Handle *server, - const struct GNUNET_CONFIGURATION_Handle *cfg) + const struct GNUNET_CONFIGURATION_Handle *cfg, + struct GNUNET_SERVICE_Handle *service) { - static const struct GNUNET_SERVER_MessageHandler handlers[] = { - /* FIXME: add handlers here! */ - {NULL, NULL, 0, 0} - }; /* FIXME: do setup here */ - GNUNET_SERVER_add_handlers (server, handlers); GNUNET_SCHEDULER_add_shutdown (&cleanup_task, NULL); } /** - * The main function for the template service. - * - * @param argc number of arguments from the command line - * @param argv command line arguments - * @return 0 ok, 1 on error + * Define "main" method using service macro. */ -int -main (int argc, char *const *argv) -{ - return (GNUNET_OK == - GNUNET_SERVICE_run (argc, argv, "template", - GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1; -} +GNUNET_SERVICE_MAIN +("template", + GNUNET_SERVICE_OPTION_NONE, + &run, + &client_connect_cb, + &client_disconnect_cb, + NULL, + GNUNET_MQ_handler_end ()); + /* end of gnunet-service-template.c */ diff --git a/src/template/gnunet-template.c b/src/template/gnunet-template.c index 987923587..22b78d632 100644 --- a/src/template/gnunet-template.c +++ b/src/template/gnunet-template.c @@ -32,6 +32,7 @@ */ static int ret; + /** * Main function that will be run by the scheduler. * @@ -41,7 +42,9 @@ static int ret; * @param cfg configuration */ static void -run (void *cls, char *const *args, const char *cfgfile, +run (void *cls, + char *const *args, + const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) { /* main code here */ @@ -62,12 +65,17 @@ main (int argc, char *const *argv) /* FIMXE: add options here */ GNUNET_GETOPT_OPTION_END }; - if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) + if (GNUNET_OK != + GNUNET_STRINGS_get_utf8_args (argc, argv, + &argc, &argv)) return 2; ret = (GNUNET_OK == - GNUNET_PROGRAM_run (argc, argv, "gnunet-template", - gettext_noop ("help text"), options, &run, + GNUNET_PROGRAM_run (argc, argv, + "gnunet-template", + gettext_noop ("help text"), + options, + &run, NULL)) ? ret : 1; GNUNET_free ((void*) argv); return ret;