CTF IR -> Trace IR
[babeltrace.git] / lib / graph / notification / stream.c
1 /*
2 * Babeltrace Plug-in Stream-related Notifications
3 *
4 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 *
6 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 * SOFTWARE.
25 */
26
27 #define BT_LOG_TAG "NOTIF-STREAM"
28 #include <babeltrace/lib-logging-internal.h>
29
30 #include <babeltrace/assert-pre-internal.h>
31 #include <babeltrace/compiler-internal.h>
32 #include <babeltrace/trace-ir/stream-internal.h>
33 #include <babeltrace/trace-ir/stream-class.h>
34 #include <babeltrace/trace-ir/stream-class-internal.h>
35 #include <babeltrace/graph/notification-stream-internal.h>
36 #include <babeltrace/graph/private-connection-private-notification-iterator.h>
37 #include <babeltrace/assert-internal.h>
38 #include <inttypes.h>
39
40 static
41 void bt_notification_stream_end_destroy(struct bt_object *obj)
42 {
43 struct bt_notification_stream_end *notification =
44 (struct bt_notification_stream_end *) obj;
45
46 BT_LOGD("Destroying stream end notification: addr=%p",
47 notification);
48 BT_LOGD_STR("Putting stream.");
49 BT_PUT(notification->stream);
50
51 if (notification->default_cv) {
52 bt_clock_value_recycle(notification->default_cv);
53 }
54
55 g_free(notification);
56 }
57
58 struct bt_notification *bt_notification_stream_end_create(
59 struct bt_private_connection_private_notification_iterator *notif_iter,
60 struct bt_stream *stream)
61 {
62 struct bt_notification_stream_end *notification;
63 struct bt_stream_class *stream_class;
64
65 BT_ASSERT_PRE_NON_NULL(stream, "Stream");
66 stream_class = bt_stream_borrow_class(stream);
67 BT_ASSERT(stream_class);
68 BT_LOGD("Creating stream end notification object: "
69 "stream-addr=%p, stream-name=\"%s\", "
70 "stream-class-addr=%p, stream-class-name=\"%s\", "
71 "stream-class-id=%" PRId64,
72 stream, bt_stream_get_name(stream),
73 stream_class,
74 bt_stream_class_get_name(stream_class),
75 bt_stream_class_get_id(stream_class));
76 notification = g_new0(struct bt_notification_stream_end, 1);
77 if (!notification) {
78 BT_LOGE_STR("Failed to allocate one stream end notification.");
79 goto error;
80 }
81
82 bt_notification_init(&notification->parent,
83 BT_NOTIFICATION_TYPE_STREAM_END,
84 bt_notification_stream_end_destroy, NULL);
85 notification->stream = bt_get(stream);
86 BT_LOGD("Created stream end notification object: "
87 "stream-addr=%p, stream-name=\"%s\", "
88 "stream-class-addr=%p, stream-class-name=\"%s\", "
89 "stream-class-id=%" PRId64 ", addr=%p",
90 stream, bt_stream_get_name(stream),
91 stream_class,
92 bt_stream_class_get_name(stream_class),
93 bt_stream_class_get_id(stream_class), notification);
94 return &notification->parent;
95 error:
96 return NULL;
97 }
98
99 struct bt_stream *bt_notification_stream_end_borrow_stream(
100 struct bt_notification *notification)
101 {
102 struct bt_notification_stream_end *stream_end;
103
104 BT_ASSERT_PRE_NON_NULL(notification, "Notification");
105 BT_ASSERT_PRE_NOTIF_IS_TYPE(notification,
106 BT_NOTIFICATION_TYPE_STREAM_END);
107 stream_end = container_of(notification,
108 struct bt_notification_stream_end, parent);
109 return stream_end->stream;
110 }
111
112 int bt_notification_stream_end_set_default_clock_value(
113 struct bt_notification *notif, uint64_t value_cycles)
114 {
115 int ret = 0;
116 struct bt_notification_stream_end *se_notif = (void *) notif;
117
118 BT_ASSERT_PRE_NON_NULL(notif, "Notification");
119 BT_ASSERT_PRE_HOT(notif, "Notification", ": %!+n", notif);
120 BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_STREAM_END);
121 BT_ASSERT_PRE(se_notif->stream->class->default_clock_class,
122 "Notification's stream class has no default clock class: "
123 "%![notif-]+n, %![sc-]+S", notif, se_notif->stream->class);
124
125 if (!se_notif->default_cv) {
126 se_notif->default_cv = bt_clock_value_create(
127 se_notif->stream->class->default_clock_class);
128 if (!se_notif->default_cv) {
129 ret = -1;
130 goto end;
131 }
132 }
133
134 bt_clock_value_set_value_inline(se_notif->default_cv, value_cycles);
135 BT_LIB_LOGV("Set notification's default clock value: %![notif-]+n, "
136 "value=%" PRIu64, value_cycles);
137
138 end:
139 return ret;
140 }
141
142 struct bt_clock_value *bt_notification_stream_end_borrow_default_clock_value(
143 struct bt_notification *notif)
144 {
145 struct bt_notification_stream_end *stream_end = (void *) notif;
146
147 BT_ASSERT_PRE_NON_NULL(notif, "Notification");
148 BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_STREAM_END);
149 return stream_end->default_cv;
150 }
151
152 static
153 void bt_notification_stream_begin_destroy(struct bt_object *obj)
154 {
155 struct bt_notification_stream_begin *notification =
156 (struct bt_notification_stream_begin *) obj;
157
158 BT_LOGD("Destroying stream beginning notification: addr=%p",
159 notification);
160 BT_LOGD_STR("Putting stream.");
161 BT_PUT(notification->stream);
162
163 if (notification->default_cv) {
164 bt_clock_value_recycle(notification->default_cv);
165 }
166
167 g_free(notification);
168 }
169
170 struct bt_notification *bt_notification_stream_begin_create(
171 struct bt_private_connection_private_notification_iterator *notif_iter,
172 struct bt_stream *stream)
173 {
174 struct bt_notification_stream_begin *notification;
175 struct bt_stream_class *stream_class;
176
177 BT_ASSERT_PRE_NON_NULL(stream, "Stream");
178 stream_class = bt_stream_borrow_class(stream);
179 BT_ASSERT(stream_class);
180 BT_LOGD("Creating stream beginning notification object: "
181 "stream-addr=%p, stream-name=\"%s\", "
182 "stream-class-addr=%p, stream-class-name=\"%s\", "
183 "stream-class-id=%" PRId64,
184 stream, bt_stream_get_name(stream),
185 stream_class,
186 bt_stream_class_get_name(stream_class),
187 bt_stream_class_get_id(stream_class));
188 notification = g_new0(struct bt_notification_stream_begin, 1);
189 if (!notification) {
190 BT_LOGE_STR("Failed to allocate one stream beginning notification.");
191 goto error;
192 }
193
194 bt_notification_init(&notification->parent,
195 BT_NOTIFICATION_TYPE_STREAM_BEGIN,
196 bt_notification_stream_begin_destroy, NULL);
197 notification->stream = bt_get(stream);
198 BT_LOGD("Created stream beginning notification object: "
199 "stream-addr=%p, stream-name=\"%s\", "
200 "stream-class-addr=%p, stream-class-name=\"%s\", "
201 "stream-class-id=%" PRId64 ", addr=%p",
202 stream, bt_stream_get_name(stream),
203 stream_class,
204 bt_stream_class_get_name(stream_class),
205 bt_stream_class_get_id(stream_class), notification);
206 return &notification->parent;
207 error:
208 return NULL;
209 }
210
211 struct bt_stream *bt_notification_stream_begin_borrow_stream(
212 struct bt_notification *notification)
213 {
214 struct bt_notification_stream_begin *stream_begin;
215
216 BT_ASSERT_PRE_NON_NULL(notification, "Notification");
217 BT_ASSERT_PRE_NOTIF_IS_TYPE(notification,
218 BT_NOTIFICATION_TYPE_STREAM_BEGIN);
219 stream_begin = container_of(notification,
220 struct bt_notification_stream_begin, parent);
221 return stream_begin->stream;
222 }
223
224 int bt_notification_stream_begin_set_default_clock_value(
225 struct bt_notification *notif, uint64_t value_cycles)
226 {
227 int ret = 0;
228 struct bt_notification_stream_begin *sb_notif = (void *) notif;
229
230 BT_ASSERT_PRE_NON_NULL(notif, "Notification");
231 BT_ASSERT_PRE_HOT(notif, "Notification", ": %!+n", notif);
232 BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_STREAM_BEGIN);
233 BT_ASSERT_PRE(sb_notif->stream->class->default_clock_class,
234 "Notification's stream class has no default clock class: "
235 "%![notif-]+n, %![sc-]+S", notif, sb_notif->stream->class);
236
237 if (!sb_notif->default_cv) {
238 sb_notif->default_cv = bt_clock_value_create(
239 sb_notif->stream->class->default_clock_class);
240 if (!sb_notif->default_cv) {
241 ret = -1;
242 goto end;
243 }
244 }
245
246 bt_clock_value_set_value_inline(sb_notif->default_cv, value_cycles);
247 BT_LIB_LOGV("Set notification's default clock value: %![notif-]+n, "
248 "value=%" PRIu64, value_cycles);
249
250 end:
251 return ret;
252 }
253
254 struct bt_clock_value *bt_notification_stream_begin_borrow_default_clock_value(
255 struct bt_notification *notif)
256 {
257 struct bt_notification_stream_begin *stream_begin = (void *) notif;
258
259 BT_ASSERT_PRE_NON_NULL(notif, "Notification");
260 BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_STREAM_BEGIN);
261 return stream_begin->default_cv;
262 }
This page took 0.043555 seconds and 4 git commands to generate.