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/bt2s/optional.hpp"
20 #include "borrowed-object.hpp"
21 #include "internal/utils.hpp"
22 #include "optional-borrowed-object.hpp"
23 #include "shared-object.hpp"
24 #include "trace-ir.hpp"
29 struct MessageRefFuncs final
31 static void get(const bt_message * const libObjPtr) noexcept
33 bt_message_get_ref(libObjPtr);
36 static void put(const bt_message * const libObjPtr) noexcept
38 bt_message_put_ref(libObjPtr);
42 } /* namespace internal */
44 template <typename ObjT, typename LibObjT>
45 using SharedMessage = SharedObject<ObjT, LibObjT, internal::MessageRefFuncs>;
47 template <typename LibObjT>
48 class CommonStreamBeginningMessage;
50 template <typename LibObjT>
51 class CommonStreamEndMessage;
53 template <typename LibObjT>
54 class CommonEventMessage;
56 template <typename LibObjT>
57 class CommonPacketBeginningMessage;
59 template <typename LibObjT>
60 class CommonPacketEndMessage;
62 template <typename LibObjT>
63 class CommonDiscardedEventsMessage;
65 template <typename LibObjT>
66 class CommonDiscardedPacketsMessage;
68 template <typename LibObjT>
69 class CommonMessageIteratorInactivityMessage;
71 enum class MessageType
73 STREAM_BEGINNING = BT_MESSAGE_TYPE_STREAM_BEGINNING,
74 STREAM_END = BT_MESSAGE_TYPE_STREAM_END,
75 EVENT = BT_MESSAGE_TYPE_EVENT,
76 PACKET_BEGINNING = BT_MESSAGE_TYPE_PACKET_BEGINNING,
77 PACKET_END = BT_MESSAGE_TYPE_PACKET_END,
78 DISCARDED_EVENTS = BT_MESSAGE_TYPE_DISCARDED_EVENTS,
79 DISCARDED_PACKETS = BT_MESSAGE_TYPE_DISCARDED_PACKETS,
80 MESSAGE_ITERATOR_INACTIVITY = BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY,
83 template <typename LibObjT>
84 class CommonMessage : public BorrowedObject<LibObjT>
87 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
90 using _ThisCommonMessage = CommonMessage<LibObjT>;
93 using typename BorrowedObject<LibObjT>::LibObjPtr;
94 using Shared = SharedMessage<CommonMessage<LibObjT>, LibObjT>;
96 explicit CommonMessage(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
100 template <typename OtherLibObjT>
101 CommonMessage(const CommonMessage<OtherLibObjT> val) noexcept : _ThisBorrowedObject {val}
105 template <typename OtherLibObjT>
106 _ThisCommonMessage operator=(const CommonMessage<OtherLibObjT> val) noexcept
108 _ThisBorrowedObject::operator=(val);
112 CommonMessage<const bt_message> asConst() const noexcept
114 return CommonMessage<const bt_message> {*this};
117 MessageType type() const noexcept
119 return static_cast<MessageType>(bt_message_get_type(this->libObjPtr()));
122 bool isStreamBeginning() const noexcept
124 return this->type() == MessageType::STREAM_BEGINNING;
127 bool isStreamEnd() const noexcept
129 return this->type() == MessageType::STREAM_END;
132 bool isEvent() const noexcept
134 return this->type() == MessageType::EVENT;
137 bool isPacketBeginning() const noexcept
139 return this->type() == MessageType::PACKET_BEGINNING;
142 bool isPacketEnd() const noexcept
144 return this->type() == MessageType::PACKET_END;
147 bool isDiscardedEvents() const noexcept
149 return this->type() == MessageType::DISCARDED_EVENTS;
152 bool isDiscardedPackets() const noexcept
154 return this->type() == MessageType::DISCARDED_PACKETS;
157 bool isMessageIteratorInactivity() const noexcept
159 return this->type() == MessageType::MESSAGE_ITERATOR_INACTIVITY;
162 Shared shared() const noexcept
164 return Shared::createWithRef(*this);
167 template <typename MessageT>
168 MessageT as() const noexcept
170 return MessageT {this->libObjPtr()};
173 CommonStreamBeginningMessage<LibObjT> asStreamBeginning() const noexcept;
174 CommonStreamEndMessage<LibObjT> asStreamEnd() const noexcept;
175 CommonEventMessage<LibObjT> asEvent() const noexcept;
176 CommonPacketBeginningMessage<LibObjT> asPacketBeginning() const noexcept;
177 CommonPacketEndMessage<LibObjT> asPacketEnd() const noexcept;
178 CommonDiscardedEventsMessage<LibObjT> asDiscardedEvents() const noexcept;
179 CommonDiscardedPacketsMessage<LibObjT> asDiscardedPackets() const noexcept;
180 CommonMessageIteratorInactivityMessage<LibObjT> asMessageIteratorInactivity() const noexcept;
183 using Message = CommonMessage<bt_message>;
184 using ConstMessage = CommonMessage<const bt_message>;
188 struct MessageTypeDescr
190 using Const = ConstMessage;
191 using NonConst = Message;
195 struct TypeDescr<Message> : public MessageTypeDescr
200 struct TypeDescr<ConstMessage> : public MessageTypeDescr
204 template <typename LibObjT>
205 struct CommonStreamBeginningMessageSpec;
207 /* Functions specific to mutable stream beginning messages */
209 struct CommonStreamBeginningMessageSpec<bt_message> final
211 static bt_stream *stream(bt_message * const libObjPtr) noexcept
213 return bt_message_stream_beginning_borrow_stream(libObjPtr);
217 /* Functions specific to constant stream beginning messages */
219 struct CommonStreamBeginningMessageSpec<const bt_message> final
221 static const bt_stream *stream(const bt_message * const libObjPtr) noexcept
223 return bt_message_stream_beginning_borrow_stream_const(libObjPtr);
227 } /* namespace internal */
229 template <typename LibObjT>
230 class CommonStreamBeginningMessage final : public CommonMessage<LibObjT>
233 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
234 using _Stream = internal::DepStream<LibObjT>;
237 using typename CommonMessage<LibObjT>::LibObjPtr;
238 using Shared = SharedMessage<CommonStreamBeginningMessage<LibObjT>, LibObjT>;
240 explicit CommonStreamBeginningMessage(const LibObjPtr libObjPtr) noexcept :
241 _ThisCommonMessage {libObjPtr}
243 BT_ASSERT_DBG(this->isStreamBeginning());
246 template <typename OtherLibObjT>
247 CommonStreamBeginningMessage(const CommonStreamBeginningMessage<OtherLibObjT> val) noexcept :
248 _ThisCommonMessage {val}
252 template <typename OtherLibObjT>
253 CommonStreamBeginningMessage<LibObjT>
254 operator=(const CommonStreamBeginningMessage<OtherLibObjT> val) noexcept
256 _ThisCommonMessage::operator=(val);
260 CommonStreamBeginningMessage<const bt_message> asConst() const noexcept
262 return CommonStreamBeginningMessage<const bt_message> {*this};
265 _Stream stream() const noexcept
268 internal::CommonStreamBeginningMessageSpec<LibObjT>::stream(this->libObjPtr())};
271 CommonStreamBeginningMessage defaultClockSnapshot(const std::uint64_t val) const noexcept
273 static_assert(!std::is_const<LibObjT>::value,
274 "Not available with `bt2::ConstStreamBeginningMessage`.");
276 bt_message_stream_beginning_set_default_clock_snapshot(this->libObjPtr(), val);
280 OptionalBorrowedObject<ConstClockSnapshot> defaultClockSnapshot() const noexcept
282 const bt_clock_snapshot *libObjPtr;
283 const auto state = bt_message_stream_beginning_borrow_default_clock_snapshot_const(
284 this->libObjPtr(), &libObjPtr);
286 if (state == BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN) {
293 Shared shared() const noexcept
295 return Shared::createWithRef(*this);
299 using StreamBeginningMessage = CommonStreamBeginningMessage<bt_message>;
300 using ConstStreamBeginningMessage = CommonStreamBeginningMessage<const bt_message>;
304 struct StreamBeginningMessageTypeDescr
306 using Const = ConstStreamBeginningMessage;
307 using NonConst = StreamBeginningMessage;
311 struct TypeDescr<StreamBeginningMessage> : public StreamBeginningMessageTypeDescr
316 struct TypeDescr<ConstStreamBeginningMessage> : public StreamBeginningMessageTypeDescr
320 template <typename LibObjT>
321 struct CommonStreamEndMessageSpec;
323 /* Functions specific to mutable stream end messages */
325 struct CommonStreamEndMessageSpec<bt_message> final
327 static bt_stream *stream(bt_message * const libObjPtr) noexcept
329 return bt_message_stream_end_borrow_stream(libObjPtr);
333 /* Functions specific to constant stream end messages */
335 struct CommonStreamEndMessageSpec<const bt_message> final
337 static const bt_stream *stream(const bt_message * const libObjPtr) noexcept
339 return bt_message_stream_end_borrow_stream_const(libObjPtr);
343 } /* namespace internal */
345 template <typename LibObjT>
346 class CommonStreamEndMessage final : public CommonMessage<LibObjT>
349 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
350 using _Stream = internal::DepStream<LibObjT>;
353 using typename CommonMessage<LibObjT>::LibObjPtr;
354 using Shared = SharedMessage<CommonStreamEndMessage<LibObjT>, LibObjT>;
356 explicit CommonStreamEndMessage(const LibObjPtr libObjPtr) noexcept :
357 _ThisCommonMessage {libObjPtr}
359 BT_ASSERT_DBG(this->isStreamEnd());
362 template <typename OtherLibObjT>
363 CommonStreamEndMessage(const CommonStreamEndMessage<OtherLibObjT> val) noexcept :
364 _ThisCommonMessage {val}
368 template <typename OtherLibObjT>
369 CommonStreamEndMessage<LibObjT>
370 operator=(const CommonStreamEndMessage<OtherLibObjT> val) noexcept
372 _ThisCommonMessage::operator=(val);
376 CommonStreamEndMessage<const bt_message> asConst() const noexcept
378 return CommonStreamEndMessage<const bt_message> {*this};
381 _Stream stream() const noexcept
383 return _Stream {internal::CommonStreamEndMessageSpec<LibObjT>::stream(this->libObjPtr())};
386 CommonStreamEndMessage defaultClockSnapshot(const std::uint64_t val) const noexcept
388 static_assert(!std::is_const<LibObjT>::value,
389 "Not available with `bt2::ConstStreamEndMessage`.");
391 bt_message_stream_end_set_default_clock_snapshot(this->libObjPtr(), val);
395 OptionalBorrowedObject<ConstClockSnapshot> defaultClockSnapshot() const noexcept
397 const bt_clock_snapshot *libObjPtr;
398 const auto state = bt_message_stream_end_borrow_default_clock_snapshot_const(
399 this->libObjPtr(), &libObjPtr);
401 if (state == BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN) {
408 Shared shared() const noexcept
410 return Shared::createWithRef(*this);
414 using StreamEndMessage = CommonStreamEndMessage<bt_message>;
415 using ConstStreamEndMessage = CommonStreamEndMessage<const bt_message>;
419 struct StreamEndMessageTypeDescr
421 using Const = ConstStreamEndMessage;
422 using NonConst = StreamEndMessage;
426 struct TypeDescr<StreamEndMessage> : public StreamEndMessageTypeDescr
431 struct TypeDescr<ConstStreamEndMessage> : public StreamEndMessageTypeDescr
435 template <typename LibObjT>
436 struct CommonPacketBeginningMessageSpec;
438 /* Functions specific to mutable packet beginning messages */
440 struct CommonPacketBeginningMessageSpec<bt_message> final
442 static bt_packet *packet(bt_message * const libObjPtr) noexcept
444 return bt_message_packet_beginning_borrow_packet(libObjPtr);
448 /* Functions specific to constant packet beginning messages */
450 struct CommonPacketBeginningMessageSpec<const bt_message> final
452 static const bt_packet *packet(const bt_message * const libObjPtr) noexcept
454 return bt_message_packet_beginning_borrow_packet_const(libObjPtr);
458 } /* namespace internal */
460 template <typename LibObjT>
461 class CommonPacketBeginningMessage final : public CommonMessage<LibObjT>
464 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
465 using _Packet = internal::DepPacket<LibObjT>;
468 using typename CommonMessage<LibObjT>::LibObjPtr;
469 using Shared = SharedMessage<CommonPacketBeginningMessage<LibObjT>, LibObjT>;
471 explicit CommonPacketBeginningMessage(const LibObjPtr libObjPtr) noexcept :
472 _ThisCommonMessage {libObjPtr}
474 BT_ASSERT_DBG(this->isPacketBeginning());
477 template <typename OtherLibObjT>
478 CommonPacketBeginningMessage(const CommonPacketBeginningMessage<OtherLibObjT> val) noexcept :
479 _ThisCommonMessage {val}
483 template <typename OtherLibObjT>
484 CommonPacketBeginningMessage<LibObjT>
485 operator=(const CommonPacketBeginningMessage<OtherLibObjT> val) noexcept
487 _ThisCommonMessage::operator=(val);
491 CommonPacketBeginningMessage<const bt_message> asConst() const noexcept
493 return CommonPacketBeginningMessage<const bt_message> {*this};
496 _Packet packet() const noexcept
499 internal::CommonPacketBeginningMessageSpec<LibObjT>::packet(this->libObjPtr())};
502 CommonPacketBeginningMessage defaultClockSnapshot(const std::uint64_t val) const noexcept
504 static_assert(!std::is_const<LibObjT>::value,
505 "Not available with `bt2::ConstPacketBeginningMessage`.");
507 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>::_ThisCommonMessage;
576 using _Packet = internal::DepPacket<LibObjT>;
579 using typename CommonMessage<LibObjT>::LibObjPtr;
580 using Shared = SharedMessage<CommonPacketEndMessage<LibObjT>, LibObjT>;
582 explicit CommonPacketEndMessage(const LibObjPtr libObjPtr) noexcept :
583 _ThisCommonMessage {libObjPtr}
585 BT_ASSERT_DBG(this->isPacketEnd());
588 template <typename OtherLibObjT>
589 CommonPacketEndMessage(const CommonPacketEndMessage<OtherLibObjT> val) noexcept :
590 _ThisCommonMessage {val}
594 template <typename OtherLibObjT>
595 CommonPacketEndMessage<LibObjT>
596 operator=(const CommonPacketEndMessage<OtherLibObjT> val) noexcept
598 _ThisCommonMessage::operator=(val);
602 CommonPacketEndMessage<const bt_message> asConst() const noexcept
604 return CommonPacketEndMessage<const bt_message> {*this};
607 _Packet packet() const noexcept
609 return _Packet {internal::CommonPacketEndMessageSpec<LibObjT>::packet(this->libObjPtr())};
612 CommonPacketEndMessage defaultClockSnapshot(const std::uint64_t val) const noexcept
614 static_assert(!std::is_const<LibObjT>::value,
615 "Not available with `bt2::ConstPacketEndMessage`.");
617 bt_message_packet_end_set_default_clock_snapshot(this->libObjPtr(), val);
621 ConstClockSnapshot defaultClockSnapshot() const noexcept
623 const auto libObjPtr =
624 bt_message_packet_end_borrow_default_clock_snapshot_const(this->libObjPtr());
626 return ConstClockSnapshot {libObjPtr};
629 Shared shared() const noexcept
631 return Shared::createWithRef(*this);
635 using PacketEndMessage = CommonPacketEndMessage<bt_message>;
636 using ConstPacketEndMessage = CommonPacketEndMessage<const bt_message>;
640 struct PacketEndMessageTypeDescr
642 using Const = ConstPacketEndMessage;
643 using NonConst = PacketEndMessage;
647 struct TypeDescr<PacketEndMessage> : public PacketEndMessageTypeDescr
652 struct TypeDescr<ConstPacketEndMessage> : public PacketEndMessageTypeDescr
656 template <typename LibObjT>
657 struct CommonEventMessageSpec;
659 /* Functions specific to mutable event messages */
661 struct CommonEventMessageSpec<bt_message> final
663 static bt_event *event(bt_message * const libObjPtr) noexcept
665 return bt_message_event_borrow_event(libObjPtr);
669 /* Functions specific to constant event messages */
671 struct CommonEventMessageSpec<const bt_message> final
673 static const bt_event *event(const bt_message * const libObjPtr) noexcept
675 return bt_message_event_borrow_event_const(libObjPtr);
679 } /* namespace internal */
681 template <typename LibObjT>
682 class CommonEventMessage final : public CommonMessage<LibObjT>
685 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
686 using _Event = internal::DepType<LibObjT, CommonEvent<bt_event>, CommonEvent<const bt_event>>;
689 using typename CommonMessage<LibObjT>::LibObjPtr;
690 using Shared = SharedMessage<CommonEventMessage<LibObjT>, LibObjT>;
692 explicit CommonEventMessage(const LibObjPtr libObjPtr) noexcept : _ThisCommonMessage {libObjPtr}
694 BT_ASSERT_DBG(this->isEvent());
697 template <typename OtherLibObjT>
698 CommonEventMessage(const CommonEventMessage<OtherLibObjT> val) noexcept :
699 _ThisCommonMessage {val}
703 template <typename OtherLibObjT>
704 CommonEventMessage<LibObjT> operator=(const CommonEventMessage<OtherLibObjT> val) noexcept
706 _ThisCommonMessage::operator=(val);
710 CommonEventMessage<const bt_message> asConst() const noexcept
712 return CommonEventMessage<const bt_message> {*this};
715 _Event event() const noexcept
717 return _Event {internal::CommonEventMessageSpec<LibObjT>::event(this->libObjPtr())};
720 OptionalBorrowedObject<ConstClockClass> streamClassDefaultClockClass() const noexcept
722 return bt_message_event_borrow_stream_class_default_clock_class_const(this->libObjPtr());
725 ConstClockSnapshot defaultClockSnapshot() const noexcept
727 const auto libObjPtr =
728 bt_message_event_borrow_default_clock_snapshot_const(this->libObjPtr());
730 return ConstClockSnapshot {libObjPtr};
733 Shared shared() const noexcept
735 return Shared::createWithRef(*this);
739 using EventMessage = CommonEventMessage<bt_message>;
740 using ConstEventMessage = CommonEventMessage<const bt_message>;
744 struct EventMessageTypeDescr
746 using Const = ConstEventMessage;
747 using NonConst = EventMessage;
751 struct TypeDescr<EventMessage> : public EventMessageTypeDescr
756 struct TypeDescr<ConstEventMessage> : public EventMessageTypeDescr
760 template <typename LibObjT>
761 struct CommonDiscardedEventsMessageSpec;
763 /* Functions specific to mutable discarded events messages */
765 struct CommonDiscardedEventsMessageSpec<bt_message> final
767 static bt_stream *stream(bt_message * const libObjPtr) noexcept
769 return bt_message_discarded_events_borrow_stream(libObjPtr);
773 /* Functions specific to constant discarded events messages */
775 struct CommonDiscardedEventsMessageSpec<const bt_message> final
777 static const bt_stream *stream(const bt_message * const libObjPtr) noexcept
779 return bt_message_discarded_events_borrow_stream_const(libObjPtr);
783 } /* namespace internal */
785 template <typename LibObjT>
786 class CommonDiscardedEventsMessage final : public CommonMessage<LibObjT>
789 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
790 using _Stream = internal::DepStream<LibObjT>;
793 using typename CommonMessage<LibObjT>::LibObjPtr;
794 using Shared = SharedMessage<CommonDiscardedEventsMessage<LibObjT>, LibObjT>;
796 explicit CommonDiscardedEventsMessage(const LibObjPtr libObjPtr) noexcept :
797 _ThisCommonMessage {libObjPtr}
799 BT_ASSERT_DBG(this->isDiscardedEvents());
802 template <typename OtherLibObjT>
803 CommonDiscardedEventsMessage(const CommonDiscardedEventsMessage<OtherLibObjT> val) noexcept :
804 _ThisCommonMessage {val}
808 template <typename OtherLibObjT>
809 CommonDiscardedEventsMessage<LibObjT>
810 operator=(const CommonDiscardedEventsMessage<OtherLibObjT> val) noexcept
812 _ThisCommonMessage::operator=(val);
816 CommonDiscardedEventsMessage<const bt_message> asConst() const noexcept
818 return CommonDiscardedEventsMessage<const bt_message> {*this};
821 _Stream stream() const noexcept
824 internal::CommonDiscardedEventsMessageSpec<LibObjT>::stream(this->libObjPtr())};
827 ConstClockSnapshot beginningDefaultClockSnapshot() const noexcept
829 const auto libObjPtr =
830 bt_message_discarded_events_borrow_beginning_default_clock_snapshot_const(
833 return ConstClockSnapshot {libObjPtr};
836 ConstClockSnapshot endDefaultClockSnapshot() const noexcept
838 const auto libObjPtr =
839 bt_message_discarded_events_borrow_end_default_clock_snapshot_const(this->libObjPtr());
841 return ConstClockSnapshot {libObjPtr};
844 CommonDiscardedEventsMessage count(const std::uint64_t count) const noexcept
846 static_assert(!std::is_const<LibObjT>::value,
847 "Not available with `bt2::ConstDiscardedEventsMessage`.");
849 bt_message_discarded_events_set_count(this->libObjPtr(), count);
853 bt2s::optional<std::uint64_t> count() const noexcept
857 if (bt_message_discarded_events_get_count(this->libObjPtr(), &count)) {
861 return bt2s::nullopt;
864 Shared shared() const noexcept
866 return Shared::createWithRef(*this);
870 using DiscardedEventsMessage = CommonDiscardedEventsMessage<bt_message>;
871 using ConstDiscardedEventsMessage = CommonDiscardedEventsMessage<const bt_message>;
875 struct DiscardedEventsMessageTypeDescr
877 using Const = ConstDiscardedEventsMessage;
878 using NonConst = DiscardedEventsMessage;
882 struct TypeDescr<DiscardedEventsMessage> : public DiscardedEventsMessageTypeDescr
887 struct TypeDescr<ConstDiscardedEventsMessage> : public DiscardedEventsMessageTypeDescr
891 template <typename LibObjT>
892 struct CommonDiscardedPacketsMessageSpec;
894 /* Functions specific to mutable discarded packets messages */
896 struct CommonDiscardedPacketsMessageSpec<bt_message> final
898 static bt_stream *stream(bt_message * const libObjPtr) noexcept
900 return bt_message_discarded_packets_borrow_stream(libObjPtr);
904 /* Functions specific to constant discarded packets messages */
906 struct CommonDiscardedPacketsMessageSpec<const bt_message> final
908 static const bt_stream *stream(const bt_message * const libObjPtr) noexcept
910 return bt_message_discarded_packets_borrow_stream_const(libObjPtr);
914 } /* namespace internal */
916 template <typename LibObjT>
917 class CommonDiscardedPacketsMessage final : public CommonMessage<LibObjT>
920 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
921 using _Stream = internal::DepStream<LibObjT>;
924 using typename CommonMessage<LibObjT>::LibObjPtr;
925 using Shared = SharedMessage<CommonDiscardedPacketsMessage<LibObjT>, LibObjT>;
927 explicit CommonDiscardedPacketsMessage(const LibObjPtr libObjPtr) noexcept :
928 _ThisCommonMessage {libObjPtr}
930 BT_ASSERT_DBG(this->isDiscardedPackets());
933 template <typename OtherLibObjT>
934 CommonDiscardedPacketsMessage(const CommonDiscardedPacketsMessage<OtherLibObjT> val) noexcept :
935 _ThisCommonMessage {val}
939 template <typename OtherLibObjT>
940 CommonDiscardedPacketsMessage<LibObjT>
941 operator=(const CommonDiscardedPacketsMessage<OtherLibObjT> val) noexcept
943 _ThisCommonMessage::operator=(val);
947 CommonDiscardedPacketsMessage<const bt_message> asConst() const noexcept
949 return CommonDiscardedPacketsMessage<const bt_message> {*this};
952 _Stream stream() const noexcept
955 internal::CommonDiscardedPacketsMessageSpec<LibObjT>::stream(this->libObjPtr())};
958 ConstClockSnapshot beginningDefaultClockSnapshot() const noexcept
960 const auto libObjPtr =
961 bt_message_discarded_packets_borrow_beginning_default_clock_snapshot_const(
964 return ConstClockSnapshot {libObjPtr};
967 ConstClockSnapshot endDefaultClockSnapshot() const noexcept
969 const auto libObjPtr =
970 bt_message_discarded_packets_borrow_end_default_clock_snapshot_const(this->libObjPtr());
972 return ConstClockSnapshot {libObjPtr};
975 CommonDiscardedPacketsMessage count(const std::uint64_t count) const noexcept
977 static_assert(!std::is_const<LibObjT>::value,
978 "Not available with `bt2::ConstDiscardedPacketsMessage`.");
980 bt_message_discarded_packets_set_count(this->libObjPtr(), count);
984 bt2s::optional<std::uint64_t> count() const noexcept
988 if (bt_message_discarded_packets_get_count(this->libObjPtr(), &count)) {
992 return bt2s::nullopt;
995 Shared shared() const noexcept
997 return Shared::createWithRef(*this);
1001 using DiscardedPacketsMessage = CommonDiscardedPacketsMessage<bt_message>;
1002 using ConstDiscardedPacketsMessage = CommonDiscardedPacketsMessage<const bt_message>;
1004 namespace internal {
1006 struct DiscardedPacketsMessageTypeDescr
1008 using Const = ConstDiscardedPacketsMessage;
1009 using NonConst = DiscardedPacketsMessage;
1013 struct TypeDescr<DiscardedPacketsMessage> : public DiscardedPacketsMessageTypeDescr
1018 struct TypeDescr<ConstDiscardedPacketsMessage> : public DiscardedPacketsMessageTypeDescr
1022 } /* namespace internal */
1024 template <typename LibObjT>
1025 class CommonMessageIteratorInactivityMessage final : public CommonMessage<LibObjT>
1028 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
1031 using typename CommonMessage<LibObjT>::LibObjPtr;
1032 using Shared = SharedMessage<CommonMessageIteratorInactivityMessage<LibObjT>, LibObjT>;
1034 explicit CommonMessageIteratorInactivityMessage(const LibObjPtr libObjPtr) noexcept :
1035 _ThisCommonMessage {libObjPtr}
1037 BT_ASSERT_DBG(this->isMessageIteratorInactivity());
1040 template <typename OtherLibObjT>
1041 CommonMessageIteratorInactivityMessage(
1042 const CommonMessageIteratorInactivityMessage<OtherLibObjT> val) noexcept :
1043 _ThisCommonMessage {val}
1047 template <typename OtherLibObjT>
1048 CommonMessageIteratorInactivityMessage<LibObjT>
1049 operator=(const CommonMessageIteratorInactivityMessage<OtherLibObjT> val) noexcept
1051 _ThisCommonMessage::operator=(val);
1055 CommonMessageIteratorInactivityMessage<const bt_message> asConst() const noexcept
1057 return CommonMessageIteratorInactivityMessage<const bt_message> {*this};
1060 ConstClockSnapshot clockSnapshot() const noexcept
1062 const auto libObjPtr =
1063 bt_message_message_iterator_inactivity_borrow_clock_snapshot_const(this->libObjPtr());
1065 return ConstClockSnapshot {libObjPtr};
1068 Shared shared() const noexcept
1070 return Shared::createWithRef(*this);
1074 using MessageIteratorInactivityMessage = CommonMessageIteratorInactivityMessage<bt_message>;
1075 using ConstMessageIteratorInactivityMessage =
1076 CommonMessageIteratorInactivityMessage<const bt_message>;
1078 namespace internal {
1080 struct MessageIteratorInactivityMessageTypeDescr
1082 using Const = ConstMessageIteratorInactivityMessage;
1083 using NonConst = MessageIteratorInactivityMessage;
1087 struct TypeDescr<MessageIteratorInactivityMessage> :
1088 public MessageIteratorInactivityMessageTypeDescr
1093 struct TypeDescr<ConstMessageIteratorInactivityMessage> :
1094 public MessageIteratorInactivityMessageTypeDescr
1098 } /* namespace internal */
1100 template <typename LibObjT>
1101 CommonStreamBeginningMessage<LibObjT> CommonMessage<LibObjT>::asStreamBeginning() const noexcept
1103 return CommonStreamBeginningMessage<LibObjT> {this->libObjPtr()};
1106 template <typename LibObjT>
1107 CommonStreamEndMessage<LibObjT> CommonMessage<LibObjT>::asStreamEnd() const noexcept
1109 return CommonStreamEndMessage<LibObjT> {this->libObjPtr()};
1112 template <typename LibObjT>
1113 CommonPacketBeginningMessage<LibObjT> CommonMessage<LibObjT>::asPacketBeginning() const noexcept
1115 return CommonPacketBeginningMessage<LibObjT> {this->libObjPtr()};
1118 template <typename LibObjT>
1119 CommonPacketEndMessage<LibObjT> CommonMessage<LibObjT>::asPacketEnd() const noexcept
1121 return CommonPacketEndMessage<LibObjT> {this->libObjPtr()};
1124 template <typename LibObjT>
1125 CommonEventMessage<LibObjT> CommonMessage<LibObjT>::asEvent() const noexcept
1127 return CommonEventMessage<LibObjT> {this->libObjPtr()};
1130 template <typename LibObjT>
1131 CommonDiscardedEventsMessage<LibObjT> CommonMessage<LibObjT>::asDiscardedEvents() const noexcept
1133 return CommonDiscardedEventsMessage<LibObjT> {this->libObjPtr()};
1136 template <typename LibObjT>
1137 CommonDiscardedPacketsMessage<LibObjT> CommonMessage<LibObjT>::asDiscardedPackets() const noexcept
1139 return CommonDiscardedPacketsMessage<LibObjT> {this->libObjPtr()};
1142 template <typename LibObjT>
1143 CommonMessageIteratorInactivityMessage<LibObjT>
1144 CommonMessage<LibObjT>::asMessageIteratorInactivity() const noexcept
1146 return CommonMessageIteratorInactivityMessage<LibObjT> {this->libObjPtr()};
1149 } /* namespace bt2 */
1151 #endif /* BABELTRACE_CPP_COMMON_BT2_MESSAGE_HPP */