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