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/ctf-ir/stream-class.h>
33 #include <babeltrace/graph/notification-stream-internal.h>
37 void bt_notification_stream_end_destroy(struct bt_object
*obj
)
39 struct bt_notification_stream_end
*notification
=
40 (struct bt_notification_stream_end
*) obj
;
42 BT_LOGD("Destroying stream end notification: addr=%p",
44 BT_LOGD_STR("Putting stream.");
45 BT_PUT(notification
->stream
);
49 struct bt_notification
*bt_notification_stream_end_create(
50 struct bt_stream
*stream
)
52 struct bt_notification_stream_end
*notification
;
53 struct bt_stream_class
*stream_class
;
56 BT_LOGW_STR("Invalid parameter: stream is NULL.");
60 stream_class
= bt_stream_borrow_stream_class(stream
);
63 if (stream
->pos
.fd
>= 0) {
64 BT_LOGW("Invalid parameter: stream is a CTF writer stream: "
65 "stream-addr=%p, stream-name=\"%s\", "
66 "stream-class-addr=%p, stream-class-name\"%s\", "
67 "stream-class-id=%" PRId64
,
68 stream
, bt_stream_get_name(stream
), stream_class
,
69 bt_stream_class_get_name(stream_class
),
70 bt_stream_class_get_id(stream_class
));
74 BT_LOGD("Creating stream end notification object: "
75 "stream-addr=%p, stream-name=\"%s\", "
76 "stream-class-addr=%p, stream-class-name=\"%s\", "
77 "stream-class-id=%" PRId64
,
78 stream
, bt_stream_get_name(stream
),
80 bt_stream_class_get_name(stream_class
),
81 bt_stream_class_get_id(stream_class
));
82 notification
= g_new0(struct bt_notification_stream_end
, 1);
84 BT_LOGE_STR("Failed to allocate one stream end notification.");
88 bt_notification_init(¬ification
->parent
,
89 BT_NOTIFICATION_TYPE_STREAM_END
,
90 bt_notification_stream_end_destroy
);
91 notification
->stream
= bt_get(stream
);
92 BT_LOGD("Created stream end notification object: "
93 "stream-addr=%p, stream-name=\"%s\", "
94 "stream-class-addr=%p, stream-class-name=\"%s\", "
95 "stream-class-id=%" PRId64
", addr=%p",
96 stream
, bt_stream_get_name(stream
),
98 bt_stream_class_get_name(stream_class
),
99 bt_stream_class_get_id(stream_class
), notification
);
100 return ¬ification
->parent
;
105 struct bt_stream
*bt_notification_stream_end_get_stream(
106 struct bt_notification
*notification
)
108 struct bt_notification_stream_end
*stream_end
;
109 struct bt_stream
*stream
= NULL
;
112 BT_LOGW_STR("Invalid parameter: notification is NULL.");
116 if (notification
->type
!= BT_NOTIFICATION_TYPE_STREAM_END
) {
117 BT_LOGW("Invalid parameter: notification is not a stream end notification: "
118 "addr%p, notif-type=%s",
119 notification
, bt_notification_type_string(
120 bt_notification_get_type(notification
)));
124 stream_end
= container_of(notification
,
125 struct bt_notification_stream_end
, parent
);
126 stream
= bt_get(stream_end
->stream
);
133 void bt_notification_stream_begin_destroy(struct bt_object
*obj
)
135 struct bt_notification_stream_begin
*notification
=
136 (struct bt_notification_stream_begin
*) obj
;
138 BT_LOGD("Destroying stream beginning notification: addr=%p",
140 BT_LOGD_STR("Putting stream.");
141 BT_PUT(notification
->stream
);
142 g_free(notification
);
145 struct bt_notification
*bt_notification_stream_begin_create(
146 struct bt_stream
*stream
)
148 struct bt_notification_stream_begin
*notification
;
149 struct bt_stream_class
*stream_class
;
152 BT_LOGW_STR("Invalid parameter: stream is NULL.");
156 stream_class
= bt_stream_borrow_stream_class(stream
);
157 assert(stream_class
);
159 if (stream
->pos
.fd
>= 0) {
160 BT_LOGW("Invalid parameter: stream is a CTF writer stream: "
161 "stream-addr=%p, stream-name=\"%s\", "
162 "stream-class-addr=%p, stream-class-name\"%s\", "
163 "stream-class-id=%" PRId64
,
164 stream
, bt_stream_get_name(stream
), stream_class
,
165 bt_stream_class_get_name(stream_class
),
166 bt_stream_class_get_id(stream_class
));
170 BT_LOGD("Creating stream beginning notification object: "
171 "stream-addr=%p, stream-name=\"%s\", "
172 "stream-class-addr=%p, stream-class-name=\"%s\", "
173 "stream-class-id=%" PRId64
,
174 stream
, bt_stream_get_name(stream
),
176 bt_stream_class_get_name(stream_class
),
177 bt_stream_class_get_id(stream_class
));
178 notification
= g_new0(struct bt_notification_stream_begin
, 1);
180 BT_LOGE_STR("Failed to allocate one stream beginning notification.");
184 bt_notification_init(¬ification
->parent
,
185 BT_NOTIFICATION_TYPE_STREAM_BEGIN
,
186 bt_notification_stream_begin_destroy
);
187 notification
->stream
= bt_get(stream
);
188 BT_LOGD("Created stream beginning notification object: "
189 "stream-addr=%p, stream-name=\"%s\", "
190 "stream-class-addr=%p, stream-class-name=\"%s\", "
191 "stream-class-id=%" PRId64
", addr=%p",
192 stream
, bt_stream_get_name(stream
),
194 bt_stream_class_get_name(stream_class
),
195 bt_stream_class_get_id(stream_class
), notification
);
196 return ¬ification
->parent
;
201 struct bt_stream
*bt_notification_stream_begin_get_stream(
202 struct bt_notification
*notification
)
204 struct bt_notification_stream_begin
*stream_begin
;
205 struct bt_stream
*stream
= NULL
;
208 BT_LOGW_STR("Invalid parameter: notification is NULL.");
212 if (notification
->type
!= BT_NOTIFICATION_TYPE_STREAM_BEGIN
) {
213 BT_LOGW("Invalid parameter: notification is not a stream beginning notification: "
214 "addr%p, notif-type=%s",
215 notification
, bt_notification_type_string(
216 bt_notification_get_type(notification
)));
220 stream_begin
= container_of(notification
,
221 struct bt_notification_stream_begin
, parent
);
222 stream
= bt_get(stream_begin
->stream
);