tap-driver.sh: flush stdout after each test result
[babeltrace.git] / lib / graph / message / stream.c
index 2bfa5600da18296a81f9eaeb3adb8bb664a2eb73..935942a7ed3d67cff1cbe5607ce4a83747a23864 100644 (file)
  */
 
 #define BT_LOG_TAG "MSG-STREAM"
-#include <babeltrace/lib-logging-internal.h>
-
-#include <babeltrace/assert-pre-internal.h>
-#include <babeltrace/compiler-internal.h>
-#include <babeltrace/trace-ir/clock-snapshot-const.h>
-#include <babeltrace/trace-ir/stream-internal.h>
-#include <babeltrace/trace-ir/stream-class.h>
-#include <babeltrace/trace-ir/stream-class-internal.h>
-#include <babeltrace/graph/message-stream.h>
-#include <babeltrace/graph/message-stream-const.h>
-#include <babeltrace/graph/message-stream-internal.h>
-#include <babeltrace/assert-internal.h>
+#include <babeltrace2/lib-logging-internal.h>
+
+#include <babeltrace2/assert-pre-internal.h>
+#include <babeltrace2/compiler-internal.h>
+#include <babeltrace2/trace-ir/clock-snapshot-const.h>
+#include <babeltrace2/trace-ir/stream-internal.h>
+#include <babeltrace2/trace-ir/stream-class.h>
+#include <babeltrace2/trace-ir/stream-class-internal.h>
+#include <babeltrace2/graph/message-stream-beginning.h>
+#include <babeltrace2/graph/message-stream-end.h>
+#include <babeltrace2/graph/message-stream-beginning-const.h>
+#include <babeltrace2/graph/message-stream-end-const.h>
+#include <babeltrace2/graph/message-stream-internal.h>
+#include <babeltrace2/assert-internal.h>
 #include <inttypes.h>
 
 static
-void bt_message_stream_end_destroy(struct bt_object *obj)
+void destroy_stream_message(struct bt_object *obj)
 {
-       struct bt_message_stream_end *message =
-                       (struct bt_message_stream_end *) obj;
+       struct bt_message_stream *message = (void *) obj;
 
-       BT_LIB_LOGD("Destroying stream end message: %!+n",
-               message);
+       BT_LIB_LOGD("Destroying stream message: %!+n", message);
        BT_LIB_LOGD("Putting stream: %!+s", message->stream);
        BT_OBJECT_PUT_REF_AND_RESET(message->stream);
-
-       if (message->default_cs) {
-               bt_clock_snapshot_recycle(message->default_cs);
-               message->default_cs = NULL;
-       }
-
        g_free(message);
 }
 
