X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=include%2Fbabeltrace%2Fgraph%2Fnotification-internal.h;h=f776f5ec95c7023b050ae3aad9e7f823732a55a8;hb=40f4ba76dd6f9508ca51b6220eaed57632281a07;hp=e13f660cf419b25bb427a56f9d49f1f823fbabc3;hpb=c55a9f585da53ea54ac458155fac3cdec1779d47;p=babeltrace.git diff --git a/include/babeltrace/graph/notification-internal.h b/include/babeltrace/graph/notification-internal.h index e13f660c..f776f5ec 100644 --- a/include/babeltrace/graph/notification-internal.h +++ b/include/babeltrace/graph/notification-internal.h @@ -1,9 +1,7 @@ -#ifndef BABELTRACE_COMPONENT_NOTIFICATION_NOTIFICATION_INTERNAL_H -#define BABELTRACE_COMPONENT_NOTIFICATION_NOTIFICATION_INTERNAL_H +#ifndef BABELTRACE_GRAPH_NOTIFICATION_NOTIFICATION_INTERNAL_H +#define BABELTRACE_GRAPH_NOTIFICATION_NOTIFICATION_INTERNAL_H /* - * BabelTrace - Plug-in Notification internal - * * Copyright 2015 Jérémie Galarneau * * Author: Jérémie Galarneau @@ -27,40 +25,111 @@ * SOFTWARE. */ -#include #include #include +#include +#include #include -#include +#include +#include #include -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct bt_ctf_stream *(*get_stream_func)( +typedef struct bt_stream *(*get_stream_func)( struct bt_notification *notification); struct bt_notification { struct bt_object base; enum bt_notification_type type; - get_stream_func get_stream; + uint64_t seq_num; bt_bool frozen; + + /* Owned by this; keeps the graph alive while the notif. is alive */ + struct bt_graph *graph; }; +#define BT_ASSERT_PRE_NOTIF_IS_TYPE(_notif, _type) \ + BT_ASSERT_PRE(((struct bt_notification *) (_notif))->type == (_type), \ + "Notification has the wrong type: expected-type=%s, " \ + "%![notif-]+n", bt_notification_type_string(_type), \ + (_notif)) + BT_HIDDEN void bt_notification_init(struct bt_notification *notification, enum bt_notification_type type, - bt_object_release_func release); + bt_object_release_func release, + struct bt_graph *graph); -BT_HIDDEN -static inline void bt_notification_freeze(struct bt_notification *notification) +static inline +void bt_notification_reset(struct bt_notification *notification) +{ + BT_ASSERT(notification); + +#ifdef BT_DEV_MODE + notification->frozen = BT_FALSE; + notification->seq_num = UINT64_C(-1); +#endif +} + +static inline +struct bt_notification *bt_notification_create_from_pool( + struct bt_object_pool *pool, struct bt_graph *graph) +{ + struct bt_notification *notif = bt_object_pool_create_object(pool); + + if (unlikely(!notif)) { +#ifdef BT_LIB_LOGE + BT_LIB_LOGE("Cannot allocate one notification from notification pool: " + "%![pool-]+o, %![graph-]+g", pool, graph); +#endif + goto error; + } + + if (likely(!notif->graph)) { + notif->graph = graph; + } + + goto end; + +error: + BT_ASSERT(!notif); + +end: + return notif; +} + +static inline void _bt_notification_freeze(struct bt_notification *notification) { notification->frozen = BT_TRUE; } -#ifdef __cplusplus +BT_HIDDEN +void bt_notification_unlink_graph(struct bt_notification *notif); + +#ifdef BT_DEV_MODE +# define bt_notification_freeze _bt_notification_freeze +#else +# define bt_notification_freeze(_x) +#endif /* BT_DEV_MODE */ + +static inline +const char *bt_notification_type_string(enum bt_notification_type type) +{ + switch (type) { + case BT_NOTIFICATION_TYPE_EVENT: + return "BT_NOTIFICATION_TYPE_EVENT"; + case BT_NOTIFICATION_TYPE_INACTIVITY: + return "BT_NOTIFICATION_TYPE_INACTIVITY"; + case BT_NOTIFICATION_TYPE_STREAM_BEGIN: + return "BT_NOTIFICATION_TYPE_STREAM_BEGIN"; + case BT_NOTIFICATION_TYPE_STREAM_END: + return "BT_NOTIFICATION_TYPE_STREAM_END"; + case BT_NOTIFICATION_TYPE_PACKET_BEGIN: + return "BT_NOTIFICATION_TYPE_PACKET_BEGIN"; + case BT_NOTIFICATION_TYPE_PACKET_END: + return "BT_NOTIFICATION_TYPE_PACKET_END"; + default: + return "(unknown)"; + } } -#endif -#endif /* BABELTRACE_COMPONENT_NOTIFICATION_NOTIFICATION_INTERNAL_H */ +#endif /* BABELTRACE_GRAPH_NOTIFICATION_NOTIFICATION_INTERNAL_H */