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 | |
parent | 51baa79fb2c3f05b79d012db22b8d47cdcacf976 (diff) | |
download | gnunet-a7e626e2a613e86f3ebf6ff6f8cfec1cc2a9758b.tar.gz gnunet-a7e626e2a613e86f3ebf6ff6f8cfec1cc2a9758b.zip |
migrate template to new service API
Diffstat (limited to 'src/template')
-rw-r--r-- | src/template/gnunet-service-template.c | 66 | ||||
-rw-r--r-- | src/template/gnunet-template.c | 16 |
2 files changed, 58 insertions, 24 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 */ |
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 @@ | |||
32 | */ | 32 | */ |
33 | static int ret; | 33 | static int ret; |
34 | 34 | ||
35 | |||
35 | /** | 36 | /** |
36 | * Main function that will be run by the scheduler. | 37 | * Main function that will be run by the scheduler. |
37 | * | 38 | * |
@@ -41,7 +42,9 @@ static int ret; | |||
41 | * @param cfg configuration | 42 | * @param cfg configuration |
42 | */ | 43 | */ |
43 | static void | 44 | static void |
44 | run (void *cls, char *const *args, const char *cfgfile, | 45 | run (void *cls, |
46 | char *const *args, | ||
47 | const char *cfgfile, | ||
45 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 48 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
46 | { | 49 | { |
47 | /* main code here */ | 50 | /* main code here */ |
@@ -62,12 +65,17 @@ main (int argc, char *const *argv) | |||
62 | /* FIMXE: add options here */ | 65 | /* FIMXE: add options here */ |
63 | GNUNET_GETOPT_OPTION_END | 66 | GNUNET_GETOPT_OPTION_END |
64 | }; | 67 | }; |
65 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | 68 | if (GNUNET_OK != |
69 | GNUNET_STRINGS_get_utf8_args (argc, argv, | ||
70 | &argc, &argv)) | ||
66 | return 2; | 71 | return 2; |
67 | 72 | ||
68 | ret = (GNUNET_OK == | 73 | ret = (GNUNET_OK == |
69 | GNUNET_PROGRAM_run (argc, argv, "gnunet-template", | 74 | GNUNET_PROGRAM_run (argc, argv, |
70 | gettext_noop ("help text"), options, &run, | 75 | "gnunet-template", |
76 | gettext_noop ("help text"), | ||
77 | options, | ||
78 | &run, | ||
71 | NULL)) ? ret : 1; | 79 | NULL)) ? ret : 1; |
72 | GNUNET_free ((void*) argv); | 80 | GNUNET_free ((void*) argv); |
73 | return ret; | 81 | return ret; |