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 "shared-object.hpp"
27 struct MessageRefFuncs final
29 static void get(const bt_message * const libObjPtr) noexcept
31 bt_message_get_ref(libObjPtr);
34 static void put(const bt_message * const libObjPtr) noexcept
36 bt_message_put_ref(libObjPtr);
40 } /* namespace internal */
42 template <typename ObjT, typename LibObjT>
43 using SharedMessage = SharedObject<ObjT, LibObjT, internal::MessageRefFuncs>;
45 template <typename LibObjT>
46 class CommonStreamBeginningMessage;
48 template <typename LibObjT>
49 class CommonStreamEndMessage;
51 template <typename LibObjT>
52 class CommonEventMessage;
54 template <typename LibObjT>
55 class CommonPacketBeginningMessage;
57 template <typename LibObjT>
58 class CommonPacketEndMessage;
60 template <typename LibObjT>
61 class CommonDiscardedEventsMessage;
63 template <typename LibObjT>
64 class CommonDiscardedPacketsMessage;
66 template <typename LibObjT>
67 class CommonMessageIteratorInactivityMessage;
69 enum class MessageType
71 STREAM_BEGINNING = BT_MESSAGE_TYPE_STREAM_BEGINNING,
72 STREAM_END = BT_MESSAGE_TYPE_STREAM_END,
73 EVENT = BT_MESSAGE_TYPE_EVENT,
74 PACKET_BEGINNING = BT_MESSAGE_TYPE_PACKET_BEGINNING,
75 PACKET_END = BT_MESSAGE_TYPE_PACKET_END,
76 DISCARDED_EVENTS = BT_MESSAGE_TYPE_DISCARDED_EVENTS,
77 DISCARDED_PACKETS = BT_MESSAGE_TYPE_DISCARDED_PACKETS,
78 MESSAGE_ITERATOR_INACTIVITY = BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY,
81 template <typename LibObjT>
82 class CommonMessage : public BorrowedObject<LibObjT>
85 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
88 using _ThisCommonMessage = CommonMessage<LibObjT>;
91 using typename BorrowedObject<LibObjT>::LibObjPtr;
92 using Shared = SharedMessage<CommonMessage<LibObjT>, LibObjT>;
94 explicit CommonMessage(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
98 template <typename OtherLibObjT>
99 CommonMessage(const CommonMessage<OtherLibObjT> val) noexcept : _ThisBorrowedObject {val}
103 template <typename OtherLibObjT>
104 _ThisCommonMessage operator=(const CommonMessage<OtherLibObjT> val) noexcept
106 _ThisBorrowedObject::operator=(val);
110 CommonMessage<const bt_message> asConst() const noexcept
112 return CommonMessage<const bt_message> {*this};
115 MessageType type() const noexcept
117 return static_cast<MessageType>(bt_message_get_type(this->libObjPtr()));
120 bool isStreamBeginning() const noexcept
122 return this->type() == MessageType::STREAM_BEGINNING;
125 bool isStreamEnd() const noexcept
127 return this->type() == MessageType::STREAM_END;
130 bool isEvent() const noexcept
132 return this->type() == MessageType::EVENT;
135 bool isPacketBeginning() const noexcept
137 return this->type() == MessageType::PACKET_BEGINNING;
140 bool isPacketEnd() const noexcept
142 return this->type() == MessageType::PACKET_END;
145 bool isDiscardedEvents() const noexcept
147 return this->type() == MessageType::DISCARDED_EVENTS;
150 bool isDiscardedPackets() const noexcept
152 return this->type() == MessageType::DISCARDED_PACKETS;
155 bool isMessageIteratorInactivity() const noexcept
157 return this->type() == MessageType::MESSAGE_ITERATOR_INACTIVITY;
160 Shared shared() const noexcept
162 return Shared::createWithRef(*this);
165 template <typename MessageT>
166 MessageT as() const noexcept
168 return MessageT {this->libObjPtr()};
171 CommonStreamBeginningMessage<LibObjT> asStreamBeginning() const noexcept;
172 CommonStreamEndMessage<LibObjT> asStreamEnd() const noexcept;
173 CommonEventMessage<LibObjT> asEvent() const noexcept;
174 CommonPacketBeginningMessage<LibObjT> asPacketBeginning() const noexcept;
175 CommonPacketEndMessage<LibObjT> asPacketEnd() const noexcept;
176 CommonDiscardedEventsMessage<LibObjT> asDiscardedEvents() const noexcept;
177 CommonDiscardedPacketsMessage<LibObjT> asDiscardedPackets() const noexcept;
178 CommonMessageIteratorInactivityMessage<LibObjT> asMessageIteratorInactivity() const noexcept;
181 using Message = CommonMessage<bt_message>;
182 using ConstMessage = CommonMessage<const bt_message>;
186 struct MessageTypeDescr
188 using Const = ConstMessage;
189 using NonConst = Message;
193 struct TypeDescr<Message> : public MessageTypeDescr
198 struct TypeDescr<ConstMessage> : public MessageTypeDescr
202 template <typename LibObjT>
203 struct CommonStreamBeginningMessageSpec;
205 /* Functions specific to mutable stream beginning messages */
207 struct CommonStreamBeginningMessageSpec<bt_message> final
209 static bt_stream *stream(bt_message * const libObjPtr) noexcept
211 return bt_message_stream_beginning_borrow_stream(libObjPtr);
215 /* Functions specific to constant stream beginning messages */
217 struct CommonStreamBeginningMessageSpec<const bt_message> final
219 static const bt_stream *stream(const bt_message * const libObjPtr) noexcept
221 return bt_message_stream_beginning_borrow_stream_const(libObjPtr);
225 } /* namespace internal */
227 template <typename LibObjT>
228 class CommonStreamBeginningMessage final : public CommonMessage<LibObjT>
231 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
232 using _Stream = internal::DepStream<LibObjT>;
235 using typename CommonMessage<LibObjT>::LibObjPtr;
236 using Shared = SharedMessage<CommonStreamBeginningMessage<LibObjT>, LibObjT>;
238 explicit CommonStreamBeginningMessage(const LibObjPtr libObjPtr) noexcept :
239 _ThisCommonMessage {libObjPtr}
241 BT_ASSERT_DBG(this->isStreamBeginning());
244 template <typename OtherLibObjT>
245 CommonStreamBeginningMessage(const CommonStreamBeginningMessage<OtherLibObjT> val) noexcept :
246 _ThisCommonMessage {val}
250 template <typename OtherLibObjT>
251 CommonStreamBeginningMessage<LibObjT>
252 operator=(const CommonStreamBeginningMessage<OtherLibObjT> val) noexcept
254 _ThisCommonMessage::operator=(val);
258 CommonStreamBeginningMessage<const bt_message> asConst() const noexcept
260 return CommonStreamBeginningMessage<const bt_message> {*this};
263 _Stream stream() const noexcept
266 internal::CommonStreamBeginningMessageSpec<LibObjT>::stream(this->libObjPtr())};
269 void defaultClockSnapshot(const std::uint64_t val) const noexcept
271 static_assert(!std::is_const<LibObjT>::value,
272 "Not available with `bt2::ConstStreamBeginningMessage`.");
274 bt_message_stream_beginning_set_default_clock_snapshot(this->libObjPtr(), val);
277 bt2s::optional<ConstClockSnapshot> defaultClockSnapshot() const noexcept
279 const bt_clock_snapshot *libObjPtr;
280 const auto state = bt_message_stream_beginning_borrow_default_clock_snapshot_const(
281 this->libObjPtr(), &libObjPtr);
283 if (state == BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN) {
284 return ConstClockSnapshot {libObjPtr};
287 return bt2s::nullopt;
290 Shared shared() const noexcept
292 return Shared::createWithRef(*this);
296 using StreamBeginningMessage = CommonStreamBeginningMessage<bt_message>;
297 using ConstStreamBeginningMessage = CommonStreamBeginningMessage<const bt_message>;
301 struct StreamBeginningMessageTypeDescr
303 using Const = ConstStreamBeginningMessage;
304 using NonConst = StreamBeginningMessage;
308 struct TypeDescr<StreamBeginningMessage> : public StreamBeginningMessageTypeDescr
313 struct TypeDescr<ConstStreamBeginningMessage> : public StreamBeginningMessageTypeDescr
317 template <typename LibObjT>
318 struct CommonStreamEndMessageSpec;
320 /* Functions specific to mutable stream end messages */
322 struct CommonStreamEndMessageSpec<bt_message> final
324 static bt_stream *stream(bt_message * const libObjPtr) noexcept
326 return bt_message_stream_end_borrow_stream(libObjPtr);
330 /* Functions specific to constant stream end messages */
332 struct CommonStreamEndMessageSpec<const bt_message> final
334 static const bt_stream *stream(const bt_message * const libObjPtr) noexcept
336 return bt_message_stream_end_borrow_stream_const(libObjPtr);
340 } /* namespace internal */
342 template <typename LibObjT>
343 class CommonStreamEndMessage final : public CommonMessage<LibObjT>
346 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
347 using _Stream = internal::DepStream<LibObjT>;
350 using typename CommonMessage<LibObjT>::LibObjPtr;
351 using Shared = SharedMessage<CommonStreamEndMessage<LibObjT>, LibObjT>;
353 explicit CommonStreamEndMessage(const LibObjPtr libObjPtr) noexcept :
354 _ThisCommonMessage {libObjPtr}
356 BT_ASSERT_DBG(this->isStreamEnd());
359 template <typename OtherLibObjT>
360 CommonStreamEndMessage(const CommonStreamEndMessage<OtherLibObjT> val) noexcept :
361 _ThisCommonMessage {val}
365 template <typename OtherLibObjT>
366 CommonStreamEndMessage<LibObjT>
367 operator=(const CommonStreamEndMessage<OtherLibObjT> val) noexcept
369 _ThisCommonMessage::operator=(val);
373 CommonStreamEndMessage<const bt_message> asConst() const noexcept
375 return CommonStreamEndMessage<const bt_message> {*this};
378 _Stream stream() const noexcept
380 return _Stream {internal::CommonStreamEndMessageSpec<LibObjT>::stream(this->libObjPtr())};
383 void defaultClockSnapshot(const std::uint64_t val) const noexcept
385 static_assert(!std::is_const<LibObjT>::value,
386 "Not available with `bt2::ConstStreamEndMessage`.");
388 bt_message_stream_end_set_default_clock_snapshot(this->libObjPtr(), val);
391 bt2s::optional<ConstClockSnapshot> defaultClockSnapshot() const noexcept
393 const bt_clock_snapshot *libObjPtr;
394 const auto state = bt_message_stream_end_borrow_default_clock_snapshot_const(
395 this->libObjPtr(), &libObjPtr);
397 if (state == BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN) {
398 return ConstClockSnapshot {libObjPtr};
401 return bt2s::nullopt;
404 Shared shared() const noexcept
406 return Shared::createWithRef(*this);
410 using StreamEndMessage = CommonStreamEndMessage<bt_message>;
411 using ConstStreamEndMessage = CommonStreamEndMessage<const bt_message>;
415 struct StreamEndMessageTypeDescr
417 using Const = ConstStreamEndMessage;
418 using NonConst = StreamEndMessage;
422 struct TypeDescr<StreamEndMessage> : public StreamEndMessageTypeDescr
427 struct TypeDescr<ConstStreamEndMessage> : public StreamEndMessageTypeDescr
431 template <typename LibObjT>
432 struct CommonPacketBeginningMessageSpec;
434 /* Functions specific to mutable packet beginning messages */
436 struct CommonPacketBeginningMessageSpec<bt_message> final
438 static bt_packet *packet(bt_message * const libObjPtr) noexcept
440 return bt_message_packet_beginning_borrow_packet(libObjPtr);
444 /* Functions specific to constant packet beginning messages */
446 struct CommonPacketBeginningMessageSpec<const bt_message> final
448 static const bt_packet *packet(const bt_message * const libObjPtr) noexcept
450 return bt_message_packet_beginning_borrow_packet_const(libObjPtr);
454 } /* namespace internal */
456 template <typename LibObjT>
457 class CommonPacketBeginningMessage final : public CommonMessage<LibObjT>
460 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
461 using _Packet = internal::DepPacket<LibObjT>;
464 using typename CommonMessage<LibObjT>::LibObjPtr;
465 using Shared = SharedMessage<CommonPacketBeginningMessage<LibObjT>, LibObjT>;
467 explicit CommonPacketBeginningMessage(const LibObjPtr libObjPtr) noexcept :
468 _ThisCommonMessage {libObjPtr}
470 BT_ASSERT_DBG(this->isPacketBeginning());
473 template <typename OtherLibObjT>
474 CommonPacketBeginningMessage(const CommonPacketBeginningMessage<OtherLibObjT> val) noexcept :
475 _ThisCommonMessage {val}
479 template <typename OtherLibObjT>
480 CommonPacketBeginningMessage<LibObjT>
481 operator=(const CommonPacketBeginningMessage<OtherLibObjT> val) noexcept
483 _ThisCommonMessage::operator=(val);
487 CommonPacketBeginningMessage<const bt_message> asConst() const noexcept
489 return CommonPacketBeginningMessage<const bt_message> {*this};
492 _Packet packet() const noexcept
495 internal::CommonPacketBeginningMessageSpec<LibObjT>::packet(this->libObjPtr())};
498 void defaultClockSnapshot(const std::uint64_t val) const noexcept
500 static_assert(!std::is_const<LibObjT>::value,
501 "Not available with `bt2::ConstPacketBeginningMessage`.");
503 bt_message_packet_beginning_set_default_clock_snapshot(this->libObjPtr(), val);
506 ConstClockSnapshot defaultClockSnapshot() const noexcept
508 const auto libObjPtr =
509 bt_message_packet_beginning_borrow_default_clock_snapshot_const(this->libObjPtr());
511 return ConstClockSnapshot {libObjPtr};
514 Shared shared() const noexcept
516 return Shared::createWithRef(*this);
520 using PacketBeginningMessage = CommonPacketBeginningMessage<bt_message>;
521 using ConstPacketBeginningMessage = CommonPacketBeginningMessage<const bt_message>;
525 struct PacketBeginningMessageTypeDescr
527 using Const = ConstPacketBeginningMessage;
528 using NonConst = PacketBeginningMessage;
532 struct TypeDescr<PacketBeginningMessage> : public PacketBeginningMessageTypeDescr
537 struct TypeDescr<ConstPacketBeginningMessage> : public PacketBeginningMessageTypeDescr
541 template <typename LibObjT>
542 struct CommonPacketEndMessageSpec;
544 /* Functions specific to mutable packet end messages */
546 struct CommonPacketEndMessageSpec<bt_message> final
548 static bt_packet *packet(bt_message * const libObjPtr) noexcept
550 return bt_message_packet_end_borrow_packet(libObjPtr);
554 /* Functions specific to constant packet end messages */
556 struct CommonPacketEndMessageSpec<const bt_message> final
558 static const bt_packet *packet(const bt_message * const libObjPtr) noexcept
560 return bt_message_packet_end_borrow_packet_const(libObjPtr);
564 } /* namespace internal */
566 template <typename LibObjT>
567 class CommonPacketEndMessage final : public CommonMessage<LibObjT>
570 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
571 using _Packet = internal::DepPacket<LibObjT>;
574 using typename CommonMessage<LibObjT>::LibObjPtr;
575 using Shared = SharedMessage<CommonPacketEndMessage<LibObjT>, LibObjT>;
577 explicit CommonPacketEndMessage(const LibObjPtr libObjPtr) noexcept :
578 _ThisCommonMessage {libObjPtr}
580 BT_ASSERT_DBG(this->isPacketEnd());
583 template <typename OtherLibObjT>
584 CommonPacketEndMessage(const CommonPacketEndMessage<OtherLibObjT> val) noexcept :
585 _ThisCommonMessage {val}
589 template <typename OtherLibObjT>
590 CommonPacketEndMessage<LibObjT>
591 operator=(const CommonPacketEndMessage<OtherLibObjT> val) noexcept
593 _ThisCommonMessage::operator=(val);
597 CommonPacketEndMessage<const bt_message> asConst() const noexcept
599 return CommonPacketEndMessage<const bt_message> {*this};
602 _Packet packet() const noexcept
604 return _Packet {internal::CommonPacketEndMessageSpec<LibObjT>::packet(this->libObjPtr())};
607 void defaultClockSnapshot(const std::uint64_t val) const noexcept
609 static_assert(!std::is_const<LibObjT>::value,
610 "Not available with `bt2::ConstPacketEndMessage`.");
612 bt_message_packet_end_set_default_clock_snapshot(this->libObjPtr(), val);
615 ConstClockSnapshot defaultClockSnapshot() const noexcept
617 const auto libObjPtr =
618 bt_message_packet_end_borrow_default_clock_snapshot_const(this->libObjPtr());
620 return ConstClockSnapshot {libObjPtr};
623 Shared shared() const noexcept
625 return Shared::createWithRef(*this);
629 using PacketEndMessage = CommonPacketEndMessage<bt_message>;
630 using ConstPacketEndMessage = CommonPacketEndMessage<const bt_message>;
634 struct PacketEndMessageTypeDescr
636 using Const = ConstPacketEndMessage;
637 using NonConst = PacketEndMessage;
641 struct TypeDescr<PacketEndMessage> : public PacketEndMessageTypeDescr
646 struct TypeDescr<ConstPacketEndMessage> : public PacketEndMessageTypeDescr
650 template <typename LibObjT>
651 struct CommonEventMessageSpec;
653 /* Functions specific to mutable event messages */
655 struct CommonEventMessageSpec<bt_message> final
657 static bt_event *event(bt_message * const libObjPtr) noexcept
659 return bt_message_event_borrow_event(libObjPtr);
663 /* Functions specific to constant event messages */
665 struct CommonEventMessageSpec<const bt_message> final
667 static const bt_event *event(const bt_message * const libObjPtr) noexcept
669 return bt_message_event_borrow_event_const(libObjPtr);
673 } /* namespace internal */
675 template <typename LibObjT>
676 class CommonEventMessage final : public CommonMessage<LibObjT>
679 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
680 using _Event = internal::DepType<LibObjT, CommonEvent<bt_event>, CommonEvent<const bt_event>>;
683 using typename CommonMessage<LibObjT>::LibObjPtr;
684 using Shared = SharedMessage<CommonEventMessage<LibObjT>, LibObjT>;
686 explicit CommonEventMessage(const LibObjPtr libObjPtr) noexcept : _ThisCommonMessage {libObjPtr}
688 BT_ASSERT_DBG(this->isEvent());
691 template <typename OtherLibObjT>
692 CommonEventMessage(const CommonEventMessage<OtherLibObjT> val) noexcept :
693 _ThisCommonMessage {val}
697 template <typename OtherLibObjT>
698 CommonEventMessage<LibObjT> operator=(const CommonEventMessage<OtherLibObjT> val) noexcept
700 _ThisCommonMessage::operator=(val);
704 CommonEventMessage<const bt_message> asConst() const noexcept
706 return CommonEventMessage<const bt_message> {*this};
709 _Event event() const noexcept
711 return _Event {internal::CommonEventMessageSpec<LibObjT>::event(this->libObjPtr())};
714 bt2s::optional<ConstClockClass> streamClassDefaultClockClass() const noexcept
716 if (const auto libClkClsPtr =
717 bt_message_event_borrow_stream_class_default_clock_class_const(this->libObjPtr())) {
718 return ConstClockClass {libClkClsPtr};
721 return bt2s::nullopt;
724 ConstClockSnapshot defaultClockSnapshot() const noexcept
726 const auto libObjPtr =
727 bt_message_event_borrow_default_clock_snapshot_const(this->libObjPtr());
729 return ConstClockSnapshot {libObjPtr};
732 Shared shared() const noexcept
734 return Shared::createWithRef(*this);
738 using EventMessage = CommonEventMessage<bt_message>;
739 using ConstEventMessage = CommonEventMessage<const bt_message>;
743 struct EventMessageTypeDescr
745 using Const = ConstEventMessage;
746 using NonConst = EventMessage;
750 struct TypeDescr<EventMessage> : public EventMessageTypeDescr
755 struct TypeDescr<ConstEventMessage> : public EventMessageTypeDescr
759 template <typename LibObjT>
760 struct CommonDiscardedEventsMessageSpec;
762 /* Functions specific to mutable discarded events messages */
764 struct CommonDiscardedEventsMessageSpec<bt_message> final
766 static bt_stream *stream(bt_message * const libObjPtr) noexcept
768 return bt_message_discarded_events_borrow_stream(libObjPtr);
772 /* Functions specific to constant discarded events messages */
774 struct CommonDiscardedEventsMessageSpec<const bt_message> final
776 static const bt_stream *stream(const bt_message * const libObjPtr) noexcept
778 return bt_message_discarded_events_borrow_stream_const(libObjPtr);
782 } /* namespace internal */
784 template <typename LibObjT>
785 class CommonDiscardedEventsMessage final : public CommonMessage<LibObjT>
788 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
789 using _Stream = internal::DepStream<LibObjT>;
792 using typename CommonMessage<LibObjT>::LibObjPtr;
793 using Shared = SharedMessage<CommonDiscardedEventsMessage<LibObjT>, LibObjT>;
795 explicit CommonDiscardedEventsMessage(const LibObjPtr libObjPtr) noexcept :
796 _ThisCommonMessage {libObjPtr}
798 BT_ASSERT_DBG(this->isDiscardedEvents());
801 template <typename OtherLibObjT>
802 CommonDiscardedEventsMessage(const CommonDiscardedEventsMessage<OtherLibObjT> val) noexcept :
803 _ThisCommonMessage {val}
807 template <typename OtherLibObjT>
808 CommonDiscardedEventsMessage<LibObjT>
809 operator=(const CommonDiscardedEventsMessage<OtherLibObjT> val) noexcept
811 _ThisCommonMessage::operator=(val);
815 CommonDiscardedEventsMessage<const bt_message> asConst() const noexcept
817 return CommonDiscardedEventsMessage<const bt_message> {*this};
820 _Stream stream() const 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) const noexcept
845 static_assert(!std::is_const<LibObjT>::value,
846 "Not available with `bt2::ConstDiscardedEventsMessage`.");
848 bt_message_discarded_events_set_count(this->libObjPtr(), count);
851 bt2s::optional<std::uint64_t> count() const noexcept
854 const auto avail = bt_message_discarded_events_get_count(this->libObjPtr(), &count);
860 return bt2s::nullopt;
863 Shared shared() const noexcept
865 return Shared::createWithRef(*this);
869 using DiscardedEventsMessage = CommonDiscardedEventsMessage<bt_message>;
870 using ConstDiscardedEventsMessage = CommonDiscardedEventsMessage<const bt_message>;
874 struct DiscardedEventsMessageTypeDescr
876 using Const = ConstDiscardedEventsMessage;
877 using NonConst = DiscardedEventsMessage;
881 struct TypeDescr<DiscardedEventsMessage> : public DiscardedEventsMessageTypeDescr
886 struct TypeDescr<ConstDiscardedEventsMessage> : public DiscardedEventsMessageTypeDescr
890 template <typename LibObjT>
891 struct CommonDiscardedPacketsMessageSpec;
893 /* Functions specific to mutable discarded packets messages */
895 struct CommonDiscardedPacketsMessageSpec<bt_message> final
897 static bt_stream *stream(bt_message * const libObjPtr) noexcept
899 return bt_message_discarded_packets_borrow_stream(libObjPtr);
903 /* Functions specific to constant discarded packets messages */
905 struct CommonDiscardedPacketsMessageSpec<const bt_message> final
907 static const bt_stream *stream(const bt_message * const libObjPtr) noexcept
909 return bt_message_discarded_packets_borrow_stream_const(libObjPtr);
913 } /* namespace internal */
915 template <typename LibObjT>
916 class CommonDiscardedPacketsMessage final : public CommonMessage<LibObjT>
919 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
920 using _Stream = internal::DepStream<LibObjT>;
923 using typename CommonMessage<LibObjT>::LibObjPtr;
924 using Shared = SharedMessage<CommonDiscardedPacketsMessage<LibObjT>, LibObjT>;
926 explicit CommonDiscardedPacketsMessage(const LibObjPtr libObjPtr) noexcept :
927 _ThisCommonMessage {libObjPtr}
929 BT_ASSERT_DBG(this->isDiscardedPackets());
932 template <typename OtherLibObjT>
933 CommonDiscardedPacketsMessage(const CommonDiscardedPacketsMessage<OtherLibObjT> val) noexcept :
934 _ThisCommonMessage {val}
938 template <typename OtherLibObjT>
939 CommonDiscardedPacketsMessage<LibObjT>
940 operator=(const CommonDiscardedPacketsMessage<OtherLibObjT> val) noexcept
942 _ThisCommonMessage::operator=(val);
946 CommonDiscardedPacketsMessage<const bt_message> asConst() const noexcept
948 return CommonDiscardedPacketsMessage<const bt_message> {*this};
951 _Stream stream() const noexcept
954 internal::CommonDiscardedPacketsMessageSpec<LibObjT>::stream(this->libObjPtr())};
957 ConstClockSnapshot beginningDefaultClockSnapshot() const noexcept
959 const auto libObjPtr =
960 bt_message_discarded_packets_borrow_beginning_default_clock_snapshot_const(
963 return ConstClockSnapshot {libObjPtr};
966 ConstClockSnapshot endDefaultClockSnapshot() const noexcept
968 const auto libObjPtr =
969 bt_message_discarded_packets_borrow_end_default_clock_snapshot_const(this->libObjPtr());
971 return ConstClockSnapshot {libObjPtr};
974 void count(const std::uint64_t count) const noexcept
976 static_assert(!std::is_const<LibObjT>::value,
977 "Not available with `bt2::ConstDiscardedPacketsMessage`.");
979 bt_message_discarded_packets_set_count(this->libObjPtr(), count);
982 bt2s::optional<std::uint64_t> count() const noexcept
985 const auto avail = bt_message_discarded_packets_get_count(this->libObjPtr(), &count);
991 return bt2s::nullopt;
994 Shared shared() const noexcept
996 return Shared::createWithRef(*this);
1000 using DiscardedPacketsMessage = CommonDiscardedPacketsMessage<bt_message>;
1001 using ConstDiscardedPacketsMessage = CommonDiscardedPacketsMessage<const bt_message>;
1003 namespace internal {
1005 struct DiscardedPacketsMessageTypeDescr
1007 using Const = ConstDiscardedPacketsMessage;
1008 using NonConst = DiscardedPacketsMessage;
1012 struct TypeDescr<DiscardedPacketsMessage> : public DiscardedPacketsMessageTypeDescr
1017 struct TypeDescr<ConstDiscardedPacketsMessage> : public DiscardedPacketsMessageTypeDescr
1021 } /* namespace internal */
1023 template <typename LibObjT>
1024 class CommonMessageIteratorInactivityMessage final : public CommonMessage<LibObjT>
1027 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
1030 using typename CommonMessage<LibObjT>::LibObjPtr;
1031 using Shared = SharedMessage<CommonMessageIteratorInactivityMessage<LibObjT>, LibObjT>;
1033 explicit CommonMessageIteratorInactivityMessage(const LibObjPtr libObjPtr) noexcept :
1034 _ThisCommonMessage {libObjPtr}
1036 BT_ASSERT_DBG(this->isMessageIteratorInactivity());
1039 template <typename OtherLibObjT>
1040 CommonMessageIteratorInactivityMessage(
1041 const CommonMessageIteratorInactivityMessage<OtherLibObjT> val) noexcept :
1042 _ThisCommonMessage {val}
1046 template <typename OtherLibObjT>
1047 CommonMessageIteratorInactivityMessage<LibObjT>
1048 operator=(const CommonMessageIteratorInactivityMessage<OtherLibObjT> val) noexcept
1050 _ThisCommonMessage::operator=(val);
1054 CommonMessageIteratorInactivityMessage<const bt_message> asConst() const noexcept
1056 return CommonMessageIteratorInactivityMessage<const bt_message> {*this};
1059 ConstClockSnapshot clockSnapshot() const noexcept
1061 const auto libObjPtr =
1062 bt_message_message_iterator_inactivity_borrow_clock_snapshot_const(this->libObjPtr());
1064 return ConstClockSnapshot {libObjPtr};
1067 Shared shared() const noexcept
1069 return Shared::createWithRef(*this);
1073 using MessageIteratorInactivityMessage = CommonMessageIteratorInactivityMessage<bt_message>;
1074 using ConstMessageIteratorInactivityMessage =
1075 CommonMessageIteratorInactivityMessage<const bt_message>;
1077 namespace internal {
1079 struct MessageIteratorInactivityMessageTypeDescr
1081 using Const = ConstMessageIteratorInactivityMessage;
1082 using NonConst = MessageIteratorInactivityMessage;
1086 struct TypeDescr<MessageIteratorInactivityMessage> :
1087 public MessageIteratorInactivityMessageTypeDescr
1092 struct TypeDescr<ConstMessageIteratorInactivityMessage> :
1093 public MessageIteratorInactivityMessageTypeDescr
1097 } /* namespace internal */
1099 template <typename LibObjT>
1100 CommonStreamBeginningMessage<LibObjT> CommonMessage<LibObjT>::asStreamBeginning() const noexcept
1102 BT_ASSERT_DBG(this->isStreamBeginning());
1103 return CommonStreamBeginningMessage<LibObjT> {this->libObjPtr()};
1106 template <typename LibObjT>
1107 CommonStreamEndMessage<LibObjT> CommonMessage<LibObjT>::asStreamEnd() const noexcept
1109 BT_ASSERT_DBG(this->isStreamEnd());
1110 return CommonStreamEndMessage<LibObjT> {this->libObjPtr()};
1113 template <typename LibObjT>
1114 CommonPacketBeginningMessage<LibObjT> CommonMessage<LibObjT>::asPacketBeginning() const noexcept
1116 BT_ASSERT_DBG(this->isPacketBeginning());
1117 return CommonPacketBeginningMessage<LibObjT> {this->libObjPtr()};
1120 template <typename LibObjT>
1121 CommonPacketEndMessage<LibObjT> CommonMessage<LibObjT>::asPacketEnd() const noexcept
1123 BT_ASSERT_DBG(this->isPacketEnd());
1124 return CommonPacketEndMessage<LibObjT> {this->libObjPtr()};
1127 template <typename LibObjT>
1128 CommonEventMessage<LibObjT> CommonMessage<LibObjT>::asEvent() const noexcept
1130 BT_ASSERT_DBG(this->isEvent());
1131 return CommonEventMessage<LibObjT> {this->libObjPtr()};
1134 template <typename LibObjT>
1135 CommonDiscardedEventsMessage<LibObjT> CommonMessage<LibObjT>::asDiscardedEvents() const noexcept
1137 BT_ASSERT_DBG(this->isDiscardedEvents());
1138 return CommonDiscardedEventsMessage<LibObjT> {this->libObjPtr()};
1141 template <typename LibObjT>
1142 CommonDiscardedPacketsMessage<LibObjT> CommonMessage<LibObjT>::asDiscardedPackets() const noexcept
1144 BT_ASSERT_DBG(this->isDiscardedPackets());
1145 return CommonDiscardedPacketsMessage<LibObjT> {this->libObjPtr()};
1148 template <typename LibObjT>
1149 CommonMessageIteratorInactivityMessage<LibObjT>
1150 CommonMessage<LibObjT>::asMessageIteratorInactivity() const noexcept
1152 BT_ASSERT_DBG(this->isMessageIteratorInactivity());
1153 return CommonMessageIteratorInactivityMessage<LibObjT> {this->libObjPtr()};
1156 } /* namespace bt2 */
1158 #endif /* BABELTRACE_CPP_COMMON_BT2_MESSAGE_HPP */