lib: return `void` when setting a simple value with no side effects
[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 = bt_object_get_ref(stream);
82 BT_LIB_LOGD("Created stream end notification object: "
83 "%![notif-]+n, %![stream-]+s, %![sc-]+S", notification,
84 stream, stream_class);
85
86 return (void *) &notification->parent;
87 error:
88 return NULL;
89 }
90
91 struct bt_stream *bt_notification_stream_end_borrow_stream(
92 struct bt_notification *notification)
93 {
94 struct bt_notification_stream_end *stream_end;
95
96 BT_ASSERT_PRE_NON_NULL(notification, "Notification");
97 BT_ASSERT_PRE_NOTIF_IS_TYPE(notification,
98 BT_NOTIFICATION_TYPE_STREAM_END);
99 stream_end = container_of(notification,
100 struct bt_notification_stream_end, parent);
101 return stream_end->stream;
102 }
103
104 struct bt_private_stream *bt_private_notification_stream_end_borrow_stream(
105 struct bt_private_notification *notification)
106 {
107 return (void *) bt_notification_stream_end_borrow_stream(
108 (void *) notification);
109 }
110
111 void bt_private_notification_stream_end_set_default_clock_value(
112 struct bt_private_notification *priv_notif,
113 uint64_t value_cycles)
114 {
115 struct bt_notification *notif = (void *) priv_notif;
116 struct bt_notification_stream_end *se_notif = (void *) notif;
117
118 BT_ASSERT_PRE_NON_NULL(notif, "Notification");
119 BT_ASSERT_PRE_HOT(notif, "Notification", ": %!+n", notif);
120 BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_STREAM_END);
121 BT_ASSERT_PRE(se_notif->stream->class->default_clock_class,
122 "Notification's stream class has no default clock class: "
123 "%![notif-]+n, %![sc-]+S", notif, se_notif->stream->class);
124
125 /* TODO: have the object already created */
126 se_notif->default_cv = bt_clock_value_create(
127 se_notif->stream->class->default_clock_class);
128 BT_ASSERT(se_notif->default_cv);
129 bt_clock_value_set_value_inline(se_notif->default_cv, value_cycles);
130 BT_LIB_LOGV("Set notification's default clock value: %![notif-]+n, "
131 "value=%" PRIu64, value_cycles);
132 }
133
134 struct bt_clock_value *bt_notification_stream_end_borrow_default_clock_value(
135 struct bt_notification *notif)
136 {
137 struct bt_notification_stream_end *stream_end = (void *) notif;
138
139 BT_ASSERT_PRE_NON_NULL(notif, "Notification");
140 BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_STREAM_END);
141 return stream_end->default_cv;
142 }
143
144 static
145 void bt_notification_stream_begin_destroy(struct bt_object *obj)
146 {
147 struct bt_notification_stream_begin *notification =
148 (struct bt_notification_stream_begin *) obj;
149
150 BT_LIB_LOGD("Destroying stream beginning notification: %!+n",
151 notification);
152 BT_LIB_LOGD("Putting stream: %!+s", notification->stream);
153 BT_OBJECT_PUT_REF_AND_RESET(notification->stream);
154
155 if (notification->default_cv) {
156 bt_clock_value_recycle(notification->default_cv);
157 notification->default_cv = NULL;
158 }
159
160 g_free(notification);
161 }
162
163 struct bt_private_notification *bt_private_notification_stream_begin_create(
164 struct bt_self_notification_iterator *self_notif_iter,
165 struct bt_private_stream *priv_stream)
166 {
167 struct bt_stream *stream = (void *) priv_stream;
168 struct bt_notification_stream_begin *notification;
169 struct bt_stream_class *stream_class;
170
171 BT_ASSERT_PRE_NON_NULL(self_notif_iter, "Notification iterator");
172 BT_ASSERT_PRE_NON_NULL(stream, "Stream");
173 stream_class = bt_stream_borrow_class(stream);
174 BT_ASSERT(stream_class);
175 BT_LIB_LOGD("Creating stream beginning notification object: "
176 "%![stream-]+s, %![sc-]+S", stream, stream_class);
177 notification = g_new0(struct bt_notification_stream_begin, 1);
178 if (!notification) {
179 BT_LOGE_STR("Failed to allocate one stream beginning notification.");
180 goto error;
181 }
182
183 bt_notification_init(&notification->parent,
184 BT_NOTIFICATION_TYPE_STREAM_BEGIN,
185 bt_notification_stream_begin_destroy, NULL);
186 notification->stream = bt_object_get_ref(stream);
187 BT_LIB_LOGD("Created stream beginning notification object: "
188 "%![notif-]+n, %![stream-]+s, %![sc-]+S", notification,
189 stream, stream_class);
190 return (void *) &notification->parent;
191 error:
192 return NULL;
193 }
194
195 struct bt_stream *bt_notification_stream_begin_borrow_stream(
196 struct bt_notification *notification)
197 {
198 struct bt_notification_stream_begin *stream_begin;
199
200 BT_ASSERT_PRE_NON_NULL(notification, "Notification");
201 BT_ASSERT_PRE_NOTIF_IS_TYPE(notification,
202 BT_NOTIFICATION_TYPE_STREAM_BEGIN);
203 stream_begin = container_of(notification,
204 struct bt_notification_stream_begin, parent);
205 return stream_begin->stream;
206 }
207
208 struct bt_private_stream *bt_private_notification_stream_begin_borrow_stream(
209 struct bt_private_notification *notification)
210 {
211 return (void *) bt_notification_stream_begin_borrow_stream(
212 (void *) notification);
213 }
214
215 void bt_private_notification_stream_begin_set_default_clock_value(
216 struct bt_private_notification *priv_notif,
217 uint64_t value_cycles)
218 {
219 struct bt_notification *notif = (void *) priv_notif;
220 struct bt_notification_stream_begin *sb_notif = (void *) notif;
221
222 BT_ASSERT_PRE_NON_NULL(notif, "Notification");
223 BT_ASSERT_PRE_HOT(notif, "Notification", ": %!+n", notif);
224 BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_STREAM_BEGIN);
225 BT_ASSERT_PRE(sb_notif->stream->class->default_clock_class,
226 "Notification's stream class has no default clock class: "
227 "%![notif-]+n, %![sc-]+S", notif, sb_notif->stream->class);
228
229 /* TODO: have the object already created */
230 sb_notif->default_cv = bt_clock_value_create(
231 sb_notif->stream->class->default_clock_class);
232 BT_ASSERT(sb_notif->default_cv);
233 bt_clock_value_set_value_inline(sb_notif->default_cv, value_cycles);
234 BT_LIB_LOGV("Set notification's default clock value: %![notif-]+n, "
235 "value=%" PRIu64, value_cycles);
236 }
237
238 struct bt_clock_value *bt_notification_stream_begin_borrow_default_clock_value(
239 struct bt_notification *notif)
240 {
241 struct bt_notification_stream_begin *stream_begin = (void *) notif;
242
243 BT_ASSERT_PRE_NON_NULL(notif, "Notification");
244 BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_STREAM_BEGIN);
245 return stream_begin->default_cv;
246 }
This page took 0.036001 seconds and 4 git commands to generate.