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"
19 #include "cpp-common/vendor/wise-enum/wise_enum.h"
21 #include "borrowed-object.hpp"
22 #include "internal/utils.hpp"
23 #include "optional-borrowed-object.hpp"
24 #include "shared-object.hpp"
25 #include "trace-ir.hpp"
30 struct MessageRefFuncs final
32 static void get(const bt_message * const libObjPtr) noexcept
34 bt_message_get_ref(libObjPtr);
37 static void put(const bt_message * const libObjPtr) noexcept
39 bt_message_put_ref(libObjPtr);
43 } /* namespace internal */
45 template <typename ObjT, typename LibObjT>
46 using SharedMessage = SharedObject<ObjT, LibObjT, internal::MessageRefFuncs>;
48 template <typename LibObjT>
49 class CommonStreamBeginningMessage;
51 template <typename LibObjT>
52 class CommonStreamEndMessage;
54 template <typename LibObjT>
55 class CommonEventMessage;
57 template <typename LibObjT>
58 class CommonPacketBeginningMessage;
60 template <typename LibObjT>
61 class CommonPacketEndMessage;
63 template <typename LibObjT>
64 class CommonDiscardedEventsMessage;
66 template <typename LibObjT>
67 class CommonDiscardedPacketsMessage;
69 template <typename LibObjT>
70 class CommonMessageIteratorInactivityMessage;
72 /* clang-format off */
74 WISE_ENUM_CLASS(MessageType,
75 (StreamBeginning, BT_MESSAGE_TYPE_STREAM_BEGINNING),
76 (StreamEnd, BT_MESSAGE_TYPE_STREAM_END),
77 (Event, BT_MESSAGE_TYPE_EVENT),
78 (PacketBeginning, BT_MESSAGE_TYPE_PACKET_BEGINNING),
79 (PacketEnd, BT_MESSAGE_TYPE_PACKET_END),
80 (DiscardedEvents, BT_MESSAGE_TYPE_DISCARDED_EVENTS),
81 (DiscardedPackets, BT_MESSAGE_TYPE_DISCARDED_PACKETS),
82 (MessageIteratorInactivity, BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY));
86 template <typename LibObjT>
87 class CommonMessage : public BorrowedObject<LibObjT>
90 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
93 using _ThisCommonMessage = CommonMessage<LibObjT>;
96 using typename BorrowedObject<LibObjT>::LibObjPtr;
97 using Shared = SharedMessage<CommonMessage<LibObjT>, LibObjT>;
99 explicit CommonMessage(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
103 template <typename OtherLibObjT>
104 CommonMessage(const CommonMessage<OtherLibObjT> val) noexcept : _ThisBorrowedObject {val}
108 template <typename OtherLibObjT>
109 _ThisCommonMessage operator=(const CommonMessage<OtherLibObjT> val) noexcept
111 _ThisBorrowedObject::operator=(val);
115 CommonMessage<const bt_message> asConst() const noexcept
117 return CommonMessage<const bt_message> {*this};
120 MessageType type() const noexcept
122 return static_cast<MessageType>(bt_message_get_type(this->libObjPtr()));
125 bool isStreamBeginning() const noexcept
127 return this->type() == MessageType::StreamBeginning;
130 bool isStreamEnd() const noexcept
132 return this->type() == MessageType::StreamEnd;
135 bool isEvent() const noexcept
137 return this->type() == MessageType::Event;
140 bool isPacketBeginning() const noexcept
142 return this->type() == MessageType::PacketBeginning;
145 bool isPacketEnd() const noexcept
147 return this->type() == MessageType::PacketEnd;
150 bool isDiscardedEvents() const noexcept
152 return this->type() == MessageType::DiscardedEvents;
155 bool isDiscardedPackets() const noexcept
157 return this->type() == MessageType::DiscardedPackets;
160 bool isMessageIteratorInactivity() const noexcept
162 return this->type() == MessageType::MessageIteratorInactivity;
165 Shared shared() const noexcept
167 return Shared::createWithRef(*this);
170 template <typename MessageT>
171 MessageT as() const noexcept
173 return MessageT {this->libObjPtr()};
176 CommonStreamBeginningMessage<LibObjT> asStreamBeginning() const noexcept;
177 CommonStreamEndMessage<LibObjT> asStreamEnd() const noexcept;
178 CommonEventMessage<LibObjT> asEvent() const noexcept;
179 CommonPacketBeginningMessage<LibObjT> asPacketBeginning() const noexcept;
180 CommonPacketEndMessage<LibObjT> asPacketEnd() const noexcept;
181 CommonDiscardedEventsMessage<LibObjT> asDiscardedEvents() const noexcept;
182 CommonDiscardedPacketsMessage<LibObjT> asDiscardedPackets() const noexcept;
183 CommonMessageIteratorInactivityMessage<LibObjT> asMessageIteratorInactivity() const noexcept;
186 using Message = CommonMessage<bt_message>;
187 using ConstMessage = CommonMessage<const bt_message>;
191 struct MessageTypeDescr
193 using Const = ConstMessage;
194 using NonConst = Message;
198 struct TypeDescr<Message> : public MessageTypeDescr
203 struct TypeDescr<ConstMessage> : public MessageTypeDescr
207 template <typename LibObjT>
208 struct CommonStreamBeginningMessageSpec;
210 /* Functions specific to mutable stream beginning messages */
212 struct CommonStreamBeginningMessageSpec<bt_message> final
214 static bt_stream *stream(bt_message * const libObjPtr) noexcept
216 return bt_message_stream_beginning_borrow_stream(libObjPtr);
220 /* Functions specific to constant stream beginning messages */
222 struct CommonStreamBeginningMessageSpec<const bt_message> final
224 static const bt_stream *stream(const bt_message * const libObjPtr) noexcept
226 return bt_message_stream_beginning_borrow_stream_const(libObjPtr);
230 } /* namespace internal */
232 template <typename LibObjT>
233 class CommonStreamBeginningMessage final : public CommonMessage<LibObjT>
236 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
237 using _Stream = internal::DepStream<LibObjT>;
240 using typename CommonMessage<LibObjT>::LibObjPtr;
241 using Shared = SharedMessage<CommonStreamBeginningMessage<LibObjT>, LibObjT>;
243 explicit CommonStreamBeginningMessage(const LibObjPtr libObjPtr) noexcept :
244 _ThisCommonMessage {libObjPtr}
246 BT_ASSERT_DBG(this->isStreamBeginning());
249 template <typename OtherLibObjT>
250 CommonStreamBeginningMessage(const CommonStreamBeginningMessage<OtherLibObjT> val) noexcept :
251 _ThisCommonMessage {val}
255 template <typename OtherLibObjT>
256 CommonStreamBeginningMessage<LibObjT>
257 operator=(const CommonStreamBeginningMessage<OtherLibObjT> val) noexcept
259 _ThisCommonMessage::operator=(val);
263 CommonStreamBeginningMessage<const bt_message> asConst() const noexcept
265 return CommonStreamBeginningMessage<const bt_message> {*this};
268 _Stream stream() const noexcept
271 internal::CommonStreamBeginningMessageSpec<LibObjT>::stream(this->libObjPtr())};
274 OptionalBorrowedObject<ConstClockClass> streamClassDefaultClockClass() const noexcept
276 return bt_message_stream_beginning_borrow_stream_class_default_clock_class_const(
280 CommonStreamBeginningMessage defaultClockSnapshot(const std::uint64_t val) const noexcept
282 static_assert(!std::is_const<LibObjT>::value,
283 "Not available with `bt2::ConstStreamBeginningMessage`.");
285 bt_message_stream_beginning_set_default_clock_snapshot(this->libObjPtr(), val);
289 OptionalBorrowedObject<ConstClockSnapshot> defaultClockSnapshot() const noexcept
291 const bt_clock_snapshot *libObjPtr;
292 const auto state = bt_message_stream_beginning_borrow_default_clock_snapshot_const(
293 this->libObjPtr(), &libObjPtr);
295 if (state == BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN) {
302 Shared shared() const noexcept
304 return Shared::createWithRef(*this);
308 using StreamBeginningMessage = CommonStreamBeginningMessage<bt_message>;
309 using ConstStreamBeginningMessage = CommonStreamBeginningMessage<const bt_message>;
313 struct StreamBeginningMessageTypeDescr
315 using Const = ConstStreamBeginningMessage;
316 using NonConst = StreamBeginningMessage;
320 struct TypeDescr<StreamBeginningMessage> : public StreamBeginningMessageTypeDescr
325 struct TypeDescr<ConstStreamBeginningMessage> : public StreamBeginningMessageTypeDescr
329 template <typename LibObjT>
330 struct CommonStreamEndMessageSpec;
332 /* Functions specific to mutable stream end messages */
334 struct CommonStreamEndMessageSpec<bt_message> final
336 static bt_stream *stream(bt_message * const libObjPtr) noexcept
338 return bt_message_stream_end_borrow_stream(libObjPtr);
342 /* Functions specific to constant stream end messages */
344 struct CommonStreamEndMessageSpec<const bt_message> final
346 static const bt_stream *stream(const bt_message * const libObjPtr) noexcept
348 return bt_message_stream_end_borrow_stream_const(libObjPtr);
352 } /* namespace internal */
354 template <typename LibObjT>
355 class CommonStreamEndMessage final : public CommonMessage<LibObjT>
358 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
359 using _Stream = internal::DepStream<LibObjT>;
362 using typename CommonMessage<LibObjT>::LibObjPtr;
363 using Shared = SharedMessage<CommonStreamEndMessage<LibObjT>, LibObjT>;
365 explicit CommonStreamEndMessage(const LibObjPtr libObjPtr) noexcept :
366 _ThisCommonMessage {libObjPtr}
368 BT_ASSERT_DBG(this->isStreamEnd());
371 template <typename OtherLibObjT>
372 CommonStreamEndMessage(const CommonStreamEndMessage<OtherLibObjT> val) noexcept :
373 _ThisCommonMessage {val}
377 template <typename OtherLibObjT>
378 CommonStreamEndMessage<LibObjT>
379 operator=(const CommonStreamEndMessage<OtherLibObjT> val) noexcept
381 _ThisCommonMessage::operator=(val);
385 CommonStreamEndMessage<const bt_message> asConst() const noexcept
387 return CommonStreamEndMessage<const bt_message> {*this};
390 _Stream stream() const noexcept
392 return _Stream {internal::CommonStreamEndMessageSpec<LibObjT>::stream(this->libObjPtr())};
395 OptionalBorrowedObject<ConstClockClass> streamClassDefaultClockClass() const noexcept
397 return bt_message_stream_end_borrow_stream_class_default_clock_class_const(
401 CommonStreamEndMessage defaultClockSnapshot(const std::uint64_t val) const noexcept
403 static_assert(!std::is_const<LibObjT>::value,
404 "Not available with `bt2::ConstStreamEndMessage`.");
406 bt_message_stream_end_set_default_clock_snapshot(this->libObjPtr(), val);
410 OptionalBorrowedObject<ConstClockSnapshot> defaultClockSnapshot() const noexcept
412 const bt_clock_snapshot *libObjPtr;
413 const auto state = bt_message_stream_end_borrow_default_clock_snapshot_const(
414 this->libObjPtr(), &libObjPtr);
416 if (state == BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN) {
423 Shared shared() const noexcept
425 return Shared::createWithRef(*this);
429 using StreamEndMessage = CommonStreamEndMessage<bt_message>;
430 using ConstStreamEndMessage = CommonStreamEndMessage<const bt_message>;
434 struct StreamEndMessageTypeDescr
436 using Const = ConstStreamEndMessage;
437 using NonConst = StreamEndMessage;
441 struct TypeDescr<StreamEndMessage> : public StreamEndMessageTypeDescr
446 struct TypeDescr<ConstStreamEndMessage> : public StreamEndMessageTypeDescr
450 template <typename LibObjT>
451 struct CommonPacketBeginningMessageSpec;
453 /* Functions specific to mutable packet beginning messages */
455 struct CommonPacketBeginningMessageSpec<bt_message> final
457 static bt_packet *packet(bt_message * const libObjPtr) noexcept
459 return bt_message_packet_beginning_borrow_packet(libObjPtr);
463 /* Functions specific to constant packet beginning messages */
465 struct CommonPacketBeginningMessageSpec<const bt_message> final
467 static const bt_packet *packet(const bt_message * const libObjPtr) noexcept
469 return bt_message_packet_beginning_borrow_packet_const(libObjPtr);
473 } /* namespace internal */
475 template <typename LibObjT>
476 class CommonPacketBeginningMessage final : public CommonMessage<LibObjT>
479 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
480 using _Packet = internal::DepPacket<LibObjT>;
483 using typename CommonMessage<LibObjT>::LibObjPtr;
484 using Shared = SharedMessage<CommonPacketBeginningMessage<LibObjT>, LibObjT>;
486 explicit CommonPacketBeginningMessage(const LibObjPtr libObjPtr) noexcept :
487 _ThisCommonMessage {libObjPtr}
489 BT_ASSERT_DBG(this->isPacketBeginning());
492 template <typename OtherLibObjT>
493 CommonPacketBeginningMessage(const CommonPacketBeginningMessage<OtherLibObjT> val) noexcept :
494 _ThisCommonMessage {val}
498 template <typename OtherLibObjT>
499 CommonPacketBeginningMessage<LibObjT>
500 operator=(const CommonPacketBeginningMessage<OtherLibObjT> val) noexcept
502 _ThisCommonMessage::operator=(val);
506 CommonPacketBeginningMessage<const bt_message> asConst() const noexcept
508 return CommonPacketBeginningMessage<const bt_message> {*this};
511 _Packet packet() const noexcept
514 internal::CommonPacketBeginningMessageSpec<LibObjT>::packet(this->libObjPtr())};
517 OptionalBorrowedObject<ConstClockClass> streamClassDefaultClockClass() const noexcept
519 return bt_message_packet_beginning_borrow_stream_class_default_clock_class_const(
523 CommonPacketBeginningMessage defaultClockSnapshot(const std::uint64_t val) const noexcept
525 static_assert(!std::is_const<LibObjT>::value,
526 "Not available with `bt2::ConstPacketBeginningMessage`.");
528 bt_message_packet_beginning_set_default_clock_snapshot(this->libObjPtr(), val);
532 ConstClockSnapshot defaultClockSnapshot() const noexcept
534 const auto libObjPtr =
535 bt_message_packet_beginning_borrow_default_clock_snapshot_const(this->libObjPtr());
537 return ConstClockSnapshot {libObjPtr};
540 Shared shared() const noexcept
542 return Shared::createWithRef(*this);
546 using PacketBeginningMessage = CommonPacketBeginningMessage<bt_message>;
547 using ConstPacketBeginningMessage = CommonPacketBeginningMessage<const bt_message>;
551 struct PacketBeginningMessageTypeDescr
553 using Const = ConstPacketBeginningMessage;
554 using NonConst = PacketBeginningMessage;
558 struct TypeDescr<PacketBeginningMessage> : public PacketBeginningMessageTypeDescr
563 struct TypeDescr<ConstPacketBeginningMessage> : public PacketBeginningMessageTypeDescr
567 template <typename LibObjT>
568 struct CommonPacketEndMessageSpec;
570 /* Functions specific to mutable packet end messages */
572 struct CommonPacketEndMessageSpec<bt_message> final
574 static bt_packet *packet(bt_message * const libObjPtr) noexcept
576 return bt_message_packet_end_borrow_packet(libObjPtr);
580 /* Functions specific to constant packet end messages */
582 struct CommonPacketEndMessageSpec<const bt_message> final
584 static const bt_packet *packet(const bt_message * const libObjPtr) noexcept
586 return bt_message_packet_end_borrow_packet_const(libObjPtr);
590 } /* namespace internal */
592 template <typename LibObjT>
593 class CommonPacketEndMessage final : public CommonMessage<LibObjT>
596 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
597 using _Packet = internal::DepPacket<LibObjT>;
600 using typename CommonMessage<LibObjT>::LibObjPtr;
601 using Shared = SharedMessage<CommonPacketEndMessage<LibObjT>, LibObjT>;
603 explicit CommonPacketEndMessage(const LibObjPtr libObjPtr) noexcept :
604 _ThisCommonMessage {libObjPtr}
606 BT_ASSERT_DBG(this->isPacketEnd());
609 template <typename OtherLibObjT>
610 CommonPacketEndMessage(const CommonPacketEndMessage<OtherLibObjT> val) noexcept :
611 _ThisCommonMessage {val}
615 template <typename OtherLibObjT>
616 CommonPacketEndMessage<LibObjT>
617 operator=(const CommonPacketEndMessage<OtherLibObjT> val) noexcept
619 _ThisCommonMessage::operator=(val);
623 CommonPacketEndMessage<const bt_message> asConst() const noexcept
625 return CommonPacketEndMessage<const bt_message> {*this};
628 _Packet packet() const noexcept
630 return _Packet {internal::CommonPacketEndMessageSpec<LibObjT>::packet(this->libObjPtr())};
633 OptionalBorrowedObject<ConstClockClass> streamClassDefaultClockClass() const noexcept
635 return bt_message_packet_end_borrow_stream_class_default_clock_class_const(
639 CommonPacketEndMessage defaultClockSnapshot(const std::uint64_t val) const noexcept
641 static_assert(!std::is_const<LibObjT>::value,
642 "Not available with `bt2::ConstPacketEndMessage`.");
644 bt_message_packet_end_set_default_clock_snapshot(this->libObjPtr(), val);
648 ConstClockSnapshot defaultClockSnapshot() const noexcept
650 const auto libObjPtr =
651 bt_message_packet_end_borrow_default_clock_snapshot_const(this->libObjPtr());
653 return ConstClockSnapshot {libObjPtr};
656 Shared shared() const noexcept
658 return Shared::createWithRef(*this);
662 using PacketEndMessage = CommonPacketEndMessage<bt_message>;
663 using ConstPacketEndMessage = CommonPacketEndMessage<const bt_message>;
667 struct PacketEndMessageTypeDescr
669 using Const = ConstPacketEndMessage;
670 using NonConst = PacketEndMessage;
674 struct TypeDescr<PacketEndMessage> : public PacketEndMessageTypeDescr
679 struct TypeDescr<ConstPacketEndMessage> : public PacketEndMessageTypeDescr
683 template <typename LibObjT>
684 struct CommonEventMessageSpec;
686 /* Functions specific to mutable event messages */
688 struct CommonEventMessageSpec<bt_message> final
690 static bt_event *event(bt_message * const libObjPtr) noexcept
692 return bt_message_event_borrow_event(libObjPtr);
696 /* Functions specific to constant event messages */
698 struct CommonEventMessageSpec<const bt_message> final
700 static const bt_event *event(const bt_message * const libObjPtr) noexcept
702 return bt_message_event_borrow_event_const(libObjPtr);
706 } /* namespace internal */
708 template <typename LibObjT>
709 class CommonEventMessage final : public CommonMessage<LibObjT>
712 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
713 using _Event = internal::DepType<LibObjT, CommonEvent<bt_event>, CommonEvent<const bt_event>>;
716 using typename CommonMessage<LibObjT>::LibObjPtr;
717 using Shared = SharedMessage<CommonEventMessage<LibObjT>, LibObjT>;
719 explicit CommonEventMessage(const LibObjPtr libObjPtr) noexcept : _ThisCommonMessage {libObjPtr}
721 BT_ASSERT_DBG(this->isEvent());
724 template <typename OtherLibObjT>
725 CommonEventMessage(const CommonEventMessage<OtherLibObjT> val) noexcept :
726 _ThisCommonMessage {val}
730 template <typename OtherLibObjT>
731 CommonEventMessage<LibObjT> operator=(const CommonEventMessage<OtherLibObjT> val) noexcept
733 _ThisCommonMessage::operator=(val);
737 CommonEventMessage<const bt_message> asConst() const noexcept
739 return CommonEventMessage<const bt_message> {*this};
742 _Event event() const noexcept
744 return _Event {internal::CommonEventMessageSpec<LibObjT>::event(this->libObjPtr())};
747 OptionalBorrowedObject<ConstClockClass> streamClassDefaultClockClass() const noexcept
749 return bt_message_event_borrow_stream_class_default_clock_class_const(this->libObjPtr());
752 ConstClockSnapshot defaultClockSnapshot() const noexcept
754 const auto libObjPtr =
755 bt_message_event_borrow_default_clock_snapshot_const(this->libObjPtr());
757 return ConstClockSnapshot {libObjPtr};
760 Shared shared() const noexcept
762 return Shared::createWithRef(*this);
766 using EventMessage = CommonEventMessage<bt_message>;
767 using ConstEventMessage = CommonEventMessage<const bt_message>;
771 struct EventMessageTypeDescr
773 using Const = ConstEventMessage;
774 using NonConst = EventMessage;
778 struct TypeDescr<EventMessage> : public EventMessageTypeDescr
783 struct TypeDescr<ConstEventMessage> : public EventMessageTypeDescr
787 template <typename LibObjT>
788 struct CommonDiscardedEventsMessageSpec;
790 /* Functions specific to mutable discarded events messages */
792 struct CommonDiscardedEventsMessageSpec<bt_message> final
794 static bt_stream *stream(bt_message * const libObjPtr) noexcept
796 return bt_message_discarded_events_borrow_stream(libObjPtr);
800 /* Functions specific to constant discarded events messages */
802 struct CommonDiscardedEventsMessageSpec<const bt_message> final
804 static const bt_stream *stream(const bt_message * const libObjPtr) noexcept
806 return bt_message_discarded_events_borrow_stream_const(libObjPtr);
810 } /* namespace internal */
812 template <typename LibObjT>
813 class CommonDiscardedEventsMessage final : public CommonMessage<LibObjT>
816 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
817 using _Stream = internal::DepStream<LibObjT>;
820 using typename CommonMessage<LibObjT>::LibObjPtr;
821 using Shared = SharedMessage<CommonDiscardedEventsMessage<LibObjT>, LibObjT>;
823 explicit CommonDiscardedEventsMessage(const LibObjPtr libObjPtr) noexcept :
824 _ThisCommonMessage {libObjPtr}
826 BT_ASSERT_DBG(this->isDiscardedEvents());
829 template <typename OtherLibObjT>
830 CommonDiscardedEventsMessage(const CommonDiscardedEventsMessage<OtherLibObjT> val) noexcept :
831 _ThisCommonMessage {val}
835 template <typename OtherLibObjT>
836 CommonDiscardedEventsMessage<LibObjT>
837 operator=(const CommonDiscardedEventsMessage<OtherLibObjT> val) noexcept
839 _ThisCommonMessage::operator=(val);
843 CommonDiscardedEventsMessage<const bt_message> asConst() const noexcept
845 return CommonDiscardedEventsMessage<const bt_message> {*this};
848 _Stream stream() const noexcept
851 internal::CommonDiscardedEventsMessageSpec<LibObjT>::stream(this->libObjPtr())};
854 OptionalBorrowedObject<ConstClockClass> streamClassDefaultClockClass() const noexcept
856 return bt_message_discarded_events_borrow_stream_class_default_clock_class_const(
860 ConstClockSnapshot beginningDefaultClockSnapshot() const noexcept
862 const auto libObjPtr =
863 bt_message_discarded_events_borrow_beginning_default_clock_snapshot_const(
866 return ConstClockSnapshot {libObjPtr};
869 ConstClockSnapshot endDefaultClockSnapshot() const noexcept
871 const auto libObjPtr =
872 bt_message_discarded_events_borrow_end_default_clock_snapshot_const(this->libObjPtr());
874 return ConstClockSnapshot {libObjPtr};
877 CommonDiscardedEventsMessage count(const std::uint64_t count) const noexcept
879 static_assert(!std::is_const<LibObjT>::value,
880 "Not available with `bt2::ConstDiscardedEventsMessage`.");
882 bt_message_discarded_events_set_count(this->libObjPtr(), count);
886 bt2s::optional<std::uint64_t> count() const noexcept
890 if (bt_message_discarded_events_get_count(this->libObjPtr(), &count)) {
894 return bt2s::nullopt;
897 Shared shared() const noexcept
899 return Shared::createWithRef(*this);
903 using DiscardedEventsMessage = CommonDiscardedEventsMessage<bt_message>;
904 using ConstDiscardedEventsMessage = CommonDiscardedEventsMessage<const bt_message>;
908 struct DiscardedEventsMessageTypeDescr
910 using Const = ConstDiscardedEventsMessage;
911 using NonConst = DiscardedEventsMessage;
915 struct TypeDescr<DiscardedEventsMessage> : public DiscardedEventsMessageTypeDescr
920 struct TypeDescr<ConstDiscardedEventsMessage> : public DiscardedEventsMessageTypeDescr
924 template <typename LibObjT>
925 struct CommonDiscardedPacketsMessageSpec;
927 /* Functions specific to mutable discarded packets messages */
929 struct CommonDiscardedPacketsMessageSpec<bt_message> final
931 static bt_stream *stream(bt_message * const libObjPtr) noexcept
933 return bt_message_discarded_packets_borrow_stream(libObjPtr);
937 /* Functions specific to constant discarded packets messages */
939 struct CommonDiscardedPacketsMessageSpec<const bt_message> final
941 static const bt_stream *stream(const bt_message * const libObjPtr) noexcept
943 return bt_message_discarded_packets_borrow_stream_const(libObjPtr);
947 } /* namespace internal */
949 template <typename LibObjT>
950 class CommonDiscardedPacketsMessage final : public CommonMessage<LibObjT>
953 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
954 using _Stream = internal::DepStream<LibObjT>;
957 using typename CommonMessage<LibObjT>::LibObjPtr;
958 using Shared = SharedMessage<CommonDiscardedPacketsMessage<LibObjT>, LibObjT>;
960 explicit CommonDiscardedPacketsMessage(const LibObjPtr libObjPtr) noexcept :
961 _ThisCommonMessage {libObjPtr}
963 BT_ASSERT_DBG(this->isDiscardedPackets());
966 template <typename OtherLibObjT>
967 CommonDiscardedPacketsMessage(const CommonDiscardedPacketsMessage<OtherLibObjT> val) noexcept :
968 _ThisCommonMessage {val}
972 template <typename OtherLibObjT>
973 CommonDiscardedPacketsMessage<LibObjT>
974 operator=(const CommonDiscardedPacketsMessage<OtherLibObjT> val) noexcept
976 _ThisCommonMessage::operator=(val);
980 CommonDiscardedPacketsMessage<const bt_message> asConst() const noexcept
982 return CommonDiscardedPacketsMessage<const bt_message> {*this};
985 _Stream stream() const noexcept
988 internal::CommonDiscardedPacketsMessageSpec<LibObjT>::stream(this->libObjPtr())};
991 OptionalBorrowedObject<ConstClockClass> streamClassDefaultClockClass() const noexcept
993 return bt_message_discarded_packets_borrow_stream_class_default_clock_class_const(
997 ConstClockSnapshot beginningDefaultClockSnapshot() const noexcept
999 const auto libObjPtr =
1000 bt_message_discarded_packets_borrow_beginning_default_clock_snapshot_const(
1003 return ConstClockSnapshot {libObjPtr};
1006 ConstClockSnapshot endDefaultClockSnapshot() const noexcept
1008 const auto libObjPtr =
1009 bt_message_discarded_packets_borrow_end_default_clock_snapshot_const(this->libObjPtr());
1011 return ConstClockSnapshot {libObjPtr};
1014 CommonDiscardedPacketsMessage count(const std::uint64_t count) const noexcept
1016 static_assert(!std::is_const<LibObjT>::value,
1017 "Not available with `bt2::ConstDiscardedPacketsMessage`.");
1019 bt_message_discarded_packets_set_count(this->libObjPtr(), count);
1023 bt2s::optional<std::uint64_t> count() const noexcept
1025 std::uint64_t count;
1027 if (bt_message_discarded_packets_get_count(this->libObjPtr(), &count)) {
1031 return bt2s::nullopt;
1034 Shared shared() const noexcept
1036 return Shared::createWithRef(*this);
1040 using DiscardedPacketsMessage = CommonDiscardedPacketsMessage<bt_message>;
1041 using ConstDiscardedPacketsMessage = CommonDiscardedPacketsMessage<const bt_message>;
1043 namespace internal {
1045 struct DiscardedPacketsMessageTypeDescr
1047 using Const = ConstDiscardedPacketsMessage;
1048 using NonConst = DiscardedPacketsMessage;
1052 struct TypeDescr<DiscardedPacketsMessage> : public DiscardedPacketsMessageTypeDescr
1057 struct TypeDescr<ConstDiscardedPacketsMessage> : public DiscardedPacketsMessageTypeDescr
1061 } /* namespace internal */
1063 template <typename LibObjT>
1064 class CommonMessageIteratorInactivityMessage final : public CommonMessage<LibObjT>
1067 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
1070 using typename CommonMessage<LibObjT>::LibObjPtr;
1071 using Shared = SharedMessage<CommonMessageIteratorInactivityMessage<LibObjT>, LibObjT>;
1073 explicit CommonMessageIteratorInactivityMessage(const LibObjPtr libObjPtr) noexcept :
1074 _ThisCommonMessage {libObjPtr}
1076 BT_ASSERT_DBG(this->isMessageIteratorInactivity());
1079 template <typename OtherLibObjT>
1080 CommonMessageIteratorInactivityMessage(
1081 const CommonMessageIteratorInactivityMessage<OtherLibObjT> val) noexcept :
1082 _ThisCommonMessage {val}
1086 template <typename OtherLibObjT>
1087 CommonMessageIteratorInactivityMessage<LibObjT>
1088 operator=(const CommonMessageIteratorInactivityMessage<OtherLibObjT> val) noexcept
1090 _ThisCommonMessage::operator=(val);
1094 CommonMessageIteratorInactivityMessage<const bt_message> asConst() const noexcept
1096 return CommonMessageIteratorInactivityMessage<const bt_message> {*this};
1099 ConstClockSnapshot clockSnapshot() const noexcept
1101 const auto libObjPtr =
1102 bt_message_message_iterator_inactivity_borrow_clock_snapshot_const(this->libObjPtr());
1104 return ConstClockSnapshot {libObjPtr};
1107 Shared shared() const noexcept
1109 return Shared::createWithRef(*this);
1113 using MessageIteratorInactivityMessage = CommonMessageIteratorInactivityMessage<bt_message>;
1114 using ConstMessageIteratorInactivityMessage =
1115 CommonMessageIteratorInactivityMessage<const bt_message>;
1117 namespace internal {
1119 struct MessageIteratorInactivityMessageTypeDescr
1121 using Const = ConstMessageIteratorInactivityMessage;
1122 using NonConst = MessageIteratorInactivityMessage;
1126 struct TypeDescr<MessageIteratorInactivityMessage> :
1127 public MessageIteratorInactivityMessageTypeDescr
1132 struct TypeDescr<ConstMessageIteratorInactivityMessage> :
1133 public MessageIteratorInactivityMessageTypeDescr
1137 } /* namespace internal */
1139 template <typename LibObjT>
1140 CommonStreamBeginningMessage<LibObjT> CommonMessage<LibObjT>::asStreamBeginning() const noexcept
1142 return CommonStreamBeginningMessage<LibObjT> {this->libObjPtr()};
1145 template <typename LibObjT>
1146 CommonStreamEndMessage<LibObjT> CommonMessage<LibObjT>::asStreamEnd() const noexcept
1148 return CommonStreamEndMessage<LibObjT> {this->libObjPtr()};
1151 template <typename LibObjT>
1152 CommonPacketBeginningMessage<LibObjT> CommonMessage<LibObjT>::asPacketBeginning() const noexcept
1154 return CommonPacketBeginningMessage<LibObjT> {this->libObjPtr()};
1157 template <typename LibObjT>
1158 CommonPacketEndMessage<LibObjT> CommonMessage<LibObjT>::asPacketEnd() const noexcept
1160 return CommonPacketEndMessage<LibObjT> {this->libObjPtr()};
1163 template <typename LibObjT>
1164 CommonEventMessage<LibObjT> CommonMessage<LibObjT>::asEvent() const noexcept
1166 return CommonEventMessage<LibObjT> {this->libObjPtr()};
1169 template <typename LibObjT>
1170 CommonDiscardedEventsMessage<LibObjT> CommonMessage<LibObjT>::asDiscardedEvents() const noexcept
1172 return CommonDiscardedEventsMessage<LibObjT> {this->libObjPtr()};
1175 template <typename LibObjT>
1176 CommonDiscardedPacketsMessage<LibObjT> CommonMessage<LibObjT>::asDiscardedPackets() const noexcept
1178 return CommonDiscardedPacketsMessage<LibObjT> {this->libObjPtr()};
1181 template <typename LibObjT>
1182 CommonMessageIteratorInactivityMessage<LibObjT>
1183 CommonMessage<LibObjT>::asMessageIteratorInactivity() const noexcept
1185 return CommonMessageIteratorInactivityMessage<LibObjT> {this->libObjPtr()};
1188 } /* namespace bt2 */
1190 #endif /* BABELTRACE_CPP_COMMON_BT2_MESSAGE_HPP */