2 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
3 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 #define BT_LOG_TAG "MSG-STREAM"
25 #include <babeltrace/lib-logging-internal.h>
27 #include <babeltrace/assert-pre-internal.h>
28 #include <babeltrace/compiler-internal.h>
29 #include <babeltrace/trace-ir/clock-snapshot-const.h>
30 #include <babeltrace/trace-ir/stream-internal.h>
31 #include <babeltrace/trace-ir/stream-class.h>
32 #include <babeltrace/trace-ir/stream-class-internal.h>
33 #include <babeltrace/graph/message-stream.h>
34 #include <babeltrace/graph/message-stream-const.h>
35 #include <babeltrace/graph/message-stream-internal.h>
36 #include <babeltrace/assert-internal.h>
40 void bt_message_stream_end_destroy(struct bt_object
*obj
)
42 struct bt_message_stream_end
*message
=
43 (struct bt_message_stream_end
*) obj
;
45 BT_LIB_LOGD("Destroying stream end message: %!+n",
47 BT_LIB_LOGD("Putting stream: %!+s", message
->stream
);
48 BT_OBJECT_PUT_REF_AND_RESET(message
->stream
);
52 struct bt_message
*bt_message_stream_end_create(
53 struct bt_self_message_iterator
*self_msg_iter
,
54 struct bt_stream
*stream
)
56 struct bt_message_stream_end
*message
;
57 struct bt_stream_class
*stream_class
;
59 BT_ASSERT_PRE_NON_NULL(self_msg_iter
, "Message iterator");
60 BT_ASSERT_PRE_NON_NULL(stream
, "Stream");
61 stream_class
= bt_stream_borrow_class(stream
);
62 BT_ASSERT(stream_class
);
63 BT_LIB_LOGD("Creating stream end message object: "
64 "%![stream-]+s, %![sc-]+S", stream
, stream_class
);
65 message
= g_new0(struct bt_message_stream_end
, 1);
67 BT_LOGE_STR("Failed to allocate one stream end message.");
71 bt_message_init(&message
->parent
,
72 BT_MESSAGE_TYPE_STREAM_END
,
73 bt_message_stream_end_destroy
, NULL
);
74 message
->stream
= stream
;
75 bt_object_get_no_null_check(message
->stream
);
76 BT_LIB_LOGD("Created stream end message object: "
77 "%![msg-]+n, %![stream-]+s, %![sc-]+S", message
,
78 stream
, stream_class
);
80 return (void *) &message
->parent
;
85 struct bt_stream
*bt_message_stream_end_borrow_stream(
86 struct bt_message
*message
)
88 struct bt_message_stream_end
*stream_end
;
90 BT_ASSERT_PRE_NON_NULL(message
, "Message");
91 BT_ASSERT_PRE_MSG_IS_TYPE(message
,
92 BT_MESSAGE_TYPE_STREAM_END
);
93 stream_end
= (void *) message
;
94 return stream_end
->stream
;
97 const struct bt_stream
*bt_message_stream_end_borrow_stream_const(
98 const struct bt_message
*message
)
100 return bt_message_stream_end_borrow_stream(
105 void bt_message_stream_beginning_destroy(struct bt_object
*obj
)
107 struct bt_message_stream_beginning
*message
=
108 (struct bt_message_stream_beginning
*) obj
;
110 BT_LIB_LOGD("Destroying stream beginning message: %!+n",
112 BT_LIB_LOGD("Putting stream: %!+s", message
->stream
);
113 BT_OBJECT_PUT_REF_AND_RESET(message
->stream
);
117 struct bt_message
*bt_message_stream_beginning_create(
118 struct bt_self_message_iterator
*self_msg_iter
,
119 struct bt_stream
*stream
)
121 struct bt_message_stream_beginning
*message
;
122 struct bt_stream_class
*stream_class
;
124 BT_ASSERT_PRE_NON_NULL(self_msg_iter
, "Message iterator");
125 BT_ASSERT_PRE_NON_NULL(stream
, "Stream");
126 stream_class
= bt_stream_borrow_class(stream
);
127 BT_ASSERT(stream_class
);
128 BT_LIB_LOGD("Creating stream beginning message object: "
129 "%![stream-]+s, %![sc-]+S", stream
, stream_class
);
130 message
= g_new0(struct bt_message_stream_beginning
, 1);
132 BT_LOGE_STR("Failed to allocate one stream beginning message.");
136 bt_message_init(&message
->parent
,
137 BT_MESSAGE_TYPE_STREAM_BEGINNING
,
138 bt_message_stream_beginning_destroy
, NULL
);
139 message
->stream
= stream
;
140 bt_object_get_no_null_check(message
->stream
);
141 BT_LIB_LOGD("Created stream beginning message object: "
142 "%![msg-]+n, %![stream-]+s, %![sc-]+S", message
,
143 stream
, stream_class
);
144 return (void *) &message
->parent
;
149 struct bt_stream
*bt_message_stream_beginning_borrow_stream(
150 struct bt_message
*message
)
152 struct bt_message_stream_beginning
*stream_begin
;
154 BT_ASSERT_PRE_NON_NULL(message
, "Message");
155 BT_ASSERT_PRE_MSG_IS_TYPE(message
,
156 BT_MESSAGE_TYPE_STREAM_BEGINNING
);
157 stream_begin
= (void *) message
;
158 return stream_begin
->stream
;
161 const struct bt_stream
*bt_message_stream_beginning_borrow_stream_const(
162 const struct bt_message
*message
)
164 return bt_message_stream_beginning_borrow_stream(