aboutsummaryrefslogtreecommitdiff
path: root/src/arm
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-09-26 23:29:02 +0000
committerChristian Grothoff <christian@grothoff.org>2016-09-26 23:29:02 +0000
commit47ef248cdc86d1aa19cd69ff363580671547102f (patch)
treed8db41698bdaa9b7a72f9c737e9ab9e444082819 /src/arm
parent7fb1bee61c0fd70255fa57061b7422fdaebe113c (diff)
downloadgnunet-47ef248cdc86d1aa19cd69ff363580671547102f.tar.gz
gnunet-47ef248cdc86d1aa19cd69ff363580671547102f.zip
convert mockup service to new service API
Diffstat (limited to 'src/arm')
-rw-r--r--src/arm/mockup-service.c89
1 files changed, 64 insertions, 25 deletions
diff --git a/src/arm/mockup-service.c b/src/arm/mockup-service.c
index 0870cea8d..fae869258 100644
--- a/src/arm/mockup-service.c
+++ b/src/arm/mockup-service.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2007, 2008, 2009 GNUnet e.V. 3 Copyright (C) 2007, 2008, 2009, 2016 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -29,18 +29,18 @@ static int special_ret = 0;
29/** 29/**
30 * Handler for STOP message. 30 * Handler for STOP message.
31 * 31 *
32 * @param cls closure (refers to service) 32 * @param cls client identification of the client
33 * @param client identification of the client
34 * @param message the actual message 33 * @param message the actual message
35 */ 34 */
36static void 35static void
37handle_stop (void *cls, 36handle_stop (void *cls,
38 struct GNUNET_SERVER_Client *client,
39 const struct GNUNET_MessageHeader *message) 37 const struct GNUNET_MessageHeader *message)
40{ 38{
39 struct GNUNET_SERVICE_Client *client = cls;
40
41 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 41 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
42 _("Initiating shutdown as requested by client.\n")); 42 _("Initiating shutdown as requested by client.\n"));
43 GNUNET_SERVER_client_persist_ (client); 43 GNUNET_SERVICE_client_persist (client);
44 GNUNET_SCHEDULER_shutdown (); 44 GNUNET_SCHEDULER_shutdown ();
45 /* ARM won't exponentially increase restart delay if we 45 /* ARM won't exponentially increase restart delay if we
46 * terminate normally. This changes the return code. 46 * terminate normally. This changes the return code.
@@ -49,31 +49,70 @@ handle_stop (void *cls,
49} 49}
50 50
51 51
52/**
53 * Callback called when a client connects to the service.
54 *
55 * @param cls closure for the service
56 * @param c the new client that connected to the service
57 * @param mq the message queue used to send messages to the client
58 * @return @a c
59 */
60static void *
61client_connect_cb (void *cls,
62 struct GNUNET_SERVICE_Client *c,
63 struct GNUNET_MQ_Handle *mq)
64{
65 return c;
66}
67
68
69/**
70 * Callback called when a client disconnected from the service
71 *
72 * @param cls closure for the service
73 * @param c the client that disconnected
74 * @param internal_cls should be equal to @a c
75 */
76static void
77client_disconnect_cb (void *cls,
78 struct GNUNET_SERVICE_Client *c,
79 void *internal_cls)
80{
81 GNUNET_assert (c == internal_cls);
82}
83
84
52static void 85static void
53run (void *cls, 86run (void *cls,
54 struct GNUNET_SERVER_Handle *server, 87 const struct GNUNET_CONFIGURATION_Handle *cfg,
55 const struct GNUNET_CONFIGURATION_Handle *cfg) 88 struct GNUNET_SERVICE_Handle *service)
56{ 89{
57 static const struct GNUNET_SERVER_MessageHandler handlers[] = { 90 /* nothing to do */
58 {&handle_stop, NULL, GNUNET_MESSAGE_TYPE_ARM_STOP,
59 sizeof (struct GNUNET_MessageHeader)},
60 {NULL, NULL, 0, 0}
61 };
62 /* process client requests */
63 GNUNET_SERVER_add_handlers (server, handlers);
64} 91}
65 92
66 93
67int 94/**
68main (int argc, char *const *argv) 95 * Define "main" method using service macro.
96 */
97GNUNET_SERVICE_MAIN
98("do-nothing",
99 GNUNET_SERVICE_OPTION_NONE,
100 &run,
101 &client_connect_cb,
102 &client_disconnect_cb,
103 NULL,
104 GNUNET_MQ_hd_fixed_size (stop,
105 GNUNET_MESSAGE_TYPE_ARM_STOP,
106 struct GNUNET_MessageHeader,
107 NULL),
108 GNUNET_MQ_handler_end ());
109
110
111/**
112 * MINIMIZE heap size (way below 128k) since this process doesn't need much.
113 */
114void __attribute__ ((destructor))
115GNUNET_mockup_done ()
69{ 116{
70 int ret; 117 _exit (special_ret);
71
72 ret =
73 (GNUNET_OK ==
74 GNUNET_SERVICE_run (argc, argv, "do-nothing", GNUNET_SERVICE_OPTION_NONE,
75 &run, NULL)) ? 0 : 1;
76 if (0 != special_ret)
77 return special_ret;
78 return ret;
79} 118}