summaryrefslogtreecommitdiff
path: root/src/template
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-10-21 22:00:26 +0000
committerChristian Grothoff <christian@grothoff.org>2016-10-21 22:00:26 +0000
commita7e626e2a613e86f3ebf6ff6f8cfec1cc2a9758b (patch)
treebf5da6bc86d387ffbc885f20974385d581679993 /src/template
parent51baa79fb2c3f05b79d012db22b8d47cdcacf976 (diff)
downloadgnunet-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.c66
-rw-r--r--src/template/gnunet-template.c16
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 */
50static void *
51client_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 */
66static void
67client_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 */
49static void 82static void
50run (void *cls, 83run (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 */
72int 96GNUNET_SERVICE_MAIN
73main (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 */
33static int ret; 33static 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 */
43static void 44static void
44run (void *cls, char *const *args, const char *cfgfile, 45run (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;