1 /* Periodic saving module */
2 /* $Id: timer.c,v 1.5 2005/09/08 14:04:09 zas Exp $ */
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
;
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");
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
);
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
);
56 init_timer(struct module
*module
)
58 struct change_hook_info timer_change_hooks
[] = {
59 { "infofiles.save_interval", periodic_save_change_hook
},
63 register_change_hooks(timer_change_hooks
);
64 periodic_save_handler(NULL
);
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"),
77 /* submodules: */ NULL
,
79 /* init: */ init_timer
,
80 /* done: */ done_timer