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
11 #include <type_traits>
13 #include <babeltrace2/babeltrace.h>
15 #include "common/assert.h"
16 #include "cpp-common/bt2/clock-snapshot.hpp"
17 #include "cpp-common/bt2/trace-ir.hpp"
18 #include "cpp-common/optional.hpp"
20 #include "borrowed-object.hpp"
21 #include "internal/utils.hpp"
22 #include "shared-object.hpp"
27 struct MessageRefFuncs final
29 static void get(const bt_message * const libObjPtr) noexcept
31 bt_message_get_ref(libObjPtr);
34 static void put(const bt_message * const libObjPtr) noexcept
36 bt_message_put_ref(libObjPtr);
40 } /* namespace internal */
42 template <typename ObjT, typename LibObjT>
43 using SharedMessage = SharedObject<ObjT, LibObjT, internal::MessageRefFuncs>;
45 template <typename LibObjT>
46 class CommonStreamBeginningMessage;
48 template <typename LibObjT>
49 class CommonStreamEndMessage;
51 template <typename LibObjT>
52 class CommonEventMessage;
54 template <typename LibObjT>
55 class CommonPacketBeginningMessage;
57 template <typename LibObjT>
58 class CommonPacketEndMessage;
60 template <typename LibObjT>
61 class CommonDiscardedEventsMessage;
63 template <typename LibObjT>
64 class CommonDiscardedPacketsMessage;
66 template <typename LibObjT>
67 class CommonMessageIteratorInactivityMessage;
69 enum class MessageType
71 STREAM_BEGINNING = BT_MESSAGE_TYPE_STREAM_BEGINNING,
72 STREAM_END = BT_MESSAGE_TYPE_STREAM_END,
73 EVENT = BT_MESSAGE_TYPE_EVENT,
74 PACKET_BEGINNING = BT_MESSAGE_TYPE_PACKET_BEGINNING,
75 PACKET_END = BT_MESSAGE_TYPE_PACKET_END,
76 DISCARDED_EVENTS = BT_MESSAGE_TYPE_DISCARDED_EVENTS,
77 DISCARDED_PACKETS = BT_MESSAGE_TYPE_DISCARDED_PACKETS,
78 MESSAGE_ITERATOR_INACTIVITY = BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY,
81 template <typename LibObjT>
82 class CommonMessage : public BorrowedObject<LibObjT>
85 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
88 using typename BorrowedObject<LibObjT>::_LibObjPtr;
89 using _ThisCommonMessage = CommonMessage<LibObjT>;
92 using Shared = SharedMessage<CommonMessage<LibObjT>, LibObjT>;
94 explicit CommonMessage(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
98 template <typename OtherLibObjT>
99 CommonMessage(const CommonMessage<OtherLibObjT> val) noexcept : _ThisBorrowedObject {val}
103 template <typename OtherLibObjT>
104 _ThisCommonMessage& operator=(const CommonMessage<OtherLibObjT> val) noexcept
106 _ThisBorrowedObject::operator=(val);
110 MessageType type() const noexcept
112 return static_cast<MessageType>(bt_message_get_type(this->libObjPtr()));
115 bool isStreamBeginning() const noexcept
117 return this->type() == MessageType::STREAM_BEGINNING;
120 bool isStreamEnd() const noexcept
122 return this->type() == MessageType::STREAM_END;
125 bool isEvent() const noexcept
127 return this->type() == MessageType::EVENT;
130 bool isPacketBeginning() const noexcept
132 return this->type() == MessageType::PACKET_BEGINNING;
135 bool isPacketEnd() const noexcept
137 return this->type() == MessageType::PACKET_END;
140 bool isDiscardedEvents() const noexcept
142 return this->type() == MessageType::DISCARDED_EVENTS;
145 bool isDiscardedPackets() const noexcept
147 return this->type() == MessageType::DISCARDED_PACKETS;
150 bool isMessageIteratorInactivity() const noexcept
152 return this->type() == MessageType::MESSAGE_ITERATOR_INACTIVITY;
155 Shared shared() const noexcept
157 return Shared::createWithRef(*this);
160 template <typename MessageT>
161 MessageT as() const noexcept
163 return MessageT {this->libObjPtr()};
166 CommonStreamBeginningMessage<LibObjT> asStreamBeginning() const noexcept;
167 CommonStreamEndMessage<LibObjT> asStreamEnd() const noexcept;
168 CommonEventMessage<LibObjT> asEvent() const noexcept;
169 CommonPacketBeginningMessage<LibObjT> asPacketBeginning() const noexcept;
170 CommonPacketEndMessage<LibObjT> asPacketEnd() const noexcept;
171 CommonDiscardedEventsMessage<LibObjT> asDiscardedEvents() const noexcept;
172 CommonDiscardedPacketsMessage<LibObjT> asDiscardedPackets() const noexcept;
173 CommonMessageIteratorInactivityMessage<LibObjT> asMessageIteratorInactivity() const noexcept;
176 using Message = CommonMessage<bt_message>;
177 using ConstMessage = CommonMessage<const bt_message>;
181 struct MessageTypeDescr
183 using Const = ConstMessage;
184 using NonConst = Message;
188 struct TypeDescr<Message> : public MessageTypeDescr
193 struct TypeDescr<ConstMessage> : public MessageTypeDescr
197 template <typename LibObjT>
198 struct CommonStreamBeginningMessageSpec;
200 /* Functions specific to mutable stream beginning messages */
202 struct CommonStreamBeginningMessageSpec<bt_message> final
204 static bt_stream *stream(bt_message * const libObjPtr) noexcept
206 return bt_message_stream_beginning_borrow_stream(libObjPtr);
210 /* Functions specific to constant stream beginning messages */
212 struct CommonStreamBeginningMessageSpec<const bt_message> final
214 static const bt_stream *stream(const bt_message * const libObjPtr) noexcept
216 return bt_message_stream_beginning_borrow_stream_const(libObjPtr);
220 } /* namespace internal */
222 template <typename LibObjT>
223 class CommonStreamBeginningMessage final : public CommonMessage<LibObjT>
226 using typename CommonMessage<LibObjT>::_LibObjPtr;
227 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
230 typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>,
231 CommonStream<bt_stream>>::type;
234 using Shared = SharedMessage<CommonStreamBeginningMessage<LibObjT>, LibObjT>;
236 explicit CommonStreamBeginningMessage(const _LibObjPtr libObjPtr) noexcept :
237 _ThisCommonMessage {libObjPtr}
239 BT_ASSERT_DBG(this->isStreamBeginning());
242 template <typename OtherLibObjT>
243 CommonStreamBeginningMessage(const CommonStreamBeginningMessage<OtherLibObjT> val) noexcept :
244 _ThisCommonMessage {val}
248 template <typename OtherLibObjT>
249 CommonStreamBeginningMessage<LibObjT>&
250 operator=(const CommonStreamBeginningMessage<OtherLibObjT> val) noexcept
252 _ThisCommonMessage::operator=(val);
256 _Stream stream() const noexcept
259 internal::CommonStreamBeginningMessageSpec<LibObjT>::stream(this->libObjPtr())};
262 void defaultClockSnapshot(const std::uint64_t val) const noexcept
264 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
266 bt_message_stream_beginning_set_default_clock_snapshot(this->libObjPtr(), val);
269 nonstd::optional<ConstClockSnapshot> defaultClockSnapshot() const noexcept
271 const bt_clock_snapshot *libObjPtr;
272 const auto state = bt_message_stream_beginning_borrow_default_clock_snapshot_const(
273 this->libObjPtr(), &libObjPtr);
275 if (state == BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN) {
276 return ConstClockSnapshot {libObjPtr};
279 return nonstd::nullopt;
282 Shared shared() const noexcept
284 return Shared::createWithRef(*this);
288 using StreamBeginningMessage = CommonStreamBeginningMessage<bt_message>;
289 using ConstStreamBeginningMessage = CommonStreamBeginningMessage<const bt_message>;
293 struct StreamBeginningMessageTypeDescr
295 using Const = ConstStreamBeginningMessage;
296 using NonConst = StreamBeginningMessage;
300 struct TypeDescr<StreamBeginningMessage> : public StreamBeginningMessageTypeDescr
305 struct TypeDescr<ConstStreamBeginningMessage> : public StreamBeginningMessageTypeDescr
309 template <typename LibObjT>
310 struct CommonStreamEndMessageSpec;
312 /* Functions specific to mutable stream end messages */
314 struct CommonStreamEndMessageSpec<bt_message> final
316 static bt_stream *stream(bt_message * const libObjPtr) noexcept
318 return bt_message_stream_end_borrow_stream(libObjPtr);
322 /* Functions specific to constant stream end messages */
324 struct CommonStreamEndMessageSpec<const bt_message> final
326 static const bt_stream *stream(const bt_message * const libObjPtr) noexcept
328 return bt_message_stream_end_borrow_stream_const(libObjPtr);
332 } /* namespace internal */
334 template <typename LibObjT>
335 class CommonStreamEndMessage final : public CommonMessage<LibObjT>
338 using typename CommonMessage<LibObjT>::_LibObjPtr;
339 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
342 typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>,
343 CommonStream<bt_stream>>::type;
346 using Shared = SharedMessage<CommonStreamEndMessage<LibObjT>, LibObjT>;
348 explicit CommonStreamEndMessage(const _LibObjPtr libObjPtr) noexcept :
349 _ThisCommonMessage {libObjPtr}
351 BT_ASSERT_DBG(this->isStreamEnd());
354 template <typename OtherLibObjT>
355 CommonStreamEndMessage(const CommonStreamEndMessage<OtherLibObjT> val) noexcept :
356 _ThisCommonMessage {val}
360 template <typename OtherLibObjT>
361 CommonStreamEndMessage<LibObjT>&
362 operator=(const CommonStreamEndMessage<OtherLibObjT> val) noexcept
364 _ThisCommonMessage::operator=(val);
368 _Stream stream() const noexcept
370 return _Stream {internal::CommonStreamEndMessageSpec<LibObjT>::stream(this->libObjPtr())};
373 void defaultClockSnapshot(const std::uint64_t val) const noexcept
375 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
377 bt_message_stream_end_set_default_clock_snapshot(this->libObjPtr(), val);
380 nonstd::optional<ConstClockSnapshot> defaultClockSnapshot() const noexcept
382 const bt_clock_snapshot *libObjPtr;
383 const auto state = bt_message_stream_end_borrow_default_clock_snapshot_const(
384 this->libObjPtr(), &libObjPtr);
386 if (state == BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN) {
387 return ConstClockSnapshot {libObjPtr};
390 return nonstd::nullopt;
393 Shared shared() const noexcept
395 return Shared::createWithRef(*this);
399 using StreamEndMessage = CommonStreamEndMessage<bt_message>;
400 using ConstStreamEndMessage = CommonStreamEndMessage<const bt_message>;
404 struct StreamEndMessageTypeDescr
406 using Const = ConstStreamEndMessage;
407 using NonConst = StreamEndMessage;
411 struct TypeDescr<StreamEndMessage> : public StreamEndMessageTypeDescr
416 struct TypeDescr<ConstStreamEndMessage> : public StreamEndMessageTypeDescr
420 template <typename LibObjT>
421 struct CommonPacketBeginningMessageSpec;
423 /* Functions specific to mutable packet beginning messages */
425 struct CommonPacketBeginningMessageSpec<bt_message> final
427 static bt_packet *packet(bt_message * const libObjPtr) noexcept
429 return bt_message_packet_beginning_borrow_packet(libObjPtr);
433 /* Functions specific to constant packet beginning messages */
435 struct CommonPacketBeginningMessageSpec<const bt_message> final
437 static const bt_packet *packet(const bt_message * const libObjPtr) noexcept
439 return bt_message_packet_beginning_borrow_packet_const(libObjPtr);
443 } /* namespace internal */
445 template <typename LibObjT>
446 class CommonPacketBeginningMessage final : public CommonMessage<LibObjT>
449 using typename CommonMessage<LibObjT>::_LibObjPtr;
450 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
453 typename std::conditional<std::is_const<LibObjT>::value, CommonPacket<const bt_packet>,
454 CommonPacket<bt_packet>>::type;
457 using Shared = SharedMessage<CommonPacketBeginningMessage<LibObjT>, LibObjT>;
459 explicit CommonPacketBeginningMessage(const _LibObjPtr libObjPtr) noexcept :
460 _ThisCommonMessage {libObjPtr}
462 BT_ASSERT_DBG(this->isPacketBeginning());
465 template <typename OtherLibObjT>
466 CommonPacketBeginningMessage(const CommonPacketBeginningMessage<OtherLibObjT> val) noexcept :
467 _ThisCommonMessage {val}
471 template <typename OtherLibObjT>
472 CommonPacketBeginningMessage<LibObjT>&
473 operator=(const CommonPacketBeginningMessage<OtherLibObjT> val) noexcept
475 _ThisCommonMessage::operator=(val);
479 _Packet packet() const noexcept
482 internal::CommonPacketBeginningMessageSpec<LibObjT>::packet(this->libObjPtr())};
485 void defaultClockSnapshot(const std::uint64_t val) const noexcept
487 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
489 bt_message_packet_beginning_set_default_clock_snapshot(this->libObjPtr(), val);
492 ConstClockSnapshot defaultClockSnapshot() const noexcept
494 const auto libObjPtr =
495 bt_message_packet_beginning_borrow_default_clock_snapshot_const(this->libObjPtr());
497 return ConstClockSnapshot {libObjPtr};
500 Shared shared() const noexcept
502 return Shared::createWithRef(*this);
506 using PacketBeginningMessage = CommonPacketBeginningMessage<bt_message>;
507 using ConstPacketBeginningMessage = CommonPacketBeginningMessage<const bt_message>;
511 struct PacketBeginningMessageTypeDescr
513 using Const = ConstPacketBeginningMessage;
514 using NonConst = PacketBeginningMessage;
518 struct TypeDescr<PacketBeginningMessage> : public PacketBeginningMessageTypeDescr
523 struct TypeDescr<ConstPacketBeginningMessage> : public PacketBeginningMessageTypeDescr
527 template <typename LibObjT>
528 struct CommonPacketEndMessageSpec;
530 /* Functions specific to mutable packet end messages */
532 struct CommonPacketEndMessageSpec<bt_message> final
534 static bt_packet *packet(bt_message * const libObjPtr) noexcept
536 return bt_message_packet_end_borrow_packet(libObjPtr);
540 /* Functions specific to constant packet end messages */
542 struct CommonPacketEndMessageSpec<const bt_message> final
544 static const bt_packet *packet(const bt_message * const libObjPtr) noexcept
546 return bt_message_packet_end_borrow_packet_const(libObjPtr);
550 } /* namespace internal */
552 template <typename LibObjT>
553 class CommonPacketEndMessage final : public CommonMessage<LibObjT>
556 using typename CommonMessage<LibObjT>::_LibObjPtr;
557 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
560 typename std::conditional<std::is_const<LibObjT>::value, CommonPacket<const bt_packet>,
561 CommonPacket<bt_packet>>::type;
564 using Shared = SharedMessage<CommonPacketEndMessage<LibObjT>, LibObjT>;
566 explicit CommonPacketEndMessage(const _LibObjPtr libObjPtr) noexcept :
567 _ThisCommonMessage {libObjPtr}
569 BT_ASSERT_DBG(this->isPacketEnd());
572 template <typename OtherLibObjT>
573 CommonPacketEndMessage(const CommonPacketEndMessage<OtherLibObjT> val) noexcept :
574 _ThisCommonMessage {val}
578 template <typename OtherLibObjT>
579 CommonPacketEndMessage<LibObjT>&
580 operator=(const CommonPacketEndMessage<OtherLibObjT> val) noexcept
582 _ThisCommonMessage::operator=(val);
586 _Packet packet() const noexcept
588 return _Packet {internal::CommonPacketEndMessageSpec<LibObjT>::packet(this->libObjPtr())};
591 void defaultClockSnapshot(const std::uint64_t val) const noexcept
593 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
595 bt_message_packet_end_set_default_clock_snapshot(this->libObjPtr(), val);
598 ConstClockSnapshot defaultClockSnapshot() const noexcept
600 const auto libObjPtr =
601 bt_message_packet_end_borrow_default_clock_snapshot_const(this->libObjPtr());
603 return ConstClockSnapshot {libObjPtr};
606 Shared shared() const noexcept
608 return Shared::createWithRef(*this);
612 using PacketEndMessage = CommonPacketEndMessage<bt_message>;
613 using ConstPacketEndMessage = CommonPacketEndMessage<const bt_message>;
617 struct PacketEndMessageTypeDescr
619 using Const = ConstPacketEndMessage;
620 using NonConst = PacketEndMessage;
624 struct TypeDescr<PacketEndMessage> : public PacketEndMessageTypeDescr
629 struct TypeDescr<ConstPacketEndMessage> : public PacketEndMessageTypeDescr
633 template <typename LibObjT>
634 struct CommonEventMessageSpec;
636 /* Functions specific to mutable event messages */
638 struct CommonEventMessageSpec<bt_message> final
640 static bt_event *event(bt_message * const libObjPtr) noexcept
642 return bt_message_event_borrow_event(libObjPtr);
646 /* Functions specific to constant event messages */
648 struct CommonEventMessageSpec<const bt_message> final
650 static const bt_event *event(const bt_message * const libObjPtr) noexcept
652 return bt_message_event_borrow_event_const(libObjPtr);
656 } /* namespace internal */
658 template <typename LibObjT>
659 class CommonEventMessage final : public CommonMessage<LibObjT>
662 using typename CommonMessage<LibObjT>::_LibObjPtr;
663 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
666 typename std::conditional<std::is_const<LibObjT>::value, CommonEvent<const bt_event>,
667 CommonEvent<bt_event>>::type;
670 using Shared = SharedMessage<CommonEventMessage<LibObjT>, LibObjT>;
672 explicit CommonEventMessage(const _LibObjPtr libObjPtr) noexcept :
673 _ThisCommonMessage {libObjPtr}
675 BT_ASSERT_DBG(this->isEvent());
678 template <typename OtherLibObjT>
679 CommonEventMessage(const CommonEventMessage<OtherLibObjT> val) noexcept :
680 _ThisCommonMessage {val}
684 template <typename OtherLibObjT>
685 CommonEventMessage<LibObjT>& operator=(const CommonEventMessage<OtherLibObjT> val) noexcept
687 _ThisCommonMessage::operator=(val);
691 _Event event() const noexcept
693 return _Event {internal::CommonEventMessageSpec<LibObjT>::event(this->libObjPtr())};
696 ConstClockSnapshot defaultClockSnapshot() const noexcept
698 const auto libObjPtr =
699 bt_message_event_borrow_default_clock_snapshot_const(this->libObjPtr());
701 return ConstClockSnapshot {libObjPtr};
704 Shared shared() const noexcept
706 return Shared::createWithRef(*this);
710 using EventMessage = CommonEventMessage<bt_message>;
711 using ConstEventMessage = CommonEventMessage<const bt_message>;
715 struct EventMessageTypeDescr
717 using Const = ConstEventMessage;
718 using NonConst = EventMessage;
722 struct TypeDescr<EventMessage> : public EventMessageTypeDescr
727 struct TypeDescr<ConstEventMessage> : public EventMessageTypeDescr
731 template <typename LibObjT>
732 struct CommonDiscardedEventsMessageSpec;
734 /* Functions specific to mutable discarded events messages */
736 struct CommonDiscardedEventsMessageSpec<bt_message> final
738 static bt_stream *stream(bt_message * const libObjPtr) noexcept
740 return bt_message_discarded_events_borrow_stream(libObjPtr);
744 /* Functions specific to constant discarded events messages */
746 struct CommonDiscardedEventsMessageSpec<const bt_message> final
748 static const bt_stream *stream(const bt_message * const libObjPtr) noexcept
750 return bt_message_discarded_events_borrow_stream_const(libObjPtr);
754 } /* namespace internal */
756 template <typename LibObjT>
757 class CommonDiscardedEventsMessage final : public CommonMessage<LibObjT>
760 using typename CommonMessage<LibObjT>::_LibObjPtr;
761 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
764 typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>,
765 CommonStream<bt_stream>>::type;
768 using Shared = SharedMessage<CommonDiscardedEventsMessage<LibObjT>, LibObjT>;
770 explicit CommonDiscardedEventsMessage(const _LibObjPtr libObjPtr) noexcept :
771 _ThisCommonMessage {libObjPtr}
773 BT_ASSERT_DBG(this->isDiscardedEvents());
776 template <typename OtherLibObjT>
777 CommonDiscardedEventsMessage(const CommonDiscardedEventsMessage<OtherLibObjT> val) noexcept :
778 _ThisCommonMessage {val}
782 template <typename OtherLibObjT>
783 CommonDiscardedEventsMessage<LibObjT>&
784 operator=(const CommonDiscardedEventsMessage<OtherLibObjT> val) noexcept
786 _ThisCommonMessage::operator=(val);
790 _Stream stream() const noexcept
793 internal::CommonDiscardedEventsMessageSpec<LibObjT>::stream(this->libObjPtr())};
796 ConstClockSnapshot beginningDefaultClockSnapshot() const noexcept
798 const auto libObjPtr =
799 bt_message_discarded_events_borrow_beginning_default_clock_snapshot_const(
802 return ConstClockSnapshot {libObjPtr};
805 ConstClockSnapshot endDefaultClockSnapshot() const noexcept
807 const auto libObjPtr =
808 bt_message_discarded_events_borrow_end_default_clock_snapshot_const(this->libObjPtr());
810 return ConstClockSnapshot {libObjPtr};
813 void count(const std::uint64_t count) const noexcept
815 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
817 bt_message_discarded_events_set_count(this->libObjPtr(), count);
820 nonstd::optional<std::uint64_t> count() const noexcept
823 const auto avail = bt_message_discarded_events_get_count(this->libObjPtr(), &count);
829 return nonstd::nullopt;
832 Shared shared() const noexcept
834 return Shared::createWithRef(*this);
838 using DiscardedEventsMessage = CommonDiscardedEventsMessage<bt_message>;
839 using ConstDiscardedEventsMessage = CommonDiscardedEventsMessage<const bt_message>;
843 struct DiscardedEventsMessageTypeDescr
845 using Const = ConstDiscardedEventsMessage;
846 using NonConst = DiscardedEventsMessage;
850 struct TypeDescr<DiscardedEventsMessage> : public DiscardedEventsMessageTypeDescr
855 struct TypeDescr<ConstDiscardedEventsMessage> : public DiscardedEventsMessageTypeDescr
859 template <typename LibObjT>
860 struct CommonDiscardedPacketsMessageSpec;
862 /* Functions specific to mutable discarded packets messages */
864 struct CommonDiscardedPacketsMessageSpec<bt_message> final
866 static bt_stream *stream(bt_message * const libObjPtr) noexcept
868 return bt_message_discarded_packets_borrow_stream(libObjPtr);
872 /* Functions specific to constant discarded packets messages */
874 struct CommonDiscardedPacketsMessageSpec<const bt_message> final
876 static const bt_stream *stream(const bt_message * const libObjPtr) noexcept
878 return bt_message_discarded_packets_borrow_stream_const(libObjPtr);
882 } /* namespace internal */
884 template <typename LibObjT>
885 class CommonDiscardedPacketsMessage final : public CommonMessage<LibObjT>
888 using typename CommonMessage<LibObjT>::_LibObjPtr;
889 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
892 typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>,
893 CommonStream<bt_stream>>::type;
896 using Shared = SharedMessage<CommonDiscardedPacketsMessage<LibObjT>, LibObjT>;
898 explicit CommonDiscardedPacketsMessage(const _LibObjPtr libObjPtr) noexcept :
899 _ThisCommonMessage {libObjPtr}
901 BT_ASSERT_DBG(this->isDiscardedPackets());
904 template <typename OtherLibObjT>
905 CommonDiscardedPacketsMessage(const CommonDiscardedPacketsMessage<OtherLibObjT> val) noexcept :
906 _ThisCommonMessage {val}
910 template <typename OtherLibObjT>
911 CommonDiscardedPacketsMessage<LibObjT>&
912 operator=(const CommonDiscardedPacketsMessage<OtherLibObjT> val) noexcept
914 _ThisCommonMessage::operator=(val);
918 _Stream stream() const noexcept
921 internal::CommonDiscardedPacketsMessageSpec<LibObjT>::stream(this->libObjPtr())};
924 ConstClockSnapshot beginningDefaultClockSnapshot() const noexcept
926 const auto libObjPtr =
927 bt_message_discarded_packets_borrow_beginning_default_clock_snapshot_const(
930 return ConstClockSnapshot {libObjPtr};
933 ConstClockSnapshot endDefaultClockSnapshot() const noexcept
935 const auto libObjPtr =
936 bt_message_discarded_packets_borrow_end_default_clock_snapshot_const(this->libObjPtr());
938 return ConstClockSnapshot {libObjPtr};
941 void count(const std::uint64_t count) const noexcept
943 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
945 bt_message_discarded_packets_set_count(this->libObjPtr(), count);
948 nonstd::optional<std::uint64_t> count() const noexcept
951 const auto avail = bt_message_discarded_packets_get_count(this->libObjPtr(), &count);
957 return nonstd::nullopt;
960 Shared shared() const noexcept
962 return Shared::createWithRef(*this);
966 using DiscardedPacketsMessage = CommonDiscardedPacketsMessage<bt_message>;
967 using ConstDiscardedPacketsMessage = CommonDiscardedPacketsMessage<const bt_message>;
971 struct DiscardedPacketsMessageTypeDescr
973 using Const = ConstDiscardedPacketsMessage;
974 using NonConst = DiscardedPacketsMessage;
978 struct TypeDescr<DiscardedPacketsMessage> : public DiscardedPacketsMessageTypeDescr
983 struct TypeDescr<ConstDiscardedPacketsMessage> : public DiscardedPacketsMessageTypeDescr
987 } /* namespace internal */
989 template <typename LibObjT>
990 class CommonMessageIteratorInactivityMessage final : public CommonMessage<LibObjT>
993 using typename CommonMessage<LibObjT>::_LibObjPtr;
994 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
997 using Shared = SharedMessage<CommonMessageIteratorInactivityMessage<LibObjT>, LibObjT>;
999 explicit CommonMessageIteratorInactivityMessage(const _LibObjPtr libObjPtr) noexcept :
1000 _ThisCommonMessage {libObjPtr}
1002 BT_ASSERT_DBG(this->isMessageIteratorInactivity());
1005 template <typename OtherLibObjT>
1006 CommonMessageIteratorInactivityMessage(
1007 const CommonMessageIteratorInactivityMessage<OtherLibObjT> val) noexcept :
1008 _ThisCommonMessage {val}
1012 template <typename OtherLibObjT>
1013 CommonMessageIteratorInactivityMessage<LibObjT>&
1014 operator=(const CommonMessageIteratorInactivityMessage<OtherLibObjT> val) noexcept
1016 _ThisCommonMessage::operator=(val);
1020 ConstClockSnapshot clockSnapshot() const noexcept
1022 const auto libObjPtr =
1023 bt_message_message_iterator_inactivity_borrow_clock_snapshot_const(this->libObjPtr());
1025 return ConstClockSnapshot {libObjPtr};
1028 Shared shared() const noexcept
1030 return Shared::createWithRef(*this);
1034 using MessageIteratorInactivityMessage = CommonMessageIteratorInactivityMessage<bt_message>;
1035 using ConstMessageIteratorInactivityMessage =
1036 CommonMessageIteratorInactivityMessage<const bt_message>;
1038 namespace internal {
1040 struct MessageIteratorInactivityMessageTypeDescr
1042 using Const = ConstMessageIteratorInactivityMessage;
1043 using NonConst = MessageIteratorInactivityMessage;
1047 struct TypeDescr<MessageIteratorInactivityMessage> :
1048 public MessageIteratorInactivityMessageTypeDescr
1053 struct TypeDescr<ConstMessageIteratorInactivityMessage> :
1054 public MessageIteratorInactivityMessageTypeDescr
1058 } /* namespace internal */
1060 template <typename LibObjT>
1061 CommonStreamBeginningMessage<LibObjT> CommonMessage<LibObjT>::asStreamBeginning() const noexcept
1063 BT_ASSERT_DBG(this->isStreamBeginning());
1064 return CommonStreamBeginningMessage<LibObjT> {this->libObjPtr()};
1067 template <typename LibObjT>
1068 CommonStreamEndMessage<LibObjT> CommonMessage<LibObjT>::asStreamEnd() const noexcept
1070 BT_ASSERT_DBG(this->isStreamEnd());
1071 return CommonStreamEndMessage<LibObjT> {this->libObjPtr()};
1074 template <typename LibObjT>
1075 CommonPacketBeginningMessage<LibObjT> CommonMessage<LibObjT>::asPacketBeginning() const noexcept
1077 BT_ASSERT_DBG(this->isPacketBeginning());
1078 return CommonPacketBeginningMessage<LibObjT> {this->libObjPtr()};
1081 template <typename LibObjT>
1082 CommonPacketEndMessage<LibObjT> CommonMessage<LibObjT>::asPacketEnd() const noexcept
1084 BT_ASSERT_DBG(this->isPacketEnd());
1085 return CommonPacketEndMessage<LibObjT> {this->libObjPtr()};
1088 template <typename LibObjT>
1089 CommonEventMessage<LibObjT> CommonMessage<LibObjT>::asEvent() const noexcept
1091 BT_ASSERT_DBG(this->isEvent());
1092 return CommonEventMessage<LibObjT> {this->libObjPtr()};
1095 template <typename LibObjT>
1096 CommonDiscardedEventsMessage<LibObjT> CommonMessage<LibObjT>::asDiscardedEvents() const noexcept
1098 BT_ASSERT_DBG(this->isDiscardedEvents());
1099 return CommonDiscardedEventsMessage<LibObjT> {this->libObjPtr()};
1102 template <typename LibObjT>
1103 CommonDiscardedPacketsMessage<LibObjT> CommonMessage<LibObjT>::asDiscardedPackets() const noexcept
1105 BT_ASSERT_DBG(this->isDiscardedPackets());
1106 return CommonDiscardedPacketsMessage<LibObjT> {this->libObjPtr()};
1109 template <typename LibObjT>
1110 CommonMessageIteratorInactivityMessage<LibObjT>
1111 CommonMessage<LibObjT>::asMessageIteratorInactivity() const noexcept
1113 BT_ASSERT_DBG(this->isMessageIteratorInactivity());
1114 return CommonMessageIteratorInactivityMessage<LibObjT> {this->libObjPtr()};
1117 } /* namespace bt2 */
1119 #endif /* BABELTRACE_CPP_COMMON_BT2_MESSAGE_HPP */