2 * Copyright (c) 2021 Philippe Proulx <pproulx@efficios.com>
4 * SPDX-License-Identifier: MIT
7 #ifndef BABELTRACE_CPP_COMMON_BT2_MESSAGE_HPP
8 #define BABELTRACE_CPP_COMMON_BT2_MESSAGE_HPP
12 #include <type_traits>
14 #include <babeltrace2/babeltrace.h>
16 #include "common/assert.h"
17 #include "common/common.h"
18 #include "cpp-common/bt2/trace-ir.hpp"
19 #include "cpp-common/optional.hpp"
20 #include "cpp-common/string_view.hpp"
23 #include "internal/borrowed-obj.hpp"
24 #include "internal/shared-obj.hpp"
25 #include "internal/utils.hpp"
30 struct MessageRefFuncs final
32 static void get(const bt_message * const libObjPtr)
34 bt_message_get_ref(libObjPtr);
37 static void put(const bt_message * const libObjPtr)
39 bt_message_put_ref(libObjPtr);
43 template <typename ObjT, typename LibObjT>
44 using SharedMessage = internal::SharedObj<ObjT, LibObjT, internal::MessageRefFuncs>;
46 } /* namespace internal */
48 template <typename LibObjT>
49 class CommonStreamBeginningMessage;
51 template <typename LibObjT>
52 class CommonStreamEndMessage;
54 template <typename LibObjT>
55 class CommonEventMessage;
57 template <typename LibObjT>
58 class CommonPacketBeginningMessage;
60 template <typename LibObjT>
61 class CommonPacketEndMessage;
63 template <typename LibObjT>
64 class CommonDiscardedEventsMessage;
66 template <typename LibObjT>
67 class CommonDiscardedPacketsMessage;
69 template <typename LibObjT>
70 class CommonMessageIteratorInactivityMessage;
72 enum class MessageType
74 STREAM_BEGINNING = BT_MESSAGE_TYPE_STREAM_BEGINNING,
75 STREAM_END = BT_MESSAGE_TYPE_STREAM_END,
76 EVENT = BT_MESSAGE_TYPE_EVENT,
77 PACKET_BEGINNING = BT_MESSAGE_TYPE_PACKET_BEGINNING,
78 PACKET_END = BT_MESSAGE_TYPE_PACKET_END,
79 DISCARDED_EVENTS = BT_MESSAGE_TYPE_DISCARDED_EVENTS,
80 DISCARDED_PACKETS = BT_MESSAGE_TYPE_DISCARDED_PACKETS,
81 MESSAGE_ITERATOR_INACTIVITY = BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY,
84 template <typename LibObjT>
85 class CommonMessage : public internal::BorrowedObj<LibObjT>
88 using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
91 using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
92 using _ThisCommonMessage = CommonMessage<LibObjT>;
95 using Shared = internal::SharedMessage<CommonMessage<LibObjT>, LibObjT>;
97 explicit CommonMessage(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr}
101 template <typename OtherLibObjT>
102 CommonMessage(const CommonMessage<OtherLibObjT> val) noexcept : _ThisBorrowedObj {val}
106 template <typename OtherLibObjT>
107 _ThisCommonMessage& operator=(const CommonMessage<OtherLibObjT> val) noexcept
109 _ThisBorrowedObj::operator=(val);
113 MessageType type() const noexcept
115 return static_cast<MessageType>(bt_message_get_type(this->libObjPtr()));
118 bool isStreamBeginning() const noexcept
120 return this->type() == MessageType::STREAM_BEGINNING;
123 bool isStreamEnd() const noexcept
125 return this->type() == MessageType::STREAM_END;
128 bool isEvent() const noexcept
130 return this->type() == MessageType::EVENT;
133 bool isPacketBeginning() const noexcept
135 return this->type() == MessageType::PACKET_BEGINNING;
138 bool isPacketEnd() const noexcept
140 return this->type() == MessageType::PACKET_END;
143 bool isDiscardedEvents() const noexcept
145 return this->type() == MessageType::DISCARDED_EVENTS;
148 bool isDiscardedPackets() const noexcept
150 return this->type() == MessageType::DISCARDED_PACKETS;
153 bool isMessageIteratorInactivity() const noexcept
155 return this->type() == MessageType::MESSAGE_ITERATOR_INACTIVITY;
158 Shared shared() const noexcept
160 return Shared::createWithRef(*this);
163 template <typename MessageT>
164 MessageT as() const noexcept
166 return MessageT {this->libObjPtr()};
169 CommonStreamBeginningMessage<LibObjT> asStreamBeginning() const noexcept;
170 CommonStreamEndMessage<LibObjT> asStreamEnd() const noexcept;
171 CommonEventMessage<LibObjT> asEvent() const noexcept;
172 CommonPacketBeginningMessage<LibObjT> asPacketBeginning() const noexcept;
173 CommonPacketEndMessage<LibObjT> asPacketEnd() const noexcept;
174 CommonDiscardedEventsMessage<LibObjT> asDiscardedEvents() const noexcept;
175 CommonDiscardedPacketsMessage<LibObjT> asDiscardedPackets() const noexcept;
176 CommonMessageIteratorInactivityMessage<LibObjT> asMessageIteratorInactivity() const noexcept;
179 using Message = CommonMessage<bt_message>;
180 using ConstMessage = CommonMessage<const bt_message>;
184 struct MessageTypeDescr
186 using Const = ConstMessage;
187 using NonConst = Message;
191 struct TypeDescr<Message> : public MessageTypeDescr
196 struct TypeDescr<ConstMessage> : public MessageTypeDescr
200 template <typename LibObjT>
201 struct CommonStreamBeginningMessageSpec;
203 /* Functions specific to mutable stream beginning messages */
205 struct CommonStreamBeginningMessageSpec<bt_message> final
207 static bt_stream *stream(bt_message * const libObjPtr) noexcept
209 return bt_message_stream_beginning_borrow_stream(libObjPtr);
213 /* Functions specific to constant stream beginning messages */
215 struct CommonStreamBeginningMessageSpec<const bt_message> final
217 static const bt_stream *stream(const bt_message * const libObjPtr) noexcept
219 return bt_message_stream_beginning_borrow_stream_const(libObjPtr);
223 } /* namespace internal */
225 template <typename LibObjT>
226 class CommonStreamBeginningMessage final : public CommonMessage<LibObjT>
229 using typename CommonMessage<LibObjT>::_LibObjPtr;
230 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
233 typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>,
234 CommonStream<bt_stream>>::type;
237 using Shared = internal::SharedMessage<CommonStreamBeginningMessage<LibObjT>, LibObjT>;
239 explicit CommonStreamBeginningMessage(const _LibObjPtr libObjPtr) noexcept :
240 _ThisCommonMessage {libObjPtr}
242 BT_ASSERT_DBG(this->isStreamBeginning());
245 template <typename OtherLibObjT>
246 CommonStreamBeginningMessage(const CommonStreamBeginningMessage<OtherLibObjT> val) noexcept :
247 _ThisCommonMessage {val}
251 template <typename OtherLibObjT>
252 CommonStreamBeginningMessage<LibObjT>&
253 operator=(const CommonStreamBeginningMessage<OtherLibObjT> val) noexcept
255 _ThisCommonMessage::operator=(val);
259 ConstStream stream() const noexcept
261 return ConstStream {internal::CommonStreamBeginningMessageSpec<const bt_message>::stream(
265 _Stream stream() noexcept
268 internal::CommonStreamBeginningMessageSpec<LibObjT>::stream(this->libObjPtr())};
271 void defaultClockSnapshot(const std::uint64_t val) noexcept
273 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
275 bt_message_stream_beginning_set_default_clock_snapshot(this->libObjPtr(), val);
278 nonstd::optional<ConstClockSnapshot> defaultClockSnapshot() const noexcept
280 const bt_clock_snapshot *libObjPtr;
281 const auto state = bt_message_stream_beginning_borrow_default_clock_snapshot_const(
282 this->libObjPtr(), &libObjPtr);
284 if (state == BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN) {
285 return ConstClockSnapshot {libObjPtr};
288 return nonstd::nullopt;
291 Shared shared() const noexcept
293 return Shared::createWithRef(*this);
297 using StreamBeginningMessage = CommonStreamBeginningMessage<bt_message>;
298 using ConstStreamBeginningMessage = CommonStreamBeginningMessage<const bt_message>;
302 struct StreamBeginningMessageTypeDescr
304 using Const = ConstStreamBeginningMessage;
305 using NonConst = StreamBeginningMessage;
309 struct TypeDescr<StreamBeginningMessage> : public StreamBeginningMessageTypeDescr
314 struct TypeDescr<ConstStreamBeginningMessage> : public StreamBeginningMessageTypeDescr
318 template <typename LibObjT>
319 struct CommonStreamEndMessageSpec;
321 /* Functions specific to mutable stream end messages */
323 struct CommonStreamEndMessageSpec<bt_message> final
325 static bt_stream *stream(bt_message * const libObjPtr) noexcept
327 return bt_message_stream_end_borrow_stream(libObjPtr);
331 /* Functions specific to constant stream end messages */
333 struct CommonStreamEndMessageSpec<const bt_message> final
335 static const bt_stream *stream(const bt_message * const libObjPtr) noexcept
337 return bt_message_stream_end_borrow_stream_const(libObjPtr);
341 } /* namespace internal */
343 template <typename LibObjT>
344 class CommonStreamEndMessage final : public CommonMessage<LibObjT>
347 using typename CommonMessage<LibObjT>::_LibObjPtr;
348 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
351 typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>,
352 CommonStream<bt_stream>>::type;
355 using Shared = internal::SharedMessage<CommonStreamEndMessage<LibObjT>, LibObjT>;
357 explicit CommonStreamEndMessage(const _LibObjPtr libObjPtr) noexcept :
358 _ThisCommonMessage {libObjPtr}
360 BT_ASSERT_DBG(this->isStreamEnd());
363 template <typename OtherLibObjT>
364 CommonStreamEndMessage(const CommonStreamEndMessage<OtherLibObjT> val) noexcept :
365 _ThisCommonMessage {val}
369 template <typename OtherLibObjT>
370 CommonStreamEndMessage<LibObjT>&
371 operator=(const CommonStreamEndMessage<OtherLibObjT> val) noexcept
373 _ThisCommonMessage::operator=(val);
377 ConstStream stream() const noexcept
380 internal::CommonStreamEndMessageSpec<const bt_message>::stream(this->libObjPtr())};
383 _Stream stream() noexcept
385 return _Stream {internal::CommonStreamEndMessageSpec<LibObjT>::stream(this->libObjPtr())};
388 void defaultClockSnapshot(const std::uint64_t val) noexcept
390 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
392 bt_message_stream_end_set_default_clock_snapshot(this->libObjPtr(), val);
395 nonstd::optional<ConstClockSnapshot> defaultClockSnapshot() const noexcept
397 const bt_clock_snapshot *libObjPtr;
398 const auto state = bt_message_stream_end_borrow_default_clock_snapshot_const(
399 this->libObjPtr(), &libObjPtr);
401 if (state == BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN) {
402 return ConstClockSnapshot {libObjPtr};
405 return nonstd::nullopt;
408 Shared shared() const noexcept
410 return Shared::createWithRef(*this);
414 using StreamEndMessage = CommonStreamEndMessage<bt_message>;
415 using ConstStreamEndMessage = CommonStreamEndMessage<const bt_message>;
419 struct StreamEndMessageTypeDescr
421 using Const = ConstStreamEndMessage;
422 using NonConst = StreamEndMessage;
426 struct TypeDescr<StreamEndMessage> : public StreamEndMessageTypeDescr
431 struct TypeDescr<ConstStreamEndMessage> : public StreamEndMessageTypeDescr
435 template <typename LibObjT>
436 struct CommonPacketBeginningMessageSpec;
438 /* Functions specific to mutable packet beginning messages */
440 struct CommonPacketBeginningMessageSpec<bt_message> final
442 static bt_packet *packet(bt_message * const libObjPtr) noexcept
444 return bt_message_packet_beginning_borrow_packet(libObjPtr);
448 /* Functions specific to constant packet beginning messages */
450 struct CommonPacketBeginningMessageSpec<const bt_message> final
452 static const bt_packet *packet(const bt_message * const libObjPtr) noexcept
454 return bt_message_packet_beginning_borrow_packet_const(libObjPtr);
458 } /* namespace internal */
460 template <typename LibObjT>
461 class CommonPacketBeginningMessage final : public CommonMessage<LibObjT>
464 using typename CommonMessage<LibObjT>::_LibObjPtr;
465 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
468 typename std::conditional<std::is_const<LibObjT>::value, CommonPacket<const bt_packet>,
469 CommonPacket<bt_packet>>::type;
472 using Shared = internal::SharedMessage<CommonPacketBeginningMessage<LibObjT>, LibObjT>;
474 explicit CommonPacketBeginningMessage(const _LibObjPtr libObjPtr) noexcept :
475 _ThisCommonMessage {libObjPtr}
477 BT_ASSERT_DBG(this->isPacketBeginning());
480 template <typename OtherLibObjT>
481 CommonPacketBeginningMessage(const CommonPacketBeginningMessage<OtherLibObjT> val) noexcept :
482 _ThisCommonMessage {val}
486 template <typename OtherLibObjT>
487 CommonPacketBeginningMessage<LibObjT>&
488 operator=(const CommonPacketBeginningMessage<OtherLibObjT> val) noexcept
490 _ThisCommonMessage::operator=(val);
494 ConstPacket packet() const noexcept
496 return ConstPacket {internal::CommonPacketBeginningMessageSpec<const bt_message>::packet(
500 _Packet packet() noexcept
503 internal::CommonPacketBeginningMessageSpec<LibObjT>::packet(this->libObjPtr())};
506 void defaultClockSnapshot(const std::uint64_t val) noexcept
508 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
510 bt_message_packet_beginning_set_default_clock_snapshot(this->libObjPtr(), val);
513 ConstClockSnapshot defaultClockSnapshot() const noexcept
515 const auto libObjPtr =
516 bt_message_packet_beginning_borrow_default_clock_snapshot_const(this->libObjPtr());
518 return ConstClockSnapshot {libObjPtr};
521 Shared shared() const noexcept
523 return Shared::createWithRef(*this);
527 using PacketBeginningMessage = CommonPacketBeginningMessage<bt_message>;
528 using ConstPacketBeginningMessage = CommonPacketBeginningMessage<const bt_message>;
532 struct PacketBeginningMessageTypeDescr
534 using Const = ConstPacketBeginningMessage;
535 using NonConst = PacketBeginningMessage;
539 struct TypeDescr<PacketBeginningMessage> : public PacketBeginningMessageTypeDescr
544 struct TypeDescr<ConstPacketBeginningMessage> : public PacketBeginningMessageTypeDescr
548 template <typename LibObjT>
549 struct CommonPacketEndMessageSpec;
551 /* Functions specific to mutable packet end messages */
553 struct CommonPacketEndMessageSpec<bt_message> final
555 static bt_packet *packet(bt_message * const libObjPtr) noexcept
557 return bt_message_packet_end_borrow_packet(libObjPtr);
561 /* Functions specific to constant packet end messages */
563 struct CommonPacketEndMessageSpec<const bt_message> final
565 static const bt_packet *packet(const bt_message * const libObjPtr) noexcept
567 return bt_message_packet_end_borrow_packet_const(libObjPtr);
571 } /* namespace internal */
573 template <typename LibObjT>
574 class CommonPacketEndMessage final : public CommonMessage<LibObjT>
577 using typename CommonMessage<LibObjT>::_LibObjPtr;
578 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
581 typename std::conditional<std::is_const<LibObjT>::value, CommonPacket<const bt_packet>,
582 CommonPacket<bt_packet>>::type;
585 using Shared = internal::SharedMessage<CommonPacketEndMessage<LibObjT>, LibObjT>;
587 explicit CommonPacketEndMessage(const _LibObjPtr libObjPtr) noexcept :
588 _ThisCommonMessage {libObjPtr}
590 BT_ASSERT_DBG(this->isPacketEnd());
593 template <typename OtherLibObjT>
594 CommonPacketEndMessage(const CommonPacketEndMessage<OtherLibObjT> val) noexcept :
595 _ThisCommonMessage {val}
599 template <typename OtherLibObjT>
600 CommonPacketEndMessage<LibObjT>&
601 operator=(const CommonPacketEndMessage<OtherLibObjT> val) noexcept
603 _ThisCommonMessage::operator=(val);
607 ConstPacket packet() const noexcept
610 internal::CommonPacketEndMessageSpec<const bt_message>::packet(this->libObjPtr())};
613 _Packet packet() noexcept
615 return _Packet {internal::CommonPacketEndMessageSpec<LibObjT>::packet(this->libObjPtr())};
618 void defaultClockSnapshot(const std::uint64_t val) noexcept
620 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
622 bt_message_packet_end_set_default_clock_snapshot(this->libObjPtr(), val);
625 ConstClockSnapshot defaultClockSnapshot() const noexcept
627 const auto libObjPtr =
628 bt_message_packet_end_borrow_default_clock_snapshot_const(this->libObjPtr());
630 return ConstClockSnapshot {libObjPtr};
633 Shared shared() const noexcept
635 return Shared::createWithRef(*this);
639 using PacketEndMessage = CommonPacketEndMessage<bt_message>;
640 using ConstPacketEndMessage = CommonPacketEndMessage<const bt_message>;
644 struct PacketEndMessageTypeDescr
646 using Const = ConstPacketEndMessage;
647 using NonConst = PacketEndMessage;
651 struct TypeDescr<PacketEndMessage> : public PacketEndMessageTypeDescr
656 struct TypeDescr<ConstPacketEndMessage> : public PacketEndMessageTypeDescr
660 template <typename LibObjT>
661 struct CommonEventMessageSpec;
663 /* Functions specific to mutable event messages */
665 struct CommonEventMessageSpec<bt_message> final
667 static bt_event *event(bt_message * const libObjPtr) noexcept
669 return bt_message_event_borrow_event(libObjPtr);
673 /* Functions specific to constant event messages */
675 struct CommonEventMessageSpec<const bt_message> final
677 static const bt_event *event(const bt_message * const libObjPtr) noexcept
679 return bt_message_event_borrow_event_const(libObjPtr);
683 } /* namespace internal */
685 template <typename LibObjT>
686 class CommonEventMessage final : public CommonMessage<LibObjT>
689 using typename CommonMessage<LibObjT>::_LibObjPtr;
690 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
693 typename std::conditional<std::is_const<LibObjT>::value, CommonEvent<const bt_event>,
694 CommonEvent<bt_event>>::type;
697 using Shared = internal::SharedMessage<CommonEventMessage<LibObjT>, LibObjT>;
699 explicit CommonEventMessage(const _LibObjPtr libObjPtr) noexcept :
700 _ThisCommonMessage {libObjPtr}
702 BT_ASSERT_DBG(this->isEvent());
705 template <typename OtherLibObjT>
706 CommonEventMessage(const CommonEventMessage<OtherLibObjT> val) noexcept :
707 _ThisCommonMessage {val}
711 template <typename OtherLibObjT>
712 CommonEventMessage<LibObjT>& operator=(const CommonEventMessage<OtherLibObjT> val) noexcept
714 _ThisCommonMessage::operator=(val);
718 ConstEvent event() const noexcept
721 internal::CommonEventMessageSpec<const bt_message>::event(this->libObjPtr())};
724 _Event event() noexcept
726 return _Event {internal::CommonEventMessageSpec<LibObjT>::event(this->libObjPtr())};
729 ConstClockSnapshot defaultClockSnapshot() const noexcept
731 const auto libObjPtr =
732 bt_message_event_borrow_default_clock_snapshot_const(this->libObjPtr());
734 return ConstClockSnapshot {libObjPtr};
737 Shared shared() const noexcept
739 return Shared::createWithRef(*this);
743 using EventMessage = CommonEventMessage<bt_message>;
744 using ConstEventMessage = CommonEventMessage<const bt_message>;
748 struct EventMessageTypeDescr
750 using Const = ConstEventMessage;
751 using NonConst = EventMessage;
755 struct TypeDescr<EventMessage> : public EventMessageTypeDescr
760 struct TypeDescr<ConstEventMessage> : public EventMessageTypeDescr
764 template <typename LibObjT>
765 struct CommonDiscardedEventsMessageSpec;
767 /* Functions specific to mutable discarded events messages */
769 struct CommonDiscardedEventsMessageSpec<bt_message> final
771 static bt_stream *stream(bt_message * const libObjPtr) noexcept
773 return bt_message_discarded_events_borrow_stream(libObjPtr);
777 /* Functions specific to constant discarded events messages */
779 struct CommonDiscardedEventsMessageSpec<const bt_message> final
781 static const bt_stream *stream(const bt_message * const libObjPtr) noexcept
783 return bt_message_discarded_events_borrow_stream_const(libObjPtr);
787 } /* namespace internal */
789 template <typename LibObjT>
790 class CommonDiscardedEventsMessage final : public CommonMessage<LibObjT>
793 using typename CommonMessage<LibObjT>::_LibObjPtr;
794 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
797 typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>,
798 CommonStream<bt_stream>>::type;
801 using Shared = internal::SharedMessage<CommonDiscardedEventsMessage<LibObjT>, LibObjT>;
803 explicit CommonDiscardedEventsMessage(const _LibObjPtr libObjPtr) noexcept :
804 _ThisCommonMessage {libObjPtr}
806 BT_ASSERT_DBG(this->isDiscardedEvents());
809 template <typename OtherLibObjT>
810 CommonDiscardedEventsMessage(const CommonDiscardedEventsMessage<OtherLibObjT> val) noexcept :
811 _ThisCommonMessage {val}
815 template <typename OtherLibObjT>
816 CommonDiscardedEventsMessage<LibObjT>&
817 operator=(const CommonDiscardedEventsMessage<OtherLibObjT> val) noexcept
819 _ThisCommonMessage::operator=(val);
823 ConstStream stream() const noexcept
825 return ConstStream {internal::CommonDiscardedEventsMessageSpec<const bt_message>::stream(
829 _Stream stream() noexcept
832 internal::CommonDiscardedEventsMessageSpec<LibObjT>::stream(this->libObjPtr())};
835 ConstClockSnapshot beginningDefaultClockSnapshot() const noexcept
837 const auto libObjPtr =
838 bt_message_discarded_events_borrow_beginning_default_clock_snapshot_const(
841 return ConstClockSnapshot {libObjPtr};
844 ConstClockSnapshot endDefaultClockSnapshot() const noexcept
846 const auto libObjPtr =
847 bt_message_discarded_events_borrow_end_default_clock_snapshot_const(this->libObjPtr());
849 return ConstClockSnapshot {libObjPtr};
852 void count(const std::uint64_t count) noexcept
854 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
856 bt_message_discarded_events_set_count(this->libObjPtr(), count);
859 nonstd::optional<std::uint64_t> count() const noexcept
862 const auto avail = bt_message_discarded_events_get_count(this->libObjPtr(), &count);
868 return nonstd::nullopt;
871 Shared shared() const noexcept
873 return Shared::createWithRef(*this);
877 using DiscardedEventsMessage = CommonDiscardedEventsMessage<bt_message>;
878 using ConstDiscardedEventsMessage = CommonDiscardedEventsMessage<const bt_message>;
882 struct DiscardedEventsMessageTypeDescr
884 using Const = ConstDiscardedEventsMessage;
885 using NonConst = DiscardedEventsMessage;
889 struct TypeDescr<DiscardedEventsMessage> : public DiscardedEventsMessageTypeDescr
894 struct TypeDescr<ConstDiscardedEventsMessage> : public DiscardedEventsMessageTypeDescr
898 template <typename LibObjT>
899 struct CommonDiscardedPacketsMessageSpec;
901 /* Functions specific to mutable discarded packets messages */
903 struct CommonDiscardedPacketsMessageSpec<bt_message> final
905 static bt_stream *stream(bt_message * const libObjPtr) noexcept
907 return bt_message_discarded_packets_borrow_stream(libObjPtr);
911 /* Functions specific to constant discarded packets messages */
913 struct CommonDiscardedPacketsMessageSpec<const bt_message> final
915 static const bt_stream *stream(const bt_message * const libObjPtr) noexcept
917 return bt_message_discarded_packets_borrow_stream_const(libObjPtr);
921 } /* namespace internal */
923 template <typename LibObjT>
924 class CommonDiscardedPacketsMessage final : public CommonMessage<LibObjT>
927 using typename CommonMessage<LibObjT>::_LibObjPtr;
928 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
931 typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>,
932 CommonStream<bt_stream>>::type;
935 using Shared = internal::SharedMessage<CommonDiscardedPacketsMessage<LibObjT>, LibObjT>;
937 explicit CommonDiscardedPacketsMessage(const _LibObjPtr libObjPtr) noexcept :
938 _ThisCommonMessage {libObjPtr}
940 BT_ASSERT_DBG(this->isDiscardedPackets());
943 template <typename OtherLibObjT>
944 CommonDiscardedPacketsMessage(const CommonDiscardedPacketsMessage<OtherLibObjT> val) noexcept :
945 _ThisCommonMessage {val}
949 template <typename OtherLibObjT>
950 CommonDiscardedPacketsMessage<LibObjT>&
951 operator=(const CommonDiscardedPacketsMessage<OtherLibObjT> val) noexcept
953 _ThisCommonMessage::operator=(val);
957 ConstStream stream() const noexcept
959 return ConstStream {internal::CommonDiscardedPacketsMessageSpec<const bt_message>::stream(
963 _Stream stream() noexcept
966 internal::CommonDiscardedPacketsMessageSpec<LibObjT>::stream(this->libObjPtr())};
969 ConstClockSnapshot beginningDefaultClockSnapshot() const noexcept
971 const auto libObjPtr =
972 bt_message_discarded_packets_borrow_beginning_default_clock_snapshot_const(
975 return ConstClockSnapshot {libObjPtr};
978 ConstClockSnapshot endDefaultClockSnapshot() const noexcept
980 const auto libObjPtr =
981 bt_message_discarded_packets_borrow_end_default_clock_snapshot_const(this->libObjPtr());
983 return ConstClockSnapshot {libObjPtr};
986 void count(const std::uint64_t count) noexcept
988 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
990 bt_message_discarded_packets_set_count(this->libObjPtr(), count);
993 nonstd::optional<std::uint64_t> count() const noexcept
996 const auto avail = bt_message_discarded_packets_get_count(this->libObjPtr(), &count);
1002 return nonstd::nullopt;
1005 Shared shared() const noexcept
1007 return Shared::createWithRef(*this);
1011 using DiscardedPacketsMessage = CommonDiscardedPacketsMessage<bt_message>;
1012 using ConstDiscardedPacketsMessage = CommonDiscardedPacketsMessage<const bt_message>;
1014 namespace internal {
1016 struct DiscardedPacketsMessageTypeDescr
1018 using Const = ConstDiscardedPacketsMessage;
1019 using NonConst = DiscardedPacketsMessage;
1023 struct TypeDescr<DiscardedPacketsMessage> : public DiscardedPacketsMessageTypeDescr
1028 struct TypeDescr<ConstDiscardedPacketsMessage> : public DiscardedPacketsMessageTypeDescr
1032 } /* namespace internal */
1034 template <typename LibObjT>
1035 class CommonMessageIteratorInactivityMessage final : public CommonMessage<LibObjT>
1038 using typename CommonMessage<LibObjT>::_LibObjPtr;
1039 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
1043 internal::SharedMessage<CommonMessageIteratorInactivityMessage<LibObjT>, LibObjT>;
1045 explicit CommonMessageIteratorInactivityMessage(const _LibObjPtr libObjPtr) noexcept :
1046 _ThisCommonMessage {libObjPtr}
1048 BT_ASSERT_DBG(this->isMessageIteratorInactivity());
1051 template <typename OtherLibObjT>
1052 CommonMessageIteratorInactivityMessage(
1053 const CommonMessageIteratorInactivityMessage<OtherLibObjT> val) noexcept :
1054 _ThisCommonMessage {val}
1058 template <typename OtherLibObjT>
1059 CommonMessageIteratorInactivityMessage<LibObjT>&
1060 operator=(const CommonMessageIteratorInactivityMessage<OtherLibObjT> val) noexcept
1062 _ThisCommonMessage::operator=(val);
1066 ConstClockSnapshot clockSnapshot() const noexcept
1068 const auto libObjPtr =
1069 bt_message_message_iterator_inactivity_borrow_clock_snapshot_const(this->libObjPtr());
1071 return ConstClockSnapshot {libObjPtr};
1074 Shared shared() const noexcept
1076 return Shared::createWithRef(*this);
1080 using MessageIteratorInactivityMessage = CommonMessageIteratorInactivityMessage<bt_message>;
1081 using ConstMessageIteratorInactivityMessage =
1082 CommonMessageIteratorInactivityMessage<const bt_message>;
1084 namespace internal {
1086 struct MessageIteratorInactivityMessageTypeDescr
1088 using Const = ConstMessageIteratorInactivityMessage;
1089 using NonConst = MessageIteratorInactivityMessage;
1093 struct TypeDescr<MessageIteratorInactivityMessage> :
1094 public MessageIteratorInactivityMessageTypeDescr
1099 struct TypeDescr<ConstMessageIteratorInactivityMessage> :
1100 public MessageIteratorInactivityMessageTypeDescr
1104 } /* namespace internal */
1106 template <typename LibObjT>
1107 CommonStreamBeginningMessage<LibObjT> CommonMessage<LibObjT>::asStreamBeginning() const noexcept
1109 BT_ASSERT_DBG(this->isStreamBeginning());
1110 return CommonStreamBeginningMessage<LibObjT> {this->libObjPtr()};
1113 template <typename LibObjT>
1114 CommonStreamEndMessage<LibObjT> CommonMessage<LibObjT>::asStreamEnd() const noexcept
1116 BT_ASSERT_DBG(this->isStreamEnd());
1117 return CommonStreamEndMessage<LibObjT> {this->libObjPtr()};
1120 template <typename LibObjT>
1121 CommonPacketBeginningMessage<LibObjT> CommonMessage<LibObjT>::asPacketBeginning() const noexcept
1123 BT_ASSERT_DBG(this->isPacketBeginning());
1124 return CommonPacketBeginningMessage<LibObjT> {this->libObjPtr()};
1127 template <typename LibObjT>
1128 CommonPacketEndMessage<LibObjT> CommonMessage<LibObjT>::asPacketEnd() const noexcept
1130 BT_ASSERT_DBG(this->isPacketEnd());
1131 return CommonPacketEndMessage<LibObjT> {this->libObjPtr()};
1134 template <typename LibObjT>
1135 CommonEventMessage<LibObjT> CommonMessage<LibObjT>::asEvent() const noexcept
1137 BT_ASSERT_DBG(this->isEvent());
1138 return CommonEventMessage<LibObjT> {this->libObjPtr()};
1141 template <typename LibObjT>
1142 CommonDiscardedEventsMessage<LibObjT> CommonMessage<LibObjT>::asDiscardedEvents() const noexcept
1144 BT_ASSERT_DBG(this->isDiscardedEvents());
1145 return CommonDiscardedEventsMessage<LibObjT> {this->libObjPtr()};
1148 template <typename LibObjT>
1149 CommonDiscardedPacketsMessage<LibObjT> CommonMessage<LibObjT>::asDiscardedPackets() const noexcept
1151 BT_ASSERT_DBG(this->isDiscardedPackets());
1152 return CommonDiscardedPacketsMessage<LibObjT> {this->libObjPtr()};
1155 template <typename LibObjT>
1156 CommonMessageIteratorInactivityMessage<LibObjT>
1157 CommonMessage<LibObjT>::asMessageIteratorInactivity() const noexcept
1159 BT_ASSERT_DBG(this->isMessageIteratorInactivity());
1160 return CommonMessageIteratorInactivityMessage<LibObjT> {this->libObjPtr()};
1163 } /* namespace bt2 */
1165 #endif /* BABELTRACE_CPP_COMMON_BT2_MESSAGE_HPP */