2 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 #define BT_LOG_TAG "NOTIF-STREAM"
26 #include <babeltrace/lib-logging-internal.h>
28 #include <babeltrace/assert-pre-internal.h>
29 #include <babeltrace/compiler-internal.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/private-notification-stream.h>
34 #include <babeltrace/graph/notification-stream-internal.h>
35 #include <babeltrace/graph/private-connection-private-notification-iterator.h>
36 #include <babeltrace/assert-internal.h>
37 #include <babeltrace/object.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_OBJECT_PUT_REF_AND_RESET(notification
->stream
);
51 if (notification
->default_cv
) {
52 bt_clock_value_recycle(notification
->default_cv
);
58 struct bt_private_notification
*bt_private_notification_stream_end_create(
59 struct bt_private_connection_private_notification_iterator
*notif_iter
,
60 struct bt_private_stream
*priv_stream
)
62 struct bt_stream
*stream
= (void *) priv_stream
;
63 struct bt_notification_stream_end
*notification
;
64 struct bt_stream_class
*stream_class
;
66 BT_ASSERT_PRE_NON_NULL(stream
, "Stream");
67 stream_class
= bt_stream_borrow_class(stream
);
68 BT_ASSERT(stream_class
);
69 BT_LOGD("Creating stream end notification object: "
70 "stream-addr=%p, stream-name=\"%s\", "
71 "stream-class-addr=%p, stream-class-name=\"%s\", "
72 "stream-class-id=%" PRId64
,
73 stream
, bt_stream_get_name(stream
),
75 bt_stream_class_get_name(stream_class
),
76 bt_stream_class_get_id(stream_class
));
77 notification
= g_new0(struct bt_notification_stream_end
, 1);
79 BT_LOGE_STR("Failed to allocate one stream end notification.");
83 bt_notification_init(¬ification
->parent
,
84 BT_NOTIFICATION_TYPE_STREAM_END
,
85 bt_notification_stream_end_destroy
, NULL
);
86 notification
->stream
= bt_object_get_ref(stream
);
87 BT_LOGD("Created stream end notification object: "
88 "stream-addr=%p, stream-name=\"%s\", "
89 "stream-class-addr=%p, stream-class-name=\"%s\", "
90 "stream-class-id=%" PRId64
", addr=%p",
91 stream
, bt_stream_get_name(stream
),
93 bt_stream_class_get_name(stream_class
),
94 bt_stream_class_get_id(stream_class
), notification
);
96 return (void *) ¬ification
->parent
;
101 struct bt_stream
*bt_notification_stream_end_borrow_stream(
102 struct bt_notification
*notification
)
104 struct bt_notification_stream_end
*stream_end
;
106 BT_ASSERT_PRE_NON_NULL(notification
, "Notification");
107 BT_ASSERT_PRE_NOTIF_IS_TYPE(notification
,
108 BT_NOTIFICATION_TYPE_STREAM_END
);
109 stream_end
= container_of(notification
,
110 struct bt_notification_stream_end
, parent
);
111 return stream_end
->stream
;
114 struct bt_private_stream
*bt_private_notification_stream_end_borrow_stream(
115 struct bt_private_notification
*notification
)
117 return (void *) bt_notification_stream_end_borrow_stream(
118 (void *) notification
);
121 int bt_private_notification_stream_end_set_default_clock_value(
122 struct bt_private_notification
*priv_notif
,
123 uint64_t value_cycles
)
126 struct bt_notification
*notif
= (void *) priv_notif
;
127 struct bt_notification_stream_end
*se_notif
= (void *) notif
;
129 BT_ASSERT_PRE_NON_NULL(notif
, "Notification");
130 BT_ASSERT_PRE_HOT(notif
, "Notification", ": %!+n", notif
);
131 BT_ASSERT_PRE_NOTIF_IS_TYPE(notif
, BT_NOTIFICATION_TYPE_STREAM_END
);
132 BT_ASSERT_PRE(se_notif
->stream
->class->default_clock_class
,
133 "Notification's stream class has no default clock class: "
134 "%![notif-]+n, %![sc-]+S", notif
, se_notif
->stream
->class);
136 if (!se_notif
->default_cv
) {
137 se_notif
->default_cv
= bt_clock_value_create(
138 se_notif
->stream
->class->default_clock_class
);
139 if (!se_notif
->default_cv
) {
145 bt_clock_value_set_value_inline(se_notif
->default_cv
, value_cycles
);
146 BT_LIB_LOGV("Set notification's default clock value: %![notif-]+n, "
147 "value=%" PRIu64
, value_cycles
);
153 struct bt_clock_value
*bt_notification_stream_end_borrow_default_clock_value(
154 struct bt_notification
*notif
)
156 struct bt_notification_stream_end
*stream_end
= (void *) notif
;
158 BT_ASSERT_PRE_NON_NULL(notif
, "Notification");
159 BT_ASSERT_PRE_NOTIF_IS_TYPE(notif
, BT_NOTIFICATION_TYPE_STREAM_END
);
160 return stream_end
->default_cv
;
164 void bt_notification_stream_begin_destroy(struct bt_object
*obj
)
166 struct bt_notification_stream_begin
*notification
=
167 (struct bt_notification_stream_begin
*) obj
;
169 BT_LOGD("Destroying stream beginning notification: addr=%p",
171 BT_LOGD_STR("Putting stream.");
172 BT_OBJECT_PUT_REF_AND_RESET(notification
->stream
);
174 if (notification
->default_cv
) {
175 bt_clock_value_recycle(notification
->default_cv
);
178 g_free(notification
);
181 struct bt_private_notification
*bt_private_notification_stream_begin_create(
182 struct bt_private_connection_private_notification_iterator
*notif_iter
,
183 struct bt_private_stream
*priv_stream
)
185 struct bt_stream
*stream
= (void *) priv_stream
;
186 struct bt_notification_stream_begin
*notification
;
187 struct bt_stream_class
*stream_class
;
189 BT_ASSERT_PRE_NON_NULL(stream
, "Stream");
190 stream_class
= bt_stream_borrow_class(stream
);
191 BT_ASSERT(stream_class
);
192 BT_LOGD("Creating stream beginning notification object: "
193 "stream-addr=%p, stream-name=\"%s\", "
194 "stream-class-addr=%p, stream-class-name=\"%s\", "
195 "stream-class-id=%" PRId64
,
196 stream
, bt_stream_get_name(stream
),
198 bt_stream_class_get_name(stream_class
),
199 bt_stream_class_get_id(stream_class
));
200 notification
= g_new0(struct bt_notification_stream_begin
, 1);
202 BT_LOGE_STR("Failed to allocate one stream beginning notification.");
206 bt_notification_init(¬ification
->parent
,
207 BT_NOTIFICATION_TYPE_STREAM_BEGIN
,
208 bt_notification_stream_begin_destroy
, NULL
);
209 notification
->stream
= bt_object_get_ref(stream
);
210 BT_LOGD("Created stream beginning notification object: "
211 "stream-addr=%p, stream-name=\"%s\", "
212 "stream-class-addr=%p, stream-class-name=\"%s\", "
213 "stream-class-id=%" PRId64
", addr=%p",
214 stream
, bt_stream_get_name(stream
),
216 bt_stream_class_get_name(stream_class
),
217 bt_stream_class_get_id(stream_class
), notification
);
218 return (void *) ¬ification
->parent
;
223 struct bt_stream
*bt_notification_stream_begin_borrow_stream(
224 struct bt_notification
*notification
)
226 struct bt_notification_stream_begin
*stream_begin
;
228 BT_ASSERT_PRE_NON_NULL(notification
, "Notification");
229 BT_ASSERT_PRE_NOTIF_IS_TYPE(notification
,
230 BT_NOTIFICATION_TYPE_STREAM_BEGIN
);
231 stream_begin
= container_of(notification
,
232 struct bt_notification_stream_begin
, parent
);
233 return stream_begin
->stream
;
236 struct bt_private_stream
*bt_private_notification_stream_begin_borrow_stream(
237 struct bt_private_notification
*notification
)
239 return (void *) bt_notification_stream_begin_borrow_stream(
240 (void *) notification
);
243 int bt_private_notification_stream_begin_set_default_clock_value(
244 struct bt_private_notification
*priv_notif
,
245 uint64_t value_cycles
)
248 struct bt_notification
*notif
= (void *) priv_notif
;
249 struct bt_notification_stream_begin
*sb_notif
= (void *) notif
;
251 BT_ASSERT_PRE_NON_NULL(notif
, "Notification");
252 BT_ASSERT_PRE_HOT(notif
, "Notification", ": %!+n", notif
);
253 BT_ASSERT_PRE_NOTIF_IS_TYPE(notif
, BT_NOTIFICATION_TYPE_STREAM_BEGIN
);
254 BT_ASSERT_PRE(sb_notif
->stream
->class->default_clock_class
,
255 "Notification's stream class has no default clock class: "
256 "%![notif-]+n, %![sc-]+S", notif
, sb_notif
->stream
->class);
258 if (!sb_notif
->default_cv
) {
259 sb_notif
->default_cv
= bt_clock_value_create(
260 sb_notif
->stream
->class->default_clock_class
);
261 if (!sb_notif
->default_cv
) {
267 bt_clock_value_set_value_inline(sb_notif
->default_cv
, value_cycles
);
268 BT_LIB_LOGV("Set notification's default clock value: %![notif-]+n, "
269 "value=%" PRIu64
, value_cycles
);
275 struct bt_clock_value
*bt_notification_stream_begin_borrow_default_clock_value(
276 struct bt_notification
*notif
)
278 struct bt_notification_stream_begin
*stream_begin
= (void *) notif
;
280 BT_ASSERT_PRE_NON_NULL(notif
, "Notification");
281 BT_ASSERT_PRE_NOTIF_IS_TYPE(notif
, BT_NOTIFICATION_TYPE_STREAM_BEGIN
);
282 return stream_begin
->default_cv
;