0d6f374c2ab88cec6ed8afda6610c14a3a07b5f0
[babeltrace.git] / lib / graph / message / stream.c
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"
25 #include <babeltrace/lib-logging-internal.h>
26
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>
37 #include <inttypes.h>
38
39 static
40 void bt_message_stream_end_destroy(struct bt_object *obj)
41 {
42 struct bt_message_stream_end *message =
43 (struct bt_message_stream_end *) obj;
44
45 BT_LIB_LOGD("Destroying stream end message: %!+n",
46 message);
47 BT_LIB_LOGD("Putting stream: %!+s", message->stream);
48 BT_OBJECT_PUT_REF_AND_RESET(message->stream);
49 g_free(message);
50 }
51
52 struct bt_message *bt_message_stream_end_create(
53 struct bt_self_message_iterator *self_msg_iter,
54 struct bt_stream *stream)
55 {
56 struct bt_message_stream_end *message;
57 struct bt_stream_class *stream_class;
58
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);
66 if (!message) {
67 BT_LOGE_STR("Failed to allocate one stream end message.");
68 goto error;
69 }
70
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);
79
80 return (void *) &message->parent;
81 error:
82 return NULL;
83 }
84
85 struct bt_stream *bt_message_stream_end_borrow_stream(
86 struct bt_message *message)
87 {
88 struct bt_message_stream_end *stream_end;
89
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;
95 }
96
97 const struct bt_stream *bt_message_stream_end_borrow_stream_const(
98 const struct bt_message *message)
99 {
100 return bt_message_stream_end_borrow_stream(
101 (void *) message);
102 }
103
104 static
105 void bt_message_stream_beginning_destroy(struct bt_object *obj)
106 {
107 struct bt_message_stream_beginning *message =
108 (struct bt_message_stream_beginning *) obj;
109
110 BT_LIB_LOGD("Destroying stream beginning message: %!+n",
111 message);
112 BT_LIB_LOGD("Putting stream: %!+s", message->stream);
113 BT_OBJECT_PUT_REF_AND_RESET(message->stream);
114 g_free(message);
115 }
116
117 struct bt_message *bt_message_stream_beginning_create(
118 struct bt_self_message_iterator *self_msg_iter,
119 struct bt_stream *stream)
120 {
121 struct bt_message_stream_beginning *message;
122 struct bt_stream_class *stream_class;
123
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);
131 if (!message) {
132 BT_LOGE_STR("Failed to allocate one stream beginning message.");
133 goto error;
134 }
135
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;
145 error:
146 return NULL;
147 }
148
149 struct bt_stream *bt_message_stream_beginning_borrow_stream(
150 struct bt_message *message)
151 {
152 struct bt_message_stream_beginning *stream_begin;
153
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;
159 }
160
161 const struct bt_stream *bt_message_stream_beginning_borrow_stream_const(
162 const struct bt_message *message)
163 {
164 return bt_message_stream_beginning_borrow_stream(
165 (void *) message);
166 }
This page took 0.032497 seconds and 3 git commands to generate.