aboutsummaryrefslogtreecommitdiff
path: root/src/sensor/gnunet-service-sensor.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/sensor/gnunet-service-sensor.c')
-rw-r--r--src/sensor/gnunet-service-sensor.c108
1 files changed, 57 insertions, 51 deletions
diff --git a/src/sensor/gnunet-service-sensor.c b/src/sensor/gnunet-service-sensor.c
index 261758595..794ba0b06 100644
--- a/src/sensor/gnunet-service-sensor.c
+++ b/src/sensor/gnunet-service-sensor.c
@@ -61,22 +61,25 @@ char *subsystem = "sensor";
61struct GNUNET_PeerIdentity peerid; 61struct GNUNET_PeerIdentity peerid;
62 62
63/** 63/**
64 * Disable a sensor 64 * Change the state of the sensor.
65 * Sensor will not run again unless 65 * Write the change to file to make it persistent.
66 * explicitly enabled or reloaded
67 * 66 *
68 * @param sensor sensor information 67 * @param sensor sensor info struct
68 * @param state new enabled state: #GNUNET_YES / #GNUNET_NO
69 */ 69 */
70static void set_sensor_enabled(struct SensorInfo *sensor, int state) 70static void
71set_sensor_enabled (struct GNUNET_SENSOR_SensorInfo *sensor, int state)
71{ 72{
72 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 73 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
73 "Sensor `%s': Setting enabled to %d.\n", 74 "Sensor `%s': Setting enabled to %d.\n",
74 sensor->name, state); 75 sensor->name, state);
75 sensor->enabled = GNUNET_NO; 76 sensor->enabled = GNUNET_NO;
76 GNUNET_assert(NULL != sensor->cfg); 77 GNUNET_assert (NULL != sensor->cfg);
77 GNUNET_CONFIGURATION_set_value_string(sensor->cfg, sensor->name, "ENABLED", 78 GNUNET_CONFIGURATION_set_value_string (sensor->cfg,
78 (GNUNET_YES == state)?"YES":"NO"); 79 sensor->name,
79 GNUNET_CONFIGURATION_write(sensor->cfg, sensor->def_file); 80 "ENABLED",
81 (GNUNET_YES == state) ? "YES" : "NO");
82 GNUNET_CONFIGURATION_write (sensor->cfg, sensor->def_file);
80} 83}
81 84
82/** 85/**
@@ -87,23 +90,23 @@ static void set_sensor_enabled(struct SensorInfo *sensor, int state)
87 */ 90 */
88static void 91static void
89shutdown_task (void *cls, 92shutdown_task (void *cls,
90 const struct GNUNET_SCHEDULER_TaskContext *tc) 93 const struct GNUNET_SCHEDULER_TaskContext *tc)
91{ 94{
92 SENSOR_update_stop (); 95 //SENSOR_update_stop ();
93 SENSOR_reporting_stop(); 96 SENSOR_reporting_stop ();
94 SENSOR_analysis_stop(); 97 SENSOR_analysis_stop ();
95 GNUNET_SENSOR_destroy_sensors (sensors); 98 GNUNET_SENSOR_destroy_sensors (sensors);
96 if(NULL != statistics) 99 if (NULL != statistics)
97 { 100 {
98 GNUNET_STATISTICS_destroy(statistics, GNUNET_YES); 101 GNUNET_STATISTICS_destroy (statistics, GNUNET_YES);
99 statistics = NULL; 102 statistics = NULL;
100 } 103 }
101 if(NULL != peerstore) 104 if (NULL != peerstore)
102 { 105 {
103 GNUNET_PEERSTORE_disconnect(peerstore, GNUNET_YES); 106 GNUNET_PEERSTORE_disconnect (peerstore, GNUNET_YES);
104 peerstore = NULL; 107 peerstore = NULL;
105 } 108 }
106 GNUNET_SCHEDULER_shutdown(); 109 GNUNET_SCHEDULER_shutdown ();
107} 110}
108 111
109 112
@@ -115,19 +118,18 @@ shutdown_task (void *cls,
115 */ 118 */
116static void 119static void
117handle_client_disconnect (void *cls, 120handle_client_disconnect (void *cls,
118 struct GNUNET_SERVER_Client 121 struct GNUNET_SERVER_Client *client)
119 * client)
120{ 122{
121} 123}
122 124
123/** 125/**
124 * Creates a structure with basic sensor info to be sent to a client 126 * Creates a structure with basic sensor info to be sent to a client.
125 * 127 *
126 * @param sensor sensor information 128 * @param sensor sensor information
127 * @return message ready to be sent to client 129 * @return message ready to be sent to client
128 */ 130 */
129static struct SensorInfoMessage * 131static struct SensorInfoMessage *
130create_sensor_info_msg(struct SensorInfo *sensor) 132create_sensor_info_msg (struct GNUNET_SENSOR_SensorInfo *sensor)
131{ 133{
132 struct SensorInfoMessage *msg; 134 struct SensorInfoMessage *msg;
133 uint16_t len; 135 uint16_t len;
@@ -171,14 +173,15 @@ create_sensor_info_msg(struct SensorInfo *sensor)
171 * @param message the actual message 173 * @param message the actual message
172 */ 174 */
173static void 175static void
174handle_get_sensor (void *cls, struct GNUNET_SERVER_Client *client, 176handle_get_sensor (void *cls,
175 const struct GNUNET_MessageHeader *message) 177 struct GNUNET_SERVER_Client *client,
178 const struct GNUNET_MessageHeader *message)
176{ 179{
177 struct GNUNET_SERVER_TransmitContext *tc; 180 struct GNUNET_SERVER_TransmitContext *tc;
178 char *sensorname; 181 char *sensorname;
179 size_t sensorname_len; 182 size_t sensorname_len;
180 struct GNUNET_HashCode key; 183 struct GNUNET_HashCode key;
181 struct SensorInfo *sensorinfo; 184 struct GNUNET_SENSOR_SensorInfo *sensorinfo;
182 struct SensorInfoMessage *msg; 185 struct SensorInfoMessage *msg;
183 186
184 sensorname = (char *)&message[1]; 187 sensorname = (char *)&message[1];
@@ -188,7 +191,7 @@ handle_get_sensor (void *cls, struct GNUNET_SERVER_Client *client,
188 tc = GNUNET_SERVER_transmit_context_create (client); 191 tc = GNUNET_SERVER_transmit_context_create (client);
189 GNUNET_CRYPTO_hash(sensorname, sensorname_len, &key); 192 GNUNET_CRYPTO_hash(sensorname, sensorname_len, &key);
190 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created key hash for requested sensor\n"); 193 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created key hash for requested sensor\n");
191 sensorinfo = (struct SensorInfo *)GNUNET_CONTAINER_multihashmap_get(sensors, &key); 194 sensorinfo = (struct GNUNET_SENSOR_SensorInfo *)GNUNET_CONTAINER_multihashmap_get(sensors, &key);
192 if(NULL != sensorinfo) 195 if(NULL != sensorinfo)
193 { 196 {
194 msg = create_sensor_info_msg(sensorinfo); 197 msg = create_sensor_info_msg(sensorinfo);
@@ -205,15 +208,16 @@ handle_get_sensor (void *cls, struct GNUNET_SERVER_Client *client,
205/** 208/**
206 * Iterator for sensors and adds them to transmit context 209 * Iterator for sensors and adds them to transmit context
207 * 210 *
208 * @param cls a 'struct GNUNET_SERVER_TransmitContext *' 211 * @param cls a `struct GNUNET_SERVER_TransmitContext *`
209 * @param key hash of sensor name, key to hashmap 212 * @param key hash of sensor name, key to hashmap
210 * @param value a 'struct SensorInfo *' 213 * @param value a `struct GNUNET_SENSOR_SensorInfo *`
211 */ 214 */
212int add_sensor_to_tc(void *cls, 215int add_sensor_to_tc (void *cls,
213 const struct GNUNET_HashCode *key, void *value) 216 const struct GNUNET_HashCode *key,
217 void *value)
214{ 218{
215 struct GNUNET_SERVER_TransmitContext *tc = cls; 219 struct GNUNET_SERVER_TransmitContext *tc = cls;
216 struct SensorInfo *sensorinfo = value; 220 struct GNUNET_SENSOR_SensorInfo *sensorinfo = value;
217 struct SensorInfoMessage *msg; 221 struct SensorInfoMessage *msg;
218 222
219 msg = create_sensor_info_msg(sensorinfo); 223 msg = create_sensor_info_msg(sensorinfo);
@@ -251,7 +255,7 @@ handle_get_all_sensors (void *cls, struct GNUNET_SERVER_Client *client,
251 * @return #GNUNET_YES / #GNUNET_NO 255 * @return #GNUNET_YES / #GNUNET_NO
252 */ 256 */
253static int 257static int
254should_run_sensor(struct SensorInfo *sensorinfo) 258should_run_sensor(struct GNUNET_SENSOR_SensorInfo *sensorinfo)
255{ 259{
256 struct GNUNET_TIME_Absolute now; 260 struct GNUNET_TIME_Absolute now;
257 261
@@ -280,7 +284,7 @@ should_run_sensor(struct SensorInfo *sensorinfo)
280/** 284/**
281 * Callback function to process statistic values 285 * Callback function to process statistic values
282 * 286 *
283 * @param cls 'struct SensorInfo *' 287 * @param cls `struct GNUNET_SENSOR_SensorInfo *`
284 * @param subsystem name of subsystem that created the statistic 288 * @param subsystem name of subsystem that created the statistic
285 * @param name the name of the datum 289 * @param name the name of the datum
286 * @param value the current value 290 * @param value the current value
@@ -293,7 +297,7 @@ int sensor_statistics_iterator (void *cls,
293 uint64_t value, 297 uint64_t value,
294 int is_persistent) 298 int is_persistent)
295{ 299{
296 struct SensorInfo *sensorinfo = cls; 300 struct GNUNET_SENSOR_SensorInfo *sensorinfo = cls;
297 double dvalue = (double)value; 301 double dvalue = (double)value;
298 struct GNUNET_TIME_Absolute expiry; 302 struct GNUNET_TIME_Absolute expiry;
299 303
@@ -315,13 +319,13 @@ int sensor_statistics_iterator (void *cls,
315/** 319/**
316 * Continuation called after sensor gets all gnunet statistics values 320 * Continuation called after sensor gets all gnunet statistics values
317 * 321 *
318 * @param cls 'struct SensorInfo *' 322 * @param cls `struct GNUNET_SENSOR_SensorInfo *`
319 * @param success #GNUNET_OK if statistics were 323 * @param success #GNUNET_OK if statistics were
320 * successfully obtained, #GNUNET_SYSERR if not. 324 * successfully obtained, #GNUNET_SYSERR if not.
321 */ 325 */
322void end_sensor_run_stat (void *cls, int success) 326void end_sensor_run_stat (void *cls, int success)
323{ 327{
324 struct SensorInfo *sensorinfo = cls; 328 struct GNUNET_SENSOR_SensorInfo *sensorinfo = cls;
325 329
326 sensorinfo->gnunet_stat_get_handle = NULL; 330 sensorinfo->gnunet_stat_get_handle = NULL;
327 sensorinfo->running = GNUNET_NO; 331 sensorinfo->running = GNUNET_NO;
@@ -337,7 +341,9 @@ void end_sensor_run_stat (void *cls, int success)
337 * @return size of new parsed value, 0 for error 341 * @return size of new parsed value, 0 for error
338 */ 342 */
339static size_t 343static size_t
340parse_sensor_value (const char *value, struct SensorInfo* sensor, void **ret) 344parse_sensor_value (const char *value,
345 struct GNUNET_SENSOR_SensorInfo *sensor,
346 void **ret)
341{ 347{
342 double *dval; 348 double *dval;
343 char *endptr; 349 char *endptr;
@@ -367,12 +373,12 @@ parse_sensor_value (const char *value, struct SensorInfo* sensor, void **ret)
367/** 373/**
368 * Callback for output of executed sensor process 374 * Callback for output of executed sensor process
369 * 375 *
370 * @param cls 'struct SensorInfo *' 376 * @param cls `struct GNUNET_SENSOR_SensorInfo *`
371 * @param line line of output from a command, NULL for the end 377 * @param line line of output from a command, NULL for the end
372 */ 378 */
373void sensor_process_callback (void *cls, const char *line) 379void sensor_process_callback (void *cls, const char *line)
374{ 380{
375 struct SensorInfo *sensorinfo = cls; 381 struct GNUNET_SENSOR_SensorInfo *sensorinfo = cls;
376 void *value; 382 void *value;
377 size_t valsize; 383 size_t valsize;
378 struct GNUNET_TIME_Absolute expiry; 384 struct GNUNET_TIME_Absolute expiry;
@@ -443,7 +449,7 @@ void
443sensor_run (void *cls, 449sensor_run (void *cls,
444 const struct GNUNET_SCHEDULER_TaskContext * tc) 450 const struct GNUNET_SCHEDULER_TaskContext * tc)
445{ 451{
446 struct SensorInfo *sensorinfo = cls; 452 struct GNUNET_SENSOR_SensorInfo *sensorinfo = cls;
447 int check_result; 453 int check_result;
448 char *sensors_dir; 454 char *sensors_dir;
449 char *process_path; 455 char *process_path;
@@ -530,7 +536,7 @@ sensor_run (void *cls,
530 * 536 *
531 * @param cls unused 537 * @param cls unused
532 * @param key hash of sensor name, key to hashmap (unused) 538 * @param key hash of sensor name, key to hashmap (unused)
533 * @param value a 'struct SensorInfo *' 539 * @param value a `struct GNUNET_SENSOR_SensorInfo *`
534 * @return #GNUNET_YES if we should continue to 540 * @return #GNUNET_YES if we should continue to
535 * iterate, 541 * iterate,
536 * #GNUNET_NO if not. 542 * #GNUNET_NO if not.
@@ -538,7 +544,7 @@ sensor_run (void *cls,
538int schedule_sensor(void *cls, 544int schedule_sensor(void *cls,
539 const struct GNUNET_HashCode *key, void *value) 545 const struct GNUNET_HashCode *key, void *value)
540{ 546{
541 struct SensorInfo *sensorinfo = value; 547 struct GNUNET_SENSOR_SensorInfo *sensorinfo = value;
542 548
543 if(GNUNET_NO == should_run_sensor(sensorinfo)) 549 if(GNUNET_NO == should_run_sensor(sensorinfo))
544 return GNUNET_YES; 550 return GNUNET_YES;
@@ -589,17 +595,17 @@ run (void *cls,
589 schedule_all_sensors(); 595 schedule_all_sensors();
590 SENSOR_analysis_start(c, sensors); 596 SENSOR_analysis_start(c, sensors);
591 SENSOR_reporting_start(c, sensors); 597 SENSOR_reporting_start(c, sensors);
592 SENSOR_update_start (c, sensors); 598 //SENSOR_update_start (c, sensors);
593 statistics = GNUNET_STATISTICS_create("sensor", cfg); 599 statistics = GNUNET_STATISTICS_create("sensor", cfg);
594 GNUNET_CRYPTO_get_peer_identity(cfg, &peerid); 600 GNUNET_CRYPTO_get_peer_identity(cfg, &peerid);
595 peerstore = GNUNET_PEERSTORE_connect(cfg); 601 peerstore = GNUNET_PEERSTORE_connect(cfg);
596 GNUNET_SERVER_add_handlers (server, handlers); 602 GNUNET_SERVER_add_handlers (server, handlers);
597 GNUNET_SERVER_disconnect_notify (server, 603 GNUNET_SERVER_disconnect_notify (server,
598 &handle_client_disconnect, 604 &handle_client_disconnect,
599 NULL); 605 NULL);
600 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 606 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
601 &shutdown_task, 607 &shutdown_task,
602 NULL); 608 NULL);
603} 609}
604 610
605 611
@@ -617,8 +623,8 @@ main (int argc, char *const *argv)
617 GNUNET_SERVICE_run (argc, 623 GNUNET_SERVICE_run (argc,
618 argv, 624 argv,
619 "sensor", 625 "sensor",
620 GNUNET_SERVICE_OPTION_NONE, 626 GNUNET_SERVICE_OPTION_NONE,
621 &run, NULL)) ? 0 : 1; 627 &run, NULL)) ? 0 : 1;
622} 628}
623 629
624/* end of gnunet-service-sensor.c */ 630/* end of gnunet-service-sensor.c */