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 "optional-borrowed-object.hpp"
23 #include "shared-object.hpp"
24 #include "trace-ir.hpp"
29 struct MessageRefFuncs final
31 static void get(const bt_message * const libObjPtr) noexcept
33 bt_message_get_ref(libObjPtr);
36 static void put(const bt_message * const libObjPtr) noexcept
38 bt_message_put_ref(libObjPtr);
42 } /* namespace internal */
44 template <typename ObjT, typename LibObjT>
45 using SharedMessage = SharedObject<ObjT, LibObjT, internal::MessageRefFuncs>;
47 template <typename LibObjT>
48 class CommonStreamBeginningMessage;
50 template <typename LibObjT>
51 class CommonStreamEndMessage;
53 template <typename LibObjT>
54 class CommonEventMessage;
56 template <typename LibObjT>
57 class CommonPacketBeginningMessage;
59 template <typename LibObjT>
60 class CommonPacketEndMessage;
62 template <typename LibObjT>
63 class CommonDiscardedEventsMessage;
65 template <typename LibObjT>
66 class CommonDiscardedPacketsMessage;
68 template <typename LibObjT>
69 class CommonMessageIteratorInactivityMessage;
71 enum class MessageType
73 STREAM_BEGINNING = BT_MESSAGE_TYPE_STREAM_BEGINNING,
74 STREAM_END = BT_MESSAGE_TYPE_STREAM_END,
75 EVENT = BT_MESSAGE_TYPE_EVENT,
76 PACKET_BEGINNING = BT_MESSAGE_TYPE_PACKET_BEGINNING,
77 PACKET_END = BT_MESSAGE_TYPE_PACKET_END,
78 DISCARDED_EVENTS = BT_MESSAGE_TYPE_DISCARDED_EVENTS,
79 DISCARDED_PACKETS = BT_MESSAGE_TYPE_DISCARDED_PACKETS,
80 MESSAGE_ITERATOR_INACTIVITY = BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY,
83 template <typename LibObjT>
84 class CommonMessage : public BorrowedObject<LibObjT>
87 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
90 using _ThisCommonMessage = CommonMessage<LibObjT>;
93 using typename BorrowedObject<LibObjT>::LibObjPtr;
94 using Shared = SharedMessage<CommonMessage<LibObjT>, LibObjT>;
96 explicit CommonMessage(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
100 template <typename OtherLibObjT>
101 CommonMessage(const CommonMessage<OtherLibObjT> val) noexcept : _ThisBorrowedObject {val}
105 template <typename OtherLibObjT>
106 _ThisCommonMessage operator=(const CommonMessage<OtherLibObjT> val) noexcept
108 _ThisBorrowedObject::operator=(val);
112 CommonMessage<const bt_message> asConst() const noexcept
114 return CommonMessage<const bt_message> {*this};
117 MessageType type() const noexcept
119 return static_cast<MessageType>(bt_message_get_type(this->libObjPtr()));
122 bool isStreamBeginning() const noexcept
124 return this->type() == MessageType::STREAM_BEGINNING;
127 bool isStreamEnd() const noexcept
129 return this->type() == MessageType::STREAM_END;
132 bool isEvent() const noexcept
134 return this->type() == MessageType::EVENT;
137 bool isPacketBeginning() const noexcept
139 return this->type() == MessageType::PACKET_BEGINNING;
142 bool isPacketEnd() const noexcept
144 return this->type() == MessageType::PACKET_END;
147 bool isDiscardedEvents() const noexcept
149 return this->type() == MessageType::DISCARDED_EVENTS;
152 bool isDiscardedPackets() const noexcept
154 return this->type() == MessageType::DISCARDED_PACKETS;
157 bool isMessageIteratorInactivity() const noexcept
159 return this->type() == MessageType::MESSAGE_ITERATOR_INACTIVITY;
162 Shared shared() const noexcept
164 return Shared::createWithRef(*this);
167 template <typename MessageT>
168 MessageT as() const noexcept
170 return MessageT {this->libObjPtr()};
173 CommonStreamBeginningMessage<LibObjT> asStreamBeginning() const noexcept;
174 CommonStreamEndMessage<LibObjT> asStreamEnd() const noexcept;
175 CommonEventMessage<LibObjT> asEvent() const noexcept;
176 CommonPacketBeginningMessage<LibObjT> asPacketBeginning() const noexcept;
177 CommonPacketEndMessage<LibObjT> asPacketEnd() const noexcept;
178 CommonDiscardedEventsMessage<LibObjT> asDiscardedEvents() const noexcept;
179 CommonDiscardedPacketsMessage<LibObjT> asDiscardedPackets() const noexcept;
180 CommonMessageIteratorInactivityMessage<LibObjT> asMessageIteratorInactivity() const noexcept;
183 using Message = CommonMessage<bt_message>;
184 using ConstMessage = CommonMessage<const bt_message>;
188 struct MessageTypeDescr
190 using Const = ConstMessage;
191 using NonConst = Message;
195 struct TypeDescr<Message> : public MessageTypeDescr
200 struct TypeDescr<ConstMessage> : public MessageTypeDescr
204 template <typename LibObjT>
205 struct CommonStreamBeginningMessageSpec;
207 /* Functions specific to mutable stream beginning messages */
209 struct CommonStreamBeginningMessageSpec<bt_message> final
211 static bt_stream *stream(bt_message * const libObjPtr) noexcept
213 return bt_message_stream_beginning_borrow_stream(libObjPtr);
217 /* Functions specific to constant stream beginning messages */
219 struct CommonStreamBeginningMessageSpec<const bt_message> final
221 static const bt_stream *stream(const bt_message * const libObjPtr) noexcept
223 return bt_message_stream_beginning_borrow_stream_const(libObjPtr);
227 } /* namespace internal */
229 template <typename LibObjT>
230 class CommonStreamBeginningMessage final : public CommonMessage<LibObjT>
233 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
234 using _Stream = internal::DepStream<LibObjT>;
237 using typename CommonMessage<LibObjT>::LibObjPtr;
238 using Shared = SharedMessage<CommonStreamBeginningMessage<LibObjT>, LibObjT>;
240 explicit CommonStreamBeginningMessage(const LibObjPtr libObjPtr) noexcept :
241 _ThisCommonMessage {libObjPtr}
243 BT_ASSERT_DBG(this->isStreamBeginning());
246 template <typename OtherLibObjT>
247 CommonStreamBeginningMessage(const CommonStreamBeginningMessage<OtherLibObjT> val) noexcept :
248 _ThisCommonMessage {val}
252 template <typename OtherLibObjT>
253 CommonStreamBeginningMessage<LibObjT>
254 operator=(const CommonStreamBeginningMessage<OtherLibObjT> val) noexcept
256 _ThisCommonMessage::operator=(val);
260 CommonStreamBeginningMessage<const bt_message> asConst() const noexcept
262 return CommonStreamBeginningMessage<const bt_message> {*this};
265 _Stream stream() const noexcept
268 internal::CommonStreamBeginningMessageSpec<LibObjT>::stream(this->libObjPtr())};
271 void defaultClockSnapshot(const std::uint64_t val) const noexcept
273 static_assert(!std::is_const<LibObjT>::value,
274 "Not available with `bt2::ConstStreamBeginningMessage`.");
276 bt_message_stream_beginning_set_default_clock_snapshot(this->libObjPtr(), val);
279 OptionalBorrowedObject<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) {
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>::_ThisCommonMessage;
349 using _Stream = internal::DepStream<LibObjT>;
352 using typename CommonMessage<LibObjT>::LibObjPtr;
353 using Shared = SharedMessage<CommonStreamEndMessage<LibObjT>, LibObjT>;
355 explicit CommonStreamEndMessage(const LibObjPtr libObjPtr) noexcept :
356 _ThisCommonMessage {libObjPtr}
358 BT_ASSERT_DBG(this->isStreamEnd());
361 template <typename OtherLibObjT>
362 CommonStreamEndMessage(const CommonStreamEndMessage<OtherLibObjT> val) noexcept :
363 _ThisCommonMessage {val}
367 template <typename OtherLibObjT>
368 CommonStreamEndMessage<LibObjT>
369 operator=(const CommonStreamEndMessage<OtherLibObjT> val) noexcept
371 _ThisCommonMessage::operator=(val);
375 CommonStreamEndMessage<const bt_message> asConst() const noexcept
377 return CommonStreamEndMessage<const bt_message> {*this};
380 _Stream stream() const noexcept
382 return _Stream {internal::CommonStreamEndMessageSpec<LibObjT>::stream(this->libObjPtr())};
385 void defaultClockSnapshot(const std::uint64_t val) const noexcept
387 static_assert(!std::is_const<LibObjT>::value,
388 "Not available with `bt2::ConstStreamEndMessage`.");
390 bt_message_stream_end_set_default_clock_snapshot(this->libObjPtr(), val);
393 OptionalBorrowedObject<ConstClockSnapshot> defaultClockSnapshot() const noexcept
395 const bt_clock_snapshot *libObjPtr;
396 const auto state = bt_message_stream_end_borrow_default_clock_snapshot_const(
397 this->libObjPtr(), &libObjPtr);
399 if (state == BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN) {
406 Shared shared() const noexcept
408 return Shared::createWithRef(*this);
412 using StreamEndMessage = CommonStreamEndMessage<bt_message>;
413 using ConstStreamEndMessage = CommonStreamEndMessage<const bt_message>;
417 struct StreamEndMessageTypeDescr
419 using Const = ConstStreamEndMessage;
420 using NonConst = StreamEndMessage;
424 struct TypeDescr<StreamEndMessage> : public StreamEndMessageTypeDescr
429 struct TypeDescr<ConstStreamEndMessage> : public StreamEndMessageTypeDescr
433 template <typename LibObjT>
434 struct CommonPacketBeginningMessageSpec;
436 /* Functions specific to mutable packet beginning messages */
438 struct CommonPacketBeginningMessageSpec<bt_message> final
440 static bt_packet *packet(bt_message * const libObjPtr) noexcept
442 return bt_message_packet_beginning_borrow_packet(libObjPtr);
446 /* Functions specific to constant packet beginning messages */
448 struct CommonPacketBeginningMessageSpec<const bt_message> final
450 static const bt_packet *packet(const bt_message * const libObjPtr) noexcept
452 return bt_message_packet_beginning_borrow_packet_const(libObjPtr);
456 } /* namespace internal */
458 template <typename LibObjT>
459 class CommonPacketBeginningMessage final : public CommonMessage<LibObjT>
462 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
463 using _Packet = internal::DepPacket<LibObjT>;
466 using typename CommonMessage<LibObjT>::LibObjPtr;
467 using Shared = SharedMessage<CommonPacketBeginningMessage<LibObjT>, LibObjT>;
469 explicit CommonPacketBeginningMessage(const LibObjPtr libObjPtr) noexcept :
470 _ThisCommonMessage {libObjPtr}
472 BT_ASSERT_DBG(this->isPacketBeginning());
475 template <typename OtherLibObjT>
476 CommonPacketBeginningMessage(const CommonPacketBeginningMessage<OtherLibObjT> val) noexcept :
477 _ThisCommonMessage {val}
481 template <typename OtherLibObjT>
482 CommonPacketBeginningMessage<LibObjT>
483 operator=(const CommonPacketBeginningMessage<OtherLibObjT> val) noexcept
485 _ThisCommonMessage::operator=(val);
489 CommonPacketBeginningMessage<const bt_message> asConst() const noexcept
491 return CommonPacketBeginningMessage<const bt_message> {*this};
494 _Packet packet() const noexcept
497 internal::CommonPacketBeginningMessageSpec<LibObjT>::packet(this->libObjPtr())};
500 void defaultClockSnapshot(const std::uint64_t val) const noexcept
502 static_assert(!std::is_const<LibObjT>::value,
503 "Not available with `bt2::ConstPacketBeginningMessage`.");
505 bt_message_packet_beginning_set_default_clock_snapshot(this->libObjPtr(), val);
508 ConstClockSnapshot defaultClockSnapshot() const noexcept
510 const auto libObjPtr =
511 bt_message_packet_beginning_borrow_default_clock_snapshot_const(this->libObjPtr());
513 return ConstClockSnapshot {libObjPtr};
516 Shared shared() const noexcept
518 return Shared::createWithRef(*this);
522 using PacketBeginningMessage = CommonPacketBeginningMessage<bt_message>;
523 using ConstPacketBeginningMessage = CommonPacketBeginningMessage<const bt_message>;
527 struct PacketBeginningMessageTypeDescr
529 using Const = ConstPacketBeginningMessage;
530 using NonConst = PacketBeginningMessage;
534 struct TypeDescr<PacketBeginningMessage> : public PacketBeginningMessageTypeDescr
539 struct TypeDescr<ConstPacketBeginningMessage> : public PacketBeginningMessageTypeDescr
543 template <typename LibObjT>
544 struct CommonPacketEndMessageSpec;
546 /* Functions specific to mutable packet end messages */
548 struct CommonPacketEndMessageSpec<bt_message> final
550 static bt_packet *packet(bt_message * const libObjPtr) noexcept
552 return bt_message_packet_end_borrow_packet(libObjPtr);
556 /* Functions specific to constant packet end messages */
558 struct CommonPacketEndMessageSpec<const bt_message> final
560 static const bt_packet *packet(const bt_message * const libObjPtr) noexcept
562 return bt_message_packet_end_borrow_packet_const(libObjPtr);
566 } /* namespace internal */
568 template <typename LibObjT>
569 class CommonPacketEndMessage final : public CommonMessage<LibObjT>
572 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
573 using _Packet = internal::DepPacket<LibObjT>;
576 using typename CommonMessage<LibObjT>::LibObjPtr;
577 using Shared = SharedMessage<CommonPacketEndMessage<LibObjT>, LibObjT>;
579 explicit CommonPacketEndMessage(const LibObjPtr libObjPtr) noexcept :
580 _ThisCommonMessage {libObjPtr}
582 BT_ASSERT_DBG(this->isPacketEnd());
585 template <typename OtherLibObjT>
586 CommonPacketEndMessage(const CommonPacketEndMessage<OtherLibObjT> val) noexcept :
587 _ThisCommonMessage {val}
591 template <typename OtherLibObjT>
592 CommonPacketEndMessage<LibObjT>
593 operator=(const CommonPacketEndMessage<OtherLibObjT> val) noexcept
595 _ThisCommonMessage::operator=(val);
599 CommonPacketEndMessage<const bt_message> asConst() const noexcept
601 return CommonPacketEndMessage<const bt_message> {*this};
604 _Packet packet() const noexcept
606 return _Packet {internal::CommonPacketEndMessageSpec<LibObjT>::packet(this->libObjPtr())};
609 void defaultClockSnapshot(const std::uint64_t val) const noexcept
611 static_assert(!std::is_const<LibObjT>::value,
612 "Not available with `bt2::ConstPacketEndMessage`.");
614 bt_message_packet_end_set_default_clock_snapshot(this->libObjPtr(), val);
617 ConstClockSnapshot defaultClockSnapshot() const noexcept
619 const auto libObjPtr =
620 bt_message_packet_end_borrow_default_clock_snapshot_const(this->libObjPtr());
622 return ConstClockSnapshot {libObjPtr};
625 Shared shared() const noexcept
627 return Shared::createWithRef(*this);
631 using PacketEndMessage = CommonPacketEndMessage<bt_message>;
632 using ConstPacketEndMessage = CommonPacketEndMessage<const bt_message>;
636 struct PacketEndMessageTypeDescr
638 using Const = ConstPacketEndMessage;
639 using NonConst = PacketEndMessage;
643 struct TypeDescr<PacketEndMessage> : public PacketEndMessageTypeDescr
648 struct TypeDescr<ConstPacketEndMessage> : public PacketEndMessageTypeDescr
652 template <typename LibObjT>
653 struct CommonEventMessageSpec;
655 /* Functions specific to mutable event messages */
657 struct CommonEventMessageSpec<bt_message> final
659 static bt_event *event(bt_message * const libObjPtr) noexcept
661 return bt_message_event_borrow_event(libObjPtr);
665 /* Functions specific to constant event messages */
667 struct CommonEventMessageSpec<const bt_message> final
669 static const bt_event *event(const bt_message * const libObjPtr) noexcept
671 return bt_message_event_borrow_event_const(libObjPtr);
675 } /* namespace internal */
677 template <typename LibObjT>
678 class CommonEventMessage final : public CommonMessage<LibObjT>
681 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
682 using _Event = internal::DepType<LibObjT, CommonEvent<bt_event>, CommonEvent<const bt_event>>;
685 using typename CommonMessage<LibObjT>::LibObjPtr;
686 using Shared = SharedMessage<CommonEventMessage<LibObjT>, LibObjT>;
688 explicit CommonEventMessage(const LibObjPtr libObjPtr) noexcept : _ThisCommonMessage {libObjPtr}
690 BT_ASSERT_DBG(this->isEvent());
693 template <typename OtherLibObjT>
694 CommonEventMessage(const CommonEventMessage<OtherLibObjT> val) noexcept :
695 _ThisCommonMessage {val}
699 template <typename OtherLibObjT>
700 CommonEventMessage<LibObjT> operator=(const CommonEventMessage<OtherLibObjT> val) noexcept
702 _ThisCommonMessage::operator=(val);
706 CommonEventMessage<const bt_message> asConst() const noexcept
708 return CommonEventMessage<const bt_message> {*this};
711 _Event event() const noexcept
713 return _Event {internal::CommonEventMessageSpec<LibObjT>::event(this->libObjPtr())};
716 OptionalBorrowedObject<ConstClockClass> streamClassDefaultClockClass() const noexcept
718 return bt_message_event_borrow_stream_class_default_clock_class_const(this->libObjPtr());
721 ConstClockSnapshot defaultClockSnapshot() const noexcept
723 const auto libObjPtr =
724 bt_message_event_borrow_default_clock_snapshot_const(this->libObjPtr());
726 return ConstClockSnapshot {libObjPtr};
729 Shared shared() const noexcept
731 return Shared::createWithRef(*this);
735 using EventMessage = CommonEventMessage<bt_message>;
736 using ConstEventMessage = CommonEventMessage<const bt_message>;
740 struct EventMessageTypeDescr
742 using Const = ConstEventMessage;
743 using NonConst = EventMessage;
747 struct TypeDescr<EventMessage> : public EventMessageTypeDescr
752 struct TypeDescr<ConstEventMessage> : public EventMessageTypeDescr
756 template <typename LibObjT>
757 struct CommonDiscardedEventsMessageSpec;
759 /* Functions specific to mutable discarded events messages */
761 struct CommonDiscardedEventsMessageSpec<bt_message> final
763 static bt_stream *stream(bt_message * const libObjPtr) noexcept
765 return bt_message_discarded_events_borrow_stream(libObjPtr);
769 /* Functions specific to constant discarded events messages */
771 struct CommonDiscardedEventsMessageSpec<const bt_message> final
773 static const bt_stream *stream(const bt_message * const libObjPtr) noexcept
775 return bt_message_discarded_events_borrow_stream_const(libObjPtr);
779 } /* namespace internal */
781 template <typename LibObjT>
782 class CommonDiscardedEventsMessage final : public CommonMessage<LibObjT>
785 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
786 using _Stream = internal::DepStream<LibObjT>;
789 using typename CommonMessage<LibObjT>::LibObjPtr;
790 using Shared = SharedMessage<CommonDiscardedEventsMessage<LibObjT>, LibObjT>;
792 explicit CommonDiscardedEventsMessage(const LibObjPtr libObjPtr) noexcept :
793 _ThisCommonMessage {libObjPtr}
795 BT_ASSERT_DBG(this->isDiscardedEvents());
798 template <typename OtherLibObjT>
799 CommonDiscardedEventsMessage(const CommonDiscardedEventsMessage<OtherLibObjT> val) noexcept :
800 _ThisCommonMessage {val}
804 template <typename OtherLibObjT>
805 CommonDiscardedEventsMessage<LibObjT>
806 operator=(const CommonDiscardedEventsMessage<OtherLibObjT> val) noexcept
808 _ThisCommonMessage::operator=(val);
812 CommonDiscardedEventsMessage<const bt_message> asConst() const noexcept
814 return CommonDiscardedEventsMessage<const bt_message> {*this};
817 _Stream stream() const noexcept
820 internal::CommonDiscardedEventsMessageSpec<LibObjT>::stream(this->libObjPtr())};
823 ConstClockSnapshot beginningDefaultClockSnapshot() const noexcept
825 const auto libObjPtr =
826 bt_message_discarded_events_borrow_beginning_default_clock_snapshot_const(
829 return ConstClockSnapshot {libObjPtr};
832 ConstClockSnapshot endDefaultClockSnapshot() const noexcept
834 const auto libObjPtr =
835 bt_message_discarded_events_borrow_end_default_clock_snapshot_const(this->libObjPtr());
837 return ConstClockSnapshot {libObjPtr};
840 void count(const std::uint64_t count) const noexcept
842 static_assert(!std::is_const<LibObjT>::value,
843 "Not available with `bt2::ConstDiscardedEventsMessage`.");
845 bt_message_discarded_events_set_count(this->libObjPtr(), count);
848 bt2s::optional<std::uint64_t> count() const noexcept
852 if (bt_message_discarded_events_get_count(this->libObjPtr(), &count)) {
856 return bt2s::nullopt;
859 Shared shared() const noexcept
861 return Shared::createWithRef(*this);
865 using DiscardedEventsMessage = CommonDiscardedEventsMessage<bt_message>;
866 using ConstDiscardedEventsMessage = CommonDiscardedEventsMessage<const bt_message>;
870 struct DiscardedEventsMessageTypeDescr
872 using Const = ConstDiscardedEventsMessage;
873 using NonConst = DiscardedEventsMessage;
877 struct TypeDescr<DiscardedEventsMessage> : public DiscardedEventsMessageTypeDescr
882 struct TypeDescr<ConstDiscardedEventsMessage> : public DiscardedEventsMessageTypeDescr
886 template <typename LibObjT>
887 struct CommonDiscardedPacketsMessageSpec;
889 /* Functions specific to mutable discarded packets messages */
891 struct CommonDiscardedPacketsMessageSpec<bt_message> final
893 static bt_stream *stream(bt_message * const libObjPtr) noexcept
895 return bt_message_discarded_packets_borrow_stream(libObjPtr);
899 /* Functions specific to constant discarded packets messages */
901 struct CommonDiscardedPacketsMessageSpec<const bt_message> final
903 static const bt_stream *stream(const bt_message * const libObjPtr) noexcept
905 return bt_message_discarded_packets_borrow_stream_const(libObjPtr);
909 } /* namespace internal */
911 template <typename LibObjT>
912 class CommonDiscardedPacketsMessage final : public CommonMessage<LibObjT>
915 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
916 using _Stream = internal::DepStream<LibObjT>;
919 using typename CommonMessage<LibObjT>::LibObjPtr;
920 using Shared = SharedMessage<CommonDiscardedPacketsMessage<LibObjT>, LibObjT>;
922 explicit CommonDiscardedPacketsMessage(const LibObjPtr libObjPtr) noexcept :
923 _ThisCommonMessage {libObjPtr}
925 BT_ASSERT_DBG(this->isDiscardedPackets());
928 template <typename OtherLibObjT>
929 CommonDiscardedPacketsMessage(const CommonDiscardedPacketsMessage<OtherLibObjT> val) noexcept :
930 _ThisCommonMessage {val}
934 template <typename OtherLibObjT>
935 CommonDiscardedPacketsMessage<LibObjT>
936 operator=(const CommonDiscardedPacketsMessage<OtherLibObjT> val) noexcept
938 _ThisCommonMessage::operator=(val);
942 CommonDiscardedPacketsMessage<const bt_message> asConst() const noexcept
944 return CommonDiscardedPacketsMessage<const bt_message> {*this};
947 _Stream stream() const noexcept
950 internal::CommonDiscardedPacketsMessageSpec<LibObjT>::stream(this->libObjPtr())};
953 ConstClockSnapshot beginningDefaultClockSnapshot() const noexcept
955 const auto libObjPtr =
956 bt_message_discarded_packets_borrow_beginning_default_clock_snapshot_const(
959 return ConstClockSnapshot {libObjPtr};
962 ConstClockSnapshot endDefaultClockSnapshot() const noexcept
964 const auto libObjPtr =
965 bt_message_discarded_packets_borrow_end_default_clock_snapshot_const(this->libObjPtr());
967 return ConstClockSnapshot {libObjPtr};
970 void count(const std::uint64_t count) const noexcept
972 static_assert(!std::is_const<LibObjT>::value,
973 "Not available with `bt2::ConstDiscardedPacketsMessage`.");
975 bt_message_discarded_packets_set_count(this->libObjPtr(), count);
978 bt2s::optional<std::uint64_t> count() const noexcept
982 if (bt_message_discarded_packets_get_count(this->libObjPtr(), &count)) {
986 return bt2s::nullopt;
989 Shared shared() const noexcept
991 return Shared::createWithRef(*this);
995 using DiscardedPacketsMessage = CommonDiscardedPacketsMessage<bt_message>;
996 using ConstDiscardedPacketsMessage = CommonDiscardedPacketsMessage<const bt_message>;
1000 struct DiscardedPacketsMessageTypeDescr
1002 using Const = ConstDiscardedPacketsMessage;
1003 using NonConst = DiscardedPacketsMessage;
1007 struct TypeDescr<DiscardedPacketsMessage> : public DiscardedPacketsMessageTypeDescr
1012 struct TypeDescr<ConstDiscardedPacketsMessage> : public DiscardedPacketsMessageTypeDescr
1016 } /* namespace internal */
1018 template <typename LibObjT>
1019 class CommonMessageIteratorInactivityMessage final : public CommonMessage<LibObjT>
1022 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
1025 using typename CommonMessage<LibObjT>::LibObjPtr;
1026 using Shared = SharedMessage<CommonMessageIteratorInactivityMessage<LibObjT>, LibObjT>;
1028 explicit CommonMessageIteratorInactivityMessage(const LibObjPtr libObjPtr) noexcept :
1029 _ThisCommonMessage {libObjPtr}
1031 BT_ASSERT_DBG(this->isMessageIteratorInactivity());
1034 template <typename OtherLibObjT>
1035 CommonMessageIteratorInactivityMessage(
1036 const CommonMessageIteratorInactivityMessage<OtherLibObjT> val) noexcept :
1037 _ThisCommonMessage {val}
1041 template <typename OtherLibObjT>
1042 CommonMessageIteratorInactivityMessage<LibObjT>
1043 operator=(const CommonMessageIteratorInactivityMessage<OtherLibObjT> val) noexcept
1045 _ThisCommonMessage::operator=(val);
1049 CommonMessageIteratorInactivityMessage<const bt_message> asConst() const noexcept
1051 return CommonMessageIteratorInactivityMessage<const bt_message> {*this};
1054 ConstClockSnapshot clockSnapshot() const noexcept
1056 const auto libObjPtr =
1057 bt_message_message_iterator_inactivity_borrow_clock_snapshot_const(this->libObjPtr());
1059 return ConstClockSnapshot {libObjPtr};
1062 Shared shared() const noexcept
1064 return Shared::createWithRef(*this);
1068 using MessageIteratorInactivityMessage = CommonMessageIteratorInactivityMessage<bt_message>;
1069 using ConstMessageIteratorInactivityMessage =
1070 CommonMessageIteratorInactivityMessage<const bt_message>;
1072 namespace internal {
1074 struct MessageIteratorInactivityMessageTypeDescr
1076 using Const = ConstMessageIteratorInactivityMessage;
1077 using NonConst = MessageIteratorInactivityMessage;
1081 struct TypeDescr<MessageIteratorInactivityMessage> :
1082 public MessageIteratorInactivityMessageTypeDescr
1087 struct TypeDescr<ConstMessageIteratorInactivityMessage> :
1088 public MessageIteratorInactivityMessageTypeDescr
1092 } /* namespace internal */
1094 template <typename LibObjT>
1095 CommonStreamBeginningMessage<LibObjT> CommonMessage<LibObjT>::asStreamBeginning() const noexcept
1097 return CommonStreamBeginningMessage<LibObjT> {this->libObjPtr()};
1100 template <typename LibObjT>
1101 CommonStreamEndMessage<LibObjT> CommonMessage<LibObjT>::asStreamEnd() const noexcept
1103 return CommonStreamEndMessage<LibObjT> {this->libObjPtr()};
1106 template <typename LibObjT>
1107 CommonPacketBeginningMessage<LibObjT> CommonMessage<LibObjT>::asPacketBeginning() const noexcept
1109 return CommonPacketBeginningMessage<LibObjT> {this->libObjPtr()};
1112 template <typename LibObjT>
1113 CommonPacketEndMessage<LibObjT> CommonMessage<LibObjT>::asPacketEnd() const noexcept
1115 return CommonPacketEndMessage<LibObjT> {this->libObjPtr()};
1118 template <typename LibObjT>
1119 CommonEventMessage<LibObjT> CommonMessage<LibObjT>::asEvent() const noexcept
1121 return CommonEventMessage<LibObjT> {this->libObjPtr()};
1124 template <typename LibObjT>
1125 CommonDiscardedEventsMessage<LibObjT> CommonMessage<LibObjT>::asDiscardedEvents() const noexcept
1127 return CommonDiscardedEventsMessage<LibObjT> {this->libObjPtr()};
1130 template <typename LibObjT>
1131 CommonDiscardedPacketsMessage<LibObjT> CommonMessage<LibObjT>::asDiscardedPackets() const noexcept
1133 return CommonDiscardedPacketsMessage<LibObjT> {this->libObjPtr()};
1136 template <typename LibObjT>
1137 CommonMessageIteratorInactivityMessage<LibObjT>
1138 CommonMessage<LibObjT>::asMessageIteratorInactivity() const noexcept
1140 return CommonMessageIteratorInactivityMessage<LibObjT> {this->libObjPtr()};
1143 } /* namespace bt2 */
1145 #endif /* BABELTRACE_CPP_COMMON_BT2_MESSAGE_HPP */