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/compiler-internal.h>
31 #include <babeltrace/ctf-ir/stream-internal.h>
32 #include <babeltrace/graph/notification-stream-internal.h>
36 void bt_notification_stream_end_destroy(struct bt_object
*obj
)
38 struct bt_notification_stream_end
*notification
=
39 (struct bt_notification_stream_end
*) obj
;
41 BT_LOGD("Destroying stream end notification: addr=%p",
43 BT_LOGD_STR("Putting stream.");
44 BT_PUT(notification
->stream
);
48 struct bt_notification
*bt_notification_stream_end_create(
49 struct bt_ctf_stream
*stream
)
51 struct bt_notification_stream_end
*notification
;
52 struct bt_ctf_stream_class
*stream_class
;
55 BT_LOGW_STR("Invalid parameter: stream is NULL.");
59 stream_class
= bt_ctf_stream_borrow_stream_class(stream
);
62 if (stream
->pos
.fd
>= 0) {
63 BT_LOGW("Invalid parameter: stream is a CTF writer stream: "
64 "stream-addr=%p, stream-name=\"%s\", "
65 "stream-class-addr=%p, stream-class-name\"%s\", "
66 "stream-class-id=%" PRId64
,
67 stream
, bt_ctf_stream_get_name(stream
), stream_class
,
68 bt_ctf_stream_class_get_name(stream_class
),
69 bt_ctf_stream_class_get_id(stream_class
));
73 BT_LOGD("Creating stream end notification object: "
74 "stream-addr=%p, stream-name=\"%s\", "
75 "stream-class-addr=%p, stream-class-name=\"%s\", "
76 "stream-class-id=%" PRId64
,
77 stream
, bt_ctf_stream_get_name(stream
),
79 bt_ctf_stream_class_get_name(stream_class
),
80 bt_ctf_stream_class_get_id(stream_class
));
81 notification
= g_new0(struct bt_notification_stream_end
, 1);
83 BT_LOGE_STR("Failed to allocate one stream end notification.");
87 bt_notification_init(¬ification
->parent
,
88 BT_NOTIFICATION_TYPE_STREAM_END
,
89 bt_notification_stream_end_destroy
);
90 notification
->stream
= bt_get(stream
);
91 BT_LOGD("Created stream end notification object: "
92 "stream-addr=%p, stream-name=\"%s\", "
93 "stream-class-addr=%p, stream-class-name=\"%s\", "
94 "stream-class-id=%" PRId64
", addr=%p",
95 stream
, bt_ctf_stream_get_name(stream
),
97 bt_ctf_stream_class_get_name(stream_class
),
98 bt_ctf_stream_class_get_id(stream_class
), notification
);
99 return ¬ification
->parent
;
104 struct bt_ctf_stream
*bt_notification_stream_end_get_stream(
105 struct bt_notification
*notification
)
107 struct bt_notification_stream_end
*stream_end
;
108 struct bt_ctf_stream
*stream
= NULL
;
111 BT_LOGW_STR("Invalid parameter: notification is NULL.");
115 if (notification
->type
!= BT_NOTIFICATION_TYPE_STREAM_END
) {
116 BT_LOGW("Invalid parameter: notification is not a stream end notification: "
117 "addr%p, notif-type=%s",
118 notification
, bt_notification_type_string(
119 bt_notification_get_type(notification
)));
123 stream_end
= container_of(notification
,
124 struct bt_notification_stream_end
, parent
);
125 stream
= bt_get(stream_end
->stream
);
132 void bt_notification_stream_begin_destroy(struct bt_object
*obj
)
134 struct bt_notification_stream_begin
*notification
=
135 (struct bt_notification_stream_begin
*) obj
;
137 BT_LOGD("Destroying stream beginning notification: addr=%p",
139 BT_LOGD_STR("Putting stream.");
140 BT_PUT(notification
->stream
);
141 g_free(notification
);
144 struct bt_notification
*bt_notification_stream_begin_create(
145 struct bt_ctf_stream
*stream
)
147 struct bt_notification_stream_begin
*notification
;
148 struct bt_ctf_stream_class
*stream_class
;
151 BT_LOGW_STR("Invalid parameter: stream is NULL.");
155 stream_class
= bt_ctf_stream_borrow_stream_class(stream
);
156 assert(stream_class
);
158 if (stream
->pos
.fd
>= 0) {
159 BT_LOGW("Invalid parameter: stream is a CTF writer stream: "
160 "stream-addr=%p, stream-name=\"%s\", "
161 "stream-class-addr=%p, stream-class-name\"%s\", "
162 "stream-class-id=%" PRId64
,
163 stream
, bt_ctf_stream_get_name(stream
), stream_class
,
164 bt_ctf_stream_class_get_name(stream_class
),
165 bt_ctf_stream_class_get_id(stream_class
));
169 BT_LOGD("Creating stream beginning notification object: "
170 "stream-addr=%p, stream-name=\"%s\", "
171 "stream-class-addr=%p, stream-class-name=\"%s\", "
172 "stream-class-id=%" PRId64
,
173 stream
, bt_ctf_stream_get_name(stream
),
175 bt_ctf_stream_class_get_name(stream_class
),
176 bt_ctf_stream_class_get_id(stream_class
));
177 notification
= g_new0(struct bt_notification_stream_begin
, 1);
179 BT_LOGE_STR("Failed to allocate one stream beginning notification.");
183 bt_notification_init(¬ification
->parent
,
184 BT_NOTIFICATION_TYPE_STREAM_BEGIN
,
185 bt_notification_stream_begin_destroy
);
186 notification
->stream
= bt_get(stream
);
187 BT_LOGD("Created stream beginning notification object: "
188 "stream-addr=%p, stream-name=\"%s\", "
189 "stream-class-addr=%p, stream-class-name=\"%s\", "
190 "stream-class-id=%" PRId64
", addr=%p",
191 stream
, bt_ctf_stream_get_name(stream
),
193 bt_ctf_stream_class_get_name(stream_class
),
194 bt_ctf_stream_class_get_id(stream_class
), notification
);
195 return ¬ification
->parent
;
200 struct bt_ctf_stream
*bt_notification_stream_begin_get_stream(
201 struct bt_notification
*notification
)
203 struct bt_notification_stream_begin
*stream_begin
;
204 struct bt_ctf_stream
*stream
= NULL
;
207 BT_LOGW_STR("Invalid parameter: notification is NULL.");
211 if (notification
->type
!= BT_NOTIFICATION_TYPE_STREAM_BEGIN
) {
212 BT_LOGW("Invalid parameter: notification is not a stream beginning notification: "
213 "addr%p, notif-type=%s",
214 notification
, bt_notification_type_string(
215 bt_notification_get_type(notification
)));
219 stream_begin
= container_of(notification
,
220 struct bt_notification_stream_begin
, parent
);
221 stream
= bt_get(stream_begin
->stream
);