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