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> |
8b45963b PP |
34 | #include <babeltrace/assert-internal.h> |
35 | #include <babeltrace/assert-pre-internal.h> | |
d229f56b | 36 | #include <inttypes.h> |
043e2020 JG |
37 | |
38 | static | |
39 | void bt_notification_stream_end_destroy(struct bt_object *obj) | |
40 | { | |
41 | struct bt_notification_stream_end *notification = | |
42 | (struct bt_notification_stream_end *) obj; | |
43 | ||
d229f56b PP |
44 | BT_LOGD("Destroying stream end notification: addr=%p", |
45 | notification); | |
46 | BT_LOGD_STR("Putting stream."); | |
043e2020 JG |
47 | BT_PUT(notification->stream); |
48 | g_free(notification); | |
49 | } | |
50 | ||
51 | struct bt_notification *bt_notification_stream_end_create( | |
839d52a5 | 52 | struct bt_stream *stream) |
043e2020 JG |
53 | { |
54 | struct bt_notification_stream_end *notification; | |
839d52a5 | 55 | struct bt_stream_class *stream_class; |
043e2020 | 56 | |
8b45963b PP |
57 | BT_ASSERT_PRE_NON_NULL(stream, "Stream"); |
58 | BT_ASSERT_PRE(stream->pos.fd < 0, | |
59 | "Stream is a CTF writer stream: %!+s", stream); | |
839d52a5 | 60 | stream_class = bt_stream_borrow_stream_class(stream); |
8b45963b | 61 | BT_ASSERT(stream_class); |
d229f56b PP |
62 | BT_LOGD("Creating stream end notification object: " |
63 | "stream-addr=%p, stream-name=\"%s\", " | |
64 | "stream-class-addr=%p, stream-class-name=\"%s\", " | |
65 | "stream-class-id=%" PRId64, | |
839d52a5 | 66 | stream, bt_stream_get_name(stream), |
d229f56b | 67 | stream_class, |
839d52a5 PP |
68 | bt_stream_class_get_name(stream_class), |
69 | bt_stream_class_get_id(stream_class)); | |
043e2020 | 70 | notification = g_new0(struct bt_notification_stream_end, 1); |
d229f56b PP |
71 | if (!notification) { |
72 | BT_LOGE_STR("Failed to allocate one stream end notification."); | |
73 | goto error; | |
74 | } | |
75 | ||
043e2020 JG |
76 | bt_notification_init(¬ification->parent, |
77 | BT_NOTIFICATION_TYPE_STREAM_END, | |
78 | bt_notification_stream_end_destroy); | |
79 | notification->stream = bt_get(stream); | |
d229f56b PP |
80 | BT_LOGD("Created stream end notification object: " |
81 | "stream-addr=%p, stream-name=\"%s\", " | |
82 | "stream-class-addr=%p, stream-class-name=\"%s\", " | |
83 | "stream-class-id=%" PRId64 ", addr=%p", | |
839d52a5 | 84 | stream, bt_stream_get_name(stream), |
d229f56b | 85 | stream_class, |
839d52a5 PP |
86 | bt_stream_class_get_name(stream_class), |
87 | bt_stream_class_get_id(stream_class), notification); | |
043e2020 JG |
88 | return ¬ification->parent; |
89 | error: | |
90 | return NULL; | |
91 | } | |
92 | ||
839d52a5 | 93 | struct bt_stream *bt_notification_stream_end_get_stream( |
043e2020 JG |
94 | struct bt_notification *notification) |
95 | { | |
96 | struct bt_notification_stream_end *stream_end; | |
97 | ||
8b45963b PP |
98 | BT_ASSERT_PRE_NON_NULL(notification, "Notification"); |
99 | BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, | |
100 | BT_NOTIFICATION_TYPE_STREAM_END); | |
043e2020 JG |
101 | stream_end = container_of(notification, |
102 | struct bt_notification_stream_end, parent); | |
8b45963b | 103 | return bt_get(stream_end->stream); |
043e2020 | 104 | } |
3230ee6b PP |
105 | |
106 | static | |
107 | void bt_notification_stream_begin_destroy(struct bt_object *obj) | |
108 | { | |
109 | struct bt_notification_stream_begin *notification = | |
110 | (struct bt_notification_stream_begin *) obj; | |
111 | ||
d229f56b PP |
112 | BT_LOGD("Destroying stream beginning notification: addr=%p", |
113 | notification); | |
114 | BT_LOGD_STR("Putting stream."); | |
3230ee6b PP |
115 | BT_PUT(notification->stream); |
116 | g_free(notification); | |
117 | } | |
118 | ||
119 | struct bt_notification *bt_notification_stream_begin_create( | |
839d52a5 | 120 | struct bt_stream *stream) |
3230ee6b PP |
121 | { |
122 | struct bt_notification_stream_begin *notification; | |
839d52a5 | 123 | struct bt_stream_class *stream_class; |
3230ee6b | 124 | |
8b45963b PP |
125 | BT_ASSERT_PRE_NON_NULL(stream, "Stream"); |
126 | BT_ASSERT_PRE(stream->pos.fd < 0, | |
127 | "Stream is a CTF writer stream: %!+s", stream); | |
839d52a5 | 128 | stream_class = bt_stream_borrow_stream_class(stream); |
8b45963b | 129 | BT_ASSERT(stream_class); |
d229f56b PP |
130 | BT_LOGD("Creating stream beginning notification object: " |
131 | "stream-addr=%p, stream-name=\"%s\", " | |
132 | "stream-class-addr=%p, stream-class-name=\"%s\", " | |
133 | "stream-class-id=%" PRId64, | |
839d52a5 | 134 | stream, bt_stream_get_name(stream), |
d229f56b | 135 | stream_class, |
839d52a5 PP |
136 | bt_stream_class_get_name(stream_class), |
137 | bt_stream_class_get_id(stream_class)); | |
3230ee6b | 138 | notification = g_new0(struct bt_notification_stream_begin, 1); |
d229f56b PP |
139 | if (!notification) { |
140 | BT_LOGE_STR("Failed to allocate one stream beginning notification."); | |
141 | goto error; | |
142 | } | |
143 | ||
3230ee6b PP |
144 | bt_notification_init(¬ification->parent, |
145 | BT_NOTIFICATION_TYPE_STREAM_BEGIN, | |
146 | bt_notification_stream_begin_destroy); | |
147 | notification->stream = bt_get(stream); | |
d229f56b PP |
148 | BT_LOGD("Created stream beginning notification object: " |
149 | "stream-addr=%p, stream-name=\"%s\", " | |
150 | "stream-class-addr=%p, stream-class-name=\"%s\", " | |
151 | "stream-class-id=%" PRId64 ", addr=%p", | |
839d52a5 | 152 | stream, bt_stream_get_name(stream), |
d229f56b | 153 | stream_class, |
839d52a5 PP |
154 | bt_stream_class_get_name(stream_class), |
155 | bt_stream_class_get_id(stream_class), notification); | |
3230ee6b PP |
156 | return ¬ification->parent; |
157 | error: | |
158 | return NULL; | |
159 | } | |
160 | ||
839d52a5 | 161 | struct bt_stream *bt_notification_stream_begin_get_stream( |
3230ee6b PP |
162 | struct bt_notification *notification) |
163 | { | |
164 | struct bt_notification_stream_begin *stream_begin; | |
165 | ||
8b45963b PP |
166 | BT_ASSERT_PRE_NON_NULL(notification, "Notification"); |
167 | BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, | |
168 | BT_NOTIFICATION_TYPE_STREAM_BEGIN); | |
3230ee6b PP |
169 | stream_begin = container_of(notification, |
170 | struct bt_notification_stream_begin, parent); | |
8b45963b | 171 | return bt_get(stream_begin->stream); |
3230ee6b | 172 | } |