Commit | Line | Data |
---|---|---|
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 | ||
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/stream-internal.h> | |
30 | #include <babeltrace/trace-ir/stream-class.h> | |
31 | #include <babeltrace/trace-ir/stream-class-internal.h> | |
32 | #include <babeltrace/graph/message-stream.h> | |
33 | #include <babeltrace/graph/message-stream-const.h> | |
34 | #include <babeltrace/graph/message-stream-internal.h> | |
35 | #include <babeltrace/assert-internal.h> | |
36 | #include <inttypes.h> | |
37 | ||
38 | static | |
39 | void bt_message_stream_end_destroy(struct bt_object *obj) | |
40 | { | |
41 | struct bt_message_stream_end *message = | |
42 | (struct bt_message_stream_end *) obj; | |
43 | ||
44 | BT_LIB_LOGD("Destroying stream end message: %!+n", | |
45 | message); | |
46 | BT_LIB_LOGD("Putting stream: %!+s", message->stream); | |
47 | BT_OBJECT_PUT_REF_AND_RESET(message->stream); | |
48 | ||
49 | if (message->default_cv) { | |
50 | bt_clock_value_recycle(message->default_cv); | |
51 | message->default_cv = NULL; | |
52 | } | |
53 | ||
54 | g_free(message); | |
55 | } | |
56 | ||
57 | struct bt_message *bt_message_stream_end_create( | |
58 | struct bt_self_message_iterator *self_msg_iter, | |
59 | struct bt_stream *stream) | |
60 | { | |
61 | struct bt_message_stream_end *message; | |
62 | struct bt_stream_class *stream_class; | |
63 | ||
64 | BT_ASSERT_PRE_NON_NULL(self_msg_iter, "Message iterator"); | |
65 | BT_ASSERT_PRE_NON_NULL(stream, "Stream"); | |
66 | stream_class = bt_stream_borrow_class(stream); | |
67 | BT_ASSERT(stream_class); | |
68 | BT_LIB_LOGD("Creating stream end message object: " | |
69 | "%![stream-]+s, %![sc-]+S", stream, stream_class); | |
70 | message = g_new0(struct bt_message_stream_end, 1); | |
71 | if (!message) { | |
72 | BT_LOGE_STR("Failed to allocate one stream end message."); | |
73 | goto error; | |
74 | } | |
75 | ||
76 | bt_message_init(&message->parent, | |
77 | BT_MESSAGE_TYPE_STREAM_END, | |
78 | bt_message_stream_end_destroy, NULL); | |
79 | message->stream = stream; | |
80 | bt_object_get_no_null_check(message->stream); | |
81 | BT_LIB_LOGD("Created stream end message object: " | |
82 | "%![msg-]+n, %![stream-]+s, %![sc-]+S", message, | |
83 | stream, stream_class); | |
84 | ||
85 | return (void *) &message->parent; | |
86 | error: | |
87 | return NULL; | |
88 | } | |
89 | ||
90 | struct bt_stream *bt_message_stream_end_borrow_stream( | |
91 | struct bt_message *message) | |
92 | { | |
93 | struct bt_message_stream_end *stream_end; | |
94 | ||
95 | BT_ASSERT_PRE_NON_NULL(message, "Message"); | |
96 | BT_ASSERT_PRE_MSG_IS_TYPE(message, | |
97 | BT_MESSAGE_TYPE_STREAM_END); | |
98 | stream_end = (void *) message; | |
99 | return stream_end->stream; | |
100 | } | |
101 | ||
102 | const struct bt_stream *bt_message_stream_end_borrow_stream_const( | |
103 | const struct bt_message *message) | |
104 | { | |
105 | return bt_message_stream_end_borrow_stream( | |
106 | (void *) message); | |
107 | } | |
108 | ||
109 | void bt_message_stream_end_set_default_clock_value( | |
110 | struct bt_message *msg, uint64_t value_cycles) | |
111 | { | |
112 | struct bt_message_stream_end *se_msg = (void *) msg; | |
113 | ||
114 | BT_ASSERT_PRE_NON_NULL(msg, "Message"); | |
115 | BT_ASSERT_PRE_HOT(msg, "Message", ": %!+n", msg); | |
116 | BT_ASSERT_PRE_MSG_IS_TYPE(msg, BT_MESSAGE_TYPE_STREAM_END); | |
117 | BT_ASSERT_PRE(se_msg->stream->class->default_clock_class, | |
118 | "Message's stream class has no default clock class: " | |
119 | "%![msg-]+n, %![sc-]+S", msg, se_msg->stream->class); | |
120 | ||
121 | /* TODO: have the object already created */ | |
122 | se_msg->default_cv = bt_clock_value_create( | |
123 | se_msg->stream->class->default_clock_class); | |
124 | BT_ASSERT(se_msg->default_cv); | |
125 | bt_clock_value_set_value_inline(se_msg->default_cv, value_cycles); | |
126 | BT_LIB_LOGV("Set message's default clock value: %![msg-]+n, " | |
127 | "value=%" PRIu64, value_cycles); | |
128 | } | |
129 | ||
130 | struct bt_clock_value *bt_message_stream_end_borrow_default_clock_value( | |
131 | struct bt_message *msg) | |
132 | { | |
133 | struct bt_message_stream_end *stream_end = (void *) msg; | |
134 | ||
135 | BT_ASSERT_PRE_NON_NULL(msg, "Message"); | |
136 | BT_ASSERT_PRE_MSG_IS_TYPE(msg, BT_MESSAGE_TYPE_STREAM_END); | |
137 | return stream_end->default_cv; | |
138 | } | |
139 | ||
140 | static | |
141 | void bt_message_stream_beginning_destroy(struct bt_object *obj) | |
142 | { | |
143 | struct bt_message_stream_beginning *message = | |
144 | (struct bt_message_stream_beginning *) obj; | |
145 | ||
146 | BT_LIB_LOGD("Destroying stream beginning message: %!+n", | |
147 | message); | |
148 | BT_LIB_LOGD("Putting stream: %!+s", message->stream); | |
149 | BT_OBJECT_PUT_REF_AND_RESET(message->stream); | |
150 | ||
151 | if (message->default_cv) { | |
152 | bt_clock_value_recycle(message->default_cv); | |
153 | message->default_cv = NULL; | |
154 | } | |
155 | ||
156 | g_free(message); | |
157 | } | |
158 | ||
159 | struct bt_message *bt_message_stream_beginning_create( | |
160 | struct bt_self_message_iterator *self_msg_iter, | |
161 | struct bt_stream *stream) | |
162 | { | |
163 | struct bt_message_stream_beginning *message; | |
164 | struct bt_stream_class *stream_class; | |
165 | ||
166 | BT_ASSERT_PRE_NON_NULL(self_msg_iter, "Message iterator"); | |
167 | BT_ASSERT_PRE_NON_NULL(stream, "Stream"); | |
168 | stream_class = bt_stream_borrow_class(stream); | |
169 | BT_ASSERT(stream_class); | |
170 | BT_LIB_LOGD("Creating stream beginning message object: " | |
171 | "%![stream-]+s, %![sc-]+S", stream, stream_class); | |
172 | message = g_new0(struct bt_message_stream_beginning, 1); | |
173 | if (!message) { | |
174 | BT_LOGE_STR("Failed to allocate one stream beginning message."); | |
175 | goto error; | |
176 | } | |
177 | ||
178 | bt_message_init(&message->parent, | |
179 | BT_MESSAGE_TYPE_STREAM_BEGINNING, | |
180 | bt_message_stream_beginning_destroy, NULL); | |
181 | message->stream = stream; | |
182 | bt_object_get_no_null_check(message->stream); | |
183 | BT_LIB_LOGD("Created stream beginning message object: " | |
184 | "%![msg-]+n, %![stream-]+s, %![sc-]+S", message, | |
185 | stream, stream_class); | |
186 | return (void *) &message->parent; | |
187 | error: | |
188 | return NULL; | |
189 | } | |
190 | ||
191 | struct bt_stream *bt_message_stream_beginning_borrow_stream( | |
192 | struct bt_message *message) | |
193 | { | |
194 | struct bt_message_stream_beginning *stream_begin; | |
195 | ||
196 | BT_ASSERT_PRE_NON_NULL(message, "Message"); | |
197 | BT_ASSERT_PRE_MSG_IS_TYPE(message, | |
198 | BT_MESSAGE_TYPE_STREAM_BEGINNING); | |
199 | stream_begin = (void *) message; | |
200 | return stream_begin->stream; | |
201 | } | |
202 | ||
203 | const struct bt_stream *bt_message_stream_beginning_borrow_stream_const( | |
204 | const struct bt_message *message) | |
205 | { | |
206 | return bt_message_stream_beginning_borrow_stream( | |
207 | (void *) message); | |
208 | } | |
209 | ||
210 | void bt_message_stream_beginning_set_default_clock_value( | |
211 | struct bt_message *msg, | |
212 | uint64_t value_cycles) | |
213 | { | |
214 | struct bt_message_stream_beginning *sb_msg = (void *) msg; | |
215 | ||
216 | BT_ASSERT_PRE_NON_NULL(msg, "Message"); | |
217 | BT_ASSERT_PRE_HOT(msg, "Message", ": %!+n", msg); | |
218 | BT_ASSERT_PRE_MSG_IS_TYPE(msg, BT_MESSAGE_TYPE_STREAM_BEGINNING); | |
219 | BT_ASSERT_PRE(sb_msg->stream->class->default_clock_class, | |
220 | "Message's stream class has no default clock class: " | |
221 | "%![msg-]+n, %![sc-]+S", msg, sb_msg->stream->class); | |
222 | ||
223 | /* TODO: have the object already created */ | |
224 | sb_msg->default_cv = bt_clock_value_create( | |
225 | sb_msg->stream->class->default_clock_class); | |
226 | BT_ASSERT(sb_msg->default_cv); | |
227 | bt_clock_value_set_value_inline(sb_msg->default_cv, value_cycles); | |
228 | BT_LIB_LOGV("Set message's default clock value: %![msg-]+n, " | |
229 | "value=%" PRIu64, value_cycles); | |
230 | } | |
231 | ||
232 | struct bt_clock_value *bt_message_stream_beginning_borrow_default_clock_value( | |
233 | struct bt_message *msg) | |
234 | { | |
235 | struct bt_message_stream_beginning *stream_begin = (void *) msg; | |
236 | ||
237 | BT_ASSERT_PRE_NON_NULL(msg, "Message"); | |
238 | BT_ASSERT_PRE_MSG_IS_TYPE(msg, BT_MESSAGE_TYPE_STREAM_BEGINNING); | |
239 | return stream_begin->default_cv; | |
240 | } |