gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r33165 - gnunet/src/sensor


From: gnunet
Subject: [GNUnet-SVN] r33165 - gnunet/src/sensor
Date: Mon, 5 May 2014 16:35:38 +0200

Author: otarabai
Date: 2014-05-05 16:35:38 +0200 (Mon, 05 May 2014)
New Revision: 33165

Modified:
   gnunet/src/sensor/gnunet-service-sensor.c
Log:
toward executing sensor processes


Modified: gnunet/src/sensor/gnunet-service-sensor.c
===================================================================
--- gnunet/src/sensor/gnunet-service-sensor.c   2014-05-05 13:09:00 UTC (rev 
33164)
+++ gnunet/src/sensor/gnunet-service-sensor.c   2014-05-05 14:35:38 UTC (rev 
33165)
@@ -154,11 +154,16 @@
    */
   struct GNUNET_TIME_Relative *p2p_interval;
 
-  /**
+  /*
    * Execution task (OR GNUNET_SCHEDULER_NO_TASK)
    */
   GNUNET_SCHEDULER_TaskIdentifier execution_task;
 
+  /*
+   * Is the sensor being executed
+   */
+  int running;
+
 };
 
 /**
@@ -186,6 +191,8 @@
  */
 struct GNUNET_STATISTICS_Handle *statistics;
 
+//TODO: logging macro that includes sensor info
+
 /**
  * Remove sensor execution from scheduler
  *
@@ -412,6 +419,8 @@
   //TODO: reporting mechanism
   //execution task
   sensor->execution_task = GNUNET_SCHEDULER_NO_TASK;
+  //running
+  sensor->running = GNUNET_NO;
 
   return sensor;
 }
@@ -706,6 +715,7 @@
 static int
 should_run_sensor(struct SensorInfo *sensorinfo)
 {
+  //FIXME: some checks should disable the sensor (e.g. expired)
   struct GNUNET_TIME_Absolute now;
 
   if(GNUNET_NO == sensorinfo->enabled)
@@ -752,21 +762,42 @@
 }
 
 /**
+ * Continuation called after sensor gets all gnunet statistics values
+ *
+ * @param cls 'struct SensorInfo *'
+ * @param success #GNUNET_OK if statistics were
+ *        successfully obtained, #GNUNET_SYSERR if not.
+ */
+void end_sensor_run_stat (void *cls, int success)
+{
+  struct SensorInfo *sensorinfo = cls;
+
+  sensorinfo->gnunet_stat_get_handle = NULL;
+  sensorinfo->running = GNUNET_NO;
+}
+
+/**
  * Actual execution of a sensor
  *
  * @param cls 'struct SensorInfo'
  * @param tc unsed
  */
 void
-run_sensor (void *cls,
+sensor_run (void *cls,
     const struct GNUNET_SCHEDULER_TaskContext * tc)
 {
   struct SensorInfo *sensorinfo = cls;
+  int check_result;
 
-  sensorinfo->execution_task = GNUNET_SCHEDULER_NO_TASK;
+  sensorinfo->execution_task = 
GNUNET_SCHEDULER_add_delayed(sensorinfo->interval, &sensor_run, sensorinfo);
+  if(GNUNET_YES == sensorinfo->running) //FIXME: should we try to kill?
+  {
+    GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Sensor `%s' running for too long, 
will try again next interval\n", sensorinfo->name);
+    return;
+  }
   if(GNUNET_NO == should_run_sensor(sensorinfo))
     return;
-  sensorinfo->execution_task = 
GNUNET_SCHEDULER_add_delayed(sensorinfo->interval, &run_sensor, sensorinfo);
+  sensorinfo->running = GNUNET_YES;
   GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Starting the execution of sensor 
`%s'\n", sensorinfo->name);
   if(sources[0] == sensorinfo->source) //gnunet-statistics
   {
@@ -777,18 +808,48 @@
     sensorinfo->gnunet_stat_get_handle = GNUNET_STATISTICS_get(statistics,
         sensorinfo->gnunet_stat_service,
         sensorinfo->gnunet_stat_name,
-        GNUNET_TIME_UNIT_FOREVER_REL,
-        NULL,
+        sensorinfo->interval, //try to get values only for the interval of the 
sensor
+        &end_sensor_run_stat,
         &sensor_statistics_iterator,
         sensorinfo);
   }
+  else if(sources[1] == sensorinfo->source)
+  {
+    //check if the process exists in $PATH
+    check_result =
+        GNUNET_OS_check_helper_binary(sensorinfo->ext_process, GNUNET_NO, 
NULL); //search in $PATH
+    if(GNUNET_SYSERR == check_result)
+    {
+      //search in sensor directory
+
+    }
+    if(GNUNET_SYSERR == check_result)
+    {
+      GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Sensor `%s' process `%s' problem: 
binary doesn't exist or not executable\n",
+          sensorinfo->name,
+          sensorinfo->ext_process);
+      //FIXME: disable sensor here?
+      sensorinfo->running = GNUNET_NO;
+      return;
+    }
+    else if(GNUNET_NO == check_result)
+    {
+
+    }
+    GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Process started for sensor `%s'\n", 
sensorinfo->name);
+  }
+  else
+  {
+    sensorinfo->running = GNUNET_NO;
+    GNUNET_break(0); //shouldn't happen
+  }
 }
 
 /**
  * Starts the execution of a sensor
  *
  * @param cls unused
- * @param key hash of sensor name, key to hashmap
+ * @param key hash of sensor name, key to hashmap (unused)
  * @param value a 'struct SensorInfo *'
  * @return #GNUNET_YES if we should continue to
  *         iterate,
@@ -808,7 +869,7 @@
     GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Sensor `%s' execution task already 
set, this should not happen\n", sensorinfo->name);
     return GNUNET_NO;
   }
-  sensorinfo->execution_task = 
GNUNET_SCHEDULER_add_delayed(sensorinfo->interval, &run_sensor, sensorinfo);
+  sensorinfo->execution_task = 
GNUNET_SCHEDULER_add_delayed(sensorinfo->interval, &sensor_run, sensorinfo);
   return GNUNET_YES;
 }
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]