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/trace-ir.hpp"
17 #include "cpp-common/optional.hpp"
19 #include "internal/borrowed-obj.hpp"
20 #include "internal/shared-obj.hpp"
21 #include "internal/utils.hpp"
26 struct MessageRefFuncs final
28 static void get(const bt_message * const libObjPtr)
30 bt_message_get_ref(libObjPtr);
33 static void put(const bt_message * const libObjPtr)
35 bt_message_put_ref(libObjPtr);
39 template <typename ObjT, typename LibObjT>
40 using SharedMessage = internal::SharedObj<ObjT, LibObjT, internal::MessageRefFuncs>;
42 } /* namespace internal */
44 template <typename LibObjT>
45 class CommonStreamBeginningMessage;
47 template <typename LibObjT>
48 class CommonStreamEndMessage;
50 template <typename LibObjT>
51 class CommonEventMessage;
53 template <typename LibObjT>
54 class CommonPacketBeginningMessage;
56 template <typename LibObjT>
57 class CommonPacketEndMessage;
59 template <typename LibObjT>
60 class CommonDiscardedEventsMessage;
62 template <typename LibObjT>
63 class CommonDiscardedPacketsMessage;
65 template <typename LibObjT>
66 class CommonMessageIteratorInactivityMessage;
68 enum class MessageType
70 STREAM_BEGINNING = BT_MESSAGE_TYPE_STREAM_BEGINNING,
71 STREAM_END = BT_MESSAGE_TYPE_STREAM_END,
72 EVENT = BT_MESSAGE_TYPE_EVENT,
73 PACKET_BEGINNING = BT_MESSAGE_TYPE_PACKET_BEGINNING,
74 PACKET_END = BT_MESSAGE_TYPE_PACKET_END,
75 DISCARDED_EVENTS = BT_MESSAGE_TYPE_DISCARDED_EVENTS,
76 DISCARDED_PACKETS = BT_MESSAGE_TYPE_DISCARDED_PACKETS,
77 MESSAGE_ITERATOR_INACTIVITY = BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY,
80 template <typename LibObjT>
81 class CommonMessage : public internal::BorrowedObj<LibObjT>
84 using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
87 using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
88 using _ThisCommonMessage = CommonMessage<LibObjT>;
91 using Shared = internal::SharedMessage<CommonMessage<LibObjT>, LibObjT>;
93 explicit CommonMessage(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr}
97 template <typename OtherLibObjT>
98 CommonMessage(const CommonMessage<OtherLibObjT> val) noexcept : _ThisBorrowedObj {val}
102 template <typename OtherLibObjT>
103 _ThisCommonMessage& operator=(const CommonMessage<OtherLibObjT> val) noexcept
105 _ThisBorrowedObj::operator=(val);
109 MessageType type() const noexcept
111 return static_cast<MessageType>(bt_message_get_type(this->libObjPtr()));
114 bool isStreamBeginning() const noexcept
116 return this->type() == MessageType::STREAM_BEGINNING;
119 bool isStreamEnd() const noexcept
121 return this->type() == MessageType::STREAM_END;
124 bool isEvent() const noexcept
126 return this->type() == MessageType::EVENT;
129 bool isPacketBeginning() const noexcept
131 return this->type() == MessageType::PACKET_BEGINNING;
134 bool isPacketEnd() const noexcept
136 return this->type() == MessageType::PACKET_END;
139 bool isDiscardedEvents() const noexcept
141 return this->type() == MessageType::DISCARDED_EVENTS;
144 bool isDiscardedPackets() const noexcept
146 return this->type() == MessageType::DISCARDED_PACKETS;
149 bool isMessageIteratorInactivity() const noexcept
151 return this->type() == MessageType::MESSAGE_ITERATOR_INACTIVITY;
154 Shared shared() const noexcept
156 return Shared::createWithRef(*this);
159 template <typename MessageT>
160 MessageT as() const noexcept
162 return MessageT {this->libObjPtr()};
165 CommonStreamBeginningMessage<LibObjT> asStreamBeginning() const noexcept;
166 CommonStreamEndMessage<LibObjT> asStreamEnd() const noexcept;
167 CommonEventMessage<LibObjT> asEvent() const noexcept;
168 CommonPacketBeginningMessage<LibObjT> asPacketBeginning() const noexcept;
169 CommonPacketEndMessage<LibObjT> asPacketEnd() const noexcept;
170 CommonDiscardedEventsMessage<LibObjT> asDiscardedEvents() const noexcept;
171 CommonDiscardedPacketsMessage<LibObjT> asDiscardedPackets() const noexcept;
172 CommonMessageIteratorInactivityMessage<LibObjT> asMessageIteratorInactivity() const noexcept;
175 using Message = CommonMessage<bt_message>;
176 using ConstMessage = CommonMessage<const bt_message>;
180 struct MessageTypeDescr
182 using Const = ConstMessage;
183 using NonConst = Message;
187 struct TypeDescr<Message> : public MessageTypeDescr
192 struct TypeDescr<ConstMessage> : public MessageTypeDescr
196 template <typename LibObjT>
197 struct CommonStreamBeginningMessageSpec;
199 /* Functions specific to mutable stream beginning messages */
201 struct CommonStreamBeginningMessageSpec<bt_message> final
203 static bt_stream *stream(bt_message * const libObjPtr) noexcept
205 return bt_message_stream_beginning_borrow_stream(libObjPtr);
209 /* Functions specific to constant stream beginning messages */
211 struct CommonStreamBeginningMessageSpec<const bt_message> final
213 static const bt_stream *stream(const bt_message * const libObjPtr) noexcept
215 return bt_message_stream_beginning_borrow_stream_const(libObjPtr);
219 } /* namespace internal */
221 template <typename LibObjT>
222 class CommonStreamBeginningMessage final : public CommonMessage<LibObjT>
225 using typename CommonMessage<LibObjT>::_LibObjPtr;
226 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
229 typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>,
230 CommonStream<bt_stream>>::type;
233 using Shared = internal::SharedMessage<CommonStreamBeginningMessage<LibObjT>, LibObjT>;
235 explicit CommonStreamBeginningMessage(const _LibObjPtr libObjPtr) noexcept :
236 _ThisCommonMessage {libObjPtr}
238 BT_ASSERT_DBG(this->isStreamBeginning());
241 template <typename OtherLibObjT>
242 CommonStreamBeginningMessage(const CommonStreamBeginningMessage<OtherLibObjT> val) noexcept :
243 _ThisCommonMessage {val}
247 template <typename OtherLibObjT>
248 CommonStreamBeginningMessage<LibObjT>&
249 operator=(const CommonStreamBeginningMessage<OtherLibObjT> val) noexcept
251 _ThisCommonMessage::operator=(val);
255 ConstStream stream() const noexcept
257 return ConstStream {internal::CommonStreamBeginningMessageSpec<const bt_message>::stream(
261 _Stream stream() noexcept
264 internal::CommonStreamBeginningMessageSpec<LibObjT>::stream(this->libObjPtr())};
267 void defaultClockSnapshot(const std::uint64_t val) noexcept
269 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
271 bt_message_stream_beginning_set_default_clock_snapshot(this->libObjPtr(), val);
274 nonstd::optional<ConstClockSnapshot> defaultClockSnapshot() const noexcept
276 const bt_clock_snapshot *libObjPtr;
277 const auto state = bt_message_stream_beginning_borrow_default_clock_snapshot_const(
278 this->libObjPtr(), &libObjPtr);
280 if (state == BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN) {
281 return ConstClockSnapshot {libObjPtr};
284 return nonstd::nullopt;
287 Shared shared() const noexcept
289 return Shared::createWithRef(*this);
293 using StreamBeginningMessage = CommonStreamBeginningMessage<bt_message>;
294 using ConstStreamBeginningMessage = CommonStreamBeginningMessage<const bt_message>;
298 struct StreamBeginningMessageTypeDescr
300 using Const = ConstStreamBeginningMessage;
301 using NonConst = StreamBeginningMessage;
305 struct TypeDescr<StreamBeginningMessage> : public StreamBeginningMessageTypeDescr
310 struct TypeDescr<ConstStreamBeginningMessage> : public StreamBeginningMessageTypeDescr
314 template <typename LibObjT>
315 struct CommonStreamEndMessageSpec;
317 /* Functions specific to mutable stream end messages */
319 struct CommonStreamEndMessageSpec<bt_message> final
321 static bt_stream *stream(bt_message * const libObjPtr) noexcept
323 return bt_message_stream_end_borrow_stream(libObjPtr);
327 /* Functions specific to constant stream end messages */
329 struct CommonStreamEndMessageSpec<const bt_message> final
331 static const bt_stream *stream(const bt_message * const libObjPtr) noexcept
333 return bt_message_stream_end_borrow_stream_const(libObjPtr);
337 } /* namespace internal */
339 template <typename LibObjT>
340 class CommonStreamEndMessage final : public CommonMessage<LibObjT>
343 using typename CommonMessage<LibObjT>::_LibObjPtr;
344 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
347 typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>,
348 CommonStream<bt_stream>>::type;
351 using Shared = internal::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 ConstStream stream() const noexcept
376 internal::CommonStreamEndMessageSpec<const bt_message>::stream(this->libObjPtr())};
379 _Stream stream() noexcept
381 return _Stream {internal::CommonStreamEndMessageSpec<LibObjT>::stream(this->libObjPtr())};
384 void defaultClockSnapshot(const std::uint64_t val) noexcept
386 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
388 bt_message_stream_end_set_default_clock_snapshot(this->libObjPtr(), val);
391 nonstd::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 nonstd::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;
464 typename std::conditional<std::is_const<LibObjT>::value, CommonPacket<const bt_packet>,
465 CommonPacket<bt_packet>>::type;
468 using Shared = internal::SharedMessage<CommonPacketBeginningMessage<LibObjT>, LibObjT>;
470 explicit CommonPacketBeginningMessage(const _LibObjPtr libObjPtr) noexcept :
471 _ThisCommonMessage {libObjPtr}
473 BT_ASSERT_DBG(this->isPacketBeginning());
476 template <typename OtherLibObjT>
477 CommonPacketBeginningMessage(const CommonPacketBeginningMessage<OtherLibObjT> val) noexcept :
478 _ThisCommonMessage {val}
482 template <typename OtherLibObjT>
483 CommonPacketBeginningMessage<LibObjT>&
484 operator=(const CommonPacketBeginningMessage<OtherLibObjT> val) noexcept
486 _ThisCommonMessage::operator=(val);
490 ConstPacket packet() const noexcept
492 return ConstPacket {internal::CommonPacketBeginningMessageSpec<const bt_message>::packet(
496 _Packet packet() noexcept
499 internal::CommonPacketBeginningMessageSpec<LibObjT>::packet(this->libObjPtr())};
502 void defaultClockSnapshot(const std::uint64_t val) noexcept
504 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
506 bt_message_packet_beginning_set_default_clock_snapshot(this->libObjPtr(), val);
509 ConstClockSnapshot defaultClockSnapshot() const noexcept
511 const auto libObjPtr =
512 bt_message_packet_beginning_borrow_default_clock_snapshot_const(this->libObjPtr());
514 return ConstClockSnapshot {libObjPtr};
517 Shared shared() const noexcept
519 return Shared::createWithRef(*this);
523 using PacketBeginningMessage = CommonPacketBeginningMessage<bt_message>;
524 using ConstPacketBeginningMessage = CommonPacketBeginningMessage<const bt_message>;
528 struct PacketBeginningMessageTypeDescr
530 using Const = ConstPacketBeginningMessage;
531 using NonConst = PacketBeginningMessage;
535 struct TypeDescr<PacketBeginningMessage> : public PacketBeginningMessageTypeDescr
540 struct TypeDescr<ConstPacketBeginningMessage> : public PacketBeginningMessageTypeDescr
544 template <typename LibObjT>
545 struct CommonPacketEndMessageSpec;
547 /* Functions specific to mutable packet end messages */
549 struct CommonPacketEndMessageSpec<bt_message> final
551 static bt_packet *packet(bt_message * const libObjPtr) noexcept
553 return bt_message_packet_end_borrow_packet(libObjPtr);
557 /* Functions specific to constant packet end messages */
559 struct CommonPacketEndMessageSpec<const bt_message> final
561 static const bt_packet *packet(const bt_message * const libObjPtr) noexcept
563 return bt_message_packet_end_borrow_packet_const(libObjPtr);
567 } /* namespace internal */
569 template <typename LibObjT>
570 class CommonPacketEndMessage final : public CommonMessage<LibObjT>
573 using typename CommonMessage<LibObjT>::_LibObjPtr;
574 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
577 typename std::conditional<std::is_const<LibObjT>::value, CommonPacket<const bt_packet>,
578 CommonPacket<bt_packet>>::type;
581 using Shared = internal::SharedMessage<CommonPacketEndMessage<LibObjT>, LibObjT>;
583 explicit CommonPacketEndMessage(const _LibObjPtr libObjPtr) noexcept :
584 _ThisCommonMessage {libObjPtr}
586 BT_ASSERT_DBG(this->isPacketEnd());
589 template <typename OtherLibObjT>
590 CommonPacketEndMessage(const CommonPacketEndMessage<OtherLibObjT> val) noexcept :
591 _ThisCommonMessage {val}
595 template <typename OtherLibObjT>
596 CommonPacketEndMessage<LibObjT>&
597 operator=(const CommonPacketEndMessage<OtherLibObjT> val) noexcept
599 _ThisCommonMessage::operator=(val);
603 ConstPacket packet() const noexcept
606 internal::CommonPacketEndMessageSpec<const bt_message>::packet(this->libObjPtr())};
609 _Packet packet() noexcept
611 return _Packet {internal::CommonPacketEndMessageSpec<LibObjT>::packet(this->libObjPtr())};
614 void defaultClockSnapshot(const std::uint64_t val) noexcept
616 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
618 bt_message_packet_end_set_default_clock_snapshot(this->libObjPtr(), val);
621 ConstClockSnapshot defaultClockSnapshot() const noexcept
623 const auto libObjPtr =
624 bt_message_packet_end_borrow_default_clock_snapshot_const(this->libObjPtr());
626 return ConstClockSnapshot {libObjPtr};
629 Shared shared() const noexcept
631 return Shared::createWithRef(*this);
635 using PacketEndMessage = CommonPacketEndMessage<bt_message>;
636 using ConstPacketEndMessage = CommonPacketEndMessage<const bt_message>;
640 struct PacketEndMessageTypeDescr
642 using Const = ConstPacketEndMessage;
643 using NonConst = PacketEndMessage;
647 struct TypeDescr<PacketEndMessage> : public PacketEndMessageTypeDescr
652 struct TypeDescr<ConstPacketEndMessage> : public PacketEndMessageTypeDescr
656 template <typename LibObjT>
657 struct CommonEventMessageSpec;
659 /* Functions specific to mutable event messages */
661 struct CommonEventMessageSpec<bt_message> final
663 static bt_event *event(bt_message * const libObjPtr) noexcept
665 return bt_message_event_borrow_event(libObjPtr);
669 /* Functions specific to constant event messages */
671 struct CommonEventMessageSpec<const bt_message> final
673 static const bt_event *event(const bt_message * const libObjPtr) noexcept
675 return bt_message_event_borrow_event_const(libObjPtr);
679 } /* namespace internal */
681 template <typename LibObjT>
682 class CommonEventMessage final : public CommonMessage<LibObjT>
685 using typename CommonMessage<LibObjT>::_LibObjPtr;
686 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
689 typename std::conditional<std::is_const<LibObjT>::value, CommonEvent<const bt_event>,
690 CommonEvent<bt_event>>::type;
693 using Shared = internal::SharedMessage<CommonEventMessage<LibObjT>, LibObjT>;
695 explicit CommonEventMessage(const _LibObjPtr libObjPtr) noexcept :
696 _ThisCommonMessage {libObjPtr}
698 BT_ASSERT_DBG(this->isEvent());
701 template <typename OtherLibObjT>
702 CommonEventMessage(const CommonEventMessage<OtherLibObjT> val) noexcept :
703 _ThisCommonMessage {val}
707 template <typename OtherLibObjT>
708 CommonEventMessage<LibObjT>& operator=(const CommonEventMessage<OtherLibObjT> val) noexcept
710 _ThisCommonMessage::operator=(val);
714 ConstEvent event() const noexcept
717 internal::CommonEventMessageSpec<const bt_message>::event(this->libObjPtr())};
720 _Event event() noexcept
722 return _Event {internal::CommonEventMessageSpec<LibObjT>::event(this->libObjPtr())};
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;
793 typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>,
794 CommonStream<bt_stream>>::type;
797 using Shared = internal::SharedMessage<CommonDiscardedEventsMessage<LibObjT>, LibObjT>;
799 explicit CommonDiscardedEventsMessage(const _LibObjPtr libObjPtr) noexcept :
800 _ThisCommonMessage {libObjPtr}
802 BT_ASSERT_DBG(this->isDiscardedEvents());
805 template <typename OtherLibObjT>
806 CommonDiscardedEventsMessage(const CommonDiscardedEventsMessage<OtherLibObjT> val) noexcept :
807 _ThisCommonMessage {val}
811 template <typename OtherLibObjT>
812 CommonDiscardedEventsMessage<LibObjT>&
813 operator=(const CommonDiscardedEventsMessage<OtherLibObjT> val) noexcept
815 _ThisCommonMessage::operator=(val);
819 ConstStream stream() const noexcept
821 return ConstStream {internal::CommonDiscardedEventsMessageSpec<const bt_message>::stream(
825 _Stream stream() 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) 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 = internal::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 ConstStream stream() const noexcept
955 return ConstStream {internal::CommonDiscardedPacketsMessageSpec<const bt_message>::stream(
959 _Stream stream() noexcept
962 internal::CommonDiscardedPacketsMessageSpec<LibObjT>::stream(this->libObjPtr())};
965 ConstClockSnapshot beginningDefaultClockSnapshot() const noexcept
967 const auto libObjPtr =
968 bt_message_discarded_packets_borrow_beginning_default_clock_snapshot_const(
971 return ConstClockSnapshot {libObjPtr};
974 ConstClockSnapshot endDefaultClockSnapshot() const noexcept
976 const auto libObjPtr =
977 bt_message_discarded_packets_borrow_end_default_clock_snapshot_const(this->libObjPtr());
979 return ConstClockSnapshot {libObjPtr};
982 void count(const std::uint64_t count) noexcept
984 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
986 bt_message_discarded_packets_set_count(this->libObjPtr(), count);
989 nonstd::optional<std::uint64_t> count() const noexcept
992 const auto avail = bt_message_discarded_packets_get_count(this->libObjPtr(), &count);
998 return nonstd::nullopt;
1001 Shared shared() const noexcept
1003 return Shared::createWithRef(*this);
1007 using DiscardedPacketsMessage = CommonDiscardedPacketsMessage<bt_message>;
1008 using ConstDiscardedPacketsMessage = CommonDiscardedPacketsMessage<const bt_message>;
1010 namespace internal {
1012 struct DiscardedPacketsMessageTypeDescr
1014 using Const = ConstDiscardedPacketsMessage;
1015 using NonConst = DiscardedPacketsMessage;
1019 struct TypeDescr<DiscardedPacketsMessage> : public DiscardedPacketsMessageTypeDescr
1024 struct TypeDescr<ConstDiscardedPacketsMessage> : public DiscardedPacketsMessageTypeDescr
1028 } /* namespace internal */
1030 template <typename LibObjT>
1031 class CommonMessageIteratorInactivityMessage final : public CommonMessage<LibObjT>
1034 using typename CommonMessage<LibObjT>::_LibObjPtr;
1035 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
1039 internal::SharedMessage<CommonMessageIteratorInactivityMessage<LibObjT>, LibObjT>;
1041 explicit CommonMessageIteratorInactivityMessage(const _LibObjPtr libObjPtr) noexcept :
1042 _ThisCommonMessage {libObjPtr}
1044 BT_ASSERT_DBG(this->isMessageIteratorInactivity());
1047 template <typename OtherLibObjT>
1048 CommonMessageIteratorInactivityMessage(
1049 const CommonMessageIteratorInactivityMessage<OtherLibObjT> val) noexcept :
1050 _ThisCommonMessage {val}
1054 template <typename OtherLibObjT>
1055 CommonMessageIteratorInactivityMessage<LibObjT>&
1056 operator=(const CommonMessageIteratorInactivityMessage<OtherLibObjT> val) noexcept
1058 _ThisCommonMessage::operator=(val);
1062 ConstClockSnapshot clockSnapshot() const noexcept
1064 const auto libObjPtr =
1065 bt_message_message_iterator_inactivity_borrow_clock_snapshot_const(this->libObjPtr());
1067 return ConstClockSnapshot {libObjPtr};
1070 Shared shared() const noexcept
1072 return Shared::createWithRef(*this);
1076 using MessageIteratorInactivityMessage = CommonMessageIteratorInactivityMessage<bt_message>;
1077 using ConstMessageIteratorInactivityMessage =
1078 CommonMessageIteratorInactivityMessage<const bt_message>;
1080 namespace internal {
1082 struct MessageIteratorInactivityMessageTypeDescr
1084 using Const = ConstMessageIteratorInactivityMessage;
1085 using NonConst = MessageIteratorInactivityMessage;
1089 struct TypeDescr<MessageIteratorInactivityMessage> :
1090 public MessageIteratorInactivityMessageTypeDescr
1095 struct TypeDescr<ConstMessageIteratorInactivityMessage> :
1096 public MessageIteratorInactivityMessageTypeDescr
1100 } /* namespace internal */
1102 template <typename LibObjT>
1103 CommonStreamBeginningMessage<LibObjT> CommonMessage<LibObjT>::asStreamBeginning() const noexcept
1105 BT_ASSERT_DBG(this->isStreamBeginning());
1106 return CommonStreamBeginningMessage<LibObjT> {this->libObjPtr()};
1109 template <typename LibObjT>
1110 CommonStreamEndMessage<LibObjT> CommonMessage<LibObjT>::asStreamEnd() const noexcept
1112 BT_ASSERT_DBG(this->isStreamEnd());
1113 return CommonStreamEndMessage<LibObjT> {this->libObjPtr()};
1116 template <typename LibObjT>
1117 CommonPacketBeginningMessage<LibObjT> CommonMessage<LibObjT>::asPacketBeginning() const noexcept
1119 BT_ASSERT_DBG(this->isPacketBeginning());
1120 return CommonPacketBeginningMessage<LibObjT> {this->libObjPtr()};
1123 template <typename LibObjT>
1124 CommonPacketEndMessage<LibObjT> CommonMessage<LibObjT>::asPacketEnd() const noexcept
1126 BT_ASSERT_DBG(this->isPacketEnd());
1127 return CommonPacketEndMessage<LibObjT> {this->libObjPtr()};
1130 template <typename LibObjT>
1131 CommonEventMessage<LibObjT> CommonMessage<LibObjT>::asEvent() const noexcept
1133 BT_ASSERT_DBG(this->isEvent());
1134 return CommonEventMessage<LibObjT> {this->libObjPtr()};
1137 template <typename LibObjT>
1138 CommonDiscardedEventsMessage<LibObjT> CommonMessage<LibObjT>::asDiscardedEvents() const noexcept
1140 BT_ASSERT_DBG(this->isDiscardedEvents());
1141 return CommonDiscardedEventsMessage<LibObjT> {this->libObjPtr()};
1144 template <typename LibObjT>
1145 CommonDiscardedPacketsMessage<LibObjT> CommonMessage<LibObjT>::asDiscardedPackets() const noexcept
1147 BT_ASSERT_DBG(this->isDiscardedPackets());
1148 return CommonDiscardedPacketsMessage<LibObjT> {this->libObjPtr()};
1151 template <typename LibObjT>
1152 CommonMessageIteratorInactivityMessage<LibObjT>
1153 CommonMessage<LibObjT>::asMessageIteratorInactivity() const noexcept
1155 BT_ASSERT_DBG(this->isMessageIteratorInactivity());
1156 return CommonMessageIteratorInactivityMessage<LibObjT> {this->libObjPtr()};
1159 } /* namespace bt2 */
1161 #endif /* BABELTRACE_CPP_COMMON_BT2_MESSAGE_HPP */