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
);
50 if (message
->default_cs
) {
51 bt_clock_snapshot_recycle(message
->default_cs
);
52 message
->default_cs
= NULL
;
58 struct bt_message
*bt_message_stream_end_create(
59 struct bt_self_message_iterator
*self_msg_iter
,
60 struct bt_stream
*stream
)
62 struct bt_message_stream_end
*message
;
63 struct bt_stream_class
*stream_class
;
65 BT_ASSERT_PRE_NON_NULL(self_msg_iter
, "Message iterator");
66 BT_ASSERT_PRE_NON_NULL(stream
, "Stream");
67 stream_class
= bt_stream_borrow_class(stream
);
68 BT_ASSERT(stream_class
);
69 BT_LIB_LOGD("Creating stream end message object: "
70 "%![stream-]+s, %![sc-]+S", stream
, stream_class
);
71 message
= g_new0(struct bt_message_stream_end
, 1);
73 BT_LOGE_STR("Failed to allocate one stream end message.");
77 bt_message_init(&message
->parent
,
78 BT_MESSAGE_TYPE_STREAM_END
,
79 bt_message_stream_end_destroy
, NULL
);
80 message
->stream
= stream
;
81 bt_object_get_no_null_check(message
->stream
);
82 BT_LIB_LOGD("Created stream end message object: "
83 "%![msg-]+n, %![stream-]+s, %![sc-]+S", message
,
84 stream
, stream_class
);
86 return (void *) &message
->parent
;
91 struct bt_stream
*bt_message_stream_end_borrow_stream(
92 struct bt_message
*message
)
94 struct bt_message_stream_end
*stream_end
;
96 BT_ASSERT_PRE_NON_NULL(message
, "Message");
97 BT_ASSERT_PRE_MSG_IS_TYPE(message
,
98 BT_MESSAGE_TYPE_STREAM_END
);
99 stream_end
= (void *) message
;
100 return stream_end
->stream
;
103 const struct bt_stream
*bt_message_stream_end_borrow_stream_const(
104 const struct bt_message
*message
)
106 return bt_message_stream_end_borrow_stream(
110 void bt_message_stream_end_set_default_clock_snapshot(
111 struct bt_message
*msg
, uint64_t value_cycles
)
113 struct bt_message_stream_end
*se_msg
= (void *) msg
;
115 BT_ASSERT_PRE_NON_NULL(msg
, "Message");
116 BT_ASSERT_PRE_HOT(msg
, "Message", ": %!+n", msg
);
117 BT_ASSERT_PRE_MSG_IS_TYPE(msg
, BT_MESSAGE_TYPE_STREAM_END
);
118 BT_ASSERT_PRE(se_msg
->stream
->class->default_clock_class
,
119 "Message's stream class has no default clock class: "
120 "%![msg-]+n, %![sc-]+S", msg
, se_msg
->stream
->class);
122 /* TODO: have the object already created */
123 se_msg
->default_cs
= bt_clock_snapshot_create(
124 se_msg
->stream
->class->default_clock_class
);
125 BT_ASSERT(se_msg
->default_cs
);
126 bt_clock_snapshot_set_raw_value(se_msg
->default_cs
, value_cycles
);
127 BT_LIB_LOGV("Set message's default clock snapshot: %![msg-]+n, "
128 "value=%" PRIu64
, value_cycles
);
131 enum bt_clock_snapshot_state
132 bt_message_stream_end_borrow_default_clock_snapshot_const(
133 const bt_message
*msg
, const bt_clock_snapshot
**snapshot
)
135 struct bt_message_stream_end
*stream_end
= (void *) msg
;
137 BT_ASSERT_PRE_NON_NULL(msg
, "Message");
138 BT_ASSERT_PRE_NON_NULL(snapshot
, "Clock snapshot (output)");
139 BT_ASSERT_PRE_MSG_IS_TYPE(msg
, BT_MESSAGE_TYPE_STREAM_END
);
140 *snapshot
= stream_end
->default_cs
;
141 return BT_CLOCK_SNAPSHOT_STATE_KNOWN
;
145 void bt_message_stream_beginning_destroy(struct bt_object
*obj
)
147 struct bt_message_stream_beginning
*message
=
148 (struct bt_message_stream_beginning
*) obj
;
150 BT_LIB_LOGD("Destroying stream beginning message: %!+n",
152 BT_LIB_LOGD("Putting stream: %!+s", message
->stream
);
153 BT_OBJECT_PUT_REF_AND_RESET(message
->stream
);
155 if (message
->default_cs
) {
156 bt_clock_snapshot_recycle(message
->default_cs
);
157 message
->default_cs
= NULL
;
163 struct bt_message
*bt_message_stream_beginning_create(
164 struct bt_self_message_iterator
*self_msg_iter
,
165 struct bt_stream
*stream
)
167 struct bt_message_stream_beginning
*message
;
168 struct bt_stream_class
*stream_class
;
170 BT_ASSERT_PRE_NON_NULL(self_msg_iter
, "Message iterator");
171 BT_ASSERT_PRE_NON_NULL(stream
, "Stream");
172 stream_class
= bt_stream_borrow_class(stream
);
173 BT_ASSERT(stream_class
);
174 BT_LIB_LOGD("Creating stream beginning message object: "
175 "%![stream-]+s, %![sc-]+S", stream
, stream_class
);
176 message
= g_new0(struct bt_message_stream_beginning
, 1);
178 BT_LOGE_STR("Failed to allocate one stream beginning message.");
182 bt_message_init(&message
->parent
,
183 BT_MESSAGE_TYPE_STREAM_BEGINNING
,
184 bt_message_stream_beginning_destroy
, NULL
);
185 message
->stream
= stream
;
186 bt_object_get_no_null_check(message
->stream
);
187 BT_LIB_LOGD("Created stream beginning message object: "
188 "%![msg-]+n, %![stream-]+s, %![sc-]+S", message
,
189 stream
, stream_class
);
190 return (void *) &message
->parent
;
195 struct bt_stream
*bt_message_stream_beginning_borrow_stream(
196 struct bt_message
*message
)
198 struct bt_message_stream_beginning
*stream_begin
;
200 BT_ASSERT_PRE_NON_NULL(message
, "Message");
201 BT_ASSERT_PRE_MSG_IS_TYPE(message
,
202 BT_MESSAGE_TYPE_STREAM_BEGINNING
);
203 stream_begin
= (void *) message
;
204 return stream_begin
->stream
;
207 const struct bt_stream
*bt_message_stream_beginning_borrow_stream_const(
208 const struct bt_message
*message
)
210 return bt_message_stream_beginning_borrow_stream(
214 void bt_message_stream_beginning_set_default_clock_snapshot(
215 struct bt_message
*msg
,
216 uint64_t value_cycles
)
218 struct bt_message_stream_beginning
*sb_msg
= (void *) msg
;
220 BT_ASSERT_PRE_NON_NULL(msg
, "Message");
221 BT_ASSERT_PRE_HOT(msg
, "Message", ": %!+n", msg
);
222 BT_ASSERT_PRE_MSG_IS_TYPE(msg
, BT_MESSAGE_TYPE_STREAM_BEGINNING
);
223 BT_ASSERT_PRE(sb_msg
->stream
->class->default_clock_class
,
224 "Message's stream class has no default clock class: "
225 "%![msg-]+n, %![sc-]+S", msg
, sb_msg
->stream
->class);
227 /* TODO: have the object already created */
228 sb_msg
->default_cs
= bt_clock_snapshot_create(
229 sb_msg
->stream
->class->default_clock_class
);
230 BT_ASSERT(sb_msg
->default_cs
);
231 bt_clock_snapshot_set_raw_value(sb_msg
->default_cs
, value_cycles
);
232 BT_LIB_LOGV("Set message's default clock snapshot: %![msg-]+n, "
233 "value=%" PRIu64
, value_cycles
);
236 enum bt_clock_snapshot_state
237 bt_message_stream_beginning_borrow_default_clock_snapshot_const(
238 const bt_message
*msg
, const bt_clock_snapshot
**snapshot
)
240 struct bt_message_stream_beginning
*stream_beginning
= (void *) msg
;
242 BT_ASSERT_PRE_NON_NULL(msg
, "Message");
243 BT_ASSERT_PRE_NON_NULL(snapshot
, "Clock snapshot (output)");
244 BT_ASSERT_PRE_MSG_IS_TYPE(msg
, BT_MESSAGE_TYPE_STREAM_END
);
245 *snapshot
= stream_beginning
->default_cs
;
246 return BT_CLOCK_SNAPSHOT_STATE_KNOWN
;