diff options
author | Omar Tarabai <tarabai@devegypt.com> | 2014-07-04 15:16:00 +0000 |
---|---|---|
committer | Omar Tarabai <tarabai@devegypt.com> | 2014-07-04 15:16:00 +0000 |
commit | 85e95fea731341b5bfdbb1175520220cd1d394d5 (patch) | |
tree | da765e955fa045c70401e16b4995b8a5b7fbd951 /src/sensordashboard | |
parent | f65ed3aab8bf35e48934cdccf4ec5b64e4b14e88 (diff) | |
download | gnunet-85e95fea731341b5bfdbb1175520220cd1d394d5.tar.gz gnunet-85e95fea731341b5bfdbb1175520220cd1d394d5.zip |
completed sensordashboard + fixes
Diffstat (limited to 'src/sensordashboard')
-rw-r--r-- | src/sensordashboard/gnunet-service-sensordashboard.c | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/src/sensordashboard/gnunet-service-sensordashboard.c b/src/sensordashboard/gnunet-service-sensordashboard.c index 91c7e98f5..841268762 100644 --- a/src/sensordashboard/gnunet-service-sensordashboard.c +++ b/src/sensordashboard/gnunet-service-sensordashboard.c | |||
@@ -23,6 +23,7 @@ | |||
23 | * @brief Service collecting sensor readings from peers | 23 | * @brief Service collecting sensor readings from peers |
24 | * @author Omar Tarabai | 24 | * @author Omar Tarabai |
25 | */ | 25 | */ |
26 | #include <inttypes.h> | ||
26 | #include "platform.h" | 27 | #include "platform.h" |
27 | #include "gnunet_util_lib.h" | 28 | #include "gnunet_util_lib.h" |
28 | #include "gnunet_applications.h" | 29 | #include "gnunet_applications.h" |
@@ -51,6 +52,7 @@ cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
51 | GNUNET_CADET_disconnect(cadet); | 52 | GNUNET_CADET_disconnect(cadet); |
52 | cadet = NULL; | 53 | cadet = NULL; |
53 | } | 54 | } |
55 | GNUNET_SENSOR_destroy_sensors (sensors); | ||
54 | GNUNET_SCHEDULER_shutdown(); | 56 | GNUNET_SCHEDULER_shutdown(); |
55 | } | 57 | } |
56 | 58 | ||
@@ -69,7 +71,9 @@ static void cadet_channel_destroyed (void *cls, | |||
69 | const struct GNUNET_CADET_Channel *channel, | 71 | const struct GNUNET_CADET_Channel *channel, |
70 | void *channel_ctx) | 72 | void *channel_ctx) |
71 | { | 73 | { |
74 | struct GNUNET_PeerIdentity *peer = channel_ctx; | ||
72 | 75 | ||
76 | GNUNET_free (peer); | ||
73 | } | 77 | } |
74 | 78 | ||
75 | /** | 79 | /** |
@@ -95,10 +99,11 @@ static void *cadet_channel_created (void *cls, | |||
95 | const struct GNUNET_PeerIdentity *initiator, | 99 | const struct GNUNET_PeerIdentity *initiator, |
96 | uint32_t port, enum GNUNET_CADET_ChannelOption options) | 100 | uint32_t port, enum GNUNET_CADET_ChannelOption options) |
97 | { | 101 | { |
98 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 102 | struct GNUNET_PeerIdentity *peer; |
99 | "CADET channel opened by remote peer `%s'.\n", | 103 | |
100 | GNUNET_i2s(initiator)); | 104 | peer = GNUNET_new (struct GNUNET_PeerIdentity); |
101 | return NULL; /* FIXME */ | 105 | memcpy (peer, initiator, sizeof (struct GNUNET_PeerIdentity)); |
106 | return peer; | ||
102 | } | 107 | } |
103 | 108 | ||
104 | /** | 109 | /** |
@@ -118,7 +123,29 @@ static void *cadet_channel_created (void *cls, | |||
118 | int sensor_reading_receiver (void *cls, struct GNUNET_CADET_Channel *channel, | 123 | int sensor_reading_receiver (void *cls, struct GNUNET_CADET_Channel *channel, |
119 | void **channel_ctx, const struct GNUNET_MessageHeader *message) | 124 | void **channel_ctx, const struct GNUNET_MessageHeader *message) |
120 | { | 125 | { |
126 | struct GNUNET_PeerIdentity *peer = *channel_ctx; | ||
127 | struct GNUNET_SENSOR_Reading *reading; | ||
121 | 128 | ||
129 | reading = GNUNET_SENSOR_parse_reading_message (message, sensors); | ||
130 | if (NULL == reading) | ||
131 | { | ||
132 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
133 | "Received an invalid sensor reading from peer `%s'\n", | ||
134 | GNUNET_i2s (peer)); | ||
135 | return GNUNET_SYSERR; | ||
136 | } | ||
137 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
138 | "Received a sensor reading from peer `%s':\n" | ||
139 | "# Sensor name: `%s'\n" | ||
140 | "# Timestamp: %" PRIu64 "\n" | ||
141 | "# Value size: %" PRIu64 ".\n", | ||
142 | GNUNET_i2s (peer), | ||
143 | reading->sensor->name, | ||
144 | reading->timestamp, | ||
145 | reading->value_size); | ||
146 | GNUNET_free (reading->value); | ||
147 | GNUNET_free (reading); | ||
148 | return GNUNET_OK; | ||
122 | } | 149 | } |
123 | 150 | ||
124 | /** | 151 | /** |