lib: add default clock snapshot property to packet beginning/end message
[babeltrace.git] / lib / graph / message / discarded-items.c
CommitLineData
4c833281
PP
1/*
2 * Copyright 2019 Philippe Proulx <pproulx@efficios.com>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23#define BT_LOG_TAG "MSG-DISCARDED-ITEMS"
24#include <babeltrace/lib-logging-internal.h>
25
26#include <babeltrace/assert-pre-internal.h>
27#include <babeltrace/object-internal.h>
28#include <babeltrace/compiler-internal.h>
29#include <babeltrace/trace-ir/clock-class.h>
30#include <babeltrace/trace-ir/clock-snapshot-internal.h>
31#include <babeltrace/trace-ir/stream-class-internal.h>
32#include <babeltrace/trace-ir/stream-internal.h>
33#include <babeltrace/property-internal.h>
34#include <babeltrace/graph/message-internal.h>
35#include <babeltrace/graph/message-discarded-items-internal.h>
36#include <babeltrace/graph/message-discarded-events.h>
37#include <babeltrace/graph/message-discarded-events-const.h>
4237f1f2
PP
38#include <babeltrace/graph/message-discarded-packets.h>
39#include <babeltrace/graph/message-discarded-packets-const.h>
4c833281
PP
40
41static
42void destroy_discarded_items_message(struct bt_object *obj)
43{
44 struct bt_message_discarded_items *message = (void *) obj;
45
46 BT_LIB_LOGD("Destroying discarded items message: %!+n", message);
47 BT_LIB_LOGD("Putting stream: %!+s", message->stream);
48 BT_OBJECT_PUT_REF_AND_RESET(message->stream);
49
50 if (message->default_begin_cs) {
51 bt_clock_snapshot_recycle(message->default_begin_cs);
52 message->default_begin_cs = NULL;
53 }
54
55 if (message->default_end_cs) {
56 bt_clock_snapshot_recycle(message->default_end_cs);
57 message->default_end_cs = NULL;
58 }
59
60 g_free(message);
61}
62
63static inline
64struct bt_message *create_discarded_items_message(
65 struct bt_self_message_iterator *self_msg_iter,
66 enum bt_message_type type, struct bt_stream *stream,
67 bool with_cs,
68 uint64_t beginning_raw_value, uint64_t end_raw_value)
69{
70 struct bt_message_discarded_items *message;
71 struct bt_stream_class *stream_class;
72
73 BT_ASSERT_PRE_NON_NULL(self_msg_iter, "Message iterator");
74 BT_ASSERT_PRE_NON_NULL(stream, "Stream");
75 stream_class = bt_stream_borrow_class(stream);
76 BT_ASSERT(stream_class);
77 BT_LIB_LOGD("Creating discarded items message object: "
78 "type=%s, %![stream-]+s, %![sc-]+S, with-cs=%d, "
79 "cs-begin-val=%" PRIu64 ", cs-end-val=%" PRIu64,
80 bt_message_type_string(type), stream, stream_class,
81 with_cs, beginning_raw_value, end_raw_value);
82 message = g_new0(struct bt_message_discarded_items, 1);
83 if (!message) {
84 BT_LOGE_STR("Failed to allocate one discarded items message.");
85 goto error;
86 }
87
88 bt_message_init(&message->parent, type,
89 destroy_discarded_items_message, NULL);
90 message->stream = stream;
91 bt_object_get_no_null_check(message->stream);
92
93 if (with_cs) {
94 message->default_begin_cs = bt_clock_snapshot_create(
95 stream_class->default_clock_class);
96 if (!message->default_begin_cs) {
97 goto error;
98 }
99
100 bt_clock_snapshot_set_raw_value(message->default_begin_cs,
101 beginning_raw_value);
102
103 message->default_end_cs = bt_clock_snapshot_create(
104 stream_class->default_clock_class);
105 if (!message->default_end_cs) {
106 goto error;
107 }
108
109 bt_clock_snapshot_set_raw_value(message->default_end_cs,
110 end_raw_value);
111 }
112
113 bt_property_uint_init(&message->count,
114 BT_PROPERTY_AVAILABILITY_NOT_AVAILABLE, 0);
115 BT_LIB_LOGD("Created discarded items message object: "
116 "%![msg-]+n, %![stream-]+s, %![sc-]+S", message,
117 stream, stream_class);
118
119 return (void *) &message->parent;
120
121error:
122 return NULL;
123}
124
125static inline
126struct bt_stream *borrow_discarded_items_message_stream(
127 struct bt_message *message)
128{
129 struct bt_message_discarded_items *disc_items_msg = (void *) message;
130
131 BT_ASSERT(message);
132 return disc_items_msg->stream;
133}
134
135static inline
136void set_discarded_items_message_count(struct bt_message *message,
137 uint64_t count)
138{
139 struct bt_message_discarded_items *disc_items_msg = (void *) message;
140
141 BT_ASSERT(message);
142 BT_ASSERT_PRE_HOT(message, "Message", ": %!+n", message);
143 bt_property_uint_set(&disc_items_msg->count, count);
144}
145
146static inline
147enum bt_property_availability get_discarded_items_message_count(
148 const struct bt_message *message, uint64_t *count)
149{
150 struct bt_message_discarded_items *disc_items_msg = (void *) message;
151
152 BT_ASSERT_PRE_NON_NULL(count, "Count (output)");
153 BT_ASSERT(message);
154 *count = disc_items_msg->count.value;
155 return disc_items_msg->count.base.avail;
156}
157
158static inline
159enum bt_clock_snapshot_state
160borrow_discarded_items_message_default_beginning_clock_snapshot_const(
161 const struct bt_message *message,
162 const struct bt_clock_snapshot **snapshot)
163{
164 struct bt_message_discarded_items *disc_items_msg = (void *) message;
165
166 BT_ASSERT(message);
167 BT_ASSERT_PRE(disc_items_msg->stream->class->default_clock_class,
168 "Message's stream's class has no default clock class: "
169 "%![msg-]+n, %![sc-]+S",
170 message, disc_items_msg->stream->class);
171 BT_ASSERT_PRE_NON_NULL(snapshot, "Clock snapshot (output)");
172 *snapshot = disc_items_msg->default_begin_cs;
173 return BT_CLOCK_SNAPSHOT_STATE_KNOWN;
174}
175
176static inline
177enum bt_clock_snapshot_state
178borrow_discarded_items_message_default_end_clock_snapshot_const(
179 const struct bt_message *message,
180 const struct bt_clock_snapshot **snapshot)
181{
182 struct bt_message_discarded_items *disc_items_msg = (void *) message;
183
184 BT_ASSERT(message);
185 BT_ASSERT_PRE(disc_items_msg->stream->class->default_clock_class,
186 "Message's stream's class has no default clock class: "
187 "%![msg-]+n, %![sc-]+S",
188 message, disc_items_msg->stream->class);
189 BT_ASSERT_PRE_NON_NULL(snapshot, "Clock snapshot (output)");
190 *snapshot = disc_items_msg->default_end_cs;
191 return BT_CLOCK_SNAPSHOT_STATE_KNOWN;
192}
193
194struct bt_message *bt_message_discarded_events_create(
195 struct bt_self_message_iterator *message_iterator,
58085ca4 196 const struct bt_stream *stream)
4c833281
PP
197{
198 return create_discarded_items_message(message_iterator,
58085ca4 199 BT_MESSAGE_TYPE_DISCARDED_EVENTS, (void *) stream,
4c833281
PP
200 false, 0, 0);
201}
202
203struct bt_message *bt_message_discarded_events_create_with_default_clock_snapshots(
204 struct bt_self_message_iterator *message_iterator,
58085ca4 205 const struct bt_stream *stream, uint64_t beginning_raw_value,
4c833281
PP
206 uint64_t end_raw_value)
207{
208 return create_discarded_items_message(message_iterator,
58085ca4 209 BT_MESSAGE_TYPE_DISCARDED_EVENTS, (void *) stream,
4c833281
PP
210 true, beginning_raw_value, end_raw_value);
211}
212
213struct bt_stream *bt_message_discarded_events_borrow_stream(
214 struct bt_message *message)
215{
216 BT_ASSERT_PRE_NON_NULL(message, "Message");
217 BT_ASSERT_PRE_MSG_IS_TYPE(message, BT_MESSAGE_TYPE_DISCARDED_EVENTS);
218 return borrow_discarded_items_message_stream(message);
219}
220
221void bt_message_discarded_events_set_count(struct bt_message *message,
222 uint64_t count)
223{
224 BT_ASSERT_PRE_NON_NULL(message, "Message");
225 BT_ASSERT_PRE_MSG_IS_TYPE(message, BT_MESSAGE_TYPE_DISCARDED_EVENTS);
226 set_discarded_items_message_count(message, count);
227}
228
229enum bt_clock_snapshot_state
230bt_message_discarded_events_borrow_default_beginning_clock_snapshot_const(
231 const struct bt_message *msg,
232 const struct bt_clock_snapshot **snapshot)
233{
234 BT_ASSERT_PRE_NON_NULL(msg, "Message");
235 BT_ASSERT_PRE_MSG_IS_TYPE(msg, BT_MESSAGE_TYPE_DISCARDED_EVENTS);
236 return borrow_discarded_items_message_default_beginning_clock_snapshot_const(
237 msg, snapshot);
238}
239
240enum bt_clock_snapshot_state
241bt_message_discarded_events_borrow_default_end_clock_snapshot_const(
242 const struct bt_message *msg,
243 const struct bt_clock_snapshot **snapshot)
244{
245 BT_ASSERT_PRE_NON_NULL(msg, "Message");
246 BT_ASSERT_PRE_MSG_IS_TYPE(msg, BT_MESSAGE_TYPE_DISCARDED_EVENTS);
247 return borrow_discarded_items_message_default_end_clock_snapshot_const(
248 msg, snapshot);
249}
250
251const struct bt_stream *
252bt_message_discarded_events_borrow_stream_const(const struct bt_message *message)
253{
254 return (void *) bt_message_discarded_events_borrow_stream(
255 (void *) message);
256}
257
258enum bt_property_availability bt_message_discarded_events_get_count(
259 const struct bt_message *message, uint64_t *count)
260{
261 BT_ASSERT_PRE_NON_NULL(message, "Message");
262 BT_ASSERT_PRE_MSG_IS_TYPE(message, BT_MESSAGE_TYPE_DISCARDED_EVENTS);
263 return get_discarded_items_message_count(message, count);
264}
4237f1f2
PP
265
266struct bt_message *bt_message_discarded_packets_create(
267 struct bt_self_message_iterator *message_iterator,
58085ca4 268 const struct bt_stream *stream)
4237f1f2
PP
269{
270 return create_discarded_items_message(message_iterator,
58085ca4 271 BT_MESSAGE_TYPE_DISCARDED_PACKETS, (void *) stream,
4237f1f2
PP
272 false, 0, 0);
273}
274
275struct bt_message *bt_message_discarded_packets_create_with_default_clock_snapshots(
276 struct bt_self_message_iterator *message_iterator,
58085ca4 277 const struct bt_stream *stream, uint64_t beginning_raw_value,
4237f1f2
PP
278 uint64_t end_raw_value)
279{
280 return create_discarded_items_message(message_iterator,
58085ca4 281 BT_MESSAGE_TYPE_DISCARDED_PACKETS, (void *) stream,
4237f1f2
PP
282 true, beginning_raw_value, end_raw_value);
283}
284
285struct bt_stream *bt_message_discarded_packets_borrow_stream(
286 struct bt_message *message)
287{
288 BT_ASSERT_PRE_NON_NULL(message, "Message");
289 BT_ASSERT_PRE_MSG_IS_TYPE(message, BT_MESSAGE_TYPE_DISCARDED_PACKETS);
290 return borrow_discarded_items_message_stream(message);
291}
292
293void bt_message_discarded_packets_set_count(struct bt_message *message,
294 uint64_t count)
295{
296 BT_ASSERT_PRE_NON_NULL(message, "Message");
297 BT_ASSERT_PRE_MSG_IS_TYPE(message, BT_MESSAGE_TYPE_DISCARDED_PACKETS);
298 set_discarded_items_message_count(message, count);
299}
300
301enum bt_clock_snapshot_state
302bt_message_discarded_packets_borrow_default_beginning_clock_snapshot_const(
303 const struct bt_message *msg,
304 const struct bt_clock_snapshot **snapshot)
305{
306 BT_ASSERT_PRE_NON_NULL(msg, "Message");
307 BT_ASSERT_PRE_MSG_IS_TYPE(msg, BT_MESSAGE_TYPE_DISCARDED_PACKETS);
308 return borrow_discarded_items_message_default_beginning_clock_snapshot_const(
309 msg, snapshot);
310}
311
312enum bt_clock_snapshot_state
313bt_message_discarded_packets_borrow_default_end_clock_snapshot_const(
314 const struct bt_message *msg,
315 const struct bt_clock_snapshot **snapshot)
316{
317 BT_ASSERT_PRE_NON_NULL(msg, "Message");
318 BT_ASSERT_PRE_MSG_IS_TYPE(msg, BT_MESSAGE_TYPE_DISCARDED_PACKETS);
319 return borrow_discarded_items_message_default_end_clock_snapshot_const(
320 msg, snapshot);
321}
322
323const struct bt_stream *
324bt_message_discarded_packets_borrow_stream_const(const struct bt_message *message)
325{
326 return (void *) bt_message_discarded_packets_borrow_stream(
327 (void *) message);
328}
329
330enum bt_property_availability bt_message_discarded_packets_get_count(
331 const struct bt_message *message, uint64_t *count)
332{
333 BT_ASSERT_PRE_NON_NULL(message, "Message");
334 BT_ASSERT_PRE_MSG_IS_TYPE(message, BT_MESSAGE_TYPE_DISCARDED_PACKETS);
335 return get_discarded_items_message_count(message, count);
336}
This page took 0.03552 seconds and 4 git commands to generate.