diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-10-21 22:00:26 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-10-21 22:00:26 +0000 |
commit | a7e626e2a613e86f3ebf6ff6f8cfec1cc2a9758b (patch) | |
tree | bf5da6bc86d387ffbc885f20974385d581679993 /src/template/gnunet-service-template.c | |
parent | 51baa79fb2c3f05b79d012db22b8d47cdcacf976 (diff) | |
download | gnunet-a7e626e2a613e86f3ebf6ff6f8cfec1cc2a9758b.tar.gz gnunet-a7e626e2a613e86f3ebf6ff6f8cfec1cc2a9758b.zip |
migrate template to new service API
Diffstat (limited to 'src/template/gnunet-service-template.c')
-rw-r--r-- | src/template/gnunet-service-template.c | 66 |
1 files changed, 46 insertions, 20 deletions
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 | |||
@@ -40,41 +40,67 @@ cleanup_task (void *cls) | |||
40 | 40 | ||
41 | 41 | ||
42 | /** | 42 | /** |
43 | * Callback called when a client connects to the service. | ||
44 | * | ||
45 | * @param cls closure for the service | ||
46 | * @param c the new client that connected to the service | ||
47 | * @param mq the message queue used to send messages to the client | ||
48 | * @return @a c | ||
49 | */ | ||
50 | static void * | ||
51 | client_connect_cb (void *cls, | ||
52 | struct GNUNET_SERVICE_Client *c, | ||
53 | struct GNUNET_MQ_Handle *mq) | ||
54 | { | ||
55 | return c; | ||
56 | } | ||
57 | |||
58 | |||
59 | /** | ||
60 | * Callback called when a client disconnected from the service | ||
61 | * | ||
62 | * @param cls closure for the service | ||
63 | * @param c the client that disconnected | ||
64 | * @param internal_cls should be equal to @a c | ||
65 | */ | ||
66 | static void | ||
67 | client_disconnect_cb (void *cls, | ||
68 | struct GNUNET_SERVICE_Client *c, | ||
69 | void *internal_cls) | ||
70 | { | ||
71 | GNUNET_assert (c == internal_cls); | ||
72 | } | ||
73 | |||
74 | |||
75 | /** | ||
43 | * Process template requests. | 76 | * Process template requests. |
44 | * | 77 | * |
45 | * @param cls closure | 78 | * @param cls closure |
46 | * @param server the initialized server | ||
47 | * @param cfg configuration to use | 79 | * @param cfg configuration to use |
80 | * @param service the initialized service | ||
48 | */ | 81 | */ |
49 | static void | 82 | static void |
50 | run (void *cls, | 83 | run (void *cls, |
51 | struct GNUNET_SERVER_Handle *server, | 84 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
52 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 85 | struct GNUNET_SERVICE_Handle *service) |
53 | { | 86 | { |
54 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { | ||
55 | /* FIXME: add handlers here! */ | ||
56 | {NULL, NULL, 0, 0} | ||
57 | }; | ||
58 | /* FIXME: do setup here */ | 87 | /* FIXME: do setup here */ |
59 | GNUNET_SERVER_add_handlers (server, handlers); | ||
60 | GNUNET_SCHEDULER_add_shutdown (&cleanup_task, | 88 | GNUNET_SCHEDULER_add_shutdown (&cleanup_task, |
61 | NULL); | 89 | NULL); |
62 | } | 90 | } |
63 | 91 | ||
64 | 92 | ||
65 | /** | 93 | /** |
66 | * The main function for the template service. | 94 | * Define "main" method using service macro. |
67 | * | ||
68 | * @param argc number of arguments from the command line | ||
69 | * @param argv command line arguments | ||
70 | * @return 0 ok, 1 on error | ||
71 | */ | 95 | */ |
72 | int | 96 | GNUNET_SERVICE_MAIN |
73 | main (int argc, char *const *argv) | 97 | ("template", |
74 | { | 98 | GNUNET_SERVICE_OPTION_NONE, |
75 | return (GNUNET_OK == | 99 | &run, |
76 | GNUNET_SERVICE_run (argc, argv, "template", | 100 | &client_connect_cb, |
77 | GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1; | 101 | &client_disconnect_cb, |
78 | } | 102 | NULL, |
103 | GNUNET_MQ_handler_end ()); | ||
104 | |||
79 | 105 | ||
80 | /* end of gnunet-service-template.c */ | 106 | /* end of gnunet-service-template.c */ |