aboutsummaryrefslogtreecommitdiff
path: root/src/sensor/gnunet-service-sensor.c
diff options
context:
space:
mode:
authorOmar Tarabai <tarabai@devegypt.com>2014-07-27 01:23:58 +0000
committerOmar Tarabai <tarabai@devegypt.com>2014-07-27 01:23:58 +0000
commit0ea6bab62cd1d29e32c5d442d865e1b6bf82bef1 (patch)
treebde73567c1341bdff909f64de851dd7178e58ca3 /src/sensor/gnunet-service-sensor.c
parent29f73bb496a579a5a7600b3e3b2ab88b859bee65 (diff)
downloadgnunet-0ea6bab62cd1d29e32c5d442d865e1b6bf82bef1.tar.gz
gnunet-0ea6bab62cd1d29e32c5d442d865e1b6bf82bef1.zip
sensor: completed update functionality
Diffstat (limited to 'src/sensor/gnunet-service-sensor.c')
-rw-r--r--src/sensor/gnunet-service-sensor.c61
1 files changed, 52 insertions, 9 deletions
diff --git a/src/sensor/gnunet-service-sensor.c b/src/sensor/gnunet-service-sensor.c
index e476db50c..4f2942fec 100644
--- a/src/sensor/gnunet-service-sensor.c
+++ b/src/sensor/gnunet-service-sensor.c
@@ -60,6 +60,15 @@ char *subsystem = "sensor";
60 */ 60 */
61struct GNUNET_PeerIdentity peerid; 61struct GNUNET_PeerIdentity peerid;
62 62
63
64/**
65 * Resets the service by stopping components, reloading sensors and starting
66 * components. This is needed when we receive new sensor updates.
67 */
68static void
69reset ();
70
71
63/** 72/**
64 * Change the state of the sensor. 73 * Change the state of the sensor.
65 * Write the change to file to make it persistent. 74 * Write the change to file to make it persistent.
@@ -82,6 +91,20 @@ set_sensor_enabled (struct GNUNET_SENSOR_SensorInfo *sensor, int state)
82 GNUNET_CONFIGURATION_write (sensor->cfg, sensor->def_file); 91 GNUNET_CONFIGURATION_write (sensor->cfg, sensor->def_file);
83} 92}
84 93
94
95/**
96 * Stops components and destroys sensors
97 */
98static void
99stop ()
100{
101 SENSOR_update_stop ();
102 SENSOR_reporting_stop ();
103 SENSOR_analysis_stop ();
104 GNUNET_SENSOR_destroy_sensors (sensors);
105}
106
107
85/** 108/**
86 * Task run during shutdown. 109 * Task run during shutdown.
87 * 110 *
@@ -92,10 +115,7 @@ static void
92shutdown_task (void *cls, 115shutdown_task (void *cls,
93 const struct GNUNET_SCHEDULER_TaskContext *tc) 116 const struct GNUNET_SCHEDULER_TaskContext *tc)
94{ 117{
95 SENSOR_update_stop (); 118 stop ();
96 SENSOR_reporting_stop ();
97 SENSOR_analysis_stop ();
98 GNUNET_SENSOR_destroy_sensors (sensors);
99 if (NULL != statistics) 119 if (NULL != statistics)
100 { 120 {
101 GNUNET_STATISTICS_destroy (statistics, GNUNET_YES); 121 GNUNET_STATISTICS_destroy (statistics, GNUNET_YES);
@@ -575,6 +595,21 @@ schedule_all_sensors()
575 GNUNET_CONTAINER_multihashmap_iterate(sensors, &schedule_sensor, NULL); 595 GNUNET_CONTAINER_multihashmap_iterate(sensors, &schedule_sensor, NULL);
576} 596}
577 597
598
599/**
600 * Loads sensors and starts different service components
601 */
602static void
603start ()
604{
605 sensors = GNUNET_SENSOR_load_all_sensors ();
606 schedule_all_sensors();
607 SENSOR_analysis_start(cfg, sensors);
608 SENSOR_reporting_start(cfg, sensors);
609 SENSOR_update_start (cfg, sensors, &reset);
610}
611
612
578/** 613/**
579 * Process statistics requests. 614 * Process statistics requests.
580 * 615 *
@@ -596,11 +631,6 @@ run (void *cls,
596 }; 631 };
597 632
598 cfg = c; 633 cfg = c;
599 sensors = GNUNET_SENSOR_load_all_sensors ();
600 schedule_all_sensors();
601 SENSOR_analysis_start(c, sensors);
602 SENSOR_reporting_start(c, sensors);
603 SENSOR_update_start (c, sensors);
604 statistics = GNUNET_STATISTICS_create("sensor", cfg); 634 statistics = GNUNET_STATISTICS_create("sensor", cfg);
605 GNUNET_CRYPTO_get_peer_identity(cfg, &peerid); 635 GNUNET_CRYPTO_get_peer_identity(cfg, &peerid);
606 peerstore = GNUNET_PEERSTORE_connect(cfg); 636 peerstore = GNUNET_PEERSTORE_connect(cfg);
@@ -611,6 +641,19 @@ run (void *cls,
611 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 641 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
612 &shutdown_task, 642 &shutdown_task,
613 NULL); 643 NULL);
644 start ();
645}
646
647
648/**
649 * Resets the service by stopping components, reloading sensors and starting
650 * components. This is needed when we receive new sensor updates.
651 */
652static void
653reset ()
654{
655 stop ();
656 start ();
614} 657}
615 658
616 659