Initial commit of the HEAD branch of the ELinks CVS repository, as of
[elinks/images.git] / src / config / timer.c
blob42b12ba031b07577a0c433adc5d819fea8658d80
1 /* Periodic saving module */
2 /* $Id: timer.c,v 1.5 2005/09/08 14:04:09 zas Exp $ */
4 #ifdef HAVE_CONFIG_H
5 #include "config.h"
6 #endif
8 #include "elinks.h"
10 #include "config/options.h"
11 #include "config/timer.h"
12 #include "intl/gettext/libintl.h"
13 #include "main/event.h"
14 #include "main/module.h"
15 #include "main/timer.h"
16 #include "util/time.h"
19 /* Timer for periodically saving configuration files to disk */
20 static timer_id_T periodic_save_timer = TIMER_ID_UNDEF;
22 static void
23 periodic_save_handler(void *xxx)
25 static int periodic_save_event_id = EVENT_NONE;
26 milliseconds_T interval;
28 if (get_cmd_opt_bool("anonymous")) return;
30 /* Don't trigger anything at startup */
31 if (periodic_save_event_id == EVENT_NONE)
32 set_event_id(periodic_save_event_id, "periodic-saving");
33 else
34 trigger_event(periodic_save_event_id);
36 interval = sec_to_ms(get_opt_int("infofiles.save_interval"));
37 if (!interval) return;
39 install_timer(&periodic_save_timer, interval, periodic_save_handler, NULL);
42 static int
43 periodic_save_change_hook(struct session *ses, struct option *current,
44 struct option *changed)
46 if (get_cmd_opt_bool("anonymous")) return 0;
48 kill_timer(&periodic_save_timer);
50 periodic_save_handler(NULL);
52 return 0;
55 static void
56 init_timer(struct module *module)
58 struct change_hook_info timer_change_hooks[] = {
59 { "infofiles.save_interval", periodic_save_change_hook },
60 { NULL, NULL },
63 register_change_hooks(timer_change_hooks);
64 periodic_save_handler(NULL);
67 static void
68 done_timer(struct module *module)
70 kill_timer(&periodic_save_timer);
73 struct module periodic_saving_module = struct_module(
74 /* name: */ N_("Periodic Saving"),
75 /* options: */ NULL,
76 /* hooks: */ NULL,
77 /* submodules: */ NULL,
78 /* data: */ NULL,
79 /* init: */ init_timer,
80 /* done: */ done_timer