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
10 #include <type_traits>
13 #include <babeltrace2/babeltrace.h>
15 #include "common/assert.h"
16 #include "common/common.h"
17 #include "internal/borrowed-obj.hpp"
18 #include "internal/shared-obj.hpp"
19 #include "internal/utils.hpp"
20 #include "cpp-common/bt2/trace-ir.hpp"
21 #include "cpp-common/optional.hpp"
22 #include "cpp-common/string_view.hpp"
28 struct MessageRefFuncs final
30 static void get(const bt_message * const libObjPtr)
32 bt_message_get_ref(libObjPtr);
35 static void put(const bt_message * const libObjPtr)
37 bt_message_put_ref(libObjPtr);
41 template <typename ObjT, typename LibObjT>
42 using SharedMessage = internal::SharedObj<ObjT, LibObjT, internal::MessageRefFuncs>;
44 } /* namespace internal */
46 template <typename LibObjT>
47 class CommonStreamBeginningMessage;
49 template <typename LibObjT>
50 class CommonStreamEndMessage;
52 template <typename LibObjT>
53 class CommonEventMessage;
55 template <typename LibObjT>
56 class CommonPacketBeginningMessage;
58 template <typename LibObjT>
59 class CommonPacketEndMessage;
61 template <typename LibObjT>
62 class CommonDiscardedEventsMessage;
64 template <typename LibObjT>
65 class CommonDiscardedPacketsMessage;
67 template <typename LibObjT>
68 class CommonMessageIteratorInactivityMessage;
70 enum class MessageType
72 STREAM_BEGINNING = BT_MESSAGE_TYPE_STREAM_BEGINNING,
73 STREAM_END = BT_MESSAGE_TYPE_STREAM_END,
74 EVENT = BT_MESSAGE_TYPE_EVENT,
75 PACKET_BEGINNING = BT_MESSAGE_TYPE_PACKET_BEGINNING,
76 PACKET_END = BT_MESSAGE_TYPE_PACKET_END,
77 DISCARDED_EVENTS = BT_MESSAGE_TYPE_DISCARDED_EVENTS,
78 DISCARDED_PACKETS = BT_MESSAGE_TYPE_DISCARDED_PACKETS,
79 MESSAGE_ITERATOR_INACTIVITY = BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY,
82 template <typename LibObjT>
83 class CommonMessage : public internal::BorrowedObj<LibObjT>
86 using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
89 using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
90 using _ThisCommonMessage = CommonMessage<LibObjT>;
93 using Shared = internal::SharedMessage<CommonMessage<LibObjT>, LibObjT>;
95 explicit CommonMessage(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr}
99 template <typename OtherLibObjT>
100 CommonMessage(const CommonMessage<OtherLibObjT> val) noexcept : _ThisBorrowedObj {val}
104 template <typename OtherLibObjT>
105 _ThisCommonMessage& operator=(const CommonMessage<OtherLibObjT> val) noexcept
107 _ThisBorrowedObj::operator=(val);
111 MessageType type() const noexcept
113 return static_cast<MessageType>(bt_message_get_type(this->libObjPtr()));
116 bool isStreamBeginning() const noexcept
118 return this->type() == MessageType::STREAM_BEGINNING;
121 bool isStreamEnd() const noexcept
123 return this->type() == MessageType::STREAM_END;
126 bool isEvent() const noexcept
128 return this->type() == MessageType::EVENT;
131 bool isPacketBeginning() const noexcept
133 return this->type() == MessageType::PACKET_BEGINNING;
136 bool isPacketEnd() const noexcept
138 return this->type() == MessageType::PACKET_END;
141 bool isDiscardedEvents() const noexcept
143 return this->type() == MessageType::DISCARDED_EVENTS;
146 bool isDiscardedPackets() const noexcept
148 return this->type() == MessageType::DISCARDED_PACKETS;
151 bool isMessageIteratorInactivity() const noexcept
153 return this->type() == MessageType::MESSAGE_ITERATOR_INACTIVITY;
156 Shared shared() const noexcept
158 return Shared::createWithRef(*this);
161 template <typename MessageT>
162 MessageT as() const noexcept
164 return MessageT {this->libObjPtr()};
167 CommonStreamBeginningMessage<LibObjT> asStreamBeginning() const noexcept;
168 CommonStreamEndMessage<LibObjT> asStreamEnd() const noexcept;
169 CommonEventMessage<LibObjT> asEvent() const noexcept;
170 CommonPacketBeginningMessage<LibObjT> asPacketBeginning() const noexcept;
171 CommonPacketEndMessage<LibObjT> asPacketEnd() const noexcept;
172 CommonDiscardedEventsMessage<LibObjT> asDiscardedEvents() const noexcept;
173 CommonDiscardedPacketsMessage<LibObjT> asDiscardedPackets() const noexcept;
174 CommonMessageIteratorInactivityMessage<LibObjT> asMessageIteratorInactivity() const noexcept;
177 using Message = CommonMessage<bt_message>;
178 using ConstMessage = CommonMessage<const bt_message>;
182 struct MessageTypeDescr
184 using Const = ConstMessage;
185 using NonConst = Message;
189 struct TypeDescr<Message> : public MessageTypeDescr
194 struct TypeDescr<ConstMessage> : public MessageTypeDescr
198 template <typename LibObjT>
199 struct CommonStreamBeginningMessageSpec;
201 /* Functions specific to mutable stream beginning messages */
203 struct CommonStreamBeginningMessageSpec<bt_message> final
205 static bt_stream *stream(bt_message * const libObjPtr) noexcept
207 return bt_message_stream_beginning_borrow_stream(libObjPtr);
211 /* Functions specific to constant stream beginning messages */
213 struct CommonStreamBeginningMessageSpec<const bt_message> final
215 static const bt_stream *stream(const bt_message * const libObjPtr) noexcept
217 return bt_message_stream_beginning_borrow_stream_const(libObjPtr);
221 } /* namespace internal */
223 template <typename LibObjT>
224 class CommonStreamBeginningMessage final : public CommonMessage<LibObjT>
227 using typename CommonMessage<LibObjT>::_LibObjPtr;
228 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
231 typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>,
232 CommonStream<bt_stream>>::type;
235 using Shared = internal::SharedMessage<CommonStreamBeginningMessage<LibObjT>, LibObjT>;
237 explicit CommonStreamBeginningMessage(const _LibObjPtr libObjPtr) noexcept :
238 _ThisCommonMessage {libObjPtr}
240 BT_ASSERT_DBG(this->isStreamBeginning());
243 template <typename OtherLibObjT>
244 CommonStreamBeginningMessage(const CommonStreamBeginningMessage<OtherLibObjT> val) noexcept :
245 _ThisCommonMessage {val}
249 template <typename OtherLibObjT>
250 CommonStreamBeginningMessage<LibObjT>&
251 operator=(const CommonStreamBeginningMessage<OtherLibObjT> val) noexcept
253 _ThisCommonMessage::operator=(val);
257 ConstStream stream() const noexcept
259 return ConstStream {internal::CommonStreamBeginningMessageSpec<const bt_message>::stream(
263 _Stream stream() noexcept
266 internal::CommonStreamBeginningMessageSpec<LibObjT>::stream(this->libObjPtr())};
269 void defaultClockSnapshot(const std::uint64_t val) noexcept
271 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
273 bt_message_stream_beginning_set_default_clock_snapshot(this->libObjPtr(), val);
276 nonstd::optional<ConstClockSnapshot> defaultClockSnapshot() const noexcept
278 const bt_clock_snapshot *libObjPtr;
279 const auto state = bt_message_stream_beginning_borrow_default_clock_snapshot_const(
280 this->libObjPtr(), &libObjPtr);
282 if (state == BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN) {
283 return ConstClockSnapshot {libObjPtr};
286 return nonstd::nullopt;
289 Shared shared() const noexcept
291 return Shared::createWithRef(*this);
295 using StreamBeginningMessage = CommonStreamBeginningMessage<bt_message>;
296 using ConstStreamBeginningMessage = CommonStreamBeginningMessage<const bt_message>;
300 struct StreamBeginningMessageTypeDescr
302 using Const = ConstStreamBeginningMessage;
303 using NonConst = StreamBeginningMessage;
307 struct TypeDescr<StreamBeginningMessage> : public StreamBeginningMessageTypeDescr
312 struct TypeDescr<ConstStreamBeginningMessage> : public StreamBeginningMessageTypeDescr
316 template <typename LibObjT>
317 struct CommonStreamEndMessageSpec;
319 /* Functions specific to mutable stream end messages */
321 struct CommonStreamEndMessageSpec<bt_message> final
323 static bt_stream *stream(bt_message * const libObjPtr) noexcept
325 return bt_message_stream_end_borrow_stream(libObjPtr);
329 /* Functions specific to constant stream end messages */
331 struct CommonStreamEndMessageSpec<const bt_message> final
333 static const bt_stream *stream(const bt_message * const libObjPtr) noexcept
335 return bt_message_stream_end_borrow_stream_const(libObjPtr);
339 } /* namespace internal */
341 template <typename LibObjT>
342 class CommonStreamEndMessage final : public CommonMessage<LibObjT>
345 using typename CommonMessage<LibObjT>::_LibObjPtr;
346 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
349 typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>,
350 CommonStream<bt_stream>>::type;
353 using Shared = internal::SharedMessage<CommonStreamEndMessage<LibObjT>, LibObjT>;
355 explicit CommonStreamEndMessage(const _LibObjPtr libObjPtr) noexcept :
356 _ThisCommonMessage {libObjPtr}
358 BT_ASSERT_DBG(this->isStreamEnd());
361 template <typename OtherLibObjT>
362 CommonStreamEndMessage(const CommonStreamEndMessage<OtherLibObjT> val) noexcept :
363 _ThisCommonMessage {val}
367 template <typename OtherLibObjT>
368 CommonStreamEndMessage<LibObjT>&
369 operator=(const CommonStreamEndMessage<OtherLibObjT> val) noexcept
371 _ThisCommonMessage::operator=(val);
375 ConstStream stream() const noexcept
378 internal::CommonStreamEndMessageSpec<const bt_message>::stream(this->libObjPtr())};
381 _Stream stream() noexcept
383 return _Stream {internal::CommonStreamEndMessageSpec<LibObjT>::stream(this->libObjPtr())};
386 void defaultClockSnapshot(const std::uint64_t val) noexcept
388 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
390 bt_message_stream_end_set_default_clock_snapshot(this->libObjPtr(), val);
393 nonstd::optional<ConstClockSnapshot> defaultClockSnapshot() const noexcept
395 const bt_clock_snapshot *libObjPtr;
396 const auto state = bt_message_stream_end_borrow_default_clock_snapshot_const(
397 this->libObjPtr(), &libObjPtr);
399 if (state == BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN) {
400 return ConstClockSnapshot {libObjPtr};
403 return nonstd::nullopt;
406 Shared shared() const noexcept
408 return Shared::createWithRef(*this);
412 using StreamEndMessage = CommonStreamEndMessage<bt_message>;
413 using ConstStreamEndMessage = CommonStreamEndMessage<const bt_message>;
417 struct StreamEndMessageTypeDescr
419 using Const = ConstStreamEndMessage;
420 using NonConst = StreamEndMessage;
424 struct TypeDescr<StreamEndMessage> : public StreamEndMessageTypeDescr
429 struct TypeDescr<ConstStreamEndMessage> : public StreamEndMessageTypeDescr
433 template <typename LibObjT>
434 struct CommonPacketBeginningMessageSpec;
436 /* Functions specific to mutable packet beginning messages */
438 struct CommonPacketBeginningMessageSpec<bt_message> final
440 static bt_packet *packet(bt_message * const libObjPtr) noexcept
442 return bt_message_packet_beginning_borrow_packet(libObjPtr);
446 /* Functions specific to constant packet beginning messages */
448 struct CommonPacketBeginningMessageSpec<const bt_message> final
450 static const bt_packet *packet(const bt_message * const libObjPtr) noexcept
452 return bt_message_packet_beginning_borrow_packet_const(libObjPtr);
456 } /* namespace internal */
458 template <typename LibObjT>
459 class CommonPacketBeginningMessage final : public CommonMessage<LibObjT>
462 using typename CommonMessage<LibObjT>::_LibObjPtr;
463 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
466 typename std::conditional<std::is_const<LibObjT>::value, CommonPacket<const bt_packet>,
467 CommonPacket<bt_packet>>::type;
470 using Shared = internal::SharedMessage<CommonPacketBeginningMessage<LibObjT>, LibObjT>;
472 explicit CommonPacketBeginningMessage(const _LibObjPtr libObjPtr) noexcept :
473 _ThisCommonMessage {libObjPtr}
475 BT_ASSERT_DBG(this->isPacketBeginning());
478 template <typename OtherLibObjT>
479 CommonPacketBeginningMessage(const CommonPacketBeginningMessage<OtherLibObjT> val) noexcept :
480 _ThisCommonMessage {val}
484 template <typename OtherLibObjT>
485 CommonPacketBeginningMessage<LibObjT>&
486 operator=(const CommonPacketBeginningMessage<OtherLibObjT> val) noexcept
488 _ThisCommonMessage::operator=(val);
492 ConstPacket packet() const noexcept
494 return ConstPacket {internal::CommonPacketBeginningMessageSpec<const bt_message>::packet(
498 _Packet packet() noexcept
501 internal::CommonPacketBeginningMessageSpec<LibObjT>::packet(this->libObjPtr())};
504 void defaultClockSnapshot(const std::uint64_t val) noexcept
506 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
508 bt_message_packet_beginning_set_default_clock_snapshot(this->libObjPtr(), val);
511 ConstClockSnapshot defaultClockSnapshot() const noexcept
513 const auto libObjPtr =
514 bt_message_packet_beginning_borrow_default_clock_snapshot_const(this->libObjPtr());
516 return ConstClockSnapshot {libObjPtr};
519 Shared shared() const noexcept
521 return Shared::createWithRef(*this);
525 using PacketBeginningMessage = CommonPacketBeginningMessage<bt_message>;
526 using ConstPacketBeginningMessage = CommonPacketBeginningMessage<const bt_message>;
530 struct PacketBeginningMessageTypeDescr
532 using Const = ConstPacketBeginningMessage;
533 using NonConst = PacketBeginningMessage;
537 struct TypeDescr<PacketBeginningMessage> : public PacketBeginningMessageTypeDescr
542 struct TypeDescr<ConstPacketBeginningMessage> : public PacketBeginningMessageTypeDescr
546 template <typename LibObjT>
547 struct CommonPacketEndMessageSpec;
549 /* Functions specific to mutable packet end messages */
551 struct CommonPacketEndMessageSpec<bt_message> final
553 static bt_packet *packet(bt_message * const libObjPtr) noexcept
555 return bt_message_packet_end_borrow_packet(libObjPtr);
559 /* Functions specific to constant packet end messages */
561 struct CommonPacketEndMessageSpec<const bt_message> final
563 static const bt_packet *packet(const bt_message * const libObjPtr) noexcept
565 return bt_message_packet_end_borrow_packet_const(libObjPtr);
569 } /* namespace internal */
571 template <typename LibObjT>
572 class CommonPacketEndMessage final : public CommonMessage<LibObjT>
575 using typename CommonMessage<LibObjT>::_LibObjPtr;
576 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
579 typename std::conditional<std::is_const<LibObjT>::value, CommonPacket<const bt_packet>,
580 CommonPacket<bt_packet>>::type;
583 using Shared = internal::SharedMessage<CommonPacketEndMessage<LibObjT>, LibObjT>;
585 explicit CommonPacketEndMessage(const _LibObjPtr libObjPtr) noexcept :
586 _ThisCommonMessage {libObjPtr}
588 BT_ASSERT_DBG(this->isPacketEnd());
591 template <typename OtherLibObjT>
592 CommonPacketEndMessage(const CommonPacketEndMessage<OtherLibObjT> val) noexcept :
593 _ThisCommonMessage {val}
597 template <typename OtherLibObjT>
598 CommonPacketEndMessage<LibObjT>&
599 operator=(const CommonPacketEndMessage<OtherLibObjT> val) noexcept
601 _ThisCommonMessage::operator=(val);
605 ConstPacket packet() const noexcept
608 internal::CommonPacketEndMessageSpec<const bt_message>::packet(this->libObjPtr())};
611 _Packet packet() noexcept
613 return _Packet {internal::CommonPacketEndMessageSpec<LibObjT>::packet(this->libObjPtr())};
616 void defaultClockSnapshot(const std::uint64_t val) noexcept
618 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
620 bt_message_packet_end_set_default_clock_snapshot(this->libObjPtr(), val);
623 ConstClockSnapshot defaultClockSnapshot() const noexcept
625 const auto libObjPtr =
626 bt_message_packet_end_borrow_default_clock_snapshot_const(this->libObjPtr());
628 return ConstClockSnapshot {libObjPtr};
631 Shared shared() const noexcept
633 return Shared::createWithRef(*this);
637 using PacketEndMessage = CommonPacketEndMessage<bt_message>;
638 using ConstPacketEndMessage = CommonPacketEndMessage<const bt_message>;
642 struct PacketEndMessageTypeDescr
644 using Const = ConstPacketEndMessage;
645 using NonConst = PacketEndMessage;
649 struct TypeDescr<PacketEndMessage> : public PacketEndMessageTypeDescr
654 struct TypeDescr<ConstPacketEndMessage> : public PacketEndMessageTypeDescr
658 template <typename LibObjT>
659 struct CommonEventMessageSpec;
661 /* Functions specific to mutable event messages */
663 struct CommonEventMessageSpec<bt_message> final
665 static bt_event *event(bt_message * const libObjPtr) noexcept
667 return bt_message_event_borrow_event(libObjPtr);
671 /* Functions specific to constant event messages */
673 struct CommonEventMessageSpec<const bt_message> final
675 static const bt_event *event(const bt_message * const libObjPtr) noexcept
677 return bt_message_event_borrow_event_const(libObjPtr);
681 } /* namespace internal */
683 template <typename LibObjT>
684 class CommonEventMessage final : public CommonMessage<LibObjT>
687 using typename CommonMessage<LibObjT>::_LibObjPtr;
688 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
691 typename std::conditional<std::is_const<LibObjT>::value, CommonEvent<const bt_event>,
692 CommonEvent<bt_event>>::type;
695 using Shared = internal::SharedMessage<CommonEventMessage<LibObjT>, LibObjT>;
697 explicit CommonEventMessage(const _LibObjPtr libObjPtr) noexcept :
698 _ThisCommonMessage {libObjPtr}
700 BT_ASSERT_DBG(this->isEvent());
703 template <typename OtherLibObjT>
704 CommonEventMessage(const CommonEventMessage<OtherLibObjT> val) noexcept :
705 _ThisCommonMessage {val}
709 template <typename OtherLibObjT>
710 CommonEventMessage<LibObjT>& operator=(const CommonEventMessage<OtherLibObjT> val) noexcept
712 _ThisCommonMessage::operator=(val);
716 ConstEvent event() const noexcept
719 internal::CommonEventMessageSpec<const bt_message>::event(this->libObjPtr())};
722 _Event event() noexcept
724 return _Event {internal::CommonEventMessageSpec<LibObjT>::event(this->libObjPtr())};
727 ConstClockSnapshot defaultClockSnapshot() const noexcept
729 const auto libObjPtr =
730 bt_message_event_borrow_default_clock_snapshot_const(this->libObjPtr());
732 return ConstClockSnapshot {libObjPtr};
735 Shared shared() const noexcept
737 return Shared::createWithRef(*this);
741 using EventMessage = CommonEventMessage<bt_message>;
742 using ConstEventMessage = CommonEventMessage<const bt_message>;
746 struct EventMessageTypeDescr
748 using Const = ConstEventMessage;
749 using NonConst = EventMessage;
753 struct TypeDescr<EventMessage> : public EventMessageTypeDescr
758 struct TypeDescr<ConstEventMessage> : public EventMessageTypeDescr
762 template <typename LibObjT>
763 struct CommonDiscardedEventsMessageSpec;
765 /* Functions specific to mutable discarded events messages */
767 struct CommonDiscardedEventsMessageSpec<bt_message> final
769 static bt_stream *stream(bt_message * const libObjPtr) noexcept
771 return bt_message_discarded_events_borrow_stream(libObjPtr);
775 /* Functions specific to constant discarded events messages */
777 struct CommonDiscardedEventsMessageSpec<const bt_message> final
779 static const bt_stream *stream(const bt_message * const libObjPtr) noexcept
781 return bt_message_discarded_events_borrow_stream_const(libObjPtr);
785 } /* namespace internal */
787 template <typename LibObjT>
788 class CommonDiscardedEventsMessage final : public CommonMessage<LibObjT>
791 using typename CommonMessage<LibObjT>::_LibObjPtr;
792 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
795 typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>,
796 CommonStream<bt_stream>>::type;
799 using Shared = internal::SharedMessage<CommonDiscardedEventsMessage<LibObjT>, LibObjT>;
801 explicit CommonDiscardedEventsMessage(const _LibObjPtr libObjPtr) noexcept :
802 _ThisCommonMessage {libObjPtr}
804 BT_ASSERT_DBG(this->isDiscardedEvents());
807 template <typename OtherLibObjT>
808 CommonDiscardedEventsMessage(const CommonDiscardedEventsMessage<OtherLibObjT> val) noexcept :
809 _ThisCommonMessage {val}
813 template <typename OtherLibObjT>
814 CommonDiscardedEventsMessage<LibObjT>&
815 operator=(const CommonDiscardedEventsMessage<OtherLibObjT> val) noexcept
817 _ThisCommonMessage::operator=(val);
821 ConstStream stream() const noexcept
823 return ConstStream {internal::CommonDiscardedEventsMessageSpec<const bt_message>::stream(
827 _Stream stream() noexcept
830 internal::CommonDiscardedEventsMessageSpec<LibObjT>::stream(this->libObjPtr())};
833 ConstClockSnapshot beginningDefaultClockSnapshot() const noexcept
835 const auto libObjPtr =
836 bt_message_discarded_events_borrow_beginning_default_clock_snapshot_const(
839 return ConstClockSnapshot {libObjPtr};
842 ConstClockSnapshot endDefaultClockSnapshot() const noexcept
844 const auto libObjPtr =
845 bt_message_discarded_events_borrow_end_default_clock_snapshot_const(this->libObjPtr());
847 return ConstClockSnapshot {libObjPtr};
850 void count(const std::uint64_t count) noexcept
852 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
854 bt_message_discarded_events_set_count(this->libObjPtr(), count);
857 nonstd::optional<std::uint64_t> count() const noexcept
860 const auto avail = bt_message_discarded_events_get_count(this->libObjPtr(), &count);
866 return nonstd::nullopt;
869 Shared shared() const noexcept
871 return Shared::createWithRef(*this);
875 using DiscardedEventsMessage = CommonDiscardedEventsMessage<bt_message>;
876 using ConstDiscardedEventsMessage = CommonDiscardedEventsMessage<const bt_message>;
880 struct DiscardedEventsMessageTypeDescr
882 using Const = ConstDiscardedEventsMessage;
883 using NonConst = DiscardedEventsMessage;
887 struct TypeDescr<DiscardedEventsMessage> : public DiscardedEventsMessageTypeDescr
892 struct TypeDescr<ConstDiscardedEventsMessage> : public DiscardedEventsMessageTypeDescr
896 template <typename LibObjT>
897 struct CommonDiscardedPacketsMessageSpec;
899 /* Functions specific to mutable discarded packets messages */
901 struct CommonDiscardedPacketsMessageSpec<bt_message> final
903 static bt_stream *stream(bt_message * const libObjPtr) noexcept
905 return bt_message_discarded_packets_borrow_stream(libObjPtr);
909 /* Functions specific to constant discarded packets messages */
911 struct CommonDiscardedPacketsMessageSpec<const bt_message> final
913 static const bt_stream *stream(const bt_message * const libObjPtr) noexcept
915 return bt_message_discarded_packets_borrow_stream_const(libObjPtr);
919 } /* namespace internal */
921 template <typename LibObjT>
922 class CommonDiscardedPacketsMessage final : public CommonMessage<LibObjT>
925 using typename CommonMessage<LibObjT>::_LibObjPtr;
926 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
929 typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>,
930 CommonStream<bt_stream>>::type;
933 using Shared = internal::SharedMessage<CommonDiscardedPacketsMessage<LibObjT>, LibObjT>;
935 explicit CommonDiscardedPacketsMessage(const _LibObjPtr libObjPtr) noexcept :
936 _ThisCommonMessage {libObjPtr}
938 BT_ASSERT_DBG(this->isDiscardedPackets());
941 template <typename OtherLibObjT>
942 CommonDiscardedPacketsMessage(const CommonDiscardedPacketsMessage<OtherLibObjT> val) noexcept :
943 _ThisCommonMessage {val}
947 template <typename OtherLibObjT>
948 CommonDiscardedPacketsMessage<LibObjT>&
949 operator=(const CommonDiscardedPacketsMessage<OtherLibObjT> val) noexcept
951 _ThisCommonMessage::operator=(val);
955 ConstStream stream() const noexcept
957 return ConstStream {internal::CommonDiscardedPacketsMessageSpec<const bt_message>::stream(
961 _Stream stream() noexcept
964 internal::CommonDiscardedPacketsMessageSpec<LibObjT>::stream(this->libObjPtr())};
967 ConstClockSnapshot beginningDefaultClockSnapshot() const noexcept
969 const auto libObjPtr =
970 bt_message_discarded_packets_borrow_beginning_default_clock_snapshot_const(
973 return ConstClockSnapshot {libObjPtr};
976 ConstClockSnapshot endDefaultClockSnapshot() const noexcept
978 const auto libObjPtr =
979 bt_message_discarded_packets_borrow_end_default_clock_snapshot_const(this->libObjPtr());
981 return ConstClockSnapshot {libObjPtr};
984 void count(const std::uint64_t count) noexcept
986 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
988 bt_message_discarded_packets_set_count(this->libObjPtr(), count);
991 nonstd::optional<std::uint64_t> count() const noexcept
994 const auto avail = bt_message_discarded_packets_get_count(this->libObjPtr(), &count);
1000 return nonstd::nullopt;
1003 Shared shared() const noexcept
1005 return Shared::createWithRef(*this);
1009 using DiscardedPacketsMessage = CommonDiscardedPacketsMessage<bt_message>;
1010 using ConstDiscardedPacketsMessage = CommonDiscardedPacketsMessage<const bt_message>;
1012 namespace internal {
1014 struct DiscardedPacketsMessageTypeDescr
1016 using Const = ConstDiscardedPacketsMessage;
1017 using NonConst = DiscardedPacketsMessage;
1021 struct TypeDescr<DiscardedPacketsMessage> : public DiscardedPacketsMessageTypeDescr
1026 struct TypeDescr<ConstDiscardedPacketsMessage> : public DiscardedPacketsMessageTypeDescr
1030 } /* namespace internal */
1032 template <typename LibObjT>
1033 class CommonMessageIteratorInactivityMessage final : public CommonMessage<LibObjT>
1036 using typename CommonMessage<LibObjT>::_LibObjPtr;
1037 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
1041 internal::SharedMessage<CommonMessageIteratorInactivityMessage<LibObjT>, LibObjT>;
1043 explicit CommonMessageIteratorInactivityMessage(const _LibObjPtr libObjPtr) noexcept :
1044 _ThisCommonMessage {libObjPtr}
1046 BT_ASSERT_DBG(this->isMessageIteratorInactivity());
1049 template <typename OtherLibObjT>
1050 CommonMessageIteratorInactivityMessage(
1051 const CommonMessageIteratorInactivityMessage<OtherLibObjT> val) noexcept :
1052 _ThisCommonMessage {val}
1056 template <typename OtherLibObjT>
1057 CommonMessageIteratorInactivityMessage<LibObjT>&
1058 operator=(const CommonMessageIteratorInactivityMessage<OtherLibObjT> val) noexcept
1060 _ThisCommonMessage::operator=(val);
1064 ConstClockSnapshot clockSnapshot() const noexcept
1066 const auto libObjPtr =
1067 bt_message_message_iterator_inactivity_borrow_clock_snapshot_const(this->libObjPtr());
1069 return ConstClockSnapshot {libObjPtr};
1072 Shared shared() const noexcept
1074 return Shared::createWithRef(*this);
1078 using MessageIteratorInactivityMessage = CommonMessageIteratorInactivityMessage<bt_message>;
1079 using ConstMessageIteratorInactivityMessage =
1080 CommonMessageIteratorInactivityMessage<const bt_message>;
1082 namespace internal {
1084 struct MessageIteratorInactivityMessageTypeDescr
1086 using Const = ConstMessageIteratorInactivityMessage;
1087 using NonConst = MessageIteratorInactivityMessage;
1091 struct TypeDescr<MessageIteratorInactivityMessage> :
1092 public MessageIteratorInactivityMessageTypeDescr
1097 struct TypeDescr<ConstMessageIteratorInactivityMessage> :
1098 public MessageIteratorInactivityMessageTypeDescr
1102 } /* namespace internal */
1104 template <typename LibObjT>
1105 CommonStreamBeginningMessage<LibObjT> CommonMessage<LibObjT>::asStreamBeginning() const noexcept
1107 BT_ASSERT_DBG(this->isStreamBeginning());
1108 return CommonStreamBeginningMessage<LibObjT> {this->libObjPtr()};
1111 template <typename LibObjT>
1112 CommonStreamEndMessage<LibObjT> CommonMessage<LibObjT>::asStreamEnd() const noexcept
1114 BT_ASSERT_DBG(this->isStreamEnd());
1115 return CommonStreamEndMessage<LibObjT> {this->libObjPtr()};
1118 template <typename LibObjT>
1119 CommonPacketBeginningMessage<LibObjT> CommonMessage<LibObjT>::asPacketBeginning() const noexcept
1121 BT_ASSERT_DBG(this->isPacketBeginning());
1122 return CommonPacketBeginningMessage<LibObjT> {this->libObjPtr()};
1125 template <typename LibObjT>
1126 CommonPacketEndMessage<LibObjT> CommonMessage<LibObjT>::asPacketEnd() const noexcept
1128 BT_ASSERT_DBG(this->isPacketEnd());
1129 return CommonPacketEndMessage<LibObjT> {this->libObjPtr()};
1132 template <typename LibObjT>
1133 CommonEventMessage<LibObjT> CommonMessage<LibObjT>::asEvent() const noexcept
1135 BT_ASSERT_DBG(this->isEvent());
1136 return CommonEventMessage<LibObjT> {this->libObjPtr()};
1139 template <typename LibObjT>
1140 CommonDiscardedEventsMessage<LibObjT> CommonMessage<LibObjT>::asDiscardedEvents() const noexcept
1142 BT_ASSERT_DBG(this->isDiscardedEvents());
1143 return CommonDiscardedEventsMessage<LibObjT> {this->libObjPtr()};
1146 template <typename LibObjT>
1147 CommonDiscardedPacketsMessage<LibObjT> CommonMessage<LibObjT>::asDiscardedPackets() const noexcept
1149 BT_ASSERT_DBG(this->isDiscardedPackets());
1150 return CommonDiscardedPacketsMessage<LibObjT> {this->libObjPtr()};
1153 template <typename LibObjT>
1154 CommonMessageIteratorInactivityMessage<LibObjT>
1155 CommonMessage<LibObjT>::asMessageIteratorInactivity() const noexcept
1157 BT_ASSERT_DBG(this->isMessageIteratorInactivity());
1158 return CommonMessageIteratorInactivityMessage<LibObjT> {this->libObjPtr()};
1161 } /* namespace bt2 */
1163 #endif /* BABELTRACE_CPP_COMMON_BT2_MESSAGE_HPP */