lib: bt_object_{get,put}_ref(): accept a `const` parameter
[babeltrace.git] / lib / graph / notification / stream.c
1 /*
2 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 *
4 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 *
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:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
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
22 * SOFTWARE.
23 */
24
25 #define BT_LOG_TAG "NOTIF-STREAM"
26 #include <babeltrace/lib-logging-internal.h>
27
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/assert-internal.h>
36 #include <babeltrace/object.h>
37 #include <inttypes.h>
38
39 static
40 void bt_notification_stream_end_destroy(struct bt_object *obj)
41 {
42 struct bt_notification_stream_end *notification =
43 (struct bt_notification_stream_end *) obj;
44
45 BT_LIB_LOGD("Destroying stream end notification: %!+n",
46 notification);
47 BT_LIB_LOGD("Putting stream: %!+s", notification->stream);
48 BT_OBJECT_PUT_REF_AND_RESET(notification->stream);
49
50 if (notification->default_cv) {
51 bt_clock_value_recycle(notification->default_cv);
52 notification->default_cv = NULL;
53 }
54
55 g_free(notification);
56 }
57
58 struct bt_private_notification *bt_private_notification_stream_end_create(
59 struct bt_self_notification_iterator *self_notif_iter,
60 struct bt_private_stream *priv_stream)
61 {
62 struct bt_stream *stream = (void *) priv_stream;
63 struct bt_notification_stream_end *notification;
64 struct bt_stream_class *stream_class;
65
66 BT_ASSERT_PRE_NON_NULL(self_notif_iter, "Notification iterator");
67 BT_ASSERT_PRE_NON_NULL(stream, "Stream");
68 stream_class = bt_stream_borrow_class(stream);
69 BT_ASSERT(stream_class);
70 BT_LIB_LOGD("Creating stream end notification object: "
71 "%![stream-]+s, %![sc-]+S", stream, stream_class);
72 notification = g_new0(struct bt_notification_stream_end, 1);
73 if (!notification) {
74 BT_LOGE_STR("Failed to allocate one stream end notification.");
75 goto error;
76 }
77
78 bt_notification_init(&notification->parent,
79 BT_NOTIFICATION_TYPE_STREAM_END,
80 bt_notification_stream_end_destroy, NULL);
81 notification->stream = stream;
82 bt_object_get_no_null_check(notification->stream);
83 BT_LIB_LOGD("Created stream end notification object: "
84 "%![notif-]+n, %![stream-]+s, %![sc-]+S", notification,
85 stream, stream_class);
86
87 return (void *) &notification->parent;
88 error:
89 return NULL;
90 }
91
92 struct bt_stream *bt_notification_stream_end_borrow_stream(
93 struct bt_notification *notification)
94 {
95 struct bt_notification_stream_end *stream_end;
96
97 BT_ASSERT_PRE_NON_NULL(notification, "Notification");
98 BT_ASSERT_PRE_NOTIF_IS_TYPE(notification,
99 BT_NOTIFICATION_TYPE_STREAM_END);
100 stream_end = container_of(notification,
101 struct bt_notification_stream_end, parent);
102 return stream_end->stream;
103 }
104
105 struct bt_private_stream *bt_private_notification_stream_end_borrow_stream(
106 struct bt_private_notification *notification)
107 {
108 return (void *) bt_notification_stream_end_borrow_stream(
109 (void *) notification);
110 }
111
112 void bt_private_notification_stream_end_set_default_clock_value(
113 struct bt_private_notification *priv_notif,
114 uint64_t value_cycles)
115 {
116 struct bt_notification *notif = (void *) priv_notif;
117 struct bt_notification_stream_end *se_notif = (void *) notif;
118
119 BT_ASSERT_PRE_NON_NULL(notif, "Notification");
120 BT_ASSERT_PRE_HOT(notif, "Notification", ": %!+n", notif);
121 BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_STREAM_END);
122 BT_ASSERT_PRE(se_notif->stream->class->default_clock_class,
123 "Notification's stream class has no default clock class: "
124 "%![notif-]+n, %![sc-]+S", notif, se_notif->stream->class);
125
126 /* TODO: have the object already created */
127 se_notif->default_cv = bt_clock_value_create(
128 se_notif->stream->class->default_clock_class);
129 BT_ASSERT(se_notif->default_cv);
130 bt_clock_value_set_value_inline(se_notif->default_cv, value_cycles);
131 BT_LIB_LOGV("Set notification's default clock value: %![notif-]+n, "
132 "value=%" PRIu64, value_cycles);
133 }
134
135 struct bt_clock_value *bt_notification_stream_end_borrow_default_clock_value(
136 struct bt_notification *notif)
137 {
138 struct bt_notification_stream_end *stream_end = (void *) notif;
139
140 BT_ASSERT_PRE_NON_NULL(notif, "Notification");
141 BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_STREAM_END);
142 return stream_end->default_cv;
143 }
144
145 static
146 void bt_notification_stream_begin_destroy(struct bt_object *obj)
147 {
148 struct bt_notification_stream_begin *notification =
149 (struct bt_notification_stream_begin *) obj;
150
151 BT_LIB_LOGD("Destroying stream beginning notification: %!+n",
152 notification);
153 BT_LIB_LOGD("Putting stream: %!+s", notification->stream);
154 BT_OBJECT_PUT_REF_AND_RESET(notification->stream);
155
156 if (notification->default_cv) {
157 bt_clock_value_recycle(notification->default_cv);
158 notification->default_cv = NULL;
159 }
160
161 g_free(notification);
162 }
163
164 struct bt_private_notification *bt_private_notification_stream_begin_create(
165 struct bt_self_notification_iterator *self_notif_iter,
166 struct bt_private_stream *priv_stream)
167 {
168 struct bt_stream *stream = (void *) priv_stream;
169 struct bt_notification_stream_begin *notification;
170 struct bt_stream_class *stream_class;
171
172 BT_ASSERT_PRE_NON_NULL(self_notif_iter, "Notification iterator");
173 BT_ASSERT_PRE_NON_NULL(stream, "Stream");
174 stream_class = bt_stream_borrow_class(stream);
175 BT_ASSERT(stream_class);
176 BT_LIB_LOGD("Creating stream beginning notification object: "
177 "%![stream-]+s, %![sc-]+S", stream, stream_class);
178 notification = g_new0(struct bt_notification_stream_begin, 1);
179 if (!notification) {
180 BT_LOGE_STR("Failed to allocate one stream beginning notification.");
181 goto error;
182 }
183
184 bt_notification_init(&notification->parent,
185 BT_NOTIFICATION_TYPE_STREAM_BEGIN,
186 bt_notification_stream_begin_destroy, NULL);
187 notification->stream = stream;
188 bt_object_get_no_null_check(notification->stream);
189 BT_LIB_LOGD("Created stream beginning notification object: "
190 "%![notif-]+n, %![stream-]+s, %![sc-]+S", notification,
191 stream, stream_class);
192 return (void *) &notification->parent;
193 error:
194 return NULL;
195 }
196
197 struct bt_stream *bt_notification_stream_begin_borrow_stream(
198 struct bt_notification *notification)
199 {
200 struct bt_notification_stream_begin *stream_begin;
201
202 BT_ASSERT_PRE_NON_NULL(notification, "Notification");
203 BT_ASSERT_PRE_NOTIF_IS_TYPE(notification,
204 BT_NOTIFICATION_TYPE_STREAM_BEGIN);
205 stream_begin = container_of(notification,
206 struct bt_notification_stream_begin, parent);
207 return stream_begin->stream;
208 }
209
210 struct bt_private_stream *bt_private_notification_stream_begin_borrow_stream(
211 struct bt_private_notification *notification)
212 {
213 return (void *) bt_notification_stream_begin_borrow_stream(
214 (void *) notification);
215 }
216
217 void bt_private_notification_stream_begin_set_default_clock_value(
218 struct bt_private_notification *priv_notif,
219 uint64_t value_cycles)
220 {
221 struct bt_notification *notif = (void *) priv_notif;
222 struct bt_notification_stream_begin *sb_notif = (void *) notif;
223
224 BT_ASSERT_PRE_NON_NULL(notif, "Notification");
225 BT_ASSERT_PRE_HOT(notif, "Notification", ": %!+n", notif);
226 BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_STREAM_BEGIN);
227 BT_ASSERT_PRE(sb_notif->stream->class->default_clock_class,
228 "Notification's stream class has no default clock class: "
229 "%![notif-]+n, %![sc-]+S", notif, sb_notif->stream->class);
230
231 /* TODO: have the object already created */
232 sb_notif->default_cv = bt_clock_value_create(
233 sb_notif->stream->class->default_clock_class);
234 BT_ASSERT(sb_notif->default_cv);
235 bt_clock_value_set_value_inline(sb_notif->default_cv, value_cycles);
236 BT_LIB_LOGV("Set notification's default clock value: %![notif-]+n, "
237 "value=%" PRIu64, value_cycles);
238 }
239
240 struct bt_clock_value *bt_notification_stream_begin_borrow_default_clock_value(
241 struct bt_notification *notif)
242 {
243 struct bt_notification_stream_begin *stream_begin = (void *) notif;
244
245 BT_ASSERT_PRE_NON_NULL(notif, "Notification");
246 BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_STREAM_BEGIN);
247 return stream_begin->default_cv;
248 }
This page took 0.037968 seconds and 4 git commands to generate.