GNUnet 0.22.1
mockup-service.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2007, 2008, 2009, 2016 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21#include "platform.h"
22#include <stdlib.h>
23#include "gnunet_util_lib.h"
24#include "gnunet_protocols.h"
25
26
27static int special_ret;
28
35static void
36handle_stop (void *cls,
37 const struct GNUNET_MessageHeader *message)
38{
39 struct GNUNET_SERVICE_Client *client = cls;
40
41 (void) message;
43 "Initiating shutdown as requested by client.\n");
46 /* ARM won't exponentially increase restart delay if we
47 * terminate normally. This changes the return code.
48 */
49 special_ret = 1;
50}
51
52
61static void *
63 struct GNUNET_SERVICE_Client *c,
64 struct GNUNET_MQ_Handle *mq)
65{
66 (void) cls;
67 (void) mq;
68 return c;
69}
70
71
79static void
81 struct GNUNET_SERVICE_Client *c,
82 void *internal_cls)
83{
84 (void) cls;
85 GNUNET_assert (c == internal_cls);
86}
87
88
89static void
90run (void *cls,
91 const struct GNUNET_CONFIGURATION_Handle *cfg,
93{
94 (void) cls;
95 (void) cfg;
96 (void) service;
97 /* nothing to do */
98}
99
100
106 &run,
109 NULL,
113 NULL),
115
116void
118
119void __attribute__ ((destructor))
121{
122 _exit (special_ret);
123}
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:108
static struct GNUNET_SERVICE_Handle * service
Handle to our service instance.
Constants for network protocols.
#define GNUNET_log(kind,...)
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
@ GNUNET_ERROR_TYPE_INFO
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
#define GNUNET_MESSAGE_TYPE_ARM_STOP
Request to ARM to stop a service.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:566
void GNUNET_SERVICE_client_persist(struct GNUNET_SERVICE_Client *c)
Set the persist option on this client.
Definition: service.c:2452
@ GNUNET_SERVICE_OPTION_NONE
Use defaults.
static void handle_stop(void *cls, const struct GNUNET_MessageHeader *message)
Handler for STOP message.
static int special_ret
void GNUNET_mockup_done(void)
static void * client_connect_cb(void *cls, struct GNUNET_SERVICE_Client *c, struct GNUNET_MQ_Handle *mq)
Callback called when a client connects to the service.
static void client_disconnect_cb(void *cls, struct GNUNET_SERVICE_Client *c, void *internal_cls)
Callback called when a client disconnected from the service.
void __attribute__((destructor))
GNUNET_SERVICE_MAIN("do-nothing", GNUNET_SERVICE_OPTION_NONE, &run, &client_connect_cb, &client_disconnect_cb, NULL, GNUNET_MQ_hd_fixed_size(stop, GNUNET_MESSAGE_TYPE_ARM_STOP, struct GNUNET_MessageHeader, NULL), GNUNET_MQ_handler_end())
Define "main" method using service macro.
static void run(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_SERVICE_Handle *service)
Handle to a message queue.
Definition: mq.c:87
Header for all communications.
Handle to a client that is connected to a service.
Definition: service.c:245
Handle to a service.
Definition: service.c:116