tap-driver.sh: flush stdout after each test result
[babeltrace.git] / lib / graph / message / stream.c
CommitLineData
b09a5592
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
24#define BT_LOG_TAG "MSG-STREAM"
71c5da58 25#include <babeltrace2/lib-logging-internal.h>
b09a5592 26
71c5da58
MJ
27#include <babeltrace2/assert-pre-internal.h>
28#include <babeltrace2/compiler-internal.h>
29#include <babeltrace2/trace-ir/clock-snapshot-const.h>
30#include <babeltrace2/trace-ir/stream-internal.h>
31#include <babeltrace2/trace-ir/stream-class.h>
32#include <babeltrace2/trace-ir/stream-class-internal.h>
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>
37#include <babeltrace2/graph/message-stream-internal.h>
38#include <babeltrace2/assert-internal.h>
b09a5592
PP
39#include <inttypes.h>
40
41static
a1f053a9 42void destroy_stream_message(struct bt_object *obj)
b09a5592 43{
a1f053a9 44 struct bt_message_stream *message = (void *) obj;
b09a5592 45
a1f053a9 46 BT_LIB_LOGD("Destroying stream message: %!+n", message);
b09a5592
PP
47 BT_LIB_LOGD("Putting stream: %!+s", message->stream);
48 BT_OBJECT_PUT_REF_AND_RESET(message->stream);
b09a5592
PP
49 g_free(message);
50}
51
a1f053a9
PP
52static inline
53struct bt_message *create_stream_message(
b09a5592 54 struct bt_self_message_iterator *self_msg_iter,
a1f053a9 55 struct bt_stream *stream, enum bt_message_type type)
b09a5592 56{
a1f053a9 57 struct bt_message_stream *message;
b09a5592
PP
58 struct bt_stream_class *stream_class;
59
60 BT_ASSERT_PRE_NON_NULL(self_msg_iter, "Message iterator");
61 BT_ASSERT_PRE_NON_NULL(stream, "Stream");
62 stream_class = bt_stream_borrow_class(stream);
63 BT_ASSERT(stream_class);
a1f053a9
PP
64 BT_LIB_LOGD("Creating stream message object: "
65 "type=%s, %![stream-]+s, %![sc-]+S",
66 bt_message_type_string(type), stream, stream_class);
67 message = g_new0(struct bt_message_stream, 1);
b09a5592 68 if (!message) {
a1f053a9 69 BT_LOGE_STR("Failed to allocate one stream message.");
b09a5592
PP
70 goto error;
71 }
72
a1f053a9
PP
73 bt_message_init(&message->parent, type,
74 destroy_stream_message, NULL);
b09a5592
PP
75 message->stream = stream;
76 bt_object_get_no_null_check(message->stream);
a1f053a9 77 BT_LIB_LOGD("Created stream message object: "
b09a5592
PP
78 "%![msg-]+n, %![stream-]+s, %![sc-]+S", message,
79 stream, stream_class);
80
81 return (void *) &message->parent;
a1f053a9 82
b09a5592
PP
83error:
84 return NULL;
85}
86
a1f053a9
PP
87struct bt_message *bt_message_stream_beginning_create(
88 struct bt_self_message_iterator *self_msg_iter,
6a6975d2 89 const struct bt_stream *stream)
b09a5592 90{
6a6975d2 91 return create_stream_message(self_msg_iter, (void *) stream,
a1f053a9 92 BT_MESSAGE_TYPE_STREAM_BEGINNING);
b09a5592
PP
93}
94
a1f053a9
PP
95struct bt_message *bt_message_stream_end_create(
96 struct bt_self_message_iterator *self_msg_iter,
6a6975d2 97 const struct bt_stream *stream)
b09a5592 98{
6a6975d2 99 return create_stream_message(self_msg_iter, (void *) stream,
a1f053a9 100 BT_MESSAGE_TYPE_STREAM_END);
b09a5592
PP
101}
102
a1f053a9
PP
103static inline
104struct bt_stream *borrow_stream_message_stream(struct bt_message *message)
b09a5592 105{
a1f053a9 106 struct bt_message_stream *stream_msg;
b09a5592 107
a1f053a9
PP
108 BT_ASSERT(message);
109 stream_msg = (void *) message;
110 return stream_msg->stream;
b09a5592
PP
111}
112
a1f053a9
PP
113struct bt_stream *bt_message_stream_beginning_borrow_stream(
114 struct bt_message *message)
b09a5592 115{
a1f053a9
PP
116 BT_ASSERT_PRE_NON_NULL(message, "Message");
117 BT_ASSERT_PRE_MSG_IS_TYPE(message, BT_MESSAGE_TYPE_STREAM_BEGINNING);
118 return borrow_stream_message_stream(message);
b09a5592
PP
119}
120
a1f053a9 121struct bt_stream *bt_message_stream_end_borrow_stream(
b09a5592
PP
122 struct bt_message *message)
123{
b09a5592 124 BT_ASSERT_PRE_NON_NULL(message, "Message");
a1f053a9
PP
125 BT_ASSERT_PRE_MSG_IS_TYPE(message, BT_MESSAGE_TYPE_STREAM_END);
126 return borrow_stream_message_stream(message);
b09a5592
PP
127}
128
129const struct bt_stream *bt_message_stream_beginning_borrow_stream_const(
130 const struct bt_message *message)
131{
132 return bt_message_stream_beginning_borrow_stream(
133 (void *) message);
134}
a1f053a9
PP
135
136const struct bt_stream *bt_message_stream_end_borrow_stream_const(
137 const struct bt_message *message)
138{
139 return bt_message_stream_end_borrow_stream(
140 (void *) message);
141}
This page took 0.034374 seconds and 4 git commands to generate.