2 This file is part of GNUnet.
3 (C) 2009 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file experimentation/gnunet-daemon-experimentation_scheduler.c
23 * @brief experimentation daemon: execute experiments
24 * @author Christian Grothoff
25 * @author Matthias Wachs
28 #include "gnunet_getopt_lib.h"
29 #include "gnunet_util_lib.h"
30 #include "gnunet_core_service.h"
31 #include "gnunet_statistics_service.h"
32 #include "gnunet-daemon-experimentation.h"
34 struct ScheduledExperiment {
35 struct ScheduledExperiment *next;
36 struct ScheduledExperiment *prev;
39 GNUNET_SCHEDULER_TaskIdentifier task;
42 struct ScheduledExperiment *list_head;
43 struct ScheduledExperiment *list_tail;
46 static void run (void *cls,const struct GNUNET_SCHEDULER_TaskContext* tc)
48 struct ScheduledExperiment *se = cls;
49 //struct GNUNET_TIME_Relative end;
50 se->task = GNUNET_SCHEDULER_NO_TASK;
52 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Running `%s'\n", se->e->name);
54 // end = GNUNET_TIME_absolute_get_remaining(se->e->stop);
55 // if (0 < end.rel_value)
56 // return; /* End of experiment is reached */
59 se->task = GNUNET_SCHEDULER_add_delayed (se->e->frequency, &run, se);
63 * Start the scheduler component
66 GNUNET_EXPERIMENTATION_scheduler_add (struct Experiment *e)
68 struct ScheduledExperiment *se;
69 struct GNUNET_TIME_Relative start;
70 struct GNUNET_TIME_Relative end;
72 start = GNUNET_TIME_absolute_get_remaining(e->start);
73 end = GNUNET_TIME_absolute_get_remaining(e->stop);
75 if (0 == end.rel_value)
76 return; /* End of experiment is reached */
78 se = GNUNET_malloc (sizeof (struct ScheduledExperiment));
80 if (0 == start.rel_value)
81 se->task = GNUNET_SCHEDULER_add_now (&run, se);
83 se->task = GNUNET_SCHEDULER_add_delayed (start, &run, se);
85 GNUNET_CONTAINER_DLL_insert (list_head, list_tail, se);
86 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Scheduled `%s'\n", e->name);
90 * Start the scheduler component
93 GNUNET_EXPERIMENTATION_scheduler_start ()
100 * Stop the scheduler component
103 GNUNET_EXPERIMENTATION_scheduler_stop ()
105 struct ScheduledExperiment *cur;
106 struct ScheduledExperiment *next;
109 while (NULL != (cur = next))
112 GNUNET_CONTAINER_DLL_remove (list_head, list_tail, cur);
113 if (GNUNET_SCHEDULER_NO_TASK != cur->task)
115 GNUNET_SCHEDULER_cancel (cur->task);
116 cur->task = GNUNET_SCHEDULER_NO_TASK;
122 /* end of gnunet-daemon-experimentation_scheduler.c */