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/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;
235 typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>,
236 CommonStream<bt_stream>>::type;
239 using Shared = SharedMessage<CommonStreamBeginningMessage<LibObjT>, LibObjT>;
241 explicit CommonStreamBeginningMessage(const _LibObjPtr libObjPtr) noexcept :
242 _ThisCommonMessage {libObjPtr}
244 BT_ASSERT_DBG(this->isStreamBeginning());
247 template <typename OtherLibObjT>
248 CommonStreamBeginningMessage(const CommonStreamBeginningMessage<OtherLibObjT> val) noexcept :
249 _ThisCommonMessage {val}
253 template <typename OtherLibObjT>
254 CommonStreamBeginningMessage<LibObjT>&
255 operator=(const CommonStreamBeginningMessage<OtherLibObjT> val) noexcept
257 _ThisCommonMessage::operator=(val);
261 CommonStreamBeginningMessage<const bt_message> asConst() const noexcept
263 return CommonStreamBeginningMessage<const bt_message> {*this};
266 _Stream stream() const noexcept
269 internal::CommonStreamBeginningMessageSpec<LibObjT>::stream(this->libObjPtr())};
272 void defaultClockSnapshot(const std::uint64_t val) const noexcept
274 static_assert(!std::is_const<LibObjT>::value,
275 "Not available with `bt2::ConstStreamBeginningMessage`.");
277 bt_message_stream_beginning_set_default_clock_snapshot(this->libObjPtr(), val);
280 nonstd::optional<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) {
287 return ConstClockSnapshot {libObjPtr};
290 return nonstd::nullopt;
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>::_LibObjPtr;
350 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
353 typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>,
354 CommonStream<bt_stream>>::type;
357 using Shared = SharedMessage<CommonStreamEndMessage<LibObjT>, LibObjT>;
359 explicit CommonStreamEndMessage(const _LibObjPtr libObjPtr) noexcept :
360 _ThisCommonMessage {libObjPtr}
362 BT_ASSERT_DBG(this->isStreamEnd());
365 template <typename OtherLibObjT>
366 CommonStreamEndMessage(const CommonStreamEndMessage<OtherLibObjT> val) noexcept :
367 _ThisCommonMessage {val}
371 template <typename OtherLibObjT>
372 CommonStreamEndMessage<LibObjT>&
373 operator=(const CommonStreamEndMessage<OtherLibObjT> val) noexcept
375 _ThisCommonMessage::operator=(val);
379 CommonStreamEndMessage<const bt_message> asConst() const noexcept
381 return CommonStreamEndMessage<const bt_message> {*this};
384 _Stream stream() const noexcept
386 return _Stream {internal::CommonStreamEndMessageSpec<LibObjT>::stream(this->libObjPtr())};
389 void defaultClockSnapshot(const std::uint64_t val) const noexcept
391 static_assert(!std::is_const<LibObjT>::value,
392 "Not available with `bt2::ConstStreamEndMessage`.");
394 bt_message_stream_end_set_default_clock_snapshot(this->libObjPtr(), val);
397 nonstd::optional<ConstClockSnapshot> defaultClockSnapshot() const noexcept
399 const bt_clock_snapshot *libObjPtr;
400 const auto state = bt_message_stream_end_borrow_default_clock_snapshot_const(
401 this->libObjPtr(), &libObjPtr);
403 if (state == BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN) {
404 return ConstClockSnapshot {libObjPtr};
407 return nonstd::nullopt;
410 Shared shared() const noexcept
412 return Shared::createWithRef(*this);
416 using StreamEndMessage = CommonStreamEndMessage<bt_message>;
417 using ConstStreamEndMessage = CommonStreamEndMessage<const bt_message>;
421 struct StreamEndMessageTypeDescr
423 using Const = ConstStreamEndMessage;
424 using NonConst = StreamEndMessage;
428 struct TypeDescr<StreamEndMessage> : public StreamEndMessageTypeDescr
433 struct TypeDescr<ConstStreamEndMessage> : public StreamEndMessageTypeDescr
437 template <typename LibObjT>
438 struct CommonPacketBeginningMessageSpec;
440 /* Functions specific to mutable packet beginning messages */
442 struct CommonPacketBeginningMessageSpec<bt_message> final
444 static bt_packet *packet(bt_message * const libObjPtr) noexcept
446 return bt_message_packet_beginning_borrow_packet(libObjPtr);
450 /* Functions specific to constant packet beginning messages */
452 struct CommonPacketBeginningMessageSpec<const bt_message> final
454 static const bt_packet *packet(const bt_message * const libObjPtr) noexcept
456 return bt_message_packet_beginning_borrow_packet_const(libObjPtr);
460 } /* namespace internal */
462 template <typename LibObjT>
463 class CommonPacketBeginningMessage final : public CommonMessage<LibObjT>
466 using typename CommonMessage<LibObjT>::_LibObjPtr;
467 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
470 typename std::conditional<std::is_const<LibObjT>::value, CommonPacket<const bt_packet>,
471 CommonPacket<bt_packet>>::type;
474 using Shared = SharedMessage<CommonPacketBeginningMessage<LibObjT>, LibObjT>;
476 explicit CommonPacketBeginningMessage(const _LibObjPtr libObjPtr) noexcept :
477 _ThisCommonMessage {libObjPtr}
479 BT_ASSERT_DBG(this->isPacketBeginning());
482 template <typename OtherLibObjT>
483 CommonPacketBeginningMessage(const CommonPacketBeginningMessage<OtherLibObjT> val) noexcept :
484 _ThisCommonMessage {val}
488 template <typename OtherLibObjT>
489 CommonPacketBeginningMessage<LibObjT>&
490 operator=(const CommonPacketBeginningMessage<OtherLibObjT> val) noexcept
492 _ThisCommonMessage::operator=(val);
496 CommonPacketBeginningMessage<const bt_message> asConst() const noexcept
498 return CommonPacketBeginningMessage<const bt_message> {*this};
501 _Packet packet() const noexcept
504 internal::CommonPacketBeginningMessageSpec<LibObjT>::packet(this->libObjPtr())};
507 void defaultClockSnapshot(const std::uint64_t val) const noexcept
509 static_assert(!std::is_const<LibObjT>::value,
510 "Not available with `bt2::ConstPacketBeginningMessage`.");
512 bt_message_packet_beginning_set_default_clock_snapshot(this->libObjPtr(), val);
515 ConstClockSnapshot defaultClockSnapshot() const noexcept
517 const auto libObjPtr =
518 bt_message_packet_beginning_borrow_default_clock_snapshot_const(this->libObjPtr());
520 return ConstClockSnapshot {libObjPtr};
523 Shared shared() const noexcept
525 return Shared::createWithRef(*this);
529 using PacketBeginningMessage = CommonPacketBeginningMessage<bt_message>;
530 using ConstPacketBeginningMessage = CommonPacketBeginningMessage<const bt_message>;
534 struct PacketBeginningMessageTypeDescr
536 using Const = ConstPacketBeginningMessage;
537 using NonConst = PacketBeginningMessage;
541 struct TypeDescr<PacketBeginningMessage> : public PacketBeginningMessageTypeDescr
546 struct TypeDescr<ConstPacketBeginningMessage> : public PacketBeginningMessageTypeDescr
550 template <typename LibObjT>
551 struct CommonPacketEndMessageSpec;
553 /* Functions specific to mutable packet end messages */
555 struct CommonPacketEndMessageSpec<bt_message> final
557 static bt_packet *packet(bt_message * const libObjPtr) noexcept
559 return bt_message_packet_end_borrow_packet(libObjPtr);
563 /* Functions specific to constant packet end messages */
565 struct CommonPacketEndMessageSpec<const bt_message> final
567 static const bt_packet *packet(const bt_message * const libObjPtr) noexcept
569 return bt_message_packet_end_borrow_packet_const(libObjPtr);
573 } /* namespace internal */
575 template <typename LibObjT>
576 class CommonPacketEndMessage final : public CommonMessage<LibObjT>
579 using typename CommonMessage<LibObjT>::_LibObjPtr;
580 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
583 typename std::conditional<std::is_const<LibObjT>::value, CommonPacket<const bt_packet>,
584 CommonPacket<bt_packet>>::type;
587 using Shared = SharedMessage<CommonPacketEndMessage<LibObjT>, LibObjT>;
589 explicit CommonPacketEndMessage(const _LibObjPtr libObjPtr) noexcept :
590 _ThisCommonMessage {libObjPtr}
592 BT_ASSERT_DBG(this->isPacketEnd());
595 template <typename OtherLibObjT>
596 CommonPacketEndMessage(const CommonPacketEndMessage<OtherLibObjT> val) noexcept :
597 _ThisCommonMessage {val}
601 template <typename OtherLibObjT>
602 CommonPacketEndMessage<LibObjT>&
603 operator=(const CommonPacketEndMessage<OtherLibObjT> val) noexcept
605 _ThisCommonMessage::operator=(val);
609 CommonPacketEndMessage<const bt_message> asConst() const noexcept
611 return CommonPacketEndMessage<const bt_message> {*this};
614 _Packet packet() const noexcept
616 return _Packet {internal::CommonPacketEndMessageSpec<LibObjT>::packet(this->libObjPtr())};
619 void defaultClockSnapshot(const std::uint64_t val) const noexcept
621 static_assert(!std::is_const<LibObjT>::value,
622 "Not available with `bt2::ConstPacketEndMessage`.");
624 bt_message_packet_end_set_default_clock_snapshot(this->libObjPtr(), val);
627 ConstClockSnapshot defaultClockSnapshot() const noexcept
629 const auto libObjPtr =
630 bt_message_packet_end_borrow_default_clock_snapshot_const(this->libObjPtr());
632 return ConstClockSnapshot {libObjPtr};
635 Shared shared() const noexcept
637 return Shared::createWithRef(*this);
641 using PacketEndMessage = CommonPacketEndMessage<bt_message>;
642 using ConstPacketEndMessage = CommonPacketEndMessage<const bt_message>;
646 struct PacketEndMessageTypeDescr
648 using Const = ConstPacketEndMessage;
649 using NonConst = PacketEndMessage;
653 struct TypeDescr<PacketEndMessage> : public PacketEndMessageTypeDescr
658 struct TypeDescr<ConstPacketEndMessage> : public PacketEndMessageTypeDescr
662 template <typename LibObjT>
663 struct CommonEventMessageSpec;
665 /* Functions specific to mutable event messages */
667 struct CommonEventMessageSpec<bt_message> final
669 static bt_event *event(bt_message * const libObjPtr) noexcept
671 return bt_message_event_borrow_event(libObjPtr);
675 /* Functions specific to constant event messages */
677 struct CommonEventMessageSpec<const bt_message> final
679 static const bt_event *event(const bt_message * const libObjPtr) noexcept
681 return bt_message_event_borrow_event_const(libObjPtr);
685 } /* namespace internal */
687 template <typename LibObjT>
688 class CommonEventMessage final : public CommonMessage<LibObjT>
691 using typename CommonMessage<LibObjT>::_LibObjPtr;
692 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
695 typename std::conditional<std::is_const<LibObjT>::value, CommonEvent<const bt_event>,
696 CommonEvent<bt_event>>::type;
699 using Shared = SharedMessage<CommonEventMessage<LibObjT>, LibObjT>;
701 explicit CommonEventMessage(const _LibObjPtr libObjPtr) noexcept :
702 _ThisCommonMessage {libObjPtr}
704 BT_ASSERT_DBG(this->isEvent());
707 template <typename OtherLibObjT>
708 CommonEventMessage(const CommonEventMessage<OtherLibObjT> val) noexcept :
709 _ThisCommonMessage {val}
713 template <typename OtherLibObjT>
714 CommonEventMessage<LibObjT>& operator=(const CommonEventMessage<OtherLibObjT> val) noexcept
716 _ThisCommonMessage::operator=(val);
720 CommonEventMessage<const bt_message> asConst() const noexcept
722 return CommonEventMessage<const bt_message> {*this};
725 _Event event() const noexcept
727 return _Event {internal::CommonEventMessageSpec<LibObjT>::event(this->libObjPtr())};
730 ConstClockSnapshot defaultClockSnapshot() const noexcept
732 const auto libObjPtr =
733 bt_message_event_borrow_default_clock_snapshot_const(this->libObjPtr());
735 return ConstClockSnapshot {libObjPtr};
738 Shared shared() const noexcept
740 return Shared::createWithRef(*this);
744 using EventMessage = CommonEventMessage<bt_message>;
745 using ConstEventMessage = CommonEventMessage<const bt_message>;
749 struct EventMessageTypeDescr
751 using Const = ConstEventMessage;
752 using NonConst = EventMessage;
756 struct TypeDescr<EventMessage> : public EventMessageTypeDescr
761 struct TypeDescr<ConstEventMessage> : public EventMessageTypeDescr
765 template <typename LibObjT>
766 struct CommonDiscardedEventsMessageSpec;
768 /* Functions specific to mutable discarded events messages */
770 struct CommonDiscardedEventsMessageSpec<bt_message> final
772 static bt_stream *stream(bt_message * const libObjPtr) noexcept
774 return bt_message_discarded_events_borrow_stream(libObjPtr);
778 /* Functions specific to constant discarded events messages */
780 struct CommonDiscardedEventsMessageSpec<const bt_message> final
782 static const bt_stream *stream(const bt_message * const libObjPtr) noexcept
784 return bt_message_discarded_events_borrow_stream_const(libObjPtr);
788 } /* namespace internal */
790 template <typename LibObjT>
791 class CommonDiscardedEventsMessage final : public CommonMessage<LibObjT>
794 using typename CommonMessage<LibObjT>::_LibObjPtr;
795 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
798 typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>,
799 CommonStream<bt_stream>>::type;
802 using Shared = SharedMessage<CommonDiscardedEventsMessage<LibObjT>, LibObjT>;
804 explicit CommonDiscardedEventsMessage(const _LibObjPtr libObjPtr) noexcept :
805 _ThisCommonMessage {libObjPtr}
807 BT_ASSERT_DBG(this->isDiscardedEvents());
810 template <typename OtherLibObjT>
811 CommonDiscardedEventsMessage(const CommonDiscardedEventsMessage<OtherLibObjT> val) noexcept :
812 _ThisCommonMessage {val}
816 template <typename OtherLibObjT>
817 CommonDiscardedEventsMessage<LibObjT>&
818 operator=(const CommonDiscardedEventsMessage<OtherLibObjT> val) noexcept
820 _ThisCommonMessage::operator=(val);
824 CommonDiscardedEventsMessage<const bt_message> asConst() const noexcept
826 return CommonDiscardedEventsMessage<const bt_message> {*this};
829 _Stream stream() const noexcept
832 internal::CommonDiscardedEventsMessageSpec<LibObjT>::stream(this->libObjPtr())};
835 ConstClockSnapshot beginningDefaultClockSnapshot() const noexcept
837 const auto libObjPtr =
838 bt_message_discarded_events_borrow_beginning_default_clock_snapshot_const(
841 return ConstClockSnapshot {libObjPtr};
844 ConstClockSnapshot endDefaultClockSnapshot() const noexcept
846 const auto libObjPtr =
847 bt_message_discarded_events_borrow_end_default_clock_snapshot_const(this->libObjPtr());
849 return ConstClockSnapshot {libObjPtr};
852 void count(const std::uint64_t count) const noexcept
854 static_assert(!std::is_const<LibObjT>::value,
855 "Not available with `bt2::ConstDiscardedEventsMessage`.");
857 bt_message_discarded_events_set_count(this->libObjPtr(), count);
860 nonstd::optional<std::uint64_t> count() const noexcept
863 const auto avail = bt_message_discarded_events_get_count(this->libObjPtr(), &count);
869 return nonstd::nullopt;
872 Shared shared() const noexcept
874 return Shared::createWithRef(*this);
878 using DiscardedEventsMessage = CommonDiscardedEventsMessage<bt_message>;
879 using ConstDiscardedEventsMessage = CommonDiscardedEventsMessage<const bt_message>;
883 struct DiscardedEventsMessageTypeDescr
885 using Const = ConstDiscardedEventsMessage;
886 using NonConst = DiscardedEventsMessage;
890 struct TypeDescr<DiscardedEventsMessage> : public DiscardedEventsMessageTypeDescr
895 struct TypeDescr<ConstDiscardedEventsMessage> : public DiscardedEventsMessageTypeDescr
899 template <typename LibObjT>
900 struct CommonDiscardedPacketsMessageSpec;
902 /* Functions specific to mutable discarded packets messages */
904 struct CommonDiscardedPacketsMessageSpec<bt_message> final
906 static bt_stream *stream(bt_message * const libObjPtr) noexcept
908 return bt_message_discarded_packets_borrow_stream(libObjPtr);
912 /* Functions specific to constant discarded packets messages */
914 struct CommonDiscardedPacketsMessageSpec<const bt_message> final
916 static const bt_stream *stream(const bt_message * const libObjPtr) noexcept
918 return bt_message_discarded_packets_borrow_stream_const(libObjPtr);
922 } /* namespace internal */
924 template <typename LibObjT>
925 class CommonDiscardedPacketsMessage final : public CommonMessage<LibObjT>
928 using typename CommonMessage<LibObjT>::_LibObjPtr;
929 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
932 typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>,
933 CommonStream<bt_stream>>::type;
936 using Shared = SharedMessage<CommonDiscardedPacketsMessage<LibObjT>, LibObjT>;
938 explicit CommonDiscardedPacketsMessage(const _LibObjPtr libObjPtr) noexcept :
939 _ThisCommonMessage {libObjPtr}
941 BT_ASSERT_DBG(this->isDiscardedPackets());
944 template <typename OtherLibObjT>
945 CommonDiscardedPacketsMessage(const CommonDiscardedPacketsMessage<OtherLibObjT> val) noexcept :
946 _ThisCommonMessage {val}
950 template <typename OtherLibObjT>
951 CommonDiscardedPacketsMessage<LibObjT>&
952 operator=(const CommonDiscardedPacketsMessage<OtherLibObjT> val) noexcept
954 _ThisCommonMessage::operator=(val);
958 CommonDiscardedPacketsMessage<const bt_message> asConst() const noexcept
960 return CommonDiscardedPacketsMessage<const bt_message> {*this};
963 _Stream stream() const noexcept
966 internal::CommonDiscardedPacketsMessageSpec<LibObjT>::stream(this->libObjPtr())};
969 ConstClockSnapshot beginningDefaultClockSnapshot() const noexcept
971 const auto libObjPtr =
972 bt_message_discarded_packets_borrow_beginning_default_clock_snapshot_const(
975 return ConstClockSnapshot {libObjPtr};
978 ConstClockSnapshot endDefaultClockSnapshot() const noexcept
980 const auto libObjPtr =
981 bt_message_discarded_packets_borrow_end_default_clock_snapshot_const(this->libObjPtr());
983 return ConstClockSnapshot {libObjPtr};
986 void count(const std::uint64_t count) const noexcept
988 static_assert(!std::is_const<LibObjT>::value,
989 "Not available with `bt2::ConstDiscardedPacketsMessage`.");
991 bt_message_discarded_packets_set_count(this->libObjPtr(), count);
994 nonstd::optional<std::uint64_t> count() const noexcept
997 const auto avail = bt_message_discarded_packets_get_count(this->libObjPtr(), &count);
1003 return nonstd::nullopt;
1006 Shared shared() const noexcept
1008 return Shared::createWithRef(*this);
1012 using DiscardedPacketsMessage = CommonDiscardedPacketsMessage<bt_message>;
1013 using ConstDiscardedPacketsMessage = CommonDiscardedPacketsMessage<const bt_message>;
1015 namespace internal {
1017 struct DiscardedPacketsMessageTypeDescr
1019 using Const = ConstDiscardedPacketsMessage;
1020 using NonConst = DiscardedPacketsMessage;
1024 struct TypeDescr<DiscardedPacketsMessage> : public DiscardedPacketsMessageTypeDescr
1029 struct TypeDescr<ConstDiscardedPacketsMessage> : public DiscardedPacketsMessageTypeDescr
1033 } /* namespace internal */
1035 template <typename LibObjT>
1036 class CommonMessageIteratorInactivityMessage final : public CommonMessage<LibObjT>
1039 using typename CommonMessage<LibObjT>::_LibObjPtr;
1040 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
1043 using Shared = SharedMessage<CommonMessageIteratorInactivityMessage<LibObjT>, LibObjT>;
1045 explicit CommonMessageIteratorInactivityMessage(const _LibObjPtr libObjPtr) noexcept :
1046 _ThisCommonMessage {libObjPtr}
1048 BT_ASSERT_DBG(this->isMessageIteratorInactivity());
1051 template <typename OtherLibObjT>
1052 CommonMessageIteratorInactivityMessage(
1053 const CommonMessageIteratorInactivityMessage<OtherLibObjT> val) noexcept :
1054 _ThisCommonMessage {val}
1058 template <typename OtherLibObjT>
1059 CommonMessageIteratorInactivityMessage<LibObjT>&
1060 operator=(const CommonMessageIteratorInactivityMessage<OtherLibObjT> val) noexcept
1062 _ThisCommonMessage::operator=(val);
1066 CommonMessageIteratorInactivityMessage<const bt_message> asConst() const noexcept
1068 return CommonMessageIteratorInactivityMessage<const bt_message> {*this};
1071 ConstClockSnapshot clockSnapshot() const noexcept
1073 const auto libObjPtr =
1074 bt_message_message_iterator_inactivity_borrow_clock_snapshot_const(this->libObjPtr());
1076 return ConstClockSnapshot {libObjPtr};
1079 Shared shared() const noexcept
1081 return Shared::createWithRef(*this);
1085 using MessageIteratorInactivityMessage = CommonMessageIteratorInactivityMessage<bt_message>;
1086 using ConstMessageIteratorInactivityMessage =
1087 CommonMessageIteratorInactivityMessage<const bt_message>;
1089 namespace internal {
1091 struct MessageIteratorInactivityMessageTypeDescr
1093 using Const = ConstMessageIteratorInactivityMessage;
1094 using NonConst = MessageIteratorInactivityMessage;
1098 struct TypeDescr<MessageIteratorInactivityMessage> :
1099 public MessageIteratorInactivityMessageTypeDescr
1104 struct TypeDescr<ConstMessageIteratorInactivityMessage> :
1105 public MessageIteratorInactivityMessageTypeDescr
1109 } /* namespace internal */
1111 template <typename LibObjT>
1112 CommonStreamBeginningMessage<LibObjT> CommonMessage<LibObjT>::asStreamBeginning() const noexcept
1114 BT_ASSERT_DBG(this->isStreamBeginning());
1115 return CommonStreamBeginningMessage<LibObjT> {this->libObjPtr()};
1118 template <typename LibObjT>
1119 CommonStreamEndMessage<LibObjT> CommonMessage<LibObjT>::asStreamEnd() const noexcept
1121 BT_ASSERT_DBG(this->isStreamEnd());
1122 return CommonStreamEndMessage<LibObjT> {this->libObjPtr()};
1125 template <typename LibObjT>
1126 CommonPacketBeginningMessage<LibObjT> CommonMessage<LibObjT>::asPacketBeginning() const noexcept
1128 BT_ASSERT_DBG(this->isPacketBeginning());
1129 return CommonPacketBeginningMessage<LibObjT> {this->libObjPtr()};
1132 template <typename LibObjT>
1133 CommonPacketEndMessage<LibObjT> CommonMessage<LibObjT>::asPacketEnd() const noexcept
1135 BT_ASSERT_DBG(this->isPacketEnd());
1136 return CommonPacketEndMessage<LibObjT> {this->libObjPtr()};
1139 template <typename LibObjT>
1140 CommonEventMessage<LibObjT> CommonMessage<LibObjT>::asEvent() const noexcept
1142 BT_ASSERT_DBG(this->isEvent());
1143 return CommonEventMessage<LibObjT> {this->libObjPtr()};
1146 template <typename LibObjT>
1147 CommonDiscardedEventsMessage<LibObjT> CommonMessage<LibObjT>::asDiscardedEvents() const noexcept
1149 BT_ASSERT_DBG(this->isDiscardedEvents());
1150 return CommonDiscardedEventsMessage<LibObjT> {this->libObjPtr()};
1153 template <typename LibObjT>
1154 CommonDiscardedPacketsMessage<LibObjT> CommonMessage<LibObjT>::asDiscardedPackets() const noexcept
1156 BT_ASSERT_DBG(this->isDiscardedPackets());
1157 return CommonDiscardedPacketsMessage<LibObjT> {this->libObjPtr()};
1160 template <typename LibObjT>
1161 CommonMessageIteratorInactivityMessage<LibObjT>
1162 CommonMessage<LibObjT>::asMessageIteratorInactivity() const noexcept
1164 BT_ASSERT_DBG(this->isMessageIteratorInactivity());
1165 return CommonMessageIteratorInactivityMessage<LibObjT> {this->libObjPtr()};
1168 } /* namespace bt2 */
1170 #endif /* BABELTRACE_CPP_COMMON_BT2_MESSAGE_HPP */