2 * Copyright 2019 Philippe Proulx <pproulx@efficios.com>
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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
23 #define BT_LOG_TAG "MSG-DISCARDED-ITEMS"
24 #include <babeltrace/lib-logging-internal.h>
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>
38 #include <babeltrace/graph/message-discarded-packets.h>
39 #include <babeltrace/graph/message-discarded-packets-const.h>
42 void destroy_discarded_items_message(struct bt_object
*obj
)
44 struct bt_message_discarded_items
*message
= (void *) obj
;
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
);
50 if (message
->default_begin_cs
) {
51 bt_clock_snapshot_recycle(message
->default_begin_cs
);
52 message
->default_begin_cs
= NULL
;
55 if (message
->default_end_cs
) {
56 bt_clock_snapshot_recycle(message
->default_end_cs
);
57 message
->default_end_cs
= NULL
;
64 struct 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
,
68 uint64_t beginning_raw_value
, uint64_t end_raw_value
)
70 struct bt_message_discarded_items
*message
;
71 struct bt_stream_class
*stream_class
;
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_ASSERT_PRE((with_cs
&& stream_class
->default_clock_class
) ||
78 (!with_cs
&& !stream_class
->default_clock_class
),
79 "Creating a message with a default clock snapshot, but without "
80 "a default clock class, or without a default clock snapshot, "
81 "but with a default clock class: ",
82 "type=%s, %![stream-]+s, %![sc-]+S, with-cs=%d, "
83 "cs-begin-val=%" PRIu64
", cs-end-val=%" PRIu64
,
84 bt_message_type_string(type
), stream
, stream_class
,
85 with_cs
, beginning_raw_value
, end_raw_value
);
86 BT_LIB_LOGD("Creating discarded items message object: "
87 "type=%s, %![stream-]+s, %![sc-]+S, with-cs=%d, "
88 "cs-begin-val=%" PRIu64
", cs-end-val=%" PRIu64
,
89 bt_message_type_string(type
), stream
, stream_class
,
90 with_cs
, beginning_raw_value
, end_raw_value
);
91 message
= g_new0(struct bt_message_discarded_items
, 1);
93 BT_LOGE_STR("Failed to allocate one discarded items message.");
97 bt_message_init(&message
->parent
, type
,
98 destroy_discarded_items_message
, NULL
);
99 message
->stream
= stream
;
100 bt_object_get_no_null_check(message
->stream
);
103 BT_ASSERT(stream_class
->default_clock_class
);
104 message
->default_begin_cs
= bt_clock_snapshot_create(
105 stream_class
->default_clock_class
);
106 if (!message
->default_begin_cs
) {
110 bt_clock_snapshot_set_raw_value(message
->default_begin_cs
,
111 beginning_raw_value
);
113 message
->default_end_cs
= bt_clock_snapshot_create(
114 stream_class
->default_clock_class
);
115 if (!message
->default_end_cs
) {
119 bt_clock_snapshot_set_raw_value(message
->default_end_cs
,
123 bt_property_uint_init(&message
->count
,
124 BT_PROPERTY_AVAILABILITY_NOT_AVAILABLE
, 0);
125 BT_LIB_LOGD("Created discarded items message object: "
126 "%![msg-]+n, %![stream-]+s, %![sc-]+S", message
,
127 stream
, stream_class
);
129 return (void *) &message
->parent
;
136 struct bt_stream
*borrow_discarded_items_message_stream(
137 struct bt_message
*message
)
139 struct bt_message_discarded_items
*disc_items_msg
= (void *) message
;
142 return disc_items_msg
->stream
;
146 void set_discarded_items_message_count(struct bt_message
*message
,
149 struct bt_message_discarded_items
*disc_items_msg
= (void *) message
;
152 BT_ASSERT_PRE_HOT(message
, "Message", ": %!+n", message
);
153 bt_property_uint_set(&disc_items_msg
->count
, count
);
157 enum bt_property_availability
get_discarded_items_message_count(
158 const struct bt_message
*message
, uint64_t *count
)
160 struct bt_message_discarded_items
*disc_items_msg
= (void *) message
;
162 BT_ASSERT_PRE_NON_NULL(count
, "Count (output)");
164 *count
= disc_items_msg
->count
.value
;
165 return disc_items_msg
->count
.base
.avail
;
169 const struct bt_clock_snapshot
*
170 borrow_discarded_items_message_default_beginning_clock_snapshot_const(
171 const struct bt_message
*message
)
173 struct bt_message_discarded_items
*disc_items_msg
= (void *) message
;
176 BT_ASSERT_PRE(disc_items_msg
->stream
->class->default_clock_class
,
177 "Message's stream's class has no default clock class: "
178 "%![msg-]+n, %![sc-]+S",
179 message
, disc_items_msg
->stream
->class);
180 return disc_items_msg
->default_begin_cs
;
184 const struct bt_clock_snapshot
*
185 borrow_discarded_items_message_default_end_clock_snapshot_const(
186 const struct bt_message
*message
)
188 struct bt_message_discarded_items
*disc_items_msg
= (void *) message
;
191 BT_ASSERT_PRE(disc_items_msg
->stream
->class->default_clock_class
,
192 "Message's stream's class has no default clock class: "
193 "%![msg-]+n, %![sc-]+S",
194 message
, disc_items_msg
->stream
->class);
195 return disc_items_msg
->default_end_cs
;
198 struct bt_message
*bt_message_discarded_events_create(
199 struct bt_self_message_iterator
*message_iterator
,
200 const struct bt_stream
*stream
)
202 return create_discarded_items_message(message_iterator
,
203 BT_MESSAGE_TYPE_DISCARDED_EVENTS
, (void *) stream
,
207 struct bt_message
*bt_message_discarded_events_create_with_default_clock_snapshots(
208 struct bt_self_message_iterator
*message_iterator
,
209 const struct bt_stream
*stream
, uint64_t beginning_raw_value
,
210 uint64_t end_raw_value
)
212 return create_discarded_items_message(message_iterator
,
213 BT_MESSAGE_TYPE_DISCARDED_EVENTS
, (void *) stream
,
214 true, beginning_raw_value
, end_raw_value
);
217 struct bt_stream
*bt_message_discarded_events_borrow_stream(
218 struct bt_message
*message
)
220 BT_ASSERT_PRE_NON_NULL(message
, "Message");
221 BT_ASSERT_PRE_MSG_IS_TYPE(message
, BT_MESSAGE_TYPE_DISCARDED_EVENTS
);
222 return borrow_discarded_items_message_stream(message
);
225 void bt_message_discarded_events_set_count(struct bt_message
*message
,
228 BT_ASSERT_PRE_NON_NULL(message
, "Message");
229 BT_ASSERT_PRE_MSG_IS_TYPE(message
, BT_MESSAGE_TYPE_DISCARDED_EVENTS
);
230 set_discarded_items_message_count(message
, count
);
233 const struct bt_clock_snapshot
*
234 bt_message_discarded_events_borrow_default_beginning_clock_snapshot_const(
235 const struct bt_message
*msg
)
237 BT_ASSERT_PRE_NON_NULL(msg
, "Message");
238 BT_ASSERT_PRE_MSG_IS_TYPE(msg
, BT_MESSAGE_TYPE_DISCARDED_EVENTS
);
239 return borrow_discarded_items_message_default_beginning_clock_snapshot_const(
243 const struct bt_clock_snapshot
*
244 bt_message_discarded_events_borrow_default_end_clock_snapshot_const(
245 const struct bt_message
*msg
)
247 BT_ASSERT_PRE_NON_NULL(msg
, "Message");
248 BT_ASSERT_PRE_MSG_IS_TYPE(msg
, BT_MESSAGE_TYPE_DISCARDED_EVENTS
);
249 return borrow_discarded_items_message_default_end_clock_snapshot_const(
253 const struct bt_stream
*
254 bt_message_discarded_events_borrow_stream_const(const struct bt_message
*message
)
256 return (void *) bt_message_discarded_events_borrow_stream(
260 enum bt_property_availability
bt_message_discarded_events_get_count(
261 const struct bt_message
*message
, uint64_t *count
)
263 BT_ASSERT_PRE_NON_NULL(message
, "Message");
264 BT_ASSERT_PRE_MSG_IS_TYPE(message
, BT_MESSAGE_TYPE_DISCARDED_EVENTS
);
265 return get_discarded_items_message_count(message
, count
);
268 struct bt_message
*bt_message_discarded_packets_create(
269 struct bt_self_message_iterator
*message_iterator
,
270 const struct bt_stream
*stream
)
272 return create_discarded_items_message(message_iterator
,
273 BT_MESSAGE_TYPE_DISCARDED_PACKETS
, (void *) stream
,
277 struct bt_message
*bt_message_discarded_packets_create_with_default_clock_snapshots(
278 struct bt_self_message_iterator
*message_iterator
,
279 const struct bt_stream
*stream
, uint64_t beginning_raw_value
,
280 uint64_t end_raw_value
)
282 return create_discarded_items_message(message_iterator
,
283 BT_MESSAGE_TYPE_DISCARDED_PACKETS
, (void *) stream
,
284 true, beginning_raw_value
, end_raw_value
);
287 struct bt_stream
*bt_message_discarded_packets_borrow_stream(
288 struct bt_message
*message
)
290 BT_ASSERT_PRE_NON_NULL(message
, "Message");
291 BT_ASSERT_PRE_MSG_IS_TYPE(message
, BT_MESSAGE_TYPE_DISCARDED_PACKETS
);
292 return borrow_discarded_items_message_stream(message
);
295 void bt_message_discarded_packets_set_count(struct bt_message
*message
,
298 BT_ASSERT_PRE_NON_NULL(message
, "Message");
299 BT_ASSERT_PRE_MSG_IS_TYPE(message
, BT_MESSAGE_TYPE_DISCARDED_PACKETS
);
300 set_discarded_items_message_count(message
, count
);
303 const struct bt_clock_snapshot
*
304 bt_message_discarded_packets_borrow_default_beginning_clock_snapshot_const(
305 const struct bt_message
*msg
)
307 BT_ASSERT_PRE_NON_NULL(msg
, "Message");
308 BT_ASSERT_PRE_MSG_IS_TYPE(msg
, BT_MESSAGE_TYPE_DISCARDED_PACKETS
);
309 return borrow_discarded_items_message_default_beginning_clock_snapshot_const(
313 const struct bt_clock_snapshot
*
314 bt_message_discarded_packets_borrow_default_end_clock_snapshot_const(
315 const struct bt_message
*msg
)
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(
323 const struct bt_stream
*
324 bt_message_discarded_packets_borrow_stream_const(const struct bt_message
*message
)
326 return (void *) bt_message_discarded_packets_borrow_stream(
330 enum bt_property_availability
bt_message_discarded_packets_get_count(
331 const struct bt_message
*message
, uint64_t *count
)
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
);
339 const struct bt_clock_class
*
340 borrow_discarded_items_message_stream_class_default_clock_class(
341 const struct bt_message
*msg
)
343 struct bt_message_discarded_items
*disc_items_msg
= (void *) msg
;
346 return disc_items_msg
->stream
->class->default_clock_class
;
349 const struct bt_clock_class
*
350 bt_message_discarded_events_borrow_stream_class_default_clock_class_const(
351 const struct bt_message
*msg
)
353 BT_ASSERT_PRE_NON_NULL(msg
, "Message");
354 BT_ASSERT_PRE_MSG_IS_TYPE(msg
, BT_MESSAGE_TYPE_DISCARDED_EVENTS
);
355 return borrow_discarded_items_message_stream_class_default_clock_class(
359 const struct bt_clock_class
*
360 bt_message_discarded_packets_borrow_stream_class_default_clock_class_const(
361 const struct bt_message
*msg
)
363 BT_ASSERT_PRE_NON_NULL(msg
, "Message");
364 BT_ASSERT_PRE_MSG_IS_TYPE(msg
, BT_MESSAGE_TYPE_DISCARDED_PACKETS
);
365 return borrow_discarded_items_message_stream_class_default_clock_class(