periodic.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334
  1. /* Copyright (c) 2015, The Tor Project, Inc. */
  2. /* See LICENSE for licensing information */
  3. #ifndef TOR_PERIODIC_H
  4. #define TOR_PERIODIC_H
  5. /** Callback function for a periodic event to take action.
  6. * The return value influences the next time the function will get called.
  7. * Return -1 to not update <b>last_action_time</b> and be polled again in
  8. * the next second. If a positive value is returned it will update the
  9. * interval time. If the returned value is larger than <b>now</b> then it
  10. * is assumed to be a future time to poll again. */
  11. typedef int (*periodic_event_helper_t)(time_t now,
  12. const or_options_t *options);
  13. /** A single item for the periodic-events-function table. */
  14. typedef struct periodic_event_item_t {
  15. periodic_event_helper_t fn; /**< The function to run the event */
  16. int interval; /**< The interval for running the function (In seconds). */
  17. time_t last_action_time; /**< The last time the function did something */
  18. periodic_timer_t *timer; /**< Timer object for this event */
  19. const char *name; /**< Name of the function -- for debug */
  20. } periodic_event_item_t;
  21. /** events will get their interval from first execution */
  22. #define PERIODIC_EVENT(fn) { fn##_callback, 0, 0, NULL, #fn }
  23. #define END_OF_PERIODIC_EVENTS { NULL, 0, 0, NULL, NULL }
  24. void periodic_event_launch(periodic_event_item_t *event);
  25. void periodic_event_destroy(periodic_event_item_t *event);
  26. void periodic_event_reschedule(periodic_event_item_t *event);
  27. #endif