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 typename BorrowedObject<LibObjT>::_LibObjPtr;
89 using _ThisCommonMessage = CommonMessage<LibObjT>;
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>::_LibObjPtr;
232 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
233 using _Stream = internal::DepStream<LibObjT>;
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>::_LibObjPtr;
347 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
348 using _Stream = internal::DepStream<LibObjT>;
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>::_LibObjPtr;
461 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
462 using _Packet = internal::DepPacket<LibObjT>;
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>::_LibObjPtr;
571 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
572 using _Packet = internal::DepPacket<LibObjT>;
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>::_LibObjPtr;
680 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
681 using _Event = internal::DepType<LibObjT, CommonEvent<bt_event>, CommonEvent<const bt_event>>;
684 using Shared = SharedMessage<CommonEventMessage<LibObjT>, LibObjT>;
686 explicit CommonEventMessage(const _LibObjPtr libObjPtr) noexcept :
687 _ThisCommonMessage {libObjPtr}
689 BT_ASSERT_DBG(this->isEvent());
692 template <typename OtherLibObjT>
693 CommonEventMessage(const CommonEventMessage<OtherLibObjT> val) noexcept :
694 _ThisCommonMessage {val}
698 template <typename OtherLibObjT>
699 CommonEventMessage<LibObjT> operator=(const CommonEventMessage<OtherLibObjT> val) noexcept
701 _ThisCommonMessage::operator=(val);
705 CommonEventMessage<const bt_message> asConst() const noexcept
707 return CommonEventMessage<const bt_message> {*this};
710 _Event event() const noexcept
712 return _Event {internal::CommonEventMessageSpec<LibObjT>::event(this->libObjPtr())};
715 bt2s::optional<ConstClockClass> streamClassDefaultClockClass() const noexcept
717 if (const auto libClkClsPtr =
718 bt_message_event_borrow_stream_class_default_clock_class_const(this->libObjPtr())) {
719 return ConstClockClass {libClkClsPtr};
722 return bt2s::nullopt;
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>::_LibObjPtr;
790 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
791 using _Stream = internal::DepStream<LibObjT>;
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 void 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);
852 bt2s::optional<std::uint64_t> count() const noexcept
855 const auto avail = 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>::_LibObjPtr;
921 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
922 using _Stream = internal::DepStream<LibObjT>;
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 void 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);
983 bt2s::optional<std::uint64_t> count() const noexcept
986 const auto avail = 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>::_LibObjPtr;
1029 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
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 BT_ASSERT_DBG(this->isStreamBeginning());
1104 return CommonStreamBeginningMessage<LibObjT> {this->libObjPtr()};
1107 template <typename LibObjT>
1108 CommonStreamEndMessage<LibObjT> CommonMessage<LibObjT>::asStreamEnd() const noexcept
1110 BT_ASSERT_DBG(this->isStreamEnd());
1111 return CommonStreamEndMessage<LibObjT> {this->libObjPtr()};
1114 template <typename LibObjT>
1115 CommonPacketBeginningMessage<LibObjT> CommonMessage<LibObjT>::asPacketBeginning() const noexcept
1117 BT_ASSERT_DBG(this->isPacketBeginning());
1118 return CommonPacketBeginningMessage<LibObjT> {this->libObjPtr()};
1121 template <typename LibObjT>
1122 CommonPacketEndMessage<LibObjT> CommonMessage<LibObjT>::asPacketEnd() const noexcept
1124 BT_ASSERT_DBG(this->isPacketEnd());
1125 return CommonPacketEndMessage<LibObjT> {this->libObjPtr()};
1128 template <typename LibObjT>
1129 CommonEventMessage<LibObjT> CommonMessage<LibObjT>::asEvent() const noexcept
1131 BT_ASSERT_DBG(this->isEvent());
1132 return CommonEventMessage<LibObjT> {this->libObjPtr()};
1135 template <typename LibObjT>
1136 CommonDiscardedEventsMessage<LibObjT> CommonMessage<LibObjT>::asDiscardedEvents() const noexcept
1138 BT_ASSERT_DBG(this->isDiscardedEvents());
1139 return CommonDiscardedEventsMessage<LibObjT> {this->libObjPtr()};
1142 template <typename LibObjT>
1143 CommonDiscardedPacketsMessage<LibObjT> CommonMessage<LibObjT>::asDiscardedPackets() const noexcept
1145 BT_ASSERT_DBG(this->isDiscardedPackets());
1146 return CommonDiscardedPacketsMessage<LibObjT> {this->libObjPtr()};
1149 template <typename LibObjT>
1150 CommonMessageIteratorInactivityMessage<LibObjT>
1151 CommonMessage<LibObjT>::asMessageIteratorInactivity() const noexcept
1153 BT_ASSERT_DBG(this->isMessageIteratorInactivity());
1154 return CommonMessageIteratorInactivityMessage<LibObjT> {this->libObjPtr()};
1157 } /* namespace bt2 */
1159 #endif /* BABELTRACE_CPP_COMMON_BT2_MESSAGE_HPP */