2017-03-15 21:13:17 +01:00
|
|
|
/* Copyright (c) 2015-2017, The Tor Project, Inc. */
|
2015-11-02 15:48:18 +01:00
|
|
|
/* See LICENSE for licensing information */
|
|
|
|
|
|
|
|
#ifndef TOR_PERIODIC_H
|
|
|
|
#define TOR_PERIODIC_H
|
|
|
|
|
2015-11-17 14:26:04 +01:00
|
|
|
#define PERIODIC_EVENT_NO_UPDATE (-1)
|
|
|
|
|
|
|
|
/** Callback function for a periodic event to take action. The return value
|
|
|
|
* influences the next time the function will get called. Return
|
|
|
|
* PERIODIC_EVENT_NO_UPDATE to not update <b>last_action_time</b> and be polled
|
|
|
|
* again in the next second. If a positive value is returned it will update the
|
|
|
|
* interval time. */
|
2015-11-02 15:48:18 +01:00
|
|
|
typedef int (*periodic_event_helper_t)(time_t now,
|
|
|
|
const or_options_t *options);
|
|
|
|
|
2015-11-02 21:36:09 +01:00
|
|
|
struct event;
|
|
|
|
|
2015-11-02 15:48:18 +01:00
|
|
|
/** A single item for the periodic-events-function table. */
|
|
|
|
typedef struct periodic_event_item_t {
|
|
|
|
periodic_event_helper_t fn; /**< The function to run the event */
|
|
|
|
time_t last_action_time; /**< The last time the function did something */
|
2015-11-02 21:36:09 +01:00
|
|
|
struct event *ev; /**< Libevent callback we're using to implement this */
|
2015-11-02 15:48:18 +01:00
|
|
|
const char *name; /**< Name of the function -- for debug */
|
|
|
|
} periodic_event_item_t;
|
|
|
|
|
|
|
|
/** events will get their interval from first execution */
|
2015-11-02 21:36:09 +01:00
|
|
|
#define PERIODIC_EVENT(fn) { fn##_callback, 0, NULL, #fn }
|
|
|
|
#define END_OF_PERIODIC_EVENTS { NULL, 0, NULL, NULL }
|
2015-11-02 15:48:18 +01:00
|
|
|
|
|
|
|
void periodic_event_launch(periodic_event_item_t *event);
|
2015-11-17 15:26:50 +01:00
|
|
|
void periodic_event_setup(periodic_event_item_t *event);
|
2015-11-02 15:48:18 +01:00
|
|
|
void periodic_event_destroy(periodic_event_item_t *event);
|
|
|
|
void periodic_event_reschedule(periodic_event_item_t *event);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|