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/optional.hpp"
21 #include "cpp-common/string_view.hpp"
22 #include "lib-error.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 {*this};
161 CommonStreamBeginningMessage<LibObjT> asStreamBeginning() const noexcept;
162 CommonStreamEndMessage<LibObjT> asStreamEnd() const noexcept;
163 CommonEventMessage<LibObjT> asEvent() const noexcept;
164 CommonPacketBeginningMessage<LibObjT> asPacketBeginning() const noexcept;
165 CommonPacketEndMessage<LibObjT> asPacketEnd() const noexcept;
166 CommonDiscardedEventsMessage<LibObjT> asDiscardedEvents() const noexcept;
167 CommonDiscardedPacketsMessage<LibObjT> asDiscardedPackets() const noexcept;
168 CommonMessageIteratorInactivityMessage<LibObjT> asMessageIteratorInactivity() const noexcept;
171 using Message = CommonMessage<bt_message>;
172 using ConstMessage = CommonMessage<const bt_message>;
176 template <typename LibObjT>
177 struct CommonStreamBeginningMessageSpec;
179 // Functions specific to mutable stream beginning messages
181 struct CommonStreamBeginningMessageSpec<bt_message> final
183 static bt_stream *stream(bt_message * const libObjPtr) noexcept
185 return bt_message_stream_beginning_borrow_stream(libObjPtr);
189 // Functions specific to constant stream beginning messages
191 struct CommonStreamBeginningMessageSpec<const bt_message> final
193 static const bt_stream *stream(const bt_message * const libObjPtr) noexcept
195 return bt_message_stream_beginning_borrow_stream_const(libObjPtr);
199 } // namespace internal
201 template <typename LibObjT>
202 class CommonStreamBeginningMessage final : public CommonMessage<LibObjT>
205 using typename CommonMessage<LibObjT>::_LibObjPtr;
206 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
209 typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>,
210 CommonStream<bt_stream>>::type;
213 using Shared = internal::SharedMessage<CommonStreamBeginningMessage<LibObjT>, LibObjT>;
215 explicit CommonStreamBeginningMessage(const _LibObjPtr libObjPtr) noexcept :
216 _ThisCommonMessage {libObjPtr}
218 BT_ASSERT_DBG(this->isStreamBeginning());
221 template <typename OtherLibObjT>
222 CommonStreamBeginningMessage(const CommonStreamBeginningMessage<OtherLibObjT>& val) noexcept :
223 _ThisCommonMessage {val}
227 template <typename OtherLibObjT>
228 CommonStreamBeginningMessage<LibObjT>&
229 operator=(const CommonStreamBeginningMessage<OtherLibObjT>& val) noexcept
231 _ThisCommonMessage::operator=(val);
235 ConstStream stream() const noexcept
237 return ConstStream {internal::CommonStreamBeginningMessageSpec<const bt_message>::stream(
238 this->_libObjPtr())};
241 _Stream stream() noexcept
244 internal::CommonStreamBeginningMessageSpec<LibObjT>::stream(this->_libObjPtr())};
247 void defaultClockSnapshot(const std::uint64_t val) noexcept
249 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
251 bt_message_stream_beginning_set_default_clock_snapshot(this->_libObjPtr(), val);
254 nonstd::optional<ConstClockSnapshot> defaultClockSnapshot() const noexcept
256 const bt_clock_snapshot *libObjPtr;
257 const auto state = bt_message_stream_beginning_borrow_default_clock_snapshot_const(
258 this->_libObjPtr(), &libObjPtr);
260 if (state == BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN) {
261 return ConstClockSnapshot {libObjPtr};
264 return nonstd::nullopt;
267 Shared shared() const noexcept
269 return Shared {*this};
273 using StreamBeginningMessage = CommonStreamBeginningMessage<bt_message>;
274 using ConstStreamBeginningMessage = CommonStreamBeginningMessage<const bt_message>;
278 template <typename LibObjT>
279 struct CommonStreamEndMessageSpec;
281 // Functions specific to mutable stream end messages
283 struct CommonStreamEndMessageSpec<bt_message> final
285 static bt_stream *stream(bt_message * const libObjPtr) noexcept
287 return bt_message_stream_end_borrow_stream(libObjPtr);
291 // Functions specific to constant stream end messages
293 struct CommonStreamEndMessageSpec<const bt_message> final
295 static const bt_stream *stream(const bt_message * const libObjPtr) noexcept
297 return bt_message_stream_end_borrow_stream_const(libObjPtr);
301 } // namespace internal
303 template <typename LibObjT>
304 class CommonStreamEndMessage final : public CommonMessage<LibObjT>
307 using typename CommonMessage<LibObjT>::_LibObjPtr;
308 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
311 typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>,
312 CommonStream<bt_stream>>::type;
315 using Shared = internal::SharedMessage<CommonStreamEndMessage<LibObjT>, LibObjT>;
317 explicit CommonStreamEndMessage(const _LibObjPtr libObjPtr) noexcept :
318 _ThisCommonMessage {libObjPtr}
320 BT_ASSERT_DBG(this->isStreamEnd());
323 template <typename OtherLibObjT>
324 CommonStreamEndMessage(const CommonStreamEndMessage<OtherLibObjT>& val) noexcept :
325 _ThisCommonMessage {val}
329 template <typename OtherLibObjT>
330 CommonStreamEndMessage<LibObjT>&
331 operator=(const CommonStreamEndMessage<OtherLibObjT>& val) noexcept
333 _ThisCommonMessage::operator=(val);
337 ConstStream stream() const noexcept
340 internal::CommonStreamEndMessageSpec<const bt_message>::stream(this->_libObjPtr())};
343 _Stream stream() noexcept
345 return _Stream {internal::CommonStreamEndMessageSpec<LibObjT>::stream(this->_libObjPtr())};
348 void defaultClockSnapshot(const std::uint64_t val) noexcept
350 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
352 bt_message_stream_end_set_default_clock_snapshot(this->_libObjPtr(), val);
355 nonstd::optional<ConstClockSnapshot> defaultClockSnapshot() const noexcept
357 const bt_clock_snapshot *libObjPtr;
358 const auto state = bt_message_stream_end_borrow_default_clock_snapshot_const(
359 this->_libObjPtr(), &libObjPtr);
361 if (state == BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN) {
362 return ConstClockSnapshot {libObjPtr};
365 return nonstd::nullopt;
368 Shared shared() const noexcept
370 return Shared {*this};
374 using StreamEndMessage = CommonStreamEndMessage<bt_message>;
375 using ConstStreamEndMessage = CommonStreamEndMessage<const bt_message>;
379 template <typename LibObjT>
380 struct CommonPacketBeginningMessageSpec;
382 // Functions specific to mutable packet beginning messages
384 struct CommonPacketBeginningMessageSpec<bt_message> final
386 static bt_packet *packet(bt_message * const libObjPtr) noexcept
388 return bt_message_packet_beginning_borrow_packet(libObjPtr);
392 // Functions specific to constant packet beginning messages
394 struct CommonPacketBeginningMessageSpec<const bt_message> final
396 static const bt_packet *packet(const bt_message * const libObjPtr) noexcept
398 return bt_message_packet_beginning_borrow_packet_const(libObjPtr);
402 } // namespace internal
404 template <typename LibObjT>
405 class CommonPacketBeginningMessage final : public CommonMessage<LibObjT>
408 using typename CommonMessage<LibObjT>::_LibObjPtr;
409 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
412 typename std::conditional<std::is_const<LibObjT>::value, CommonPacket<const bt_packet>,
413 CommonPacket<bt_packet>>::type;
416 using Shared = internal::SharedMessage<CommonPacketBeginningMessage<LibObjT>, LibObjT>;
418 explicit CommonPacketBeginningMessage(const _LibObjPtr libObjPtr) noexcept :
419 _ThisCommonMessage {libObjPtr}
421 BT_ASSERT_DBG(this->isPacketBeginning());
424 template <typename OtherLibObjT>
425 CommonPacketBeginningMessage(const CommonPacketBeginningMessage<OtherLibObjT>& val) noexcept :
426 _ThisCommonMessage {val}
430 template <typename OtherLibObjT>
431 CommonPacketBeginningMessage<LibObjT>&
432 operator=(const CommonPacketBeginningMessage<OtherLibObjT>& val) noexcept
434 _ThisCommonMessage::operator=(val);
438 ConstPacket packet() const noexcept
440 return ConstPacket {internal::CommonPacketBeginningMessageSpec<const bt_message>::packet(
441 this->_libObjPtr())};
444 _Packet packet() noexcept
447 internal::CommonPacketBeginningMessageSpec<LibObjT>::packet(this->_libObjPtr())};
450 void defaultClockSnapshot(const std::uint64_t val) noexcept
452 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
454 bt_message_packet_beginning_set_default_clock_snapshot(this->_libObjPtr(), val);
457 ConstClockSnapshot defaultClockSnapshot() const noexcept
459 const auto libObjPtr =
460 bt_message_packet_beginning_borrow_default_clock_snapshot_const(this->_libObjPtr());
462 return ConstClockSnapshot {libObjPtr};
465 Shared shared() const noexcept
467 return Shared {*this};
471 using PacketBeginningMessage = CommonPacketBeginningMessage<bt_message>;
472 using ConstPacketBeginningMessage = CommonPacketBeginningMessage<const bt_message>;
476 template <typename LibObjT>
477 struct CommonPacketEndMessageSpec;
479 // Functions specific to mutable packet end messages
481 struct CommonPacketEndMessageSpec<bt_message> final
483 static bt_packet *packet(bt_message * const libObjPtr) noexcept
485 return bt_message_packet_end_borrow_packet(libObjPtr);
489 // Functions specific to constant packet end messages
491 struct CommonPacketEndMessageSpec<const bt_message> final
493 static const bt_packet *packet(const bt_message * const libObjPtr) noexcept
495 return bt_message_packet_end_borrow_packet_const(libObjPtr);
499 } // namespace internal
501 template <typename LibObjT>
502 class CommonPacketEndMessage final : public CommonMessage<LibObjT>
505 using typename CommonMessage<LibObjT>::_LibObjPtr;
506 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
509 typename std::conditional<std::is_const<LibObjT>::value, CommonPacket<const bt_packet>,
510 CommonPacket<bt_packet>>::type;
513 using Shared = internal::SharedMessage<CommonPacketEndMessage<LibObjT>, LibObjT>;
515 explicit CommonPacketEndMessage(const _LibObjPtr libObjPtr) noexcept :
516 _ThisCommonMessage {libObjPtr}
518 BT_ASSERT_DBG(this->isPacketEnd());
521 template <typename OtherLibObjT>
522 CommonPacketEndMessage(const CommonPacketEndMessage<OtherLibObjT>& val) noexcept :
523 _ThisCommonMessage {val}
527 template <typename OtherLibObjT>
528 CommonPacketEndMessage<LibObjT>&
529 operator=(const CommonPacketEndMessage<OtherLibObjT>& val) noexcept
531 _ThisCommonMessage::operator=(val);
535 ConstPacket packet() const noexcept
538 internal::CommonPacketEndMessageSpec<const bt_message>::packet(this->_libObjPtr())};
541 _Packet packet() noexcept
543 return _Packet {internal::CommonPacketEndMessageSpec<LibObjT>::packet(this->_libObjPtr())};
546 void defaultClockSnapshot(const std::uint64_t val) noexcept
548 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
550 bt_message_packet_end_set_default_clock_snapshot(this->_libObjPtr(), val);
553 ConstClockSnapshot defaultClockSnapshot() const noexcept
555 const auto libObjPtr =
556 bt_message_packet_end_borrow_default_clock_snapshot_const(this->_libObjPtr());
558 return ConstClockSnapshot {libObjPtr};
561 Shared shared() const noexcept
563 return Shared {*this};
567 using PacketEndMessage = CommonPacketEndMessage<bt_message>;
568 using ConstPacketEndMessage = CommonPacketEndMessage<const bt_message>;
572 template <typename LibObjT>
573 struct CommonEventMessageSpec;
575 // Functions specific to mutable event messages
577 struct CommonEventMessageSpec<bt_message> final
579 static bt_event *event(bt_message * const libObjPtr) noexcept
581 return bt_message_event_borrow_event(libObjPtr);
585 // Functions specific to constant event messages
587 struct CommonEventMessageSpec<const bt_message> final
589 static const bt_event *event(const bt_message * const libObjPtr) noexcept
591 return bt_message_event_borrow_event_const(libObjPtr);
595 } // namespace internal
597 template <typename LibObjT>
598 class CommonEventMessage final : public CommonMessage<LibObjT>
601 using typename CommonMessage<LibObjT>::_LibObjPtr;
602 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
605 typename std::conditional<std::is_const<LibObjT>::value, CommonEvent<const bt_event>,
606 CommonEvent<bt_event>>::type;
609 using Shared = internal::SharedMessage<CommonEventMessage<LibObjT>, LibObjT>;
611 explicit CommonEventMessage(const _LibObjPtr libObjPtr) noexcept :
612 _ThisCommonMessage {libObjPtr}
614 BT_ASSERT_DBG(this->isEvent());
617 template <typename OtherLibObjT>
618 CommonEventMessage(const CommonEventMessage<OtherLibObjT>& val) noexcept :
619 _ThisCommonMessage {val}
623 template <typename OtherLibObjT>
624 CommonEventMessage<LibObjT>& operator=(const CommonEventMessage<OtherLibObjT>& val) noexcept
626 _ThisCommonMessage::operator=(val);
630 ConstEvent event() const noexcept
633 internal::CommonEventMessageSpec<const bt_message>::event(this->_libObjPtr())};
636 _Event event() noexcept
638 return _Event {internal::CommonEventMessageSpec<LibObjT>::event(this->_libObjPtr())};
641 ConstClockSnapshot defaultClockSnapshot() const noexcept
643 const auto libObjPtr =
644 bt_message_event_borrow_default_clock_snapshot_const(this->_libObjPtr());
646 return ConstClockSnapshot {libObjPtr};
649 Shared shared() const noexcept
651 return Shared {*this};
655 using EventMessage = CommonEventMessage<bt_message>;
656 using ConstEventMessage = CommonEventMessage<const bt_message>;
660 template <typename LibObjT>
661 struct CommonDiscardedEventsMessageSpec;
663 // Functions specific to mutable discarded events messages
665 struct CommonDiscardedEventsMessageSpec<bt_message> final
667 static bt_stream *stream(bt_message * const libObjPtr) noexcept
669 return bt_message_discarded_events_borrow_stream(libObjPtr);
673 // Functions specific to constant discarded events messages
675 struct CommonDiscardedEventsMessageSpec<const bt_message> final
677 static const bt_stream *stream(const bt_message * const libObjPtr) noexcept
679 return bt_message_discarded_events_borrow_stream_const(libObjPtr);
683 } // namespace internal
685 template <typename LibObjT>
686 class CommonDiscardedEventsMessage 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, CommonStream<const bt_stream>,
694 CommonStream<bt_stream>>::type;
697 using Shared = internal::SharedMessage<CommonDiscardedEventsMessage<LibObjT>, LibObjT>;
699 explicit CommonDiscardedEventsMessage(const _LibObjPtr libObjPtr) noexcept :
700 _ThisCommonMessage {libObjPtr}
702 BT_ASSERT_DBG(this->isDiscardedEvents());
705 template <typename OtherLibObjT>
706 CommonDiscardedEventsMessage(const CommonDiscardedEventsMessage<OtherLibObjT>& val) noexcept :
707 _ThisCommonMessage {val}
711 template <typename OtherLibObjT>
712 CommonDiscardedEventsMessage<LibObjT>&
713 operator=(const CommonDiscardedEventsMessage<OtherLibObjT>& val) noexcept
715 _ThisCommonMessage::operator=(val);
719 ConstStream stream() const noexcept
721 return ConstStream {internal::CommonDiscardedEventsMessageSpec<const bt_message>::stream(
722 this->_libObjPtr())};
725 _Stream stream() noexcept
728 internal::CommonDiscardedEventsMessageSpec<LibObjT>::stream(this->_libObjPtr())};
731 ConstClockSnapshot beginningDefaultClockSnapshot() const noexcept
733 const auto libObjPtr =
734 bt_message_discarded_events_borrow_beginning_default_clock_snapshot_const(
737 return ConstClockSnapshot {libObjPtr};
740 ConstClockSnapshot endDefaultClockSnapshot() const noexcept
742 const auto libObjPtr =
743 bt_message_discarded_events_borrow_end_default_clock_snapshot_const(this->_libObjPtr());
745 return ConstClockSnapshot {libObjPtr};
748 void count(const std::uint64_t count) noexcept
750 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
752 bt_message_discarded_events_set_count(this->_libObjPtr(), count);
755 nonstd::optional<std::uint64_t> count() const noexcept
758 const auto avail = bt_message_discarded_events_get_count(this->_libObjPtr(), &count);
764 return nonstd::nullopt;
767 Shared shared() const noexcept
769 return Shared {*this};
773 using DiscardedEventsMessage = CommonDiscardedEventsMessage<bt_message>;
774 using ConstDiscardedEventsMessage = CommonDiscardedEventsMessage<const bt_message>;
778 template <typename LibObjT>
779 struct CommonDiscardedPacketsMessageSpec;
781 // Functions specific to mutable discarded packets messages
783 struct CommonDiscardedPacketsMessageSpec<bt_message> final
785 static bt_stream *stream(bt_message * const libObjPtr) noexcept
787 return bt_message_discarded_packets_borrow_stream(libObjPtr);
791 // Functions specific to constant discarded packets messages
793 struct CommonDiscardedPacketsMessageSpec<const bt_message> final
795 static const bt_stream *stream(const bt_message * const libObjPtr) noexcept
797 return bt_message_discarded_packets_borrow_stream_const(libObjPtr);
801 } // namespace internal
803 template <typename LibObjT>
804 class CommonDiscardedPacketsMessage final : public CommonMessage<LibObjT>
807 using typename CommonMessage<LibObjT>::_LibObjPtr;
808 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
811 typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>,
812 CommonStream<bt_stream>>::type;
815 using Shared = internal::SharedMessage<CommonDiscardedPacketsMessage<LibObjT>, LibObjT>;
817 explicit CommonDiscardedPacketsMessage(const _LibObjPtr libObjPtr) noexcept :
818 _ThisCommonMessage {libObjPtr}
820 BT_ASSERT_DBG(this->isDiscardedPackets());
823 template <typename OtherLibObjT>
824 CommonDiscardedPacketsMessage(const CommonDiscardedPacketsMessage<OtherLibObjT>& val) noexcept :
825 _ThisCommonMessage {val}
829 template <typename OtherLibObjT>
830 CommonDiscardedPacketsMessage<LibObjT>&
831 operator=(const CommonDiscardedPacketsMessage<OtherLibObjT>& val) noexcept
833 _ThisCommonMessage::operator=(val);
837 ConstStream stream() const noexcept
839 return ConstStream {internal::CommonDiscardedPacketsMessageSpec<const bt_message>::stream(
840 this->_libObjPtr())};
843 _Stream stream() noexcept
846 internal::CommonDiscardedPacketsMessageSpec<LibObjT>::stream(this->_libObjPtr())};
849 ConstClockSnapshot beginningDefaultClockSnapshot() const noexcept
851 const auto libObjPtr =
852 bt_message_discarded_packets_borrow_beginning_default_clock_snapshot_const(
855 return ConstClockSnapshot {libObjPtr};
858 ConstClockSnapshot endDefaultClockSnapshot() const noexcept
860 const auto libObjPtr = bt_message_discarded_packets_borrow_end_default_clock_snapshot_const(
863 return ConstClockSnapshot {libObjPtr};
866 void count(const std::uint64_t count) noexcept
868 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
870 bt_message_discarded_packets_set_count(this->_libObjPtr(), count);
873 nonstd::optional<std::uint64_t> count() const noexcept
876 const auto avail = bt_message_discarded_packets_get_count(this->_libObjPtr(), &count);
882 return nonstd::nullopt;
885 Shared shared() const noexcept
887 return Shared {*this};
891 using DiscardedPacketsMessage = CommonDiscardedPacketsMessage<bt_message>;
892 using ConstDiscardedPacketsMessage = CommonDiscardedPacketsMessage<const bt_message>;
894 template <typename LibObjT>
895 class CommonMessageIteratorInactivityMessage final : public CommonMessage<LibObjT>
898 using typename CommonMessage<LibObjT>::_LibObjPtr;
899 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
903 internal::SharedMessage<CommonMessageIteratorInactivityMessage<LibObjT>, LibObjT>;
905 explicit CommonMessageIteratorInactivityMessage(const _LibObjPtr libObjPtr) noexcept :
906 _ThisCommonMessage {libObjPtr}
908 BT_ASSERT_DBG(this->isMessageIteratorInactivity());
911 template <typename OtherLibObjT>
912 CommonMessageIteratorInactivityMessage(
913 const CommonMessageIteratorInactivityMessage<OtherLibObjT>& val) noexcept :
914 _ThisCommonMessage {val}
918 template <typename OtherLibObjT>
919 CommonMessageIteratorInactivityMessage<LibObjT>&
920 operator=(const CommonMessageIteratorInactivityMessage<OtherLibObjT>& val) noexcept
922 _ThisCommonMessage::operator=(val);
926 ConstClockSnapshot clockSnapshot() const noexcept
928 const auto libObjPtr =
929 bt_message_message_iterator_inactivity_borrow_clock_snapshot_const(this->_libObjPtr());
931 return ConstClockSnapshot {libObjPtr};
934 Shared shared() const noexcept
936 return Shared {*this};
940 using MessageIteratorInactivityMessage = CommonMessageIteratorInactivityMessage<bt_message>;
941 using ConstMessageIteratorInactivityMessage =
942 CommonMessageIteratorInactivityMessage<const bt_message>;
944 template <typename LibObjT>
945 CommonStreamBeginningMessage<LibObjT> CommonMessage<LibObjT>::asStreamBeginning() const noexcept
947 BT_ASSERT_DBG(this->isStreamBeginning());
948 return CommonStreamBeginningMessage<LibObjT> {this->_libObjPtr()};
951 template <typename LibObjT>
952 CommonStreamEndMessage<LibObjT> CommonMessage<LibObjT>::asStreamEnd() const noexcept
954 BT_ASSERT_DBG(this->isStreamEnd());
955 return CommonStreamEndMessage<LibObjT> {this->_libObjPtr()};
958 template <typename LibObjT>
959 CommonPacketBeginningMessage<LibObjT> CommonMessage<LibObjT>::asPacketBeginning() const noexcept
961 BT_ASSERT_DBG(this->isPacketBeginning());
962 return CommonPacketBeginningMessage<LibObjT> {this->_libObjPtr()};
965 template <typename LibObjT>
966 CommonPacketEndMessage<LibObjT> CommonMessage<LibObjT>::asPacketEnd() const noexcept
968 BT_ASSERT_DBG(this->isPacketEnd());
969 return CommonPacketEndMessage<LibObjT> {this->_libObjPtr()};
972 template <typename LibObjT>
973 CommonEventMessage<LibObjT> CommonMessage<LibObjT>::asEvent() const noexcept
975 BT_ASSERT_DBG(this->isEvent());
976 return CommonEventMessage<LibObjT> {this->_libObjPtr()};
979 template <typename LibObjT>
980 CommonDiscardedEventsMessage<LibObjT> CommonMessage<LibObjT>::asDiscardedEvents() const noexcept
982 BT_ASSERT_DBG(this->isDiscardedEvents());
983 return CommonDiscardedEventsMessage<LibObjT> {this->_libObjPtr()};
986 template <typename LibObjT>
987 CommonMessageIteratorInactivityMessage<LibObjT>
988 CommonMessage<LibObjT>::asMessageIteratorInactivity() const noexcept
990 BT_ASSERT_DBG(this->isMessageIteratorInactivity());
991 return CommonMessageIteratorInactivityMessage<LibObjT> {this->_libObjPtr()};
996 #endif // BABELTRACE_CPP_COMMON_BT2_MESSAGE_HPP