aboutsummaryrefslogtreecommitdiff
path: root/src/sensor
diff options
context:
space:
mode:
authorOmar Tarabai <tarabai@devegypt.com>2014-05-05 14:35:38 +0000
committerOmar Tarabai <tarabai@devegypt.com>2014-05-05 14:35:38 +0000
commit5b96946e6dcb61d9b32227bc510f2a8ea0a96893 (patch)
tree5e352c11a7d1869a5603161a402c952722053ac4 /src/sensor
parent04763dd4b84cafbdab8eb8b60f02a36173aad412 (diff)
downloadgnunet-5b96946e6dcb61d9b32227bc510f2a8ea0a96893.tar.gz
gnunet-5b96946e6dcb61d9b32227bc510f2a8ea0a96893.zip
toward executing sensor processes
Diffstat (limited to 'src/sensor')
-rw-r--r--src/sensor/gnunet-service-sensor.c77
1 files changed, 69 insertions, 8 deletions
diff --git a/src/sensor/gnunet-service-sensor.c b/src/sensor/gnunet-service-sensor.c
index d500cbec9..7718fafee 100644
--- a/src/sensor/gnunet-service-sensor.c
+++ b/src/sensor/gnunet-service-sensor.c
@@ -154,11 +154,16 @@ struct SensorInfo
154 */ 154 */
155 struct GNUNET_TIME_Relative *p2p_interval; 155 struct GNUNET_TIME_Relative *p2p_interval;
156 156
157 /** 157 /*
158 * Execution task (OR GNUNET_SCHEDULER_NO_TASK) 158 * Execution task (OR GNUNET_SCHEDULER_NO_TASK)
159 */ 159 */
160 GNUNET_SCHEDULER_TaskIdentifier execution_task; 160 GNUNET_SCHEDULER_TaskIdentifier execution_task;
161 161
162 /*
163 * Is the sensor being executed
164 */
165 int running;
166
162}; 167};
163 168
164/** 169/**
@@ -186,6 +191,8 @@ static const char *datatypes[] = { "uint64", "double", "string", NULL };
186 */ 191 */
187struct GNUNET_STATISTICS_Handle *statistics; 192struct GNUNET_STATISTICS_Handle *statistics;
188 193
194//TODO: logging macro that includes sensor info
195
189/** 196/**
190 * Remove sensor execution from scheduler 197 * Remove sensor execution from scheduler
191 * 198 *
@@ -412,6 +419,8 @@ load_sensor_from_cfg(struct GNUNET_CONFIGURATION_Handle *cfg, const char *sectio
412 //TODO: reporting mechanism 419 //TODO: reporting mechanism
413 //execution task 420 //execution task
414 sensor->execution_task = GNUNET_SCHEDULER_NO_TASK; 421 sensor->execution_task = GNUNET_SCHEDULER_NO_TASK;
422 //running
423 sensor->running = GNUNET_NO;
415 424
416 return sensor; 425 return sensor;
417} 426}
@@ -706,6 +715,7 @@ handle_get_all_sensors (void *cls, struct GNUNET_SERVER_Client *client,
706static int 715static int
707should_run_sensor(struct SensorInfo *sensorinfo) 716should_run_sensor(struct SensorInfo *sensorinfo)
708{ 717{
718 //FIXME: some checks should disable the sensor (e.g. expired)
709 struct GNUNET_TIME_Absolute now; 719 struct GNUNET_TIME_Absolute now;
710 720
711 if(GNUNET_NO == sensorinfo->enabled) 721 if(GNUNET_NO == sensorinfo->enabled)
@@ -752,21 +762,42 @@ int sensor_statistics_iterator (void *cls,
752} 762}
753 763
754/** 764/**
765 * Continuation called after sensor gets all gnunet statistics values
766 *
767 * @param cls 'struct SensorInfo *'
768 * @param success #GNUNET_OK if statistics were
769 * successfully obtained, #GNUNET_SYSERR if not.
770 */
771void end_sensor_run_stat (void *cls, int success)
772{
773 struct SensorInfo *sensorinfo = cls;
774
775 sensorinfo->gnunet_stat_get_handle = NULL;
776 sensorinfo->running = GNUNET_NO;
777}
778
779/**
755 * Actual execution of a sensor 780 * Actual execution of a sensor
756 * 781 *
757 * @param cls 'struct SensorInfo' 782 * @param cls 'struct SensorInfo'
758 * @param tc unsed 783 * @param tc unsed
759 */ 784 */
760void 785void
761run_sensor (void *cls, 786sensor_run (void *cls,
762 const struct GNUNET_SCHEDULER_TaskContext * tc) 787 const struct GNUNET_SCHEDULER_TaskContext * tc)
763{ 788{
764 struct SensorInfo *sensorinfo = cls; 789 struct SensorInfo *sensorinfo = cls;
790 int check_result;
765 791
766 sensorinfo->execution_task = GNUNET_SCHEDULER_NO_TASK; 792 sensorinfo->execution_task = GNUNET_SCHEDULER_add_delayed(sensorinfo->interval, &sensor_run, sensorinfo);
793 if(GNUNET_YES == sensorinfo->running) //FIXME: should we try to kill?
794 {
795 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Sensor `%s' running for too long, will try again next interval\n", sensorinfo->name);
796 return;
797 }
767 if(GNUNET_NO == should_run_sensor(sensorinfo)) 798 if(GNUNET_NO == should_run_sensor(sensorinfo))
768 return; 799 return;
769 sensorinfo->execution_task = GNUNET_SCHEDULER_add_delayed(sensorinfo->interval, &run_sensor, sensorinfo); 800 sensorinfo->running = GNUNET_YES;
770 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Starting the execution of sensor `%s'\n", sensorinfo->name); 801 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Starting the execution of sensor `%s'\n", sensorinfo->name);
771 if(sources[0] == sensorinfo->source) //gnunet-statistics 802 if(sources[0] == sensorinfo->source) //gnunet-statistics
772 { 803 {
@@ -777,18 +808,48 @@ run_sensor (void *cls,
777 sensorinfo->gnunet_stat_get_handle = GNUNET_STATISTICS_get(statistics, 808 sensorinfo->gnunet_stat_get_handle = GNUNET_STATISTICS_get(statistics,
778 sensorinfo->gnunet_stat_service, 809 sensorinfo->gnunet_stat_service,
779 sensorinfo->gnunet_stat_name, 810 sensorinfo->gnunet_stat_name,
780 GNUNET_TIME_UNIT_FOREVER_REL, 811 sensorinfo->interval, //try to get values only for the interval of the sensor
781 NULL, 812 &end_sensor_run_stat,
782 &sensor_statistics_iterator, 813 &sensor_statistics_iterator,
783 sensorinfo); 814 sensorinfo);
784 } 815 }
816 else if(sources[1] == sensorinfo->source)
817 {
818 //check if the process exists in $PATH
819 check_result =
820 GNUNET_OS_check_helper_binary(sensorinfo->ext_process, GNUNET_NO, NULL); //search in $PATH
821 if(GNUNET_SYSERR == check_result)
822 {
823 //search in sensor directory
824
825 }
826 if(GNUNET_SYSERR == check_result)
827 {
828 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Sensor `%s' process `%s' problem: binary doesn't exist or not executable\n",
829 sensorinfo->name,
830 sensorinfo->ext_process);
831 //FIXME: disable sensor here?
832 sensorinfo->running = GNUNET_NO;
833 return;
834 }
835 else if(GNUNET_NO == check_result)
836 {
837
838 }
839 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Process started for sensor `%s'\n", sensorinfo->name);
840 }
841 else
842 {
843 sensorinfo->running = GNUNET_NO;
844 GNUNET_break(0); //shouldn't happen
845 }
785} 846}
786 847
787/** 848/**
788 * Starts the execution of a sensor 849 * Starts the execution of a sensor
789 * 850 *
790 * @param cls unused 851 * @param cls unused
791 * @param key hash of sensor name, key to hashmap 852 * @param key hash of sensor name, key to hashmap (unused)
792 * @param value a 'struct SensorInfo *' 853 * @param value a 'struct SensorInfo *'
793 * @return #GNUNET_YES if we should continue to 854 * @return #GNUNET_YES if we should continue to
794 * iterate, 855 * iterate,
@@ -808,7 +869,7 @@ int schedule_sensor(void *cls,
808 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Sensor `%s' execution task already set, this should not happen\n", sensorinfo->name); 869 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Sensor `%s' execution task already set, this should not happen\n", sensorinfo->name);
809 return GNUNET_NO; 870 return GNUNET_NO;
810 } 871 }
811 sensorinfo->execution_task = GNUNET_SCHEDULER_add_delayed(sensorinfo->interval, &run_sensor, sensorinfo); 872 sensorinfo->execution_task = GNUNET_SCHEDULER_add_delayed(sensorinfo->interval, &sensor_run, sensorinfo);
812 return GNUNET_YES; 873 return GNUNET_YES;
813} 874}
814 875