Commit | Line | Data |
---|---|---|
043e2020 JG |
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 | ||
d229f56b PP |
27 | #define BT_LOG_TAG "NOTIF-STREAM" |
28 | #include <babeltrace/lib-logging-internal.h> | |
29 | ||
3d9990ac | 30 | #include <babeltrace/compiler-internal.h> |
3230ee6b | 31 | #include <babeltrace/ctf-ir/stream-internal.h> |
e0831b38 | 32 | #include <babeltrace/ctf-ir/stream-class.h> |
b2e0c907 | 33 | #include <babeltrace/graph/notification-stream-internal.h> |
d229f56b | 34 | #include <inttypes.h> |
043e2020 JG |
35 | |
36 | static | |
37 | void bt_notification_stream_end_destroy(struct bt_object *obj) | |
38 | { | |
39 | struct bt_notification_stream_end *notification = | |
40 | (struct bt_notification_stream_end *) obj; | |
41 | ||
d229f56b PP |
42 | BT_LOGD("Destroying stream end notification: addr=%p", |
43 | notification); | |
44 | BT_LOGD_STR("Putting stream."); | |
043e2020 JG |
45 | BT_PUT(notification->stream); |
46 | g_free(notification); | |
47 | } | |
48 | ||
49 | struct bt_notification *bt_notification_stream_end_create( | |
839d52a5 | 50 | struct bt_stream *stream) |
043e2020 JG |
51 | { |
52 | struct bt_notification_stream_end *notification; | |
839d52a5 | 53 | struct bt_stream_class *stream_class; |
043e2020 | 54 | |
d229f56b PP |
55 | if (!stream) { |
56 | BT_LOGW_STR("Invalid parameter: stream is NULL."); | |
043e2020 JG |
57 | goto error; |
58 | } | |
59 | ||
839d52a5 | 60 | stream_class = bt_stream_borrow_stream_class(stream); |
d229f56b PP |
61 | assert(stream_class); |
62 | ||
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, | |
839d52a5 PP |
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)); | |
d229f56b PP |
71 | goto error; |
72 | } | |
73 | ||
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, | |
839d52a5 | 78 | stream, bt_stream_get_name(stream), |
d229f56b | 79 | stream_class, |
839d52a5 PP |
80 | bt_stream_class_get_name(stream_class), |
81 | bt_stream_class_get_id(stream_class)); | |
043e2020 | 82 | notification = g_new0(struct bt_notification_stream_end, 1); |
d229f56b PP |
83 | if (!notification) { |
84 | BT_LOGE_STR("Failed to allocate one stream end notification."); | |
85 | goto error; | |
86 | } | |
87 | ||
043e2020 JG |
88 | bt_notification_init(¬ification->parent, |
89 | BT_NOTIFICATION_TYPE_STREAM_END, | |
90 | bt_notification_stream_end_destroy); | |
91 | notification->stream = bt_get(stream); | |
d229f56b PP |
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", | |
839d52a5 | 96 | stream, bt_stream_get_name(stream), |
d229f56b | 97 | stream_class, |
839d52a5 PP |
98 | bt_stream_class_get_name(stream_class), |
99 | bt_stream_class_get_id(stream_class), notification); | |
043e2020 JG |
100 | return ¬ification->parent; |
101 | error: | |
102 | return NULL; | |
103 | } | |
104 | ||
839d52a5 | 105 | struct bt_stream *bt_notification_stream_end_get_stream( |
043e2020 JG |
106 | struct bt_notification *notification) |
107 | { | |
108 | struct bt_notification_stream_end *stream_end; | |
839d52a5 | 109 | struct bt_stream *stream = NULL; |
d229f56b PP |
110 | |
111 | if (!notification) { | |
112 | BT_LOGW_STR("Invalid parameter: notification is NULL."); | |
113 | goto end; | |
114 | } | |
115 | ||
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))); | |
121 | goto end; | |
122 | } | |
043e2020 JG |
123 | |
124 | stream_end = container_of(notification, | |
125 | struct bt_notification_stream_end, parent); | |
d229f56b PP |
126 | stream = bt_get(stream_end->stream); |
127 | ||
128 | end: | |
129 | return stream; | |
043e2020 | 130 | } |
3230ee6b PP |
131 | |
132 | static | |
133 | void bt_notification_stream_begin_destroy(struct bt_object *obj) | |
134 | { | |
135 | struct bt_notification_stream_begin *notification = | |
136 | (struct bt_notification_stream_begin *) obj; | |
137 | ||
d229f56b PP |
138 | BT_LOGD("Destroying stream beginning notification: addr=%p", |
139 | notification); | |
140 | BT_LOGD_STR("Putting stream."); | |
3230ee6b PP |
141 | BT_PUT(notification->stream); |
142 | g_free(notification); | |
143 | } | |
144 | ||
145 | struct bt_notification *bt_notification_stream_begin_create( | |
839d52a5 | 146 | struct bt_stream *stream) |
3230ee6b PP |
147 | { |
148 | struct bt_notification_stream_begin *notification; | |
839d52a5 | 149 | struct bt_stream_class *stream_class; |
3230ee6b | 150 | |
d229f56b PP |
151 | if (!stream) { |
152 | BT_LOGW_STR("Invalid parameter: stream is NULL."); | |
3230ee6b PP |
153 | goto error; |
154 | } | |
155 | ||
839d52a5 | 156 | stream_class = bt_stream_borrow_stream_class(stream); |
d229f56b PP |
157 | assert(stream_class); |
158 | ||
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, | |
839d52a5 PP |
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)); | |
d229f56b PP |
167 | goto error; |
168 | } | |
169 | ||
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, | |
839d52a5 | 174 | stream, bt_stream_get_name(stream), |
d229f56b | 175 | stream_class, |
839d52a5 PP |
176 | bt_stream_class_get_name(stream_class), |
177 | bt_stream_class_get_id(stream_class)); | |
3230ee6b | 178 | notification = g_new0(struct bt_notification_stream_begin, 1); |
d229f56b PP |
179 | if (!notification) { |
180 | BT_LOGE_STR("Failed to allocate one stream beginning notification."); | |
181 | goto error; | |
182 | } | |
183 | ||
3230ee6b PP |
184 | bt_notification_init(¬ification->parent, |
185 | BT_NOTIFICATION_TYPE_STREAM_BEGIN, | |
186 | bt_notification_stream_begin_destroy); | |
187 | notification->stream = bt_get(stream); | |
d229f56b PP |
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", | |
839d52a5 | 192 | stream, bt_stream_get_name(stream), |
d229f56b | 193 | stream_class, |
839d52a5 PP |
194 | bt_stream_class_get_name(stream_class), |
195 | bt_stream_class_get_id(stream_class), notification); | |
3230ee6b PP |
196 | return ¬ification->parent; |
197 | error: | |
198 | return NULL; | |
199 | } | |
200 | ||
839d52a5 | 201 | struct bt_stream *bt_notification_stream_begin_get_stream( |
3230ee6b PP |
202 | struct bt_notification *notification) |
203 | { | |
204 | struct bt_notification_stream_begin *stream_begin; | |
839d52a5 | 205 | struct bt_stream *stream = NULL; |
d229f56b PP |
206 | |
207 | if (!notification) { | |
208 | BT_LOGW_STR("Invalid parameter: notification is NULL."); | |
209 | goto end; | |
210 | } | |
211 | ||
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))); | |
217 | goto end; | |
218 | } | |
3230ee6b PP |
219 | |
220 | stream_begin = container_of(notification, | |
221 | struct bt_notification_stream_begin, parent); | |
d229f56b PP |
222 | stream = bt_get(stream_begin->stream); |
223 | ||
224 | end: | |
225 | return stream; | |
3230ee6b | 226 | } |