-fix off-by-1
[oweals/gnunet.git] / src / statistics / statistics_api.c
index 52d49308aba7dc6b29278228fcfa087581d2d399..32b973eeccfe8af5ab306a6a7ee536c018af0625 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2009, 2010, 2011 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2009, 2010, 2011 GNUnet e.V.
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -14,8 +14,8 @@
 
      You should have received a copy of the GNU General Public License
      along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-     Boston, MA 02111-1307, USA.
+     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+     Boston, MA 02110-1301, USA.
 */
 
 /**
@@ -149,7 +149,7 @@ struct GNUNET_STATISTICS_GetHandle
   /**
    * Task run on timeout.
    */
-  GNUNET_SCHEDULER_TaskIdentifier timeout_task;
+  struct GNUNET_SCHEDULER_Task * timeout_task;
 
   /**
    * Associated value.
@@ -230,7 +230,7 @@ struct GNUNET_STATISTICS_Handle
   /**
    * Task doing exponential back-off trying to reconnect.
    */
-  GNUNET_SCHEDULER_TaskIdentifier backoff_task;
+  struct GNUNET_SCHEDULER_Task * backoff_task;
 
   /**
    * Time for next connect retry.
@@ -367,10 +367,10 @@ schedule_watch_request (struct GNUNET_STATISTICS_Handle *h,
 static void
 free_action_item (struct GNUNET_STATISTICS_GetHandle *gh)
 {
-  if (GNUNET_SCHEDULER_NO_TASK != gh->timeout_task)
+  if (NULL != gh->timeout_task)
   {
     GNUNET_SCHEDULER_cancel (gh->timeout_task);
-    gh->timeout_task = GNUNET_SCHEDULER_NO_TASK;
+    gh->timeout_task = NULL;
   }
   GNUNET_free_non_null (gh->subsystem);
   GNUNET_free_non_null (gh->name);
@@ -426,7 +426,7 @@ try_connect (struct GNUNET_STATISTICS_Handle *h)
   struct GNUNET_STATISTICS_GetHandle *gn;
   unsigned int i;
 
-  if (GNUNET_SCHEDULER_NO_TASK != h->backoff_task)
+  if (NULL != h->backoff_task)
     return GNUNET_NO;
   if (NULL != h->client)
     return GNUNET_YES;
@@ -462,15 +462,13 @@ try_connect (struct GNUNET_STATISTICS_Handle *h)
  * We've waited long enough, reconnect now.
  *
  * @param cls the `struct GNUNET_STATISTICS_Handle` to reconnect
- * @param tc scheduler context (unused)
  */
 static void
-reconnect_task (void *cls,
-                const struct GNUNET_SCHEDULER_TaskContext *tc)
+reconnect_task (void *cls)
 {
   struct GNUNET_STATISTICS_Handle *h = cls;
 
-  h->backoff_task = GNUNET_SCHEDULER_NO_TASK;
+  h->backoff_task = NULL;
   schedule_action (h);
 }
 
