2 * Babeltrace Plug-in Stream-related Notifications
4 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
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:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
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
27 #define BT_LOG_TAG "NOTIF-STREAM"
28 #include <babeltrace/lib-logging-internal.h>
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>
41 void bt_notification_stream_end_destroy(struct bt_object
*obj
)
43 struct bt_notification_stream_end
*notification
=
44 (struct bt_notification_stream_end
*) obj
;
46 BT_LOGD("Destroying stream end notification: addr=%p",
48 BT_LOGD_STR("Putting stream.");
49 BT_PUT(notification
->stream
);
51 if (notification
->default_cv
) {
52 bt_clock_value_recycle(notification
->default_cv
);
58 struct bt_notification
*bt_notification_stream_end_create(
59 struct bt_private_connection_private_notification_iterator
*notif_iter
,
60 struct bt_stream
*stream
)
62 struct bt_notification_stream_end
*notification
;
63 struct bt_stream_class
*stream_class
;
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
),
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);
78 BT_LOGE_STR("Failed to allocate one stream end notification.");
82 bt_notification_init(¬ification
->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
),
92 bt_stream_class_get_name(stream_class
),
93 bt_stream_class_get_id(stream_class
), notification
);
94 return ¬ification
->parent
;
99 struct bt_stream
*bt_notification_stream_end_borrow_stream(
100 struct bt_notification
*notification
)
102 struct bt_notification_stream_end
*stream_end
;
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
;
112 int bt_notification_stream_end_set_default_clock_value(
113 struct bt_notification
*notif
, uint64_t value_cycles
)
116 struct bt_notification_stream_end
*se_notif
= (void *) notif
;
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);
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
) {
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
);
142 struct bt_clock_value
*bt_notification_stream_end_borrow_default_clock_value(
143 struct bt_notification
*notif
)
145 struct bt_notification_stream_end
*stream_end
= (void *) notif
;
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
;
153 void bt_notification_stream_begin_destroy(struct bt_object
*obj
)
155 struct bt_notification_stream_begin
*notification
=
156 (struct bt_notification_stream_begin
*) obj
;
158 BT_LOGD("Destroying stream beginning notification: addr=%p",
160 BT_LOGD_STR("Putting stream.");
161 BT_PUT(notification
->stream
);
163 if (notification
->default_cv
) {
164 bt_clock_value_recycle(notification
->default_cv
);
167 g_free(notification
);
170 struct bt_notification
*bt_notification_stream_begin_create(
171 struct bt_private_connection_private_notification_iterator
*notif_iter
,
172 struct bt_stream
*stream
)
174 struct bt_notification_stream_begin
*notification
;
175 struct bt_stream_class
*stream_class
;
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
),
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);
190 BT_LOGE_STR("Failed to allocate one stream beginning notification.");
194 bt_notification_init(¬ification
->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
),
204 bt_stream_class_get_name(stream_class
),
205 bt_stream_class_get_id(stream_class
), notification
);
206 return ¬ification
->parent
;
211 struct bt_stream
*bt_notification_stream_begin_borrow_stream(
212 struct bt_notification
*notification
)
214 struct bt_notification_stream_begin
*stream_begin
;
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
;
224 int bt_notification_stream_begin_set_default_clock_value(
225 struct bt_notification
*notif
, uint64_t value_cycles
)
228 struct bt_notification_stream_begin
*sb_notif
= (void *) notif
;
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);
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
) {
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
);
254 struct bt_clock_value
*bt_notification_stream_begin_borrow_default_clock_value(
255 struct bt_notification
*notif
)
257 struct bt_notification_stream_begin
*stream_begin
= (void *) notif
;
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
;