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"
27 struct MessageRefFuncs final
29 static void get(const bt_message * const libObjPtr)
31 bt_message_get_ref(libObjPtr);
34 static void put(const bt_message * const libObjPtr)
36 bt_message_put_ref(libObjPtr);
40 template <typename ObjT, typename LibObjT>
41 using SharedMessage = internal::SharedObj<ObjT, LibObjT, internal::MessageRefFuncs>;
43 } /* namespace internal */
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 internal::BorrowedObj<LibObjT>
85 using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
88 using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
89 using _ThisCommonMessage = CommonMessage<LibObjT>;
92 using Shared = internal::SharedMessage<CommonMessage<LibObjT>, LibObjT>;
94 explicit CommonMessage(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr}
98 template <typename OtherLibObjT>
99 CommonMessage(const CommonMessage<OtherLibObjT>& val) noexcept : _ThisBorrowedObj {val}
103 template <typename OtherLibObjT>
104 _ThisCommonMessage& operator=(const CommonMessage<OtherLibObjT>& val) noexcept
106 _ThisBorrowedObj::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 {*this};
160 CommonStreamBeginningMessage<LibObjT> asStreamBeginning() const noexcept;
161 CommonStreamEndMessage<LibObjT> asStreamEnd() const noexcept;
162 CommonEventMessage<LibObjT> asEvent() const noexcept;
163 CommonPacketBeginningMessage<LibObjT> asPacketBeginning() const noexcept;
164 CommonPacketEndMessage<LibObjT> asPacketEnd() const noexcept;
165 CommonDiscardedEventsMessage<LibObjT> asDiscardedEvents() const noexcept;
166 CommonDiscardedPacketsMessage<LibObjT> asDiscardedPackets() const noexcept;
167 CommonMessageIteratorInactivityMessage<LibObjT> asMessageIteratorInactivity() const noexcept;
170 using Message = CommonMessage<bt_message>;
171 using ConstMessage = CommonMessage<const bt_message>;
175 struct MessageTypeDescr
177 using Const = ConstMessage;
178 using NonConst = Message;
182 struct TypeDescr<Message> : public MessageTypeDescr
187 struct TypeDescr<ConstMessage> : public MessageTypeDescr
191 template <typename LibObjT>
192 struct CommonStreamBeginningMessageSpec;
194 /* Functions specific to mutable stream beginning messages */
196 struct CommonStreamBeginningMessageSpec<bt_message> final
198 static bt_stream *stream(bt_message * const libObjPtr) noexcept
200 return bt_message_stream_beginning_borrow_stream(libObjPtr);
204 /* Functions specific to constant stream beginning messages */
206 struct CommonStreamBeginningMessageSpec<const bt_message> final
208 static const bt_stream *stream(const bt_message * const libObjPtr) noexcept
210 return bt_message_stream_beginning_borrow_stream_const(libObjPtr);
214 } /* namespace internal */
216 template <typename LibObjT>
217 class CommonStreamBeginningMessage final : public CommonMessage<LibObjT>
220 using typename CommonMessage<LibObjT>::_LibObjPtr;
221 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
224 typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>,
225 CommonStream<bt_stream>>::type;
228 using Shared = internal::SharedMessage<CommonStreamBeginningMessage<LibObjT>, LibObjT>;
230 explicit CommonStreamBeginningMessage(const _LibObjPtr libObjPtr) noexcept :
231 _ThisCommonMessage {libObjPtr}
233 BT_ASSERT_DBG(this->isStreamBeginning());
236 template <typename OtherLibObjT>
237 CommonStreamBeginningMessage(const CommonStreamBeginningMessage<OtherLibObjT>& val) noexcept :
238 _ThisCommonMessage {val}
242 template <typename OtherLibObjT>
243 CommonStreamBeginningMessage<LibObjT>&
244 operator=(const CommonStreamBeginningMessage<OtherLibObjT>& val) noexcept
246 _ThisCommonMessage::operator=(val);
250 ConstStream stream() const noexcept
252 return ConstStream {internal::CommonStreamBeginningMessageSpec<const bt_message>::stream(
256 _Stream stream() noexcept
259 internal::CommonStreamBeginningMessageSpec<LibObjT>::stream(this->libObjPtr())};
262 void defaultClockSnapshot(const std::uint64_t val) 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 {*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 = internal::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 ConstStream stream() const noexcept
371 internal::CommonStreamEndMessageSpec<const bt_message>::stream(this->libObjPtr())};
374 _Stream stream() noexcept
376 return _Stream {internal::CommonStreamEndMessageSpec<LibObjT>::stream(this->libObjPtr())};
379 void defaultClockSnapshot(const std::uint64_t val) noexcept
381 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
383 bt_message_stream_end_set_default_clock_snapshot(this->libObjPtr(), val);
386 nonstd::optional<ConstClockSnapshot> defaultClockSnapshot() const noexcept
388 const bt_clock_snapshot *libObjPtr;
389 const auto state = bt_message_stream_end_borrow_default_clock_snapshot_const(
390 this->libObjPtr(), &libObjPtr);
392 if (state == BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN) {
393 return ConstClockSnapshot {libObjPtr};
396 return nonstd::nullopt;
399 Shared shared() const noexcept
401 return Shared {*this};
405 using StreamEndMessage = CommonStreamEndMessage<bt_message>;
406 using ConstStreamEndMessage = CommonStreamEndMessage<const bt_message>;
410 struct StreamEndMessageTypeDescr
412 using Const = ConstStreamEndMessage;
413 using NonConst = StreamEndMessage;
417 struct TypeDescr<StreamEndMessage> : public StreamEndMessageTypeDescr
422 struct TypeDescr<ConstStreamEndMessage> : public StreamEndMessageTypeDescr
426 template <typename LibObjT>
427 struct CommonPacketBeginningMessageSpec;
429 /* Functions specific to mutable packet beginning messages */
431 struct CommonPacketBeginningMessageSpec<bt_message> final
433 static bt_packet *packet(bt_message * const libObjPtr) noexcept
435 return bt_message_packet_beginning_borrow_packet(libObjPtr);
439 /* Functions specific to constant packet beginning messages */
441 struct CommonPacketBeginningMessageSpec<const bt_message> final
443 static const bt_packet *packet(const bt_message * const libObjPtr) noexcept
445 return bt_message_packet_beginning_borrow_packet_const(libObjPtr);
449 } /* namespace internal */
451 template <typename LibObjT>
452 class CommonPacketBeginningMessage final : public CommonMessage<LibObjT>
455 using typename CommonMessage<LibObjT>::_LibObjPtr;
456 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
459 typename std::conditional<std::is_const<LibObjT>::value, CommonPacket<const bt_packet>,
460 CommonPacket<bt_packet>>::type;
463 using Shared = internal::SharedMessage<CommonPacketBeginningMessage<LibObjT>, LibObjT>;
465 explicit CommonPacketBeginningMessage(const _LibObjPtr libObjPtr) noexcept :
466 _ThisCommonMessage {libObjPtr}
468 BT_ASSERT_DBG(this->isPacketBeginning());
471 template <typename OtherLibObjT>
472 CommonPacketBeginningMessage(const CommonPacketBeginningMessage<OtherLibObjT>& val) noexcept :
473 _ThisCommonMessage {val}
477 template <typename OtherLibObjT>
478 CommonPacketBeginningMessage<LibObjT>&
479 operator=(const CommonPacketBeginningMessage<OtherLibObjT>& val) noexcept
481 _ThisCommonMessage::operator=(val);
485 ConstPacket packet() const noexcept
487 return ConstPacket {internal::CommonPacketBeginningMessageSpec<const bt_message>::packet(
491 _Packet packet() noexcept
494 internal::CommonPacketBeginningMessageSpec<LibObjT>::packet(this->libObjPtr())};
497 void defaultClockSnapshot(const std::uint64_t val) noexcept
499 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
501 bt_message_packet_beginning_set_default_clock_snapshot(this->libObjPtr(), val);
504 ConstClockSnapshot defaultClockSnapshot() const noexcept
506 const auto libObjPtr =
507 bt_message_packet_beginning_borrow_default_clock_snapshot_const(this->libObjPtr());
509 return ConstClockSnapshot {libObjPtr};
512 Shared shared() const noexcept
514 return Shared {*this};
518 using PacketBeginningMessage = CommonPacketBeginningMessage<bt_message>;
519 using ConstPacketBeginningMessage = CommonPacketBeginningMessage<const bt_message>;
523 struct PacketBeginningMessageTypeDescr
525 using Const = ConstPacketBeginningMessage;
526 using NonConst = PacketBeginningMessage;
530 struct TypeDescr<PacketBeginningMessage> : public PacketBeginningMessageTypeDescr
535 struct TypeDescr<ConstPacketBeginningMessage> : public PacketBeginningMessageTypeDescr
539 template <typename LibObjT>
540 struct CommonPacketEndMessageSpec;
542 /* Functions specific to mutable packet end messages */
544 struct CommonPacketEndMessageSpec<bt_message> final
546 static bt_packet *packet(bt_message * const libObjPtr) noexcept
548 return bt_message_packet_end_borrow_packet(libObjPtr);
552 /* Functions specific to constant packet end messages */
554 struct CommonPacketEndMessageSpec<const bt_message> final
556 static const bt_packet *packet(const bt_message * const libObjPtr) noexcept
558 return bt_message_packet_end_borrow_packet_const(libObjPtr);
562 } /* namespace internal */
564 template <typename LibObjT>
565 class CommonPacketEndMessage final : public CommonMessage<LibObjT>
568 using typename CommonMessage<LibObjT>::_LibObjPtr;
569 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
572 typename std::conditional<std::is_const<LibObjT>::value, CommonPacket<const bt_packet>,
573 CommonPacket<bt_packet>>::type;
576 using Shared = internal::SharedMessage<CommonPacketEndMessage<LibObjT>, LibObjT>;
578 explicit CommonPacketEndMessage(const _LibObjPtr libObjPtr) noexcept :
579 _ThisCommonMessage {libObjPtr}
581 BT_ASSERT_DBG(this->isPacketEnd());
584 template <typename OtherLibObjT>
585 CommonPacketEndMessage(const CommonPacketEndMessage<OtherLibObjT>& val) noexcept :
586 _ThisCommonMessage {val}
590 template <typename OtherLibObjT>
591 CommonPacketEndMessage<LibObjT>&
592 operator=(const CommonPacketEndMessage<OtherLibObjT>& val) noexcept
594 _ThisCommonMessage::operator=(val);
598 ConstPacket packet() const noexcept
601 internal::CommonPacketEndMessageSpec<const bt_message>::packet(this->libObjPtr())};
604 _Packet packet() noexcept
606 return _Packet {internal::CommonPacketEndMessageSpec<LibObjT>::packet(this->libObjPtr())};
609 void defaultClockSnapshot(const std::uint64_t val) noexcept
611 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
613 bt_message_packet_end_set_default_clock_snapshot(this->libObjPtr(), val);
616 ConstClockSnapshot defaultClockSnapshot() const noexcept
618 const auto libObjPtr =
619 bt_message_packet_end_borrow_default_clock_snapshot_const(this->libObjPtr());
621 return ConstClockSnapshot {libObjPtr};
624 Shared shared() const noexcept
626 return Shared {*this};
630 using PacketEndMessage = CommonPacketEndMessage<bt_message>;
631 using ConstPacketEndMessage = CommonPacketEndMessage<const bt_message>;
635 struct PacketEndMessageTypeDescr
637 using Const = ConstPacketEndMessage;
638 using NonConst = PacketEndMessage;
642 struct TypeDescr<PacketEndMessage> : public PacketEndMessageTypeDescr
647 struct TypeDescr<ConstPacketEndMessage> : public PacketEndMessageTypeDescr
651 template <typename LibObjT>
652 struct CommonEventMessageSpec;
654 /* Functions specific to mutable event messages */
656 struct CommonEventMessageSpec<bt_message> final
658 static bt_event *event(bt_message * const libObjPtr) noexcept
660 return bt_message_event_borrow_event(libObjPtr);
664 /* Functions specific to constant event messages */
666 struct CommonEventMessageSpec<const bt_message> final
668 static const bt_event *event(const bt_message * const libObjPtr) noexcept
670 return bt_message_event_borrow_event_const(libObjPtr);
674 } /* namespace internal */
676 template <typename LibObjT>
677 class CommonEventMessage final : public CommonMessage<LibObjT>
680 using typename CommonMessage<LibObjT>::_LibObjPtr;
681 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
684 typename std::conditional<std::is_const<LibObjT>::value, CommonEvent<const bt_event>,
685 CommonEvent<bt_event>>::type;
688 using Shared = internal::SharedMessage<CommonEventMessage<LibObjT>, LibObjT>;
690 explicit CommonEventMessage(const _LibObjPtr libObjPtr) noexcept :
691 _ThisCommonMessage {libObjPtr}
693 BT_ASSERT_DBG(this->isEvent());
696 template <typename OtherLibObjT>
697 CommonEventMessage(const CommonEventMessage<OtherLibObjT>& val) noexcept :
698 _ThisCommonMessage {val}
702 template <typename OtherLibObjT>
703 CommonEventMessage<LibObjT>& operator=(const CommonEventMessage<OtherLibObjT>& val) noexcept
705 _ThisCommonMessage::operator=(val);
709 ConstEvent event() const noexcept
712 internal::CommonEventMessageSpec<const bt_message>::event(this->libObjPtr())};
715 _Event event() noexcept
717 return _Event {internal::CommonEventMessageSpec<LibObjT>::event(this->libObjPtr())};
720 ConstClockSnapshot defaultClockSnapshot() const noexcept
722 const auto libObjPtr =
723 bt_message_event_borrow_default_clock_snapshot_const(this->libObjPtr());
725 return ConstClockSnapshot {libObjPtr};
728 Shared shared() const noexcept
730 return Shared {*this};
734 using EventMessage = CommonEventMessage<bt_message>;
735 using ConstEventMessage = CommonEventMessage<const bt_message>;
739 struct EventMessageTypeDescr
741 using Const = ConstEventMessage;
742 using NonConst = EventMessage;
746 struct TypeDescr<EventMessage> : public EventMessageTypeDescr
751 struct TypeDescr<ConstEventMessage> : public EventMessageTypeDescr
755 template <typename LibObjT>
756 struct CommonDiscardedEventsMessageSpec;
758 /* Functions specific to mutable discarded events messages */
760 struct CommonDiscardedEventsMessageSpec<bt_message> final
762 static bt_stream *stream(bt_message * const libObjPtr) noexcept
764 return bt_message_discarded_events_borrow_stream(libObjPtr);
768 /* Functions specific to constant discarded events messages */
770 struct CommonDiscardedEventsMessageSpec<const bt_message> final
772 static const bt_stream *stream(const bt_message * const libObjPtr) noexcept
774 return bt_message_discarded_events_borrow_stream_const(libObjPtr);
778 } /* namespace internal */
780 template <typename LibObjT>
781 class CommonDiscardedEventsMessage final : public CommonMessage<LibObjT>
784 using typename CommonMessage<LibObjT>::_LibObjPtr;
785 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
788 typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>,
789 CommonStream<bt_stream>>::type;
792 using Shared = internal::SharedMessage<CommonDiscardedEventsMessage<LibObjT>, LibObjT>;
794 explicit CommonDiscardedEventsMessage(const _LibObjPtr libObjPtr) noexcept :
795 _ThisCommonMessage {libObjPtr}
797 BT_ASSERT_DBG(this->isDiscardedEvents());
800 template <typename OtherLibObjT>
801 CommonDiscardedEventsMessage(const CommonDiscardedEventsMessage<OtherLibObjT>& val) noexcept :
802 _ThisCommonMessage {val}
806 template <typename OtherLibObjT>
807 CommonDiscardedEventsMessage<LibObjT>&
808 operator=(const CommonDiscardedEventsMessage<OtherLibObjT>& val) noexcept
810 _ThisCommonMessage::operator=(val);
814 ConstStream stream() const noexcept
816 return ConstStream {internal::CommonDiscardedEventsMessageSpec<const bt_message>::stream(
820 _Stream stream() noexcept
823 internal::CommonDiscardedEventsMessageSpec<LibObjT>::stream(this->libObjPtr())};
826 ConstClockSnapshot beginningDefaultClockSnapshot() const noexcept
828 const auto libObjPtr =
829 bt_message_discarded_events_borrow_beginning_default_clock_snapshot_const(
832 return ConstClockSnapshot {libObjPtr};
835 ConstClockSnapshot endDefaultClockSnapshot() const noexcept
837 const auto libObjPtr =
838 bt_message_discarded_events_borrow_end_default_clock_snapshot_const(this->libObjPtr());
840 return ConstClockSnapshot {libObjPtr};
843 void count(const std::uint64_t count) noexcept
845 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
847 bt_message_discarded_events_set_count(this->libObjPtr(), count);
850 nonstd::optional<std::uint64_t> count() const noexcept
853 const auto avail = bt_message_discarded_events_get_count(this->libObjPtr(), &count);
859 return nonstd::nullopt;
862 Shared shared() const noexcept
864 return Shared {*this};
868 using DiscardedEventsMessage = CommonDiscardedEventsMessage<bt_message>;
869 using ConstDiscardedEventsMessage = CommonDiscardedEventsMessage<const bt_message>;
873 struct DiscardedEventsMessageTypeDescr
875 using Const = ConstDiscardedEventsMessage;
876 using NonConst = DiscardedEventsMessage;
880 struct TypeDescr<DiscardedEventsMessage> : public DiscardedEventsMessageTypeDescr
885 struct TypeDescr<ConstDiscardedEventsMessage> : public DiscardedEventsMessageTypeDescr
889 template <typename LibObjT>
890 struct CommonDiscardedPacketsMessageSpec;
892 /* Functions specific to mutable discarded packets messages */
894 struct CommonDiscardedPacketsMessageSpec<bt_message> final
896 static bt_stream *stream(bt_message * const libObjPtr) noexcept
898 return bt_message_discarded_packets_borrow_stream(libObjPtr);
902 /* Functions specific to constant discarded packets messages */
904 struct CommonDiscardedPacketsMessageSpec<const bt_message> final
906 static const bt_stream *stream(const bt_message * const libObjPtr) noexcept
908 return bt_message_discarded_packets_borrow_stream_const(libObjPtr);
912 } /* namespace internal */
914 template <typename LibObjT>
915 class CommonDiscardedPacketsMessage final : public CommonMessage<LibObjT>
918 using typename CommonMessage<LibObjT>::_LibObjPtr;
919 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
922 typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>,
923 CommonStream<bt_stream>>::type;
926 using Shared = internal::SharedMessage<CommonDiscardedPacketsMessage<LibObjT>, LibObjT>;
928 explicit CommonDiscardedPacketsMessage(const _LibObjPtr libObjPtr) noexcept :
929 _ThisCommonMessage {libObjPtr}
931 BT_ASSERT_DBG(this->isDiscardedPackets());
934 template <typename OtherLibObjT>
935 CommonDiscardedPacketsMessage(const CommonDiscardedPacketsMessage<OtherLibObjT>& val) noexcept :
936 _ThisCommonMessage {val}
940 template <typename OtherLibObjT>
941 CommonDiscardedPacketsMessage<LibObjT>&
942 operator=(const CommonDiscardedPacketsMessage<OtherLibObjT>& val) noexcept
944 _ThisCommonMessage::operator=(val);
948 ConstStream stream() const noexcept
950 return ConstStream {internal::CommonDiscardedPacketsMessageSpec<const bt_message>::stream(
954 _Stream stream() noexcept
957 internal::CommonDiscardedPacketsMessageSpec<LibObjT>::stream(this->libObjPtr())};
960 ConstClockSnapshot beginningDefaultClockSnapshot() const noexcept
962 const auto libObjPtr =
963 bt_message_discarded_packets_borrow_beginning_default_clock_snapshot_const(
966 return ConstClockSnapshot {libObjPtr};
969 ConstClockSnapshot endDefaultClockSnapshot() const noexcept
971 const auto libObjPtr =
972 bt_message_discarded_packets_borrow_end_default_clock_snapshot_const(this->libObjPtr());
974 return ConstClockSnapshot {libObjPtr};
977 void count(const std::uint64_t count) noexcept
979 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
981 bt_message_discarded_packets_set_count(this->libObjPtr(), count);
984 nonstd::optional<std::uint64_t> count() const noexcept
987 const auto avail = bt_message_discarded_packets_get_count(this->libObjPtr(), &count);
993 return nonstd::nullopt;
996 Shared shared() const noexcept
998 return Shared {*this};
1002 using DiscardedPacketsMessage = CommonDiscardedPacketsMessage<bt_message>;
1003 using ConstDiscardedPacketsMessage = CommonDiscardedPacketsMessage<const bt_message>;
1005 namespace internal {
1007 struct DiscardedPacketsMessageTypeDescr
1009 using Const = ConstDiscardedPacketsMessage;
1010 using NonConst = DiscardedPacketsMessage;
1014 struct TypeDescr<DiscardedPacketsMessage> : public DiscardedPacketsMessageTypeDescr
1019 struct TypeDescr<ConstDiscardedPacketsMessage> : public DiscardedPacketsMessageTypeDescr
1023 } /* namespace internal */
1025 template <typename LibObjT>
1026 class CommonMessageIteratorInactivityMessage final : public CommonMessage<LibObjT>
1029 using typename CommonMessage<LibObjT>::_LibObjPtr;
1030 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
1034 internal::SharedMessage<CommonMessageIteratorInactivityMessage<LibObjT>, LibObjT>;
1036 explicit CommonMessageIteratorInactivityMessage(const _LibObjPtr libObjPtr) noexcept :
1037 _ThisCommonMessage {libObjPtr}
1039 BT_ASSERT_DBG(this->isMessageIteratorInactivity());
1042 template <typename OtherLibObjT>
1043 CommonMessageIteratorInactivityMessage(
1044 const CommonMessageIteratorInactivityMessage<OtherLibObjT>& val) noexcept :
1045 _ThisCommonMessage {val}
1049 template <typename OtherLibObjT>
1050 CommonMessageIteratorInactivityMessage<LibObjT>&
1051 operator=(const CommonMessageIteratorInactivityMessage<OtherLibObjT>& val) noexcept
1053 _ThisCommonMessage::operator=(val);
1057 ConstClockSnapshot clockSnapshot() const noexcept
1059 const auto libObjPtr =
1060 bt_message_message_iterator_inactivity_borrow_clock_snapshot_const(this->libObjPtr());
1062 return ConstClockSnapshot {libObjPtr};
1065 Shared shared() const noexcept
1067 return Shared {*this};
1071 using MessageIteratorInactivityMessage = CommonMessageIteratorInactivityMessage<bt_message>;
1072 using ConstMessageIteratorInactivityMessage =
1073 CommonMessageIteratorInactivityMessage<const bt_message>;
1075 namespace internal {
1077 struct MessageIteratorInactivityMessageTypeDescr
1079 using Const = ConstMessageIteratorInactivityMessage;
1080 using NonConst = MessageIteratorInactivityMessage;
1084 struct TypeDescr<MessageIteratorInactivityMessage> :
1085 public MessageIteratorInactivityMessageTypeDescr
1090 struct TypeDescr<ConstMessageIteratorInactivityMessage> :
1091 public MessageIteratorInactivityMessageTypeDescr
1095 } /* namespace internal */
1097 template <typename LibObjT>
1098 CommonStreamBeginningMessage<LibObjT> CommonMessage<LibObjT>::asStreamBeginning() const noexcept
1100 BT_ASSERT_DBG(this->isStreamBeginning());
1101 return CommonStreamBeginningMessage<LibObjT> {this->libObjPtr()};
1104 template <typename LibObjT>
1105 CommonStreamEndMessage<LibObjT> CommonMessage<LibObjT>::asStreamEnd() const noexcept
1107 BT_ASSERT_DBG(this->isStreamEnd());
1108 return CommonStreamEndMessage<LibObjT> {this->libObjPtr()};
1111 template <typename LibObjT>
1112 CommonPacketBeginningMessage<LibObjT> CommonMessage<LibObjT>::asPacketBeginning() const noexcept
1114 BT_ASSERT_DBG(this->isPacketBeginning());
1115 return CommonPacketBeginningMessage<LibObjT> {this->libObjPtr()};
1118 template <typename LibObjT>
1119 CommonPacketEndMessage<LibObjT> CommonMessage<LibObjT>::asPacketEnd() const noexcept
1121 BT_ASSERT_DBG(this->isPacketEnd());
1122 return CommonPacketEndMessage<LibObjT> {this->libObjPtr()};
1125 template <typename LibObjT>
1126 CommonEventMessage<LibObjT> CommonMessage<LibObjT>::asEvent() const noexcept
1128 BT_ASSERT_DBG(this->isEvent());
1129 return CommonEventMessage<LibObjT> {this->libObjPtr()};
1132 template <typename LibObjT>
1133 CommonDiscardedEventsMessage<LibObjT> CommonMessage<LibObjT>::asDiscardedEvents() const noexcept
1135 BT_ASSERT_DBG(this->isDiscardedEvents());
1136 return CommonDiscardedEventsMessage<LibObjT> {this->libObjPtr()};
1139 template <typename LibObjT>
1140 CommonMessageIteratorInactivityMessage<LibObjT>
1141 CommonMessage<LibObjT>::asMessageIteratorInactivity() const noexcept
1143 BT_ASSERT_DBG(this->isMessageIteratorInactivity());
1144 return CommonMessageIteratorInactivityMessage<LibObjT> {this->libObjPtr()};
1147 } /* namespace bt2 */
1149 #endif /* BABELTRACE_CPP_COMMON_BT2_MESSAGE_HPP */