Merge branch 'getopt'
[oweals/gnunet.git] / src / util / test_scheduler.c
index 70ff95550736a6566985ea1ebd984713087c650a..55d4c7137e5366e662f2d52a0703665cfd714435 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2009 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2009 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.
 */
 /**
  * @file util/test_scheduler.c
 #include "gnunet_util_lib.h"
 
 
-struct GNUNET_DISK_PipeHandle *p;
+static struct GNUNET_DISK_PipeHandle *p;
 
 static const struct GNUNET_DISK_FileHandle *fds[2];
 
 
 static void
-task2 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+task2 (void *cls)
 {
   int *ok = cls;
 
@@ -44,7 +44,7 @@ task2 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 
 
 static void
-task3 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+task3 (void *cls)
 {
   int *ok = cls;
 
@@ -54,11 +54,13 @@ task3 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 
 
 static void
-taskWrt (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+taskWrt (void *cls)
 {
   static char c;
   int *ok = cls;
+  const struct GNUNET_SCHEDULER_TaskContext *tc;
 
+  tc = GNUNET_SCHEDULER_get_task_context ();
   GNUNET_assert (6 == *ok);
   GNUNET_assert (GNUNET_NETWORK_fdset_handle_isset (tc->write_ready, fds[1]));
   (*ok) = 7;
@@ -67,41 +69,42 @@ taskWrt (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 
 
 static void
-taskNeverRun (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+taskNeverRun (void *cls)
 {
   GNUNET_assert (0);
 }
 
 
 static void
-taskLast (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+taskLast (void *cls)
 {
   int *ok = cls;
 
-  /* t4 should be ready (albeit with lower priority) */
   GNUNET_assert (8 == *ok);
   (*ok) = 0;
 }
 
 
 static void
-taskRd (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+taskRd (void *cls)
 {
   static char c;
   int *ok = cls;
+  const struct GNUNET_SCHEDULER_TaskContext *tc;
 
+  tc = GNUNET_SCHEDULER_get_task_context ();
   GNUNET_assert (7 == *ok);
   GNUNET_assert (GNUNET_NETWORK_fdset_handle_isset (tc->read_ready, fds[0]));
   GNUNET_assert (1 == GNUNET_DISK_file_read (fds[0], &c, 1));
   (*ok) = 8;
-  GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, &taskLast,
-                                      cls);
+  GNUNET_SCHEDULER_add_shutdown (&taskLast,
+                                cls);
   GNUNET_SCHEDULER_shutdown ();
 }
 
 
 static void
-task4 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+task4 (void *cls)
 {
   int *ok = cls;
 
@@ -111,24 +114,31 @@ task4 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   GNUNET_assert (NULL != p);
   fds[0] = GNUNET_DISK_pipe_handle (p, GNUNET_DISK_PIPE_END_READ);
   fds[1] = GNUNET_DISK_pipe_handle (p, GNUNET_DISK_PIPE_END_WRITE);
-  GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, fds[0], &taskRd,
+  GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
+                                 fds[0],
+                                 &taskRd,
                                   cls);
-  GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, fds[1],
-                                   &taskWrt, cls);
+  GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
+                                  fds[1],
+                                   &taskWrt,
+                                  cls);
 }
 
 
 static void
-task1 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+task1 (void *cls)
 {
   int *ok = cls;
 
   GNUNET_assert (1 == *ok);
   (*ok) = 2;
   GNUNET_SCHEDULER_add_now (&task3, cls);
-  GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_UI, &task2,
+  GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_UI,
+                                     &task2,
                                       cls);
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &task4, cls);
+  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+                               &task4,
+                               cls);
 }
 
 
@@ -148,13 +158,13 @@ check ()
 
 
 static void
-taskShutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+taskShutdown (void *cls)
 {
   int *ok = cls;
 
   GNUNET_assert (1 == *ok);
   *ok = 8;
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &taskLast, cls);
+  GNUNET_SCHEDULER_add_shutdown (&taskLast, cls);
   GNUNET_SCHEDULER_shutdown ();
 }
 
@@ -176,14 +186,15 @@ checkShutdown ()
 
 #ifndef MINGW
 static void
-taskSig (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+taskSig (void *cls)
 {
   int *ok = cls;
 
   GNUNET_assert (1 == *ok);
   *ok = 8;
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &taskLast, cls);
-  GNUNET_break (0 == PLIBC_KILL (getpid (), SIGTERM));
+  GNUNET_SCHEDULER_add_shutdown (&taskLast, cls);
+  GNUNET_break (0 == PLIBC_KILL (getpid (),
+                                GNUNET_TERM_SIG));
 }
 
 
@@ -204,14 +215,13 @@ checkSignal ()
 
 
 static void
-taskCancel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+taskCancel (void *cls)
 {
   int *ok = cls;
 
   GNUNET_assert (1 == *ok);
   *ok = 0;
-  GNUNET_SCHEDULER_cancel (GNUNET_SCHEDULER_add_now
-                           (&taskNeverRun, NULL));
+  GNUNET_SCHEDULER_cancel (GNUNET_SCHEDULER_add_now (&taskNeverRun, NULL));
 }