2ronwalf#ifndef LOG_THROTTLE_H
2ronwalf#define LOG_THROTTLE_H
2ronwalf
2ronwalfstruct log_throttle_settings {
2ronwalf /* Start throttling after we reach this many log events/interval. */
2ronwalf unsigned int throttle_at_max_per_interval;
2ronwalf /* Throttling continues until there's only this many or below
2ronwalf log events/interval. */
2ronwalf unsigned int unthrottle_at_max_per_interval;
2ronwalf /* Interval unit in milliseconds. The throttled-callback is also called
2ronwalf at this interval. Default (0) is 1000 milliseconds. */
2ronwalf unsigned int interval_msecs;
2ronwalf};
2ronwalf
2ronwalftypedef void
2ronwalflog_throttle_callback_t(unsigned int new_events_count, void *context);
2ronwalf
2ronwalfstruct log_throttle *
2ronwalflog_throttle_init(const struct log_throttle_settings *set,
2ronwalf log_throttle_callback_t *callback, void *context);
2ronwalf#define log_throttle_init(set, callback, context) \
2ronwalf log_throttle_init(set + \
2ronwalf CALLBACK_TYPECHECK(callback, void (*)(unsigned int, typeof(context))), \
2ronwalf (log_throttle_callback_t *)callback, context)
2ronwalfvoid log_throttle_deinit(struct log_throttle **throttle);
2ronwalf
2ronwalf/* Increase event count. Returns TRUE if the event should be logged,
2ronwalf FALSE if it's throttled. ioloop_timeval is used to determine the current
2ronwalf time. */
2ronwalfbool log_throttle_accept(struct log_throttle *throttle);
2ronwalf
2ronwalf#endif
2ronwalf