@@ -479,11 +477,9 @@ reconnect_task (void *cls,
  * Task used by 'reconnect_later' to shutdown the handle
  *
  * @param cls the statistics handle
- * @param tc scheduler context
  */
 static void
-do_destroy (void *cls,
-            const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_destroy (void *cls)
 {
   struct GNUNET_STATISTICS_Handle *h = cls;
 
@@ -502,7 +498,7 @@ reconnect_later (struct GNUNET_STATISTICS_Handle *h)
   int loss;
   struct GNUNET_STATISTICS_GetHandle *gh;
 
-  GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == h->backoff_task);
+  GNUNET_assert (NULL == h->backoff_task);
   if (GNUNET_YES == h->do_destroy)
   {
     /* So we are shutting down and the service is not reachable.
@@ -518,8 +514,7 @@ reconnect_later (struct GNUNET_STATISTICS_Handle *h)
       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                  _("Could not save some persistent statistics\n"));
     h->do_destroy = GNUNET_NO;
-    GNUNET_SCHEDULER_add_continuation (&do_destroy, h,
-                                      GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+    GNUNET_SCHEDULER_add_now (&do_destroy, h);
     return;
   }
   h->backoff_task =
@@ -628,11 +623,9 @@ process_watch_value (struct GNUNET_STATISTICS_Handle *h,
  * Task used to destroy the statistics handle.
  *
  * @param cls the `struct GNUNET_STATISTICS_Handle`
- * @param tc the scheduler context
  */
 static void
-destroy_task (void *cls,
-             const struct GNUNET_SCHEDULER_TaskContext *tc)
+destroy_task (void *cls)
 {
   struct GNUNET_STATISTICS_Handle *h = cls;
 
@@ -674,8 +667,7 @@ receive_stats (void *cls,
       return;
     }
     h->do_destroy = GNUNET_NO;
-    GNUNET_SCHEDULER_add_continuation (&destroy_task, h,
-                                      GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+    GNUNET_SCHEDULER_add_now (&destroy_task, h);
     break;
   case GNUNET_MESSAGE_TYPE_STATISTICS_END:
     LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -992,10 +984,10 @@ GNUNET_STATISTICS_destroy (struct GNUNET_STATISTICS_Handle *h,
   if (NULL == h)
     return;
   GNUNET_assert (GNUNET_NO == h->do_destroy); // Don't call twice.
-  if (GNUNET_SCHEDULER_NO_TASK != h->backoff_task)
+  if (NULL != h->backoff_task)
   {
     GNUNET_SCHEDULER_cancel (h->backoff_task);
-    h->backoff_task = GNUNET_SCHEDULER_NO_TASK;
+    h->backoff_task = NULL;
   }
   if (sync_first)
   {
@@ -1089,8 +1081,7 @@ transmit_test_on_shutdown (void *cls,
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                _("Failed to receive acknowledgement from statistics service, some statistics might have been lost!\n"));
     h->do_destroy = GNUNET_NO;
-    GNUNET_SCHEDULER_add_continuation (&destroy_task, h,
-                                      GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+    GNUNET_SCHEDULER_add_now (&destroy_task, h);
     return 0;
   }
   hdr.type = htons (GNUNET_MESSAGE_TYPE_TEST);
@@ -1117,7 +1108,7 @@ schedule_action (struct GNUNET_STATISTICS_Handle *h)
   struct GNUNET_TIME_Relative timeout;
 
   if ( (NULL != h->th) ||
-       (GNUNET_SCHEDULER_NO_TASK != h->backoff_task) )
+       (NULL != h->backoff_task) )
     return;                     /* action already pending */
   if (GNUNET_YES != try_connect (h))
   {
@@ -1162,17 +1153,15 @@ schedule_action (struct GNUNET_STATISTICS_Handle *h)
  * call the continuation.
  *
  * @param cls the `struct GNUNET_STATISTICS_GetHandle`
- * @param tc scheduler context
  */
 static void
-run_get_timeout (void *cls,
-                 const struct GNUNET_SCHEDULER_TaskContext *tc)
+run_get_timeout (void *cls)
 {
   struct GNUNET_STATISTICS_GetHandle *gh = cls;
   GNUNET_STATISTICS_Callback cont = gh->cont;
   void *cont_cls = gh->cls;
 
-  gh->timeout_task = GNUNET_SCHEDULER_NO_TASK;
+  gh->timeout_task = NULL;
   GNUNET_STATISTICS_get_cancel (gh);
   cont (cont_cls, GNUNET_SYSERR);
 }
@@ -1228,7 +1217,8 @@ GNUNET_STATISTICS_get (struct GNUNET_STATISTICS_Handle *handle,
   ai->timeout_task = GNUNET_SCHEDULER_add_delayed (timeout,
                                                    &run_get_timeout,
                                                    ai);
-  GNUNET_CONTAINER_DLL_insert_tail (handle->action_head, handle->action_tail,
+  GNUNET_CONTAINER_DLL_insert_tail (handle->action_head,
+                                   handle->action_tail,
                                    ai);
   schedule_action (handle);
   return ai;
@@ -1246,10 +1236,10 @@ GNUNET_STATISTICS_get_cancel (struct GNUNET_STATISTICS_GetHandle *gh)
 {
   if (NULL == gh)
     return;
-  if (GNUNET_SCHEDULER_NO_TASK != gh->timeout_task)
+  if (NULL != gh->timeout_task)
   {
     GNUNET_SCHEDULER_cancel (gh->timeout_task);
-    gh->timeout_task = GNUNET_SCHEDULER_NO_TASK;
+    gh->timeout_task = NULL;
   }
   gh->cont = NULL;
   if (gh->sh->current == gh)