2 This file is part of GNUnet.
3 (C) 2009 Christian Grothoff (and other contributing authors)
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
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
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 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file sensordashboard/gnunet-service-sensordashboard.c
23 * @brief Service collecting sensor readings from peers
24 * @author Omar Tarabai
27 #include "gnunet_util_lib.h"
28 #include "gnunet_applications.h"
29 #include "gnunet_cadet_service.h"
31 static struct GNUNET_CADET_Handle *cadet;
34 * Task run during shutdown.
40 cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
44 GNUNET_CADET_disconnect(cadet);
47 GNUNET_SCHEDULER_shutdown();
51 * Function called whenever a channel is destroyed. Should clean up
52 * any associated state.
54 * It must NOT call #GNUNET_CADET_channel_destroy on the channel.
56 * @param cls closure (set from #GNUNET_CADET_connect)
57 * @param channel connection to the other end (henceforth invalid)
58 * @param channel_ctx place where local state associated
59 * with the channel is stored
61 static void cadet_channel_destroyed (void *cls,
62 const struct GNUNET_CADET_Channel *channel,
69 * Method called whenever another peer has added us to a channel
70 * the other peer initiated.
71 * Only called (once) upon reception of data with a message type which was
72 * subscribed to in #GNUNET_CADET_connect.
74 * A call to #GNUNET_CADET_channel_destroy causes the channel to be ignored. In
75 * this case the handler MUST return NULL.
78 * @param channel new handle to the channel
79 * @param initiator peer that started the channel
80 * @param port Port this channel is for.
81 * @param options CadetOption flag field, with all active option bits set to 1.
83 * @return initial channel context for the channel
84 * (can be NULL -- that's not an error)
86 static void *cadet_channel_created (void *cls,
87 struct GNUNET_CADET_Channel *channel,
88 const struct GNUNET_PeerIdentity *initiator,
89 uint32_t port, enum GNUNET_CADET_ChannelOption options)
91 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
92 "CADET channel opened by remote peer `%s'.\n",
93 GNUNET_i2s(initiator));
94 return NULL; /* FIXME */
98 * Process sensordashboard requests.
101 * @param server the initialized server
102 * @param cfg configuration to use
105 run (void *cls, struct GNUNET_SERVER_Handle *server,
106 const struct GNUNET_CONFIGURATION_Handle *cfg)
108 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
111 static struct GNUNET_CADET_MessageHandler cadet_handlers[] = {
114 static uint32_t cadet_ports[] = {
115 GNUNET_APPLICATION_TYPE_SENSORDASHBOARD,
116 GNUNET_APPLICATION_TYPE_END
118 cadet = GNUNET_CADET_connect(cfg,
120 &cadet_channel_created,
121 &cadet_channel_destroyed,
126 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
127 _("Failed to connect to CADET service.\n"));
128 GNUNET_SCHEDULER_add_now (&cleanup_task, NULL);
131 GNUNET_SERVER_add_handlers (server, handlers);
132 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task,
138 * The main function for the sensordashboard service.
140 * @param argc number of arguments from the command line
141 * @param argv command line arguments
142 * @return 0 ok, 1 on error
145 main (int argc, char *const *argv)
148 GNUNET_SERVICE_run (argc, argv, "sensordashboard",
149 GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1;
152 /* end of gnunet-service-sensordashboard.c */