Python: Give goto_url_hook only one argument, like follow_url_hook.
[elinks.git] / src / config / timer.c
blob0a7a9cecab5512d160eb565959347b8ca529a8c9
1 /* Periodic saving module */
3 #ifdef HAVE_CONFIG_H
4 #include "config.h"
5 #endif
7 #include "elinks.h"
9 #include "config/options.h"
10 #include "config/timer.h"
11 #include "intl/gettext/libintl.h"
12 #include "main/event.h"
13 #include "main/module.h"
14 #include "main/timer.h"
15 #include "util/time.h"
18 /* Timer for periodically saving configuration files to disk */
19 static timer_id_T periodic_save_timer = TIMER_ID_UNDEF;
21 /* Timer callback for @periodic_save_timer. As explained in @install_timer,
22 * this function must erase the expired timer ID from all variables. */
23 static void
24 periodic_save_handler(void *xxx)
26 static int periodic_save_event_id = EVENT_NONE;
27 milliseconds_T interval;
29 if (get_cmd_opt_bool("anonymous")) return;
31 /* Don't trigger anything at startup */
32 if (periodic_save_event_id == EVENT_NONE)
33 set_event_id(periodic_save_event_id, "periodic-saving");
34 else
35 trigger_event(periodic_save_event_id);
37 interval = sec_to_ms(get_opt_int("infofiles.save_interval"));
38 if (!interval) {
39 /* We should get here only if @periodic_save_handler
40 * is being called from @periodic_save_change_hook or
41 * @init_timer, rather than from the timer system. */
42 assert(periodic_save_timer == TIMER_ID_UNDEF);
43 return;
46 install_timer(&periodic_save_timer, interval, periodic_save_handler, NULL);
47 /* The expired timer ID has now been erased. */
50 static int
51 periodic_save_change_hook(struct session *ses, struct option *current,
52 struct option *changed)
54 if (get_cmd_opt_bool("anonymous")) return 0;
56 kill_timer(&periodic_save_timer);
58 periodic_save_handler(NULL);
60 return 0;
63 static void
64 init_timer(struct module *module)
66 struct change_hook_info timer_change_hooks[] = {
67 { "infofiles.save_interval", periodic_save_change_hook },
68 { NULL, NULL },
71 register_change_hooks(timer_change_hooks);
72 periodic_save_handler(NULL);
75 static void
76 done_timer(struct module *module)
78 kill_timer(&periodic_save_timer);
81 struct module periodic_saving_module = struct_module(
82 /* name: */ N_("Periodic Saving"),
83 /* options: */ NULL,
84 /* hooks: */ NULL,
85 /* submodules: */ NULL,
86 /* data: */ NULL,
87 /* init: */ init_timer,
88 /* done: */ done_timer