#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-beginning.h>
+#include <babeltrace/graph/message-stream-end.h>
+#include <babeltrace/graph/message-stream-beginning-const.h>
+#include <babeltrace/graph/message-stream-end-const.h>
#include <babeltrace/graph/message-stream-internal.h>
#include <babeltrace/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_cv) {
- bt_clock_value_recycle(message->default_cv);
- message->default_cv = 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_value(
- 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_cv = bt_clock_value_create(
- se_msg->stream->class->default_clock_class);
- BT_ASSERT(se_msg->default_cv);
- bt_clock_value_set_value_inline(se_msg->default_cv, value_cycles);
- BT_LIB_LOGV("Set message's default clock value: %![msg-]+n, "
- "value=%" PRIu64, value_cycles);
+ return create_stream_message(self_msg_iter, (void *) stream,
+ BT_MESSAGE_TYPE_STREAM_BEGINNING);
}
-struct bt_clock_value *bt_message_stream_end_borrow_default_clock_value(
- struct bt_message *msg)
+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_MSG_IS_TYPE(msg, BT_MESSAGE_TYPE_STREAM_END);
- return stream_end->default_cv;
+ 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_cv) {
- bt_clock_value_recycle(message->default_cv);
- message->default_cv = 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(
(void *) message);
}
-void bt_message_stream_beginning_set_default_clock_value(
- 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_cv = bt_clock_value_create(
- sb_msg->stream->class->default_clock_class);
- BT_ASSERT(sb_msg->default_cv);
- bt_clock_value_set_value_inline(sb_msg->default_cv, value_cycles);
- BT_LIB_LOGV("Set message's default clock value: %![msg-]+n, "
- "value=%" PRIu64, value_cycles);
-}
-
-struct bt_clock_value *bt_message_stream_beginning_borrow_default_clock_value(
- struct bt_message *msg)
+const struct bt_stream *bt_message_stream_end_borrow_stream_const(
+ const struct bt_message *message)
{
- struct bt_message_stream_beginning *stream_begin = (void *) msg;
-
- BT_ASSERT_PRE_NON_NULL(msg, "Message");
- BT_ASSERT_PRE_MSG_IS_TYPE(msg, BT_MESSAGE_TYPE_STREAM_BEGINNING);
- return stream_begin->default_cv;
+ return bt_message_stream_end_borrow_stream(
+ (void *) message);
}