aboutsummaryrefslogtreecommitdiff
path: root/src/sensordashboard
diff options
context:
space:
mode:
authorOmar Tarabai <tarabai@devegypt.com>2014-07-01 17:42:04 +0000
committerOmar Tarabai <tarabai@devegypt.com>2014-07-01 17:42:04 +0000
commit82a7032fa39250385877b2b91d79e0601378021a (patch)
tree7ca8f1ea6104c86164d37bba1c9a4e5f412385b5 /src/sensordashboard
parent33ccf61eb6b2a102f720111737f3c9b7f6c6099b (diff)
downloadgnunet-82a7032fa39250385877b2b91d79e0601378021a.tar.gz
gnunet-82a7032fa39250385877b2b91d79e0601378021a.zip
sensor dashboard (collection point) initial commit
Diffstat (limited to 'src/sensordashboard')
-rw-r--r--src/sensordashboard/Makefile.am50
-rw-r--r--src/sensordashboard/gnunet-sensordashboard.c75
-rw-r--r--src/sensordashboard/gnunet-service-sensordashboard.c152
-rw-r--r--src/sensordashboard/sensordashboard.conf.in4
-rw-r--r--src/sensordashboard/test_sensordashboard_api.c42
5 files changed, 323 insertions, 0 deletions
diff --git a/src/sensordashboard/Makefile.am b/src/sensordashboard/Makefile.am
new file mode 100644
index 000000000..419486ff4
--- /dev/null
+++ b/src/sensordashboard/Makefile.am
@@ -0,0 +1,50 @@
1AM_CPPFLAGS = -I$(top_srcdir)/src/include
2
3pkgcfgdir= $(pkgdatadir)/config.d/
4
5libexecdir= $(pkglibdir)/libexec/
6
7dist_pkgcfg_DATA = \
8 sensordashboard.conf
9
10if MINGW
11 WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols
12endif
13
14if USE_COVERAGE
15 AM_CFLAGS = -fprofile-arcs -ftest-coverage
16endif
17
18bin_PROGRAMS = \
19 gnunet-sensordashboard
20
21libexec_PROGRAMS = \
22 gnunet-service-sensordashboard
23
24gnunet_sensordashboard_SOURCES = \
25 gnunet-sensordashboard.c
26gnunet_sensordashboard_LDADD = \
27 $(top_builddir)/src/util/libgnunetutil.la \
28 $(GN_LIBINTL)
29
30gnunet_service_sensordashboard_SOURCES = \
31 gnunet-service-sensordashboard.c
32gnunet_service_sensordashboard_LDADD = \
33 $(top_builddir)/src/util/libgnunetutil.la \
34 $(top_builddir)/src/cadet/libgnunetcadet.la \
35 $(GN_LIBINTL)
36
37
38check_PROGRAMS = \
39 test_sensordashboard_api
40
41if ENABLE_TEST_RUN
42AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;
43TESTS = $(check_PROGRAMS)
44endif
45
46test_sensordashboard_api_SOURCES = \
47 test_sensordashboard_api.c
48test_sensordashboard_api_LDADD = \
49 $(top_builddir)/src/util/libgnunetutil.la
50
diff --git a/src/sensordashboard/gnunet-sensordashboard.c b/src/sensordashboard/gnunet-sensordashboard.c
new file mode 100644
index 000000000..630a3cf77
--- /dev/null
+++ b/src/sensordashboard/gnunet-sensordashboard.c
@@ -0,0 +1,75 @@
1/*
2 This file is part of GNUnet.
3 (C) 2001, 2002, 2004, 2005, 2006, 2007, 2009 Christian Grothoff (and other contributing authors)
4
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.
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 General Public License for more details.
14
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.
19*/
20
21/**
22 * @file sensordashboard/gnunet-sensordashboard.c
23 * @brief sensor dashboard tool
24 * @author Omar Tarabai
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28
29/**
30 * Final status code.
31 */
32static int ret;
33
34/**
35 * Main function that will be run by the scheduler.
36 *
37 * @param cls closure
38 * @param args remaining command-line arguments
39 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
40 * @param cfg configuration
41 */
42static void
43run (void *cls, char *const *args, const char *cfgfile,
44 const struct GNUNET_CONFIGURATION_Handle *cfg)
45{
46 /* main code here */
47}
48
49
50/**
51 * The main function.
52 *
53 * @param argc number of arguments from the command line
54 * @param argv command line arguments
55 * @return 0 ok, 1 on error
56 */
57int
58main (int argc, char *const *argv)
59{
60 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
61 /* FIMXE: add options here */
62 GNUNET_GETOPT_OPTION_END
63 };
64 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
65 return 2;
66
67 ret = (GNUNET_OK ==
68 GNUNET_PROGRAM_run (argc, argv, "gnunet-sensordashboard",
69 gettext_noop ("help text"), options, &run,
70 NULL)) ? ret : 1;
71 GNUNET_free ((void*) argv);
72 return ret;
73}
74
75/* end of gnunet-sensordashboard.c */
diff --git a/src/sensordashboard/gnunet-service-sensordashboard.c b/src/sensordashboard/gnunet-service-sensordashboard.c
new file mode 100644
index 000000000..b3fbf5d9d
--- /dev/null
+++ b/src/sensordashboard/gnunet-service-sensordashboard.c
@@ -0,0 +1,152 @@
1/*
2 This file is part of GNUnet.
3 (C) 2009 Christian Grothoff (and other contributing authors)
4
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.
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 General Public License for more details.
14
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.
19*/
20
21/**
22 * @file sensordashboard/gnunet-service-sensordashboard.c
23 * @brief Service collecting sensor readings from peers
24 * @author Omar Tarabai
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_applications.h"
29#include "gnunet_cadet_service.h"
30
31static struct GNUNET_CADET_Handle *cadet;
32
33/**
34 * Task run during shutdown.
35 *
36 * @param cls unused
37 * @param tc unused
38 */
39static void
40cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
41{
42 if (NULL != cadet)
43 {
44 GNUNET_CADET_disconnect(cadet);
45 cadet = NULL;
46 }
47 GNUNET_SCHEDULER_shutdown();
48}
49
50/**
51 * Function called whenever a channel is destroyed. Should clean up
52 * any associated state.
53 *
54 * It must NOT call #GNUNET_CADET_channel_destroy on the channel.
55 *
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
60 */
61static void cadet_channel_destroyed (void *cls,
62 const struct GNUNET_CADET_Channel *channel,
63 void *channel_ctx)
64{
65
66}
67
68/**
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.
73 *
74 * A call to #GNUNET_CADET_channel_destroy causes the channel to be ignored. In
75 * this case the handler MUST return NULL.
76 *
77 * @param cls closure
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.
82 *
83 * @return initial channel context for the channel
84 * (can be NULL -- that's not an error)
85 */
86static 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)
90{
91 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
92 "CADET channel opened by remote peer `%s'.\n",
93 GNUNET_i2s(initiator));
94 return NULL; /* FIXME */
95}
96
97/**
98 * Process sensordashboard requests.
99 *
100 * @param cls closure
101 * @param server the initialized server
102 * @param cfg configuration to use
103 */
104static void
105run (void *cls, struct GNUNET_SERVER_Handle *server,
106 const struct GNUNET_CONFIGURATION_Handle *cfg)
107{
108 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
109 {NULL, NULL, 0, 0}
110 };
111 static struct GNUNET_CADET_MessageHandler cadet_handlers[] = {
112 {NULL, 0, 0}
113 };
114 static uint32_t cadet_ports[] = {
115 GNUNET_APPLICATION_TYPE_SENSORDASHBOARD,
116 GNUNET_APPLICATION_TYPE_END
117 };
118 cadet = GNUNET_CADET_connect(cfg,
119 NULL,
120 &cadet_channel_created,
121 &cadet_channel_destroyed,
122 cadet_handlers,
123 cadet_ports);
124 if(NULL == cadet)
125 {
126 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
127 _("Failed to connect to CADET service.\n"));
128 GNUNET_SCHEDULER_add_now (&cleanup_task, NULL);
129 return;
130 }
131 GNUNET_SERVER_add_handlers (server, handlers);
132 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task,
133 NULL);
134}
135
136
137/**
138 * The main function for the sensordashboard service.
139 *
140 * @param argc number of arguments from the command line
141 * @param argv command line arguments
142 * @return 0 ok, 1 on error
143 */
144int
145main (int argc, char *const *argv)
146{
147 return (GNUNET_OK ==
148 GNUNET_SERVICE_run (argc, argv, "sensordashboard",
149 GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1;
150}
151
152/* end of gnunet-service-sensordashboard.c */
diff --git a/src/sensordashboard/sensordashboard.conf.in b/src/sensordashboard/sensordashboard.conf.in
new file mode 100644
index 000000000..a375ca676
--- /dev/null
+++ b/src/sensordashboard/sensordashboard.conf.in
@@ -0,0 +1,4 @@
1[sensordashboard]
2BINARY = gnunet-service-sensordashboard
3UNIXPATH = /tmp/gnunet-service-sensordashboard.sock
4HOME = $SERVICEHOME
diff --git a/src/sensordashboard/test_sensordashboard_api.c b/src/sensordashboard/test_sensordashboard_api.c
new file mode 100644
index 000000000..855fadc2f
--- /dev/null
+++ b/src/sensordashboard/test_sensordashboard_api.c
@@ -0,0 +1,42 @@
1/*
2 This file is part of GNUnet.
3 (C) 2009 Christian Grothoff (and other contributing authors)
4
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.
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 General Public License for more details.
14
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.
19*/
20/**
21 * @file template/test_template_api.c
22 * @brief testcase for template.c
23 */
24#include "platform.h"
25
26static int
27check ()
28{
29 return 0;
30}
31
32int
33main (int argc, char *argv[])
34{
35 int ret;
36
37 ret = check ();
38
39 return ret;
40}
41
42/* end of test_template_api.c */