b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen#ifndef LIB_EVENT_PRIVATE_H
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen#define LIB_EVENT_PRIVATE_H
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainenstruct event {
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen struct event_passthrough event_passthrough;
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen /* linked list of all events, newest first */
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen struct event *prev, *next;
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen int refcount;
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen pool_t pool;
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen struct event *parent;
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen uint64_t id;
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen char *log_prefix;
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen bool log_prefix_from_system_pool:1;
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen bool log_prefix_replace:1;
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen bool passthrough:1;
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen bool forced_debug:1;
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen bool always_log_source:1;
c6ab22366939966e59492b29fd42a350d54331f0Timo Sirainen bool sending_debug_log:1;
b63e20ea9bc84f1aa90a551f217d01385e070b73Timo Sirainen bool id_sent_to_stats:1;
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen /* Call callbacks with EVENT_CALLBACK_TYPE_FREE for this event. */
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen bool call_free:1;
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen
53ea4ad7b37e6c78a834151cdc30374316da4e34Timo Sirainen/* Fields that are exported & imported: */
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen struct timeval tv_created;
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen struct timeval tv_last_sent;
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen const char *source_filename;
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen unsigned int source_linenum;
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen /* This is the event's name while it's being sent. It'll be removed
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen after the event is sent. */
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen char *sending_name;
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen ARRAY(struct event_category *) categories;
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen ARRAY(struct event_field) fields;
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen};
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainenenum event_callback_type {
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen /* Event is being sent */
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen EVENT_CALLBACK_TYPE_EVENT,
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen /* Event with call_free=TRUE is being freed */
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen EVENT_CALLBACK_TYPE_FREE,
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen};
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen/* Returns TRUE if the event should continue to the next handler. Unless
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen stopped, the final handler logs the event if it matches the log filter. */
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainentypedef bool event_callback_t(struct event *event,
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen enum event_callback_type type,
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen struct failure_context *ctx,
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen const char *fmt, va_list args);
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen/* Called when category is registered or unregistered. The parent category
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen is always already registered. */
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainentypedef void event_category_callback_t(struct event_category *category);
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen
ddd5a0932db39f7336123f5089fdd77f6a38bce6Timo Sirainenvoid event_send(struct event *event, struct failure_context *ctx,
ddd5a0932db39f7336123f5089fdd77f6a38bce6Timo Sirainen const char *fmt, ...) ATTR_FORMAT(3, 4);
68f5234e8c0a79b72546e1b1013aae4b86f394a4Timo Sirainenvoid event_vsend(struct event *event, struct failure_context *ctx,
68f5234e8c0a79b72546e1b1013aae4b86f394a4Timo Sirainen const char *fmt, va_list args) ATTR_FORMAT(3, 0);
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainenstruct event *events_get_head(void);
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen/* Find event category by name. This only finds registered categories. */
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainenstruct event_category *event_category_find_registered(const char *name);
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen/* Return all registered categories. */
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainenstruct event_category *const *
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainenevent_get_registered_categories(unsigned int *count_r);
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen/* Register callback to be called whenever events are sent. */
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainenvoid event_register_callback(event_callback_t *callback);
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainenvoid event_unregister_callback(event_callback_t *callback);
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen/* Register callback to be called whenever categories are registered or
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen unregistered. */
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainenvoid event_category_register_callback(event_category_callback_t *callback);
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainenvoid event_category_unregister_callback(event_category_callback_t *callback);
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen
b8a1347a9ea2cecf0d16f24748c2600fea8c7158Timo Sirainen#endif