-struct bt_message *bt_message_stream_end_create(
+static inline
+struct bt_message *create_stream_message(
                struct bt_self_message_iterator *self_msg_iter,
-               struct bt_stream *stream)
+               struct bt_stream *stream, enum bt_message_type type)
 {
-       struct bt_message_stream_end *message;
+       struct bt_message_stream *message;
        struct bt_stream_class *stream_class;
 
        BT_ASSERT_PRE_NON_NULL(self_msg_iter, "Message iterator");
        BT_ASSERT_PRE_NON_NULL(stream, "Stream");
        stream_class = bt_stream_borrow_class(stream);
        BT_ASSERT(stream_class);
-       BT_LIB_LOGD("Creating stream end message object: "
-               "%![stream-]+s, %![sc-]+S", stream, stream_class);
-       message = g_new0(struct bt_message_stream_end, 1);
+       BT_LIB_LOGD("Creating stream message object: "
+               "type=%s, %![stream-]+s, %![sc-]+S",
+               bt_message_type_string(type), stream, stream_class);
+       message = g_new0(struct bt_message_stream, 1);
        if (!message) {
-               BT_LOGE_STR("Failed to allocate one stream end message.");
+               BT_LOGE_STR("Failed to allocate one stream message.");
                goto error;
        }
 
-       bt_message_init(&message->parent,
-                       BT_MESSAGE_TYPE_STREAM_END,
-                       bt_message_stream_end_destroy, NULL);
+       bt_message_init(&message->parent, type,
+               destroy_stream_message, NULL);
        message->stream = stream;
        bt_object_get_no_null_check(message->stream);
-       BT_LIB_LOGD("Created stream end message object: "
+       BT_LIB_LOGD("Created stream message object: "
                "%![msg-]+n, %![stream-]+s, %![sc-]+S", message,
                stream, stream_class);
 
        return (void *) &message->parent;
+
 error:
        return NULL;
 }
 
-struct bt_stream *bt_message_stream_end_borrow_stream(
-               struct bt_message *message)
-{
-       struct bt_message_stream_end *stream_end;
-
-       BT_ASSERT_PRE_NON_NULL(message, "Message");
-       BT_ASSERT_PRE_MSG_IS_TYPE(message,
-               BT_MESSAGE_TYPE_STREAM_END);
-       stream_end = (void *) message;
-       return stream_end->stream;
-}
-
-const struct bt_stream *bt_message_stream_end_borrow_stream_const(
-               const struct bt_message *message)
-{
-       return bt_message_stream_end_borrow_stream(
-               (void *) message);
-}
-
-void bt_message_stream_end_set_default_clock_snapshot(
-               struct bt_message *msg, uint64_t value_cycles)
+struct bt_message *bt_message_stream_beginning_create(
+               struct bt_self_message_iterator *self_msg_iter,
+               const struct bt_stream *stream)
 {
-       struct bt_message_stream_end *se_msg = (void *) msg;
-
-       BT_ASSERT_PRE_NON_NULL(msg, "Message");
-       BT_ASSERT_PRE_HOT(msg, "Message", ": %!+n", msg);
-       BT_ASSERT_PRE_MSG_IS_TYPE(msg, BT_MESSAGE_TYPE_STREAM_END);
-       BT_ASSERT_PRE(se_msg->stream->class->default_clock_class,
-               "Message's stream class has no default clock class: "
-               "%![msg-]+n, %![sc-]+S", msg, se_msg->stream->class);
-
-       /* TODO: have the object already created */
-       se_msg->default_cs = bt_clock_snapshot_create(
-               se_msg->stream->class->default_clock_class);
-       BT_ASSERT(se_msg->default_cs);
-       bt_clock_snapshot_set_raw_value(se_msg->default_cs, value_cycles);
-       BT_LIB_LOGV("Set message's default clock snapshot: %![msg-]+n, "
-               "value=%" PRIu64, value_cycles);
+       return create_stream_message(self_msg_iter, (void *) stream,
+               BT_MESSAGE_TYPE_STREAM_BEGINNING);
 }
 
-enum bt_clock_snapshot_state
-bt_message_stream_end_borrow_default_clock_snapshot_const(
-               const bt_message *msg, const bt_clock_snapshot **snapshot)
+struct bt_message *bt_message_stream_end_create(
+               struct bt_self_message_iterator *self_msg_iter,
+               const struct bt_stream *stream)
 {
-       struct bt_message_stream_end *stream_end = (void *) msg;
-
-       BT_ASSERT_PRE_NON_NULL(msg, "Message");
-       BT_ASSERT_PRE_NON_NULL(snapshot, "Clock snapshot (output)");
-       BT_ASSERT_PRE_MSG_IS_TYPE(msg, BT_MESSAGE_TYPE_STREAM_END);
-       *snapshot = stream_end->default_cs;
-       return BT_CLOCK_SNAPSHOT_STATE_KNOWN;
+       return create_stream_message(self_msg_iter, (void *) stream,
+               BT_MESSAGE_TYPE_STREAM_END);
 }
 
-static
-void bt_message_stream_beginning_destroy(struct bt_object *obj)
+static inline
+struct bt_stream *borrow_stream_message_stream(struct bt_message *message)
 {
-       struct bt_message_stream_beginning *message =
-                       (struct bt_message_stream_beginning *) obj;
-
-       BT_LIB_LOGD("Destroying stream beginning message: %!+n",
-               message);
-       BT_LIB_LOGD("Putting stream: %!+s", message->stream);
-       BT_OBJECT_PUT_REF_AND_RESET(message->stream);
-
-       if (message->default_cs) {
-               bt_clock_snapshot_recycle(message->default_cs);
-               message->default_cs = NULL;
-       }
+       struct bt_message_stream *stream_msg;
 
-       g_free(message);
+       BT_ASSERT(message);
+       stream_msg = (void *) message;
+       return stream_msg->stream;
 }
 
-struct bt_message *bt_message_stream_beginning_create(
-               struct bt_self_message_iterator *self_msg_iter,
-               struct bt_stream *stream)
+struct bt_stream *bt_message_stream_beginning_borrow_stream(
+               struct bt_message *message)
 {
-       struct bt_message_stream_beginning *message;
-       struct bt_stream_class *stream_class;
-
-       BT_ASSERT_PRE_NON_NULL(self_msg_iter, "Message iterator");
-       BT_ASSERT_PRE_NON_NULL(stream, "Stream");
-       stream_class = bt_stream_borrow_class(stream);
-       BT_ASSERT(stream_class);
-       BT_LIB_LOGD("Creating stream beginning message object: "
-               "%![stream-]+s, %![sc-]+S", stream, stream_class);
-       message = g_new0(struct bt_message_stream_beginning, 1);
-       if (!message) {
-               BT_LOGE_STR("Failed to allocate one stream beginning message.");
-               goto error;
-       }
-
-       bt_message_init(&message->parent,
-                       BT_MESSAGE_TYPE_STREAM_BEGINNING,
-                       bt_message_stream_beginning_destroy, NULL);
-       message->stream = stream;
-       bt_object_get_no_null_check(message->stream);
-       BT_LIB_LOGD("Created stream beginning message object: "
-               "%![msg-]+n, %![stream-]+s, %![sc-]+S", message,
-               stream, stream_class);
-       return (void *) &message->parent;
-error:
-       return NULL;
+       BT_ASSERT_PRE_NON_NULL(message, "Message");
+       BT_ASSERT_PRE_MSG_IS_TYPE(message, BT_MESSAGE_TYPE_STREAM_BEGINNING);
+       return borrow_stream_message_stream(message);
 }
 
-struct bt_stream *bt_message_stream_beginning_borrow_stream(
+struct bt_stream *bt_message_stream_end_borrow_stream(
                struct bt_message *message)
 {
-       struct bt_message_stream_beginning *stream_begin;
-
        BT_ASSERT_PRE_NON_NULL(message, "Message");
-       BT_ASSERT_PRE_MSG_IS_TYPE(message,
-               BT_MESSAGE_TYPE_STREAM_BEGINNING);
-       stream_begin = (void *) message;
-       return stream_begin->stream;
+       BT_ASSERT_PRE_MSG_IS_TYPE(message, BT_MESSAGE_TYPE_STREAM_END);
+       return borrow_stream_message_stream(message);
 }
 
 const struct bt_stream *bt_message_stream_beginning_borrow_stream_const(
@@ -211,37 +133,9 @@ const struct bt_stream *bt_message_stream_beginning_borrow_stream_const(
                (void *) message);
 }
 
-void bt_message_stream_beginning_set_default_clock_snapshot(
-               struct bt_message *msg,
-               uint64_t value_cycles)
-{
-       struct bt_message_stream_beginning *sb_msg = (void *) msg;
-
-       BT_ASSERT_PRE_NON_NULL(msg, "Message");
-       BT_ASSERT_PRE_HOT(msg, "Message", ": %!+n", msg);
-       BT_ASSERT_PRE_MSG_IS_TYPE(msg, BT_MESSAGE_TYPE_STREAM_BEGINNING);
-       BT_ASSERT_PRE(sb_msg->stream->class->default_clock_class,
-               "Message's stream class has no default clock class: "
-               "%![msg-]+n, %![sc-]+S", msg, sb_msg->stream->class);
-
-       /* TODO: have the object already created */
-       sb_msg->default_cs = bt_clock_snapshot_create(
-               sb_msg->stream->class->default_clock_class);
-       BT_ASSERT(sb_msg->default_cs);
-       bt_clock_snapshot_set_raw_value(sb_msg->default_cs, value_cycles);
-       BT_LIB_LOGV("Set message's default clock snapshot: %![msg-]+n, "
-               "value=%" PRIu64, value_cycles);
-}
-
-enum bt_clock_snapshot_state
-bt_message_stream_beginning_borrow_default_clock_snapshot_const(
-               const bt_message *msg, const bt_clock_snapshot **snapshot)
+const struct bt_stream *bt_message_stream_end_borrow_stream_const(
+               const struct bt_message *message)
 {
-       struct bt_message_stream_beginning *stream_beginning = (void *) msg;
-
-       BT_ASSERT_PRE_NON_NULL(msg, "Message");
-       BT_ASSERT_PRE_NON_NULL(snapshot, "Clock snapshot (output)");
-       BT_ASSERT_PRE_MSG_IS_TYPE(msg, BT_MESSAGE_TYPE_STREAM_END);
-       *snapshot = stream_beginning->default_cs;
-       return BT_CLOCK_SNAPSHOT_STATE_KNOWN;
+       return bt_message_stream_end_borrow_stream(
+               (void *) message);
 }
This page took 0.026013 seconds and 4 git commands to generate.