diff options
author | Christian Grothoff <christian@grothoff.org> | 2009-11-04 14:10:32 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2009-11-04 14:10:32 +0000 |
commit | cf45b8dff29c366d51aa2e6ea6a64b99b514b9c9 (patch) | |
tree | 5cb37c041743daff5af528dbbe24f5c563ce702e /src/statistics/gnunet-service-statistics.c | |
parent | b91546a3de767292e6472c6b1927480adba43d88 (diff) | |
download | gnunet-cf45b8dff29c366d51aa2e6ea6a64b99b514b9c9.tar.gz gnunet-cf45b8dff29c366d51aa2e6ea6a64b99b514b9c9.zip |
bugfixes and redesigning scheduler API
Diffstat (limited to 'src/statistics/gnunet-service-statistics.c')
-rw-r--r-- | src/statistics/gnunet-service-statistics.c | 44 |
1 files changed, 32 insertions, 12 deletions
diff --git a/src/statistics/gnunet-service-statistics.c b/src/statistics/gnunet-service-statistics.c index 3221fe2ae..8de9a8047 100644 --- a/src/statistics/gnunet-service-statistics.c +++ b/src/statistics/gnunet-service-statistics.c | |||
@@ -83,6 +83,11 @@ struct StatsEntry | |||
83 | }; | 83 | }; |
84 | 84 | ||
85 | /** | 85 | /** |
86 | * Our configuration. | ||
87 | */ | ||
88 | static const struct GNUNET_CONFIGURATION_Handle *cfg; | ||
89 | |||
90 | /** | ||
86 | * Linked list of our active statistics. | 91 | * Linked list of our active statistics. |
87 | */ | 92 | */ |
88 | static struct StatsEntry *start; | 93 | static struct StatsEntry *start; |
@@ -96,10 +101,11 @@ static uint32_t uidgen; | |||
96 | * Load persistent values from disk. Disk format is | 101 | * Load persistent values from disk. Disk format is |
97 | * exactly the same format that we also use for | 102 | * exactly the same format that we also use for |
98 | * setting the values over the network. | 103 | * setting the values over the network. |
104 | * | ||
105 | * @param server handle to the server context | ||
99 | */ | 106 | */ |
100 | static void | 107 | static void |
101 | load (struct GNUNET_SERVER_Handle *server, | 108 | load (struct GNUNET_SERVER_Handle *server) |
102 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
103 | { | 109 | { |
104 | char *fn; | 110 | char *fn; |
105 | struct GNUNET_DISK_FileHandle *fh; | 111 | struct GNUNET_DISK_FileHandle *fh; |
@@ -153,16 +159,11 @@ load (struct GNUNET_SERVER_Handle *server, | |||
153 | GNUNET_free (fn); | 159 | GNUNET_free (fn); |
154 | } | 160 | } |
155 | 161 | ||
156 | |||
157 | /** | 162 | /** |
158 | * Write persistent statistics to disk. | 163 | * Write persistent statistics to disk. |
159 | * | ||
160 | * @param cls closure | ||
161 | * @param cfg configuration to use | ||
162 | */ | 164 | */ |
163 | static void | 165 | static void |
164 | save (void *cls, | 166 | save () |
165 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
166 | { | 167 | { |
167 | struct StatsEntry *pos; | 168 | struct StatsEntry *pos; |
168 | char *fn; | 169 | char *fn; |
@@ -435,21 +436,40 @@ static struct GNUNET_SERVER_MessageHandler handlers[] = { | |||
435 | 436 | ||
436 | 437 | ||
437 | /** | 438 | /** |
439 | * Task run during shutdown. | ||
440 | * | ||
441 | * @param cls unused | ||
442 | * @param tc unused | ||
443 | */ | ||
444 | static void | ||
445 | shutdown_task (void *cls, | ||
446 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
447 | { | ||
448 | save (); | ||
449 | } | ||
450 | |||
451 | |||
452 | /** | ||
438 | * Process statistics requests. | 453 | * Process statistics requests. |
439 | * | 454 | * |
440 | * @param cls closure | 455 | * @param cls closure |
441 | * @param sched scheduler to use | 456 | * @param sched scheduler to use |
442 | * @param server the initialized server | 457 | * @param server the initialized server |
443 | * @param cfg configuration to use | 458 | * @param c configuration to use |
444 | */ | 459 | */ |
445 | static void | 460 | static void |
446 | run (void *cls, | 461 | run (void *cls, |
447 | struct GNUNET_SCHEDULER_Handle *sched, | 462 | struct GNUNET_SCHEDULER_Handle *sched, |
448 | struct GNUNET_SERVER_Handle *server, | 463 | struct GNUNET_SERVER_Handle *server, |
449 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 464 | const struct GNUNET_CONFIGURATION_Handle *c) |
450 | { | 465 | { |
466 | cfg = c; | ||
451 | GNUNET_SERVER_add_handlers (server, handlers); | 467 | GNUNET_SERVER_add_handlers (server, handlers); |
452 | load (server, cfg); | 468 | load (server); |
469 | GNUNET_SCHEDULER_add_delayed (sched, | ||
470 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
471 | &shutdown_task, | ||
472 | NULL); | ||
453 | } | 473 | } |
454 | 474 | ||
455 | 475 | ||
@@ -466,7 +486,7 @@ main (int argc, char *const *argv) | |||
466 | return (GNUNET_OK == | 486 | return (GNUNET_OK == |
467 | GNUNET_SERVICE_run (argc, | 487 | GNUNET_SERVICE_run (argc, |
468 | argv, | 488 | argv, |
469 | "statistics", &run, NULL, &save, NULL)) ? 0 : 1; | 489 | "statistics", &run, NULL)) ? 0 : 1; |
470 | } | 490 | } |
471 | 491 | ||
472 | /* end of gnunet-service-statistics.c */ | 492 | /* end of gnunet-service-statistics.c */ |