Commit | Line | Data |
---|---|---|
d6e69534 | 1 | /* |
0235b0db MJ |
2 | * SPDX-License-Identifier: MIT |
3 | * | |
d6e69534 PP |
4 | * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com> |
5 | * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com> | |
d6e69534 PP |
6 | */ |
7 | ||
350ad6c1 | 8 | #define BT_LOG_TAG "LIB/MSG-STREAM" |
c2d9d9cf | 9 | #include "lib/logging.h" |
d6e69534 | 10 | |
d98421f2 | 11 | #include "lib/assert-cond.h" |
578e048b | 12 | #include "compat/compiler.h" |
43c59509 | 13 | #include <babeltrace2/trace-ir/clock-snapshot.h> |
578e048b | 14 | #include "lib/trace-ir/stream.h" |
3fadfbc0 | 15 | #include <babeltrace2/trace-ir/stream-class.h> |
578e048b | 16 | #include "lib/trace-ir/stream-class.h" |
43c59509 | 17 | #include <babeltrace2/graph/message.h> |
578e048b | 18 | #include "common/assert.h" |
d6e69534 PP |
19 | #include <inttypes.h> |
20 | ||
578e048b MJ |
21 | #include "stream.h" |
22 | ||
d6e69534 | 23 | static |
5df26c89 | 24 | void destroy_stream_message(struct bt_object *obj) |
d6e69534 | 25 | { |
5df26c89 | 26 | struct bt_message_stream *message = (void *) obj; |
d6e69534 | 27 | |
5df26c89 | 28 | BT_LIB_LOGD("Destroying stream message: %!+n", message); |
82cacf47 PP |
29 | |
30 | if (message->default_cs) { | |
31 | BT_LIB_LOGD("Putting default clock snapshot: %!+k", | |
32 | message->default_cs); | |
33 | bt_clock_snapshot_destroy(message->default_cs); | |
34 | message->default_cs = NULL; | |
35 | } | |
36 | ||
d6e69534 PP |
37 | BT_LIB_LOGD("Putting stream: %!+s", message->stream); |
38 | BT_OBJECT_PUT_REF_AND_RESET(message->stream); | |
d6e69534 PP |
39 | g_free(message); |
40 | } | |
41 | ||
5df26c89 PP |
42 | static inline |
43 | struct bt_message *create_stream_message( | |
d6e69534 | 44 | struct bt_self_message_iterator *self_msg_iter, |
5df26c89 | 45 | struct bt_stream *stream, enum bt_message_type type) |
d6e69534 | 46 | { |
5df26c89 | 47 | struct bt_message_stream *message; |
d6e69534 PP |
48 | struct bt_stream_class *stream_class; |
49 | ||
50 | BT_ASSERT_PRE_NON_NULL(self_msg_iter, "Message iterator"); | |
51 | BT_ASSERT_PRE_NON_NULL(stream, "Stream"); | |
52 | stream_class = bt_stream_borrow_class(stream); | |
53 | BT_ASSERT(stream_class); | |
5df26c89 PP |
54 | BT_LIB_LOGD("Creating stream message object: " |
55 | "type=%s, %![stream-]+s, %![sc-]+S", | |
56 | bt_message_type_string(type), stream, stream_class); | |
57 | message = g_new0(struct bt_message_stream, 1); | |
d6e69534 | 58 | if (!message) { |
870631a2 PP |
59 | BT_LIB_LOGE_APPEND_CAUSE( |
60 | "Failed to allocate one stream message."); | |
d6e69534 PP |
61 | goto error; |
62 | } | |
63 | ||
5df26c89 PP |
64 | bt_message_init(&message->parent, type, |
65 | destroy_stream_message, NULL); | |
d6e69534 | 66 | message->stream = stream; |
6871026b | 67 | bt_object_get_ref_no_null_check(message->stream); |
188edac1 SM |
68 | |
69 | if (stream_class->default_clock_class) { | |
70 | message->default_cs = bt_clock_snapshot_create( | |
71 | stream_class->default_clock_class); | |
72 | if (!message->default_cs) { | |
73 | goto error; | |
74 | } | |
75 | } | |
76 | ||
5df26c89 | 77 | BT_LIB_LOGD("Created stream message object: " |
d6e69534 PP |
78 | "%![msg-]+n, %![stream-]+s, %![sc-]+S", message, |
79 | stream, stream_class); | |
80 | ||
188edac1 | 81 | goto end; |
5df26c89 | 82 | |
d6e69534 | 83 | error: |
188edac1 SM |
84 | if (message) { |
85 | g_free(message); | |
86 | message = NULL; | |
87 | } | |
88 | ||
89 | end: | |
90 | return &message->parent; | |
d6e69534 PP |
91 | } |
92 | ||
5df26c89 PP |
93 | struct bt_message *bt_message_stream_beginning_create( |
94 | struct bt_self_message_iterator *self_msg_iter, | |
58085ca4 | 95 | const struct bt_stream *stream) |
d6e69534 | 96 | { |
17f3083a SM |
97 | BT_ASSERT_PRE_DEV_NO_ERROR(); |
98 | ||
58085ca4 | 99 | return create_stream_message(self_msg_iter, (void *) stream, |
5df26c89 | 100 | BT_MESSAGE_TYPE_STREAM_BEGINNING); |
d6e69534 PP |
101 | } |
102 | ||
5df26c89 PP |
103 | struct bt_message *bt_message_stream_end_create( |
104 | struct bt_self_message_iterator *self_msg_iter, | |
58085ca4 | 105 | const struct bt_stream *stream) |
d6e69534 | 106 | { |
17f3083a SM |
107 | BT_ASSERT_PRE_DEV_NO_ERROR(); |
108 | ||
58085ca4 | 109 | return create_stream_message(self_msg_iter, (void *) stream, |
5df26c89 | 110 | BT_MESSAGE_TYPE_STREAM_END); |
d6e69534 PP |
111 | } |
112 | ||
5df26c89 PP |
113 | static inline |
114 | struct bt_stream *borrow_stream_message_stream(struct bt_message *message) | |
d6e69534 | 115 | { |
5df26c89 | 116 | struct bt_message_stream *stream_msg; |
d6e69534 | 117 | |
98b15851 | 118 | BT_ASSERT_DBG(message); |
5df26c89 PP |
119 | stream_msg = (void *) message; |
120 | return stream_msg->stream; | |
d6e69534 PP |
121 | } |
122 | ||
5df26c89 PP |
123 | struct bt_stream *bt_message_stream_beginning_borrow_stream( |
124 | struct bt_message *message) | |
d6e69534 | 125 | { |
bdb288b3 | 126 | BT_ASSERT_PRE_DEV_NON_NULL(message, "Message"); |
0a83319b | 127 | BT_ASSERT_PRE_DEV_MSG_HAS_TYPE(message, |
bdb288b3 | 128 | BT_MESSAGE_TYPE_STREAM_BEGINNING); |
5df26c89 | 129 | return borrow_stream_message_stream(message); |
d6e69534 PP |
130 | } |
131 | ||
5df26c89 | 132 | struct bt_stream *bt_message_stream_end_borrow_stream( |
d6e69534 PP |
133 | struct bt_message *message) |
134 | { | |
bdb288b3 | 135 | BT_ASSERT_PRE_DEV_NON_NULL(message, "Message"); |
0a83319b | 136 | BT_ASSERT_PRE_DEV_MSG_HAS_TYPE(message, |
bdb288b3 | 137 | BT_MESSAGE_TYPE_STREAM_END); |
5df26c89 | 138 | return borrow_stream_message_stream(message); |
d6e69534 PP |
139 | } |
140 | ||
141 | const struct bt_stream *bt_message_stream_beginning_borrow_stream_const( | |
142 | const struct bt_message *message) | |
143 | { | |
144 | return bt_message_stream_beginning_borrow_stream( | |
145 | (void *) message); | |
146 | } | |
5df26c89 PP |
147 | |
148 | const struct bt_stream *bt_message_stream_end_borrow_stream_const( | |
149 | const struct bt_message *message) | |
150 | { | |
151 | return bt_message_stream_end_borrow_stream( | |
152 | (void *) message); | |
153 | } | |
188edac1 SM |
154 | |
155 | static | |
156 | void bt_message_stream_set_default_clock_snapshot( | |
157 | struct bt_message *msg, uint64_t raw_value) | |
158 | { | |
159 | struct bt_message_stream *stream_msg = (void *) msg; | |
160 | struct bt_stream_class *sc; | |
161 | ||
162 | BT_ASSERT(msg); | |
bdb288b3 | 163 | BT_ASSERT_PRE_DEV_HOT(msg, "Message", ": %!+n", msg); |
188edac1 SM |
164 | sc = stream_msg->stream->class; |
165 | BT_ASSERT(sc); | |
166 | BT_ASSERT_PRE(sc->default_clock_class, | |
167 | "Message's stream's class has no default clock class: " | |
168 | "%![msg-]+n, %![sc-]+S", msg, sc); | |
169 | BT_ASSERT(stream_msg->default_cs); | |
170 | bt_clock_snapshot_set_raw_value(stream_msg->default_cs, raw_value); | |
171 | stream_msg->default_cs_state = BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN; | |
172 | BT_LIB_LOGD("Set stream message's default clock snapshot: " | |
173 | "%![msg-]+n, value=%" PRIu64, msg, raw_value); | |
174 | } | |
175 | ||
176 | void bt_message_stream_beginning_set_default_clock_snapshot( | |
177 | struct bt_message *message, uint64_t raw_value) | |
178 | { | |
179 | BT_ASSERT_PRE_NON_NULL(message, "Message"); | |
0a83319b | 180 | BT_ASSERT_PRE_MSG_HAS_TYPE(message, BT_MESSAGE_TYPE_STREAM_BEGINNING); |
188edac1 SM |
181 | |
182 | bt_message_stream_set_default_clock_snapshot(message, raw_value); | |
183 | } | |
184 | ||
185 | void bt_message_stream_end_set_default_clock_snapshot( | |
186 | struct bt_message *message, uint64_t raw_value) | |
187 | { | |
188 | BT_ASSERT_PRE_NON_NULL(message, "Message"); | |
0a83319b | 189 | BT_ASSERT_PRE_MSG_HAS_TYPE(message, BT_MESSAGE_TYPE_STREAM_END); |
188edac1 SM |
190 | |
191 | return bt_message_stream_set_default_clock_snapshot(message, raw_value); | |
192 | } | |
193 | ||
194 | static enum bt_message_stream_clock_snapshot_state | |
195 | bt_message_stream_borrow_default_clock_snapshot_const( | |
196 | const bt_message *msg, const bt_clock_snapshot **snapshot) | |
197 | { | |
198 | struct bt_message_stream *stream_msg = (void *) msg; | |
199 | struct bt_stream_class *sc; | |
200 | ||
98b15851 | 201 | BT_ASSERT_DBG(msg); |
188edac1 | 202 | sc = stream_msg->stream->class; |
98b15851 | 203 | BT_ASSERT_DBG(sc); |
bdb288b3 | 204 | BT_ASSERT_PRE_DEV(sc->default_clock_class, |
188edac1 SM |
205 | "Message's stream's class has no default clock class: " |
206 | "%![msg-]+n, %![sc-]+S", msg, sc); | |
98b15851 | 207 | BT_ASSERT_DBG(stream_msg->default_cs); |
188edac1 SM |
208 | |
209 | *snapshot = stream_msg->default_cs; | |
210 | ||
211 | return stream_msg->default_cs_state; | |
212 | } | |
213 | ||
214 | enum bt_message_stream_clock_snapshot_state | |
215 | bt_message_stream_beginning_borrow_default_clock_snapshot_const( | |
216 | const bt_message *message, const bt_clock_snapshot **snapshot) | |
217 | { | |
bdb288b3 | 218 | BT_ASSERT_PRE_DEV_NON_NULL(message, "Message"); |
0a83319b | 219 | BT_ASSERT_PRE_DEV_MSG_HAS_TYPE(message, |
bdb288b3 | 220 | BT_MESSAGE_TYPE_STREAM_BEGINNING); |
188edac1 SM |
221 | return bt_message_stream_borrow_default_clock_snapshot_const( |
222 | message, snapshot); | |
223 | } | |
224 | ||
225 | enum bt_message_stream_clock_snapshot_state | |
226 | bt_message_stream_end_borrow_default_clock_snapshot_const( | |
227 | const bt_message *message, const bt_clock_snapshot **snapshot) | |
228 | { | |
bdb288b3 | 229 | BT_ASSERT_PRE_DEV_NON_NULL(message, "Message"); |
0a83319b | 230 | BT_ASSERT_PRE_DEV_MSG_HAS_TYPE(message, BT_MESSAGE_TYPE_STREAM_END); |
188edac1 SM |
231 | return bt_message_stream_borrow_default_clock_snapshot_const( |
232 | message, snapshot); | |
233 | } | |
234 | ||
235 | static inline | |
236 | const struct bt_clock_class * | |
237 | borrow_stream_message_stream_class_default_clock_class( | |
238 | const struct bt_message *msg) | |
239 | { | |
240 | struct bt_message_stream *stream_msg = (void *) msg; | |
241 | ||
98b15851 | 242 | BT_ASSERT_DBG(msg); |
188edac1 SM |
243 | return stream_msg->stream->class->default_clock_class; |
244 | } | |
245 | ||
246 | const struct bt_clock_class * | |
247 | bt_message_stream_beginning_borrow_stream_class_default_clock_class_const( | |
248 | const struct bt_message *msg) | |
249 | { | |
bdb288b3 | 250 | BT_ASSERT_PRE_DEV_NON_NULL(msg, "Message"); |
0a83319b | 251 | BT_ASSERT_PRE_DEV_MSG_HAS_TYPE(msg, |
188edac1 SM |
252 | BT_MESSAGE_TYPE_STREAM_BEGINNING); |
253 | return borrow_stream_message_stream_class_default_clock_class(msg); | |
254 | } | |
255 | ||
256 | const struct bt_clock_class * | |
257 | bt_message_stream_end_borrow_stream_class_default_clock_class_const( | |
258 | const struct bt_message *msg) | |
259 | { | |
bdb288b3 | 260 | BT_ASSERT_PRE_DEV_NON_NULL(msg, "Message"); |
0a83319b | 261 | BT_ASSERT_PRE_DEV_MSG_HAS_TYPE(msg, BT_MESSAGE_TYPE_STREAM_END); |
188edac1 SM |
262 | return borrow_stream_message_stream_class_default_clock_class(msg); |
263 | } |