Notification iterator: transform precondition checks to BT_ASSERT_PRE()
[babeltrace.git] / include / babeltrace / graph / notification-internal.h
index e13f660cf419b25bb427a56f9d49f1f823fbabc3..d1149055717fc61c451f2dbbf66563f6a96f8720 100644 (file)
 #include <babeltrace/ctf-ir/stream.h>
 #include <babeltrace/types.h>
 
-#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;
 };
 
+#define BT_ASSERT_PRE_NOTIF_IS_TYPE(_notif, _type)                     \
+       BT_ASSERT_PRE((_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_HIDDEN
 static inline void bt_notification_freeze(struct bt_notification *notification)
 {
        notification->frozen = BT_TRUE;
 }
 
-#ifdef __cplusplus
+static inline
+const char *bt_notification_type_string(enum bt_notification_type type)
+{
+       switch (type) {
+       case BT_NOTIFICATION_TYPE_UNKNOWN:
+               return "BT_NOTIFICATION_TYPE_UNKNOWN";
+       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";
+       case BT_NOTIFICATION_TYPE_DISCARDED_EVENTS:
+               return "BT_NOTIFICATION_TYPE_DISCARDED_EVENTS";
+       case BT_NOTIFICATION_TYPE_DISCARDED_PACKETS:
+               return "BT_NOTIFICATION_TYPE_DISCARDED_PACKETS";
+       default:
+               return "(unknown)";
+       }
 }
-#endif
 
 #endif /* BABELTRACE_COMPONENT_NOTIFICATION_NOTIFICATION_INTERNAL_H */
This page took 0.025377 seconds and 4 git commands to generate.