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, "`LibObjT` must NOT be `const`.");
276 bt_message_stream_beginning_set_default_clock_snapshot(this->libObjPtr(), val);
279 nonstd::optional<ConstClockSnapshot> defaultClockSnapshot() const noexcept
281 const bt_clock_snapshot *libObjPtr;
282 const auto state = bt_message_stream_beginning_borrow_default_clock_snapshot_const(
283 this->libObjPtr(), &libObjPtr);
285 if (state == BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN) {
286 return ConstClockSnapshot {libObjPtr};
289 return nonstd::nullopt;
292 Shared shared() const noexcept
294 return Shared::createWithRef(*this);
298 using StreamBeginningMessage = CommonStreamBeginningMessage<bt_message>;
299 using ConstStreamBeginningMessage = CommonStreamBeginningMessage<const bt_message>;
303 struct StreamBeginningMessageTypeDescr
305 using Const = ConstStreamBeginningMessage;
306 using NonConst = StreamBeginningMessage;
310 struct TypeDescr<StreamBeginningMessage> : public StreamBeginningMessageTypeDescr
315 struct TypeDescr<ConstStreamBeginningMessage> : public StreamBeginningMessageTypeDescr
319 template <typename LibObjT>
320 struct CommonStreamEndMessageSpec;
322 /* Functions specific to mutable stream end messages */
324 struct CommonStreamEndMessageSpec<bt_message> final
326 static bt_stream *stream(bt_message * const libObjPtr) noexcept
328 return bt_message_stream_end_borrow_stream(libObjPtr);
332 /* Functions specific to constant stream end messages */
334 struct CommonStreamEndMessageSpec<const bt_message> final
336 static const bt_stream *stream(const bt_message * const libObjPtr) noexcept
338 return bt_message_stream_end_borrow_stream_const(libObjPtr);
342 } /* namespace internal */
344 template <typename LibObjT>
345 class CommonStreamEndMessage final : public CommonMessage<LibObjT>
348 using typename CommonMessage<LibObjT>::_LibObjPtr;
349 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
352 typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>,
353 CommonStream<bt_stream>>::type;
356 using Shared = SharedMessage<CommonStreamEndMessage<LibObjT>, LibObjT>;
358 explicit CommonStreamEndMessage(const _LibObjPtr libObjPtr) noexcept :
359 _ThisCommonMessage {libObjPtr}
361 BT_ASSERT_DBG(this->isStreamEnd());
364 template <typename OtherLibObjT>
365 CommonStreamEndMessage(const CommonStreamEndMessage<OtherLibObjT> val) noexcept :
366 _ThisCommonMessage {val}
370 template <typename OtherLibObjT>
371 CommonStreamEndMessage<LibObjT>&
372 operator=(const CommonStreamEndMessage<OtherLibObjT> val) noexcept
374 _ThisCommonMessage::operator=(val);
378 CommonStreamEndMessage<const bt_message> asConst() const noexcept
380 return CommonStreamEndMessage<const bt_message> {*this};
383 _Stream stream() const noexcept
385 return _Stream {internal::CommonStreamEndMessageSpec<LibObjT>::stream(this->libObjPtr())};
388 void defaultClockSnapshot(const std::uint64_t val) const noexcept
390 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
392 bt_message_stream_end_set_default_clock_snapshot(this->libObjPtr(), val);
395 nonstd::optional<ConstClockSnapshot> defaultClockSnapshot() const noexcept
397 const bt_clock_snapshot *libObjPtr;
398 const auto state = bt_message_stream_end_borrow_default_clock_snapshot_const(
399 this->libObjPtr(), &libObjPtr);
401 if (state == BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN) {
402 return ConstClockSnapshot {libObjPtr};
405 return nonstd::nullopt;
408 Shared shared() const noexcept
410 return Shared::createWithRef(*this);
414 using StreamEndMessage = CommonStreamEndMessage<bt_message>;
415 using ConstStreamEndMessage = CommonStreamEndMessage<const bt_message>;
419 struct StreamEndMessageTypeDescr
421 using Const = ConstStreamEndMessage;
422 using NonConst = StreamEndMessage;
426 struct TypeDescr<StreamEndMessage> : public StreamEndMessageTypeDescr
431 struct TypeDescr<ConstStreamEndMessage> : public StreamEndMessageTypeDescr
435 template <typename LibObjT>
436 struct CommonPacketBeginningMessageSpec;
438 /* Functions specific to mutable packet beginning messages */
440 struct CommonPacketBeginningMessageSpec<bt_message> final
442 static bt_packet *packet(bt_message * const libObjPtr) noexcept
444 return bt_message_packet_beginning_borrow_packet(libObjPtr);
448 /* Functions specific to constant packet beginning messages */
450 struct CommonPacketBeginningMessageSpec<const bt_message> final
452 static const bt_packet *packet(const bt_message * const libObjPtr) noexcept
454 return bt_message_packet_beginning_borrow_packet_const(libObjPtr);
458 } /* namespace internal */
460 template <typename LibObjT>
461 class CommonPacketBeginningMessage final : public CommonMessage<LibObjT>
464 using typename CommonMessage<LibObjT>::_LibObjPtr;
465 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
468 typename std::conditional<std::is_const<LibObjT>::value, CommonPacket<const bt_packet>,
469 CommonPacket<bt_packet>>::type;
472 using Shared = SharedMessage<CommonPacketBeginningMessage<LibObjT>, LibObjT>;
474 explicit CommonPacketBeginningMessage(const _LibObjPtr libObjPtr) noexcept :
475 _ThisCommonMessage {libObjPtr}
477 BT_ASSERT_DBG(this->isPacketBeginning());
480 template <typename OtherLibObjT>
481 CommonPacketBeginningMessage(const CommonPacketBeginningMessage<OtherLibObjT> val) noexcept :
482 _ThisCommonMessage {val}
486 template <typename OtherLibObjT>
487 CommonPacketBeginningMessage<LibObjT>&
488 operator=(const CommonPacketBeginningMessage<OtherLibObjT> val) noexcept
490 _ThisCommonMessage::operator=(val);
494 CommonPacketBeginningMessage<const bt_message> asConst() const noexcept
496 return CommonPacketBeginningMessage<const bt_message> {*this};
499 _Packet packet() const noexcept
502 internal::CommonPacketBeginningMessageSpec<LibObjT>::packet(this->libObjPtr())};
505 void defaultClockSnapshot(const std::uint64_t val) const noexcept
507 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
509 bt_message_packet_beginning_set_default_clock_snapshot(this->libObjPtr(), val);
512 ConstClockSnapshot defaultClockSnapshot() const noexcept
514 const auto libObjPtr =
515 bt_message_packet_beginning_borrow_default_clock_snapshot_const(this->libObjPtr());
517 return ConstClockSnapshot {libObjPtr};
520 Shared shared() const noexcept
522 return Shared::createWithRef(*this);
526 using PacketBeginningMessage = CommonPacketBeginningMessage<bt_message>;
527 using ConstPacketBeginningMessage = CommonPacketBeginningMessage<const bt_message>;
531 struct PacketBeginningMessageTypeDescr
533 using Const = ConstPacketBeginningMessage;
534 using NonConst = PacketBeginningMessage;
538 struct TypeDescr<PacketBeginningMessage> : public PacketBeginningMessageTypeDescr
543 struct TypeDescr<ConstPacketBeginningMessage> : public PacketBeginningMessageTypeDescr
547 template <typename LibObjT>
548 struct CommonPacketEndMessageSpec;
550 /* Functions specific to mutable packet end messages */
552 struct CommonPacketEndMessageSpec<bt_message> final
554 static bt_packet *packet(bt_message * const libObjPtr) noexcept
556 return bt_message_packet_end_borrow_packet(libObjPtr);
560 /* Functions specific to constant packet end messages */
562 struct CommonPacketEndMessageSpec<const bt_message> final
564 static const bt_packet *packet(const bt_message * const libObjPtr) noexcept
566 return bt_message_packet_end_borrow_packet_const(libObjPtr);
570 } /* namespace internal */
572 template <typename LibObjT>
573 class CommonPacketEndMessage final : public CommonMessage<LibObjT>
576 using typename CommonMessage<LibObjT>::_LibObjPtr;
577 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
580 typename std::conditional<std::is_const<LibObjT>::value, CommonPacket<const bt_packet>,
581 CommonPacket<bt_packet>>::type;
584 using Shared = SharedMessage<CommonPacketEndMessage<LibObjT>, LibObjT>;
586 explicit CommonPacketEndMessage(const _LibObjPtr libObjPtr) noexcept :
587 _ThisCommonMessage {libObjPtr}
589 BT_ASSERT_DBG(this->isPacketEnd());
592 template <typename OtherLibObjT>
593 CommonPacketEndMessage(const CommonPacketEndMessage<OtherLibObjT> val) noexcept :
594 _ThisCommonMessage {val}
598 template <typename OtherLibObjT>
599 CommonPacketEndMessage<LibObjT>&
600 operator=(const CommonPacketEndMessage<OtherLibObjT> val) noexcept
602 _ThisCommonMessage::operator=(val);
606 CommonPacketEndMessage<const bt_message> asConst() const noexcept
608 return CommonPacketEndMessage<const bt_message> {*this};
611 _Packet packet() const noexcept
613 return _Packet {internal::CommonPacketEndMessageSpec<LibObjT>::packet(this->libObjPtr())};
616 void defaultClockSnapshot(const std::uint64_t val) const noexcept
618 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
620 bt_message_packet_end_set_default_clock_snapshot(this->libObjPtr(), val);
623 ConstClockSnapshot defaultClockSnapshot() const noexcept
625 const auto libObjPtr =
626 bt_message_packet_end_borrow_default_clock_snapshot_const(this->libObjPtr());
628 return ConstClockSnapshot {libObjPtr};
631 Shared shared() const noexcept
633 return Shared::createWithRef(*this);
637 using PacketEndMessage = CommonPacketEndMessage<bt_message>;
638 using ConstPacketEndMessage = CommonPacketEndMessage<const bt_message>;
642 struct PacketEndMessageTypeDescr
644 using Const = ConstPacketEndMessage;
645 using NonConst = PacketEndMessage;
649 struct TypeDescr<PacketEndMessage> : public PacketEndMessageTypeDescr
654 struct TypeDescr<ConstPacketEndMessage> : public PacketEndMessageTypeDescr
658 template <typename LibObjT>
659 struct CommonEventMessageSpec;
661 /* Functions specific to mutable event messages */
663 struct CommonEventMessageSpec<bt_message> final
665 static bt_event *event(bt_message * const libObjPtr) noexcept
667 return bt_message_event_borrow_event(libObjPtr);
671 /* Functions specific to constant event messages */
673 struct CommonEventMessageSpec<const bt_message> final
675 static const bt_event *event(const bt_message * const libObjPtr) noexcept
677 return bt_message_event_borrow_event_const(libObjPtr);
681 } /* namespace internal */
683 template <typename LibObjT>
684 class CommonEventMessage final : public CommonMessage<LibObjT>
687 using typename CommonMessage<LibObjT>::_LibObjPtr;
688 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
691 typename std::conditional<std::is_const<LibObjT>::value, CommonEvent<const bt_event>,
692 CommonEvent<bt_event>>::type;
695 using Shared = SharedMessage<CommonEventMessage<LibObjT>, LibObjT>;
697 explicit CommonEventMessage(const _LibObjPtr libObjPtr) noexcept :
698 _ThisCommonMessage {libObjPtr}
700 BT_ASSERT_DBG(this->isEvent());
703 template <typename OtherLibObjT>
704 CommonEventMessage(const CommonEventMessage<OtherLibObjT> val) noexcept :
705 _ThisCommonMessage {val}
709 template <typename OtherLibObjT>
710 CommonEventMessage<LibObjT>& operator=(const CommonEventMessage<OtherLibObjT> val) noexcept
712 _ThisCommonMessage::operator=(val);
716 CommonEventMessage<const bt_message> asConst() const noexcept
718 return CommonEventMessage<const bt_message> {*this};
721 _Event event() const noexcept
723 return _Event {internal::CommonEventMessageSpec<LibObjT>::event(this->libObjPtr())};
726 ConstClockSnapshot defaultClockSnapshot() const noexcept
728 const auto libObjPtr =
729 bt_message_event_borrow_default_clock_snapshot_const(this->libObjPtr());
731 return ConstClockSnapshot {libObjPtr};
734 Shared shared() const noexcept
736 return Shared::createWithRef(*this);
740 using EventMessage = CommonEventMessage<bt_message>;
741 using ConstEventMessage = CommonEventMessage<const bt_message>;
745 struct EventMessageTypeDescr
747 using Const = ConstEventMessage;
748 using NonConst = EventMessage;
752 struct TypeDescr<EventMessage> : public EventMessageTypeDescr
757 struct TypeDescr<ConstEventMessage> : public EventMessageTypeDescr
761 template <typename LibObjT>
762 struct CommonDiscardedEventsMessageSpec;
764 /* Functions specific to mutable discarded events messages */
766 struct CommonDiscardedEventsMessageSpec<bt_message> final
768 static bt_stream *stream(bt_message * const libObjPtr) noexcept
770 return bt_message_discarded_events_borrow_stream(libObjPtr);
774 /* Functions specific to constant discarded events messages */
776 struct CommonDiscardedEventsMessageSpec<const bt_message> final
778 static const bt_stream *stream(const bt_message * const libObjPtr) noexcept
780 return bt_message_discarded_events_borrow_stream_const(libObjPtr);
784 } /* namespace internal */
786 template <typename LibObjT>
787 class CommonDiscardedEventsMessage final : public CommonMessage<LibObjT>
790 using typename CommonMessage<LibObjT>::_LibObjPtr;
791 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
794 typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>,
795 CommonStream<bt_stream>>::type;
798 using Shared = SharedMessage<CommonDiscardedEventsMessage<LibObjT>, LibObjT>;
800 explicit CommonDiscardedEventsMessage(const _LibObjPtr libObjPtr) noexcept :
801 _ThisCommonMessage {libObjPtr}
803 BT_ASSERT_DBG(this->isDiscardedEvents());
806 template <typename OtherLibObjT>
807 CommonDiscardedEventsMessage(const CommonDiscardedEventsMessage<OtherLibObjT> val) noexcept :
808 _ThisCommonMessage {val}
812 template <typename OtherLibObjT>
813 CommonDiscardedEventsMessage<LibObjT>&
814 operator=(const CommonDiscardedEventsMessage<OtherLibObjT> val) noexcept
816 _ThisCommonMessage::operator=(val);
820 CommonDiscardedEventsMessage<const bt_message> asConst() const noexcept
822 return CommonDiscardedEventsMessage<const bt_message> {*this};
825 _Stream stream() const noexcept
828 internal::CommonDiscardedEventsMessageSpec<LibObjT>::stream(this->libObjPtr())};
831 ConstClockSnapshot beginningDefaultClockSnapshot() const noexcept
833 const auto libObjPtr =
834 bt_message_discarded_events_borrow_beginning_default_clock_snapshot_const(
837 return ConstClockSnapshot {libObjPtr};
840 ConstClockSnapshot endDefaultClockSnapshot() const noexcept
842 const auto libObjPtr =
843 bt_message_discarded_events_borrow_end_default_clock_snapshot_const(this->libObjPtr());
845 return ConstClockSnapshot {libObjPtr};
848 void count(const std::uint64_t count) const noexcept
850 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
852 bt_message_discarded_events_set_count(this->libObjPtr(), count);
855 nonstd::optional<std::uint64_t> count() const noexcept
858 const auto avail = bt_message_discarded_events_get_count(this->libObjPtr(), &count);
864 return nonstd::nullopt;
867 Shared shared() const noexcept
869 return Shared::createWithRef(*this);
873 using DiscardedEventsMessage = CommonDiscardedEventsMessage<bt_message>;
874 using ConstDiscardedEventsMessage = CommonDiscardedEventsMessage<const bt_message>;
878 struct DiscardedEventsMessageTypeDescr
880 using Const = ConstDiscardedEventsMessage;
881 using NonConst = DiscardedEventsMessage;
885 struct TypeDescr<DiscardedEventsMessage> : public DiscardedEventsMessageTypeDescr
890 struct TypeDescr<ConstDiscardedEventsMessage> : public DiscardedEventsMessageTypeDescr
894 template <typename LibObjT>
895 struct CommonDiscardedPacketsMessageSpec;
897 /* Functions specific to mutable discarded packets messages */
899 struct CommonDiscardedPacketsMessageSpec<bt_message> final
901 static bt_stream *stream(bt_message * const libObjPtr) noexcept
903 return bt_message_discarded_packets_borrow_stream(libObjPtr);
907 /* Functions specific to constant discarded packets messages */
909 struct CommonDiscardedPacketsMessageSpec<const bt_message> final
911 static const bt_stream *stream(const bt_message * const libObjPtr) noexcept
913 return bt_message_discarded_packets_borrow_stream_const(libObjPtr);
917 } /* namespace internal */
919 template <typename LibObjT>
920 class CommonDiscardedPacketsMessage final : public CommonMessage<LibObjT>
923 using typename CommonMessage<LibObjT>::_LibObjPtr;
924 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
927 typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>,
928 CommonStream<bt_stream>>::type;
931 using Shared = SharedMessage<CommonDiscardedPacketsMessage<LibObjT>, LibObjT>;
933 explicit CommonDiscardedPacketsMessage(const _LibObjPtr libObjPtr) noexcept :
934 _ThisCommonMessage {libObjPtr}
936 BT_ASSERT_DBG(this->isDiscardedPackets());
939 template <typename OtherLibObjT>
940 CommonDiscardedPacketsMessage(const CommonDiscardedPacketsMessage<OtherLibObjT> val) noexcept :
941 _ThisCommonMessage {val}
945 template <typename OtherLibObjT>
946 CommonDiscardedPacketsMessage<LibObjT>&
947 operator=(const CommonDiscardedPacketsMessage<OtherLibObjT> val) noexcept
949 _ThisCommonMessage::operator=(val);
953 CommonDiscardedPacketsMessage<const bt_message> asConst() const noexcept
955 return CommonDiscardedPacketsMessage<const bt_message> {*this};
958 _Stream stream() const noexcept
961 internal::CommonDiscardedPacketsMessageSpec<LibObjT>::stream(this->libObjPtr())};
964 ConstClockSnapshot beginningDefaultClockSnapshot() const noexcept
966 const auto libObjPtr =
967 bt_message_discarded_packets_borrow_beginning_default_clock_snapshot_const(
970 return ConstClockSnapshot {libObjPtr};
973 ConstClockSnapshot endDefaultClockSnapshot() const noexcept
975 const auto libObjPtr =
976 bt_message_discarded_packets_borrow_end_default_clock_snapshot_const(this->libObjPtr());
978 return ConstClockSnapshot {libObjPtr};
981 void count(const std::uint64_t count) const noexcept
983 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
985 bt_message_discarded_packets_set_count(this->libObjPtr(), count);
988 nonstd::optional<std::uint64_t> count() const noexcept
991 const auto avail = bt_message_discarded_packets_get_count(this->libObjPtr(), &count);
997 return nonstd::nullopt;
1000 Shared shared() const noexcept
1002 return Shared::createWithRef(*this);
1006 using DiscardedPacketsMessage = CommonDiscardedPacketsMessage<bt_message>;
1007 using ConstDiscardedPacketsMessage = CommonDiscardedPacketsMessage<const bt_message>;
1009 namespace internal {
1011 struct DiscardedPacketsMessageTypeDescr
1013 using Const = ConstDiscardedPacketsMessage;
1014 using NonConst = DiscardedPacketsMessage;
1018 struct TypeDescr<DiscardedPacketsMessage> : public DiscardedPacketsMessageTypeDescr
1023 struct TypeDescr<ConstDiscardedPacketsMessage> : public DiscardedPacketsMessageTypeDescr
1027 } /* namespace internal */
1029 template <typename LibObjT>
1030 class CommonMessageIteratorInactivityMessage final : public CommonMessage<LibObjT>
1033 using typename CommonMessage<LibObjT>::_LibObjPtr;
1034 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
1037 using Shared = SharedMessage<CommonMessageIteratorInactivityMessage<LibObjT>, LibObjT>;
1039 explicit CommonMessageIteratorInactivityMessage(const _LibObjPtr libObjPtr) noexcept :
1040 _ThisCommonMessage {libObjPtr}
1042 BT_ASSERT_DBG(this->isMessageIteratorInactivity());
1045 template <typename OtherLibObjT>
1046 CommonMessageIteratorInactivityMessage(
1047 const CommonMessageIteratorInactivityMessage<OtherLibObjT> val) noexcept :
1048 _ThisCommonMessage {val}
1052 template <typename OtherLibObjT>
1053 CommonMessageIteratorInactivityMessage<LibObjT>&
1054 operator=(const CommonMessageIteratorInactivityMessage<OtherLibObjT> val) noexcept
1056 _ThisCommonMessage::operator=(val);
1060 CommonMessageIteratorInactivityMessage<const bt_message> asConst() const noexcept
1062 return CommonMessageIteratorInactivityMessage<const bt_message> {*this};
1065 ConstClockSnapshot clockSnapshot() const noexcept
1067 const auto libObjPtr =
1068 bt_message_message_iterator_inactivity_borrow_clock_snapshot_const(this->libObjPtr());
1070 return ConstClockSnapshot {libObjPtr};
1073 Shared shared() const noexcept
1075 return Shared::createWithRef(*this);
1079 using MessageIteratorInactivityMessage = CommonMessageIteratorInactivityMessage<bt_message>;
1080 using ConstMessageIteratorInactivityMessage =
1081 CommonMessageIteratorInactivityMessage<const bt_message>;
1083 namespace internal {
1085 struct MessageIteratorInactivityMessageTypeDescr
1087 using Const = ConstMessageIteratorInactivityMessage;
1088 using NonConst = MessageIteratorInactivityMessage;
1092 struct TypeDescr<MessageIteratorInactivityMessage> :
1093 public MessageIteratorInactivityMessageTypeDescr
1098 struct TypeDescr<ConstMessageIteratorInactivityMessage> :
1099 public MessageIteratorInactivityMessageTypeDescr
1103 } /* namespace internal */
1105 template <typename LibObjT>
1106 CommonStreamBeginningMessage<LibObjT> CommonMessage<LibObjT>::asStreamBeginning() const noexcept
1108 BT_ASSERT_DBG(this->isStreamBeginning());
1109 return CommonStreamBeginningMessage<LibObjT> {this->libObjPtr()};
1112 template <typename LibObjT>
1113 CommonStreamEndMessage<LibObjT> CommonMessage<LibObjT>::asStreamEnd() const noexcept
1115 BT_ASSERT_DBG(this->isStreamEnd());
1116 return CommonStreamEndMessage<LibObjT> {this->libObjPtr()};
1119 template <typename LibObjT>
1120 CommonPacketBeginningMessage<LibObjT> CommonMessage<LibObjT>::asPacketBeginning() const noexcept
1122 BT_ASSERT_DBG(this->isPacketBeginning());
1123 return CommonPacketBeginningMessage<LibObjT> {this->libObjPtr()};
1126 template <typename LibObjT>
1127 CommonPacketEndMessage<LibObjT> CommonMessage<LibObjT>::asPacketEnd() const noexcept
1129 BT_ASSERT_DBG(this->isPacketEnd());
1130 return CommonPacketEndMessage<LibObjT> {this->libObjPtr()};
1133 template <typename LibObjT>
1134 CommonEventMessage<LibObjT> CommonMessage<LibObjT>::asEvent() const noexcept
1136 BT_ASSERT_DBG(this->isEvent());
1137 return CommonEventMessage<LibObjT> {this->libObjPtr()};
1140 template <typename LibObjT>
1141 CommonDiscardedEventsMessage<LibObjT> CommonMessage<LibObjT>::asDiscardedEvents() const noexcept
1143 BT_ASSERT_DBG(this->isDiscardedEvents());
1144 return CommonDiscardedEventsMessage<LibObjT> {this->libObjPtr()};
1147 template <typename LibObjT>
1148 CommonDiscardedPacketsMessage<LibObjT> CommonMessage<LibObjT>::asDiscardedPackets() const noexcept
1150 BT_ASSERT_DBG(this->isDiscardedPackets());
1151 return CommonDiscardedPacketsMessage<LibObjT> {this->libObjPtr()};
1154 template <typename LibObjT>
1155 CommonMessageIteratorInactivityMessage<LibObjT>
1156 CommonMessage<LibObjT>::asMessageIteratorInactivity() const noexcept
1158 BT_ASSERT_DBG(this->isMessageIteratorInactivity());
1159 return CommonMessageIteratorInactivityMessage<LibObjT> {this->libObjPtr()};
1162 } /* namespace bt2 */
1164 #endif /* BABELTRACE_CPP_COMMON_BT2_MESSAGE_HPP */