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 StreamBeginning = BT_MESSAGE_TYPE_STREAM_BEGINNING,
74 StreamEnd = BT_MESSAGE_TYPE_STREAM_END,
75 Event = BT_MESSAGE_TYPE_EVENT,
76 PacketBeginning = BT_MESSAGE_TYPE_PACKET_BEGINNING,
77 PacketEnd = BT_MESSAGE_TYPE_PACKET_END,
78 DiscardedEvents = BT_MESSAGE_TYPE_DISCARDED_EVENTS,
79 DiscardedPackets = BT_MESSAGE_TYPE_DISCARDED_PACKETS,
80 MessageIteratorInactivity = 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::StreamBeginning;
127 bool isStreamEnd() const noexcept
129 return this->type() == MessageType::StreamEnd;
132 bool isEvent() const noexcept
134 return this->type() == MessageType::Event;
137 bool isPacketBeginning() const noexcept
139 return this->type() == MessageType::PacketBeginning;
142 bool isPacketEnd() const noexcept
144 return this->type() == MessageType::PacketEnd;
147 bool isDiscardedEvents() const noexcept
149 return this->type() == MessageType::DiscardedEvents;
152 bool isDiscardedPackets() const noexcept
154 return this->type() == MessageType::DiscardedPackets;
157 bool isMessageIteratorInactivity() const noexcept
159 return this->type() == MessageType::MessageIteratorInactivity;
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 OptionalBorrowedObject<ConstClockClass> streamClassDefaultClockClass() const noexcept
273 return bt_message_stream_beginning_borrow_stream_class_default_clock_class_const(
277 CommonStreamBeginningMessage defaultClockSnapshot(const std::uint64_t val) const noexcept
279 static_assert(!std::is_const<LibObjT>::value,
280 "Not available with `bt2::ConstStreamBeginningMessage`.");
282 bt_message_stream_beginning_set_default_clock_snapshot(this->libObjPtr(), val);
286 OptionalBorrowedObject<ConstClockSnapshot> defaultClockSnapshot() const noexcept
288 const bt_clock_snapshot *libObjPtr;
289 const auto state = bt_message_stream_beginning_borrow_default_clock_snapshot_const(
290 this->libObjPtr(), &libObjPtr);
292 if (state == BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN) {
299 Shared shared() const noexcept
301 return Shared::createWithRef(*this);
305 using StreamBeginningMessage = CommonStreamBeginningMessage<bt_message>;
306 using ConstStreamBeginningMessage = CommonStreamBeginningMessage<const bt_message>;
310 struct StreamBeginningMessageTypeDescr
312 using Const = ConstStreamBeginningMessage;
313 using NonConst = StreamBeginningMessage;
317 struct TypeDescr<StreamBeginningMessage> : public StreamBeginningMessageTypeDescr
322 struct TypeDescr<ConstStreamBeginningMessage> : public StreamBeginningMessageTypeDescr
326 template <typename LibObjT>
327 struct CommonStreamEndMessageSpec;
329 /* Functions specific to mutable stream end messages */
331 struct CommonStreamEndMessageSpec<bt_message> final
333 static bt_stream *stream(bt_message * const libObjPtr) noexcept
335 return bt_message_stream_end_borrow_stream(libObjPtr);
339 /* Functions specific to constant stream end messages */
341 struct CommonStreamEndMessageSpec<const bt_message> final
343 static const bt_stream *stream(const bt_message * const libObjPtr) noexcept
345 return bt_message_stream_end_borrow_stream_const(libObjPtr);
349 } /* namespace internal */
351 template <typename LibObjT>
352 class CommonStreamEndMessage final : public CommonMessage<LibObjT>
355 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
356 using _Stream = internal::DepStream<LibObjT>;
359 using typename CommonMessage<LibObjT>::LibObjPtr;
360 using Shared = SharedMessage<CommonStreamEndMessage<LibObjT>, LibObjT>;
362 explicit CommonStreamEndMessage(const LibObjPtr libObjPtr) noexcept :
363 _ThisCommonMessage {libObjPtr}
365 BT_ASSERT_DBG(this->isStreamEnd());
368 template <typename OtherLibObjT>
369 CommonStreamEndMessage(const CommonStreamEndMessage<OtherLibObjT> val) noexcept :
370 _ThisCommonMessage {val}
374 template <typename OtherLibObjT>
375 CommonStreamEndMessage<LibObjT>
376 operator=(const CommonStreamEndMessage<OtherLibObjT> val) noexcept
378 _ThisCommonMessage::operator=(val);
382 CommonStreamEndMessage<const bt_message> asConst() const noexcept
384 return CommonStreamEndMessage<const bt_message> {*this};
387 _Stream stream() const noexcept
389 return _Stream {internal::CommonStreamEndMessageSpec<LibObjT>::stream(this->libObjPtr())};
392 OptionalBorrowedObject<ConstClockClass> streamClassDefaultClockClass() const noexcept
394 return bt_message_stream_end_borrow_stream_class_default_clock_class_const(
398 CommonStreamEndMessage defaultClockSnapshot(const std::uint64_t val) const noexcept
400 static_assert(!std::is_const<LibObjT>::value,
401 "Not available with `bt2::ConstStreamEndMessage`.");
403 bt_message_stream_end_set_default_clock_snapshot(this->libObjPtr(), val);
407 OptionalBorrowedObject<ConstClockSnapshot> defaultClockSnapshot() const noexcept
409 const bt_clock_snapshot *libObjPtr;
410 const auto state = bt_message_stream_end_borrow_default_clock_snapshot_const(
411 this->libObjPtr(), &libObjPtr);
413 if (state == BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN) {
420 Shared shared() const noexcept
422 return Shared::createWithRef(*this);
426 using StreamEndMessage = CommonStreamEndMessage<bt_message>;
427 using ConstStreamEndMessage = CommonStreamEndMessage<const bt_message>;
431 struct StreamEndMessageTypeDescr
433 using Const = ConstStreamEndMessage;
434 using NonConst = StreamEndMessage;
438 struct TypeDescr<StreamEndMessage> : public StreamEndMessageTypeDescr
443 struct TypeDescr<ConstStreamEndMessage> : public StreamEndMessageTypeDescr
447 template <typename LibObjT>
448 struct CommonPacketBeginningMessageSpec;
450 /* Functions specific to mutable packet beginning messages */
452 struct CommonPacketBeginningMessageSpec<bt_message> final
454 static bt_packet *packet(bt_message * const libObjPtr) noexcept
456 return bt_message_packet_beginning_borrow_packet(libObjPtr);
460 /* Functions specific to constant packet beginning messages */
462 struct CommonPacketBeginningMessageSpec<const bt_message> final
464 static const bt_packet *packet(const bt_message * const libObjPtr) noexcept
466 return bt_message_packet_beginning_borrow_packet_const(libObjPtr);
470 } /* namespace internal */
472 template <typename LibObjT>
473 class CommonPacketBeginningMessage final : public CommonMessage<LibObjT>
476 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
477 using _Packet = internal::DepPacket<LibObjT>;
480 using typename CommonMessage<LibObjT>::LibObjPtr;
481 using Shared = SharedMessage<CommonPacketBeginningMessage<LibObjT>, LibObjT>;
483 explicit CommonPacketBeginningMessage(const LibObjPtr libObjPtr) noexcept :
484 _ThisCommonMessage {libObjPtr}
486 BT_ASSERT_DBG(this->isPacketBeginning());
489 template <typename OtherLibObjT>
490 CommonPacketBeginningMessage(const CommonPacketBeginningMessage<OtherLibObjT> val) noexcept :
491 _ThisCommonMessage {val}
495 template <typename OtherLibObjT>
496 CommonPacketBeginningMessage<LibObjT>
497 operator=(const CommonPacketBeginningMessage<OtherLibObjT> val) noexcept
499 _ThisCommonMessage::operator=(val);
503 CommonPacketBeginningMessage<const bt_message> asConst() const noexcept
505 return CommonPacketBeginningMessage<const bt_message> {*this};
508 _Packet packet() const noexcept
511 internal::CommonPacketBeginningMessageSpec<LibObjT>::packet(this->libObjPtr())};
514 OptionalBorrowedObject<ConstClockClass> streamClassDefaultClockClass() const noexcept
516 return bt_message_packet_beginning_borrow_stream_class_default_clock_class_const(
520 CommonPacketBeginningMessage defaultClockSnapshot(const std::uint64_t val) const noexcept
522 static_assert(!std::is_const<LibObjT>::value,
523 "Not available with `bt2::ConstPacketBeginningMessage`.");
525 bt_message_packet_beginning_set_default_clock_snapshot(this->libObjPtr(), val);
529 ConstClockSnapshot defaultClockSnapshot() const noexcept
531 const auto libObjPtr =
532 bt_message_packet_beginning_borrow_default_clock_snapshot_const(this->libObjPtr());
534 return ConstClockSnapshot {libObjPtr};
537 Shared shared() const noexcept
539 return Shared::createWithRef(*this);
543 using PacketBeginningMessage = CommonPacketBeginningMessage<bt_message>;
544 using ConstPacketBeginningMessage = CommonPacketBeginningMessage<const bt_message>;
548 struct PacketBeginningMessageTypeDescr
550 using Const = ConstPacketBeginningMessage;
551 using NonConst = PacketBeginningMessage;
555 struct TypeDescr<PacketBeginningMessage> : public PacketBeginningMessageTypeDescr
560 struct TypeDescr<ConstPacketBeginningMessage> : public PacketBeginningMessageTypeDescr
564 template <typename LibObjT>
565 struct CommonPacketEndMessageSpec;
567 /* Functions specific to mutable packet end messages */
569 struct CommonPacketEndMessageSpec<bt_message> final
571 static bt_packet *packet(bt_message * const libObjPtr) noexcept
573 return bt_message_packet_end_borrow_packet(libObjPtr);
577 /* Functions specific to constant packet end messages */
579 struct CommonPacketEndMessageSpec<const bt_message> final
581 static const bt_packet *packet(const bt_message * const libObjPtr) noexcept
583 return bt_message_packet_end_borrow_packet_const(libObjPtr);
587 } /* namespace internal */
589 template <typename LibObjT>
590 class CommonPacketEndMessage final : public CommonMessage<LibObjT>
593 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
594 using _Packet = internal::DepPacket<LibObjT>;
597 using typename CommonMessage<LibObjT>::LibObjPtr;
598 using Shared = SharedMessage<CommonPacketEndMessage<LibObjT>, LibObjT>;
600 explicit CommonPacketEndMessage(const LibObjPtr libObjPtr) noexcept :
601 _ThisCommonMessage {libObjPtr}
603 BT_ASSERT_DBG(this->isPacketEnd());
606 template <typename OtherLibObjT>
607 CommonPacketEndMessage(const CommonPacketEndMessage<OtherLibObjT> val) noexcept :
608 _ThisCommonMessage {val}
612 template <typename OtherLibObjT>
613 CommonPacketEndMessage<LibObjT>
614 operator=(const CommonPacketEndMessage<OtherLibObjT> val) noexcept
616 _ThisCommonMessage::operator=(val);
620 CommonPacketEndMessage<const bt_message> asConst() const noexcept
622 return CommonPacketEndMessage<const bt_message> {*this};
625 _Packet packet() const noexcept
627 return _Packet {internal::CommonPacketEndMessageSpec<LibObjT>::packet(this->libObjPtr())};
630 OptionalBorrowedObject<ConstClockClass> streamClassDefaultClockClass() const noexcept
632 return bt_message_packet_end_borrow_stream_class_default_clock_class_const(
636 CommonPacketEndMessage defaultClockSnapshot(const std::uint64_t val) const noexcept
638 static_assert(!std::is_const<LibObjT>::value,
639 "Not available with `bt2::ConstPacketEndMessage`.");
641 bt_message_packet_end_set_default_clock_snapshot(this->libObjPtr(), val);
645 ConstClockSnapshot defaultClockSnapshot() const noexcept
647 const auto libObjPtr =
648 bt_message_packet_end_borrow_default_clock_snapshot_const(this->libObjPtr());
650 return ConstClockSnapshot {libObjPtr};
653 Shared shared() const noexcept
655 return Shared::createWithRef(*this);
659 using PacketEndMessage = CommonPacketEndMessage<bt_message>;
660 using ConstPacketEndMessage = CommonPacketEndMessage<const bt_message>;
664 struct PacketEndMessageTypeDescr
666 using Const = ConstPacketEndMessage;
667 using NonConst = PacketEndMessage;
671 struct TypeDescr<PacketEndMessage> : public PacketEndMessageTypeDescr
676 struct TypeDescr<ConstPacketEndMessage> : public PacketEndMessageTypeDescr
680 template <typename LibObjT>
681 struct CommonEventMessageSpec;
683 /* Functions specific to mutable event messages */
685 struct CommonEventMessageSpec<bt_message> final
687 static bt_event *event(bt_message * const libObjPtr) noexcept
689 return bt_message_event_borrow_event(libObjPtr);
693 /* Functions specific to constant event messages */
695 struct CommonEventMessageSpec<const bt_message> final
697 static const bt_event *event(const bt_message * const libObjPtr) noexcept
699 return bt_message_event_borrow_event_const(libObjPtr);
703 } /* namespace internal */
705 template <typename LibObjT>
706 class CommonEventMessage final : public CommonMessage<LibObjT>
709 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
710 using _Event = internal::DepType<LibObjT, CommonEvent<bt_event>, CommonEvent<const bt_event>>;
713 using typename CommonMessage<LibObjT>::LibObjPtr;
714 using Shared = SharedMessage<CommonEventMessage<LibObjT>, LibObjT>;
716 explicit CommonEventMessage(const LibObjPtr libObjPtr) noexcept : _ThisCommonMessage {libObjPtr}
718 BT_ASSERT_DBG(this->isEvent());
721 template <typename OtherLibObjT>
722 CommonEventMessage(const CommonEventMessage<OtherLibObjT> val) noexcept :
723 _ThisCommonMessage {val}
727 template <typename OtherLibObjT>
728 CommonEventMessage<LibObjT> operator=(const CommonEventMessage<OtherLibObjT> val) noexcept
730 _ThisCommonMessage::operator=(val);
734 CommonEventMessage<const bt_message> asConst() const noexcept
736 return CommonEventMessage<const bt_message> {*this};
739 _Event event() const noexcept
741 return _Event {internal::CommonEventMessageSpec<LibObjT>::event(this->libObjPtr())};
744 OptionalBorrowedObject<ConstClockClass> streamClassDefaultClockClass() const noexcept
746 return bt_message_event_borrow_stream_class_default_clock_class_const(this->libObjPtr());
749 ConstClockSnapshot defaultClockSnapshot() const noexcept
751 const auto libObjPtr =
752 bt_message_event_borrow_default_clock_snapshot_const(this->libObjPtr());
754 return ConstClockSnapshot {libObjPtr};
757 Shared shared() const noexcept
759 return Shared::createWithRef(*this);
763 using EventMessage = CommonEventMessage<bt_message>;
764 using ConstEventMessage = CommonEventMessage<const bt_message>;
768 struct EventMessageTypeDescr
770 using Const = ConstEventMessage;
771 using NonConst = EventMessage;
775 struct TypeDescr<EventMessage> : public EventMessageTypeDescr
780 struct TypeDescr<ConstEventMessage> : public EventMessageTypeDescr
784 template <typename LibObjT>
785 struct CommonDiscardedEventsMessageSpec;
787 /* Functions specific to mutable discarded events messages */
789 struct CommonDiscardedEventsMessageSpec<bt_message> final
791 static bt_stream *stream(bt_message * const libObjPtr) noexcept
793 return bt_message_discarded_events_borrow_stream(libObjPtr);
797 /* Functions specific to constant discarded events messages */
799 struct CommonDiscardedEventsMessageSpec<const bt_message> final
801 static const bt_stream *stream(const bt_message * const libObjPtr) noexcept
803 return bt_message_discarded_events_borrow_stream_const(libObjPtr);
807 } /* namespace internal */
809 template <typename LibObjT>
810 class CommonDiscardedEventsMessage final : public CommonMessage<LibObjT>
813 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
814 using _Stream = internal::DepStream<LibObjT>;
817 using typename CommonMessage<LibObjT>::LibObjPtr;
818 using Shared = SharedMessage<CommonDiscardedEventsMessage<LibObjT>, LibObjT>;
820 explicit CommonDiscardedEventsMessage(const LibObjPtr libObjPtr) noexcept :
821 _ThisCommonMessage {libObjPtr}
823 BT_ASSERT_DBG(this->isDiscardedEvents());
826 template <typename OtherLibObjT>
827 CommonDiscardedEventsMessage(const CommonDiscardedEventsMessage<OtherLibObjT> val) noexcept :
828 _ThisCommonMessage {val}
832 template <typename OtherLibObjT>
833 CommonDiscardedEventsMessage<LibObjT>
834 operator=(const CommonDiscardedEventsMessage<OtherLibObjT> val) noexcept
836 _ThisCommonMessage::operator=(val);
840 CommonDiscardedEventsMessage<const bt_message> asConst() const noexcept
842 return CommonDiscardedEventsMessage<const bt_message> {*this};
845 _Stream stream() const noexcept
848 internal::CommonDiscardedEventsMessageSpec<LibObjT>::stream(this->libObjPtr())};
851 OptionalBorrowedObject<ConstClockClass> streamClassDefaultClockClass() const noexcept
853 return bt_message_discarded_events_borrow_stream_class_default_clock_class_const(
857 ConstClockSnapshot beginningDefaultClockSnapshot() const noexcept
859 const auto libObjPtr =
860 bt_message_discarded_events_borrow_beginning_default_clock_snapshot_const(
863 return ConstClockSnapshot {libObjPtr};
866 ConstClockSnapshot endDefaultClockSnapshot() const noexcept
868 const auto libObjPtr =
869 bt_message_discarded_events_borrow_end_default_clock_snapshot_const(this->libObjPtr());
871 return ConstClockSnapshot {libObjPtr};
874 CommonDiscardedEventsMessage count(const std::uint64_t count) const noexcept
876 static_assert(!std::is_const<LibObjT>::value,
877 "Not available with `bt2::ConstDiscardedEventsMessage`.");
879 bt_message_discarded_events_set_count(this->libObjPtr(), count);
883 bt2s::optional<std::uint64_t> count() const noexcept
887 if (bt_message_discarded_events_get_count(this->libObjPtr(), &count)) {
891 return bt2s::nullopt;
894 Shared shared() const noexcept
896 return Shared::createWithRef(*this);
900 using DiscardedEventsMessage = CommonDiscardedEventsMessage<bt_message>;
901 using ConstDiscardedEventsMessage = CommonDiscardedEventsMessage<const bt_message>;
905 struct DiscardedEventsMessageTypeDescr
907 using Const = ConstDiscardedEventsMessage;
908 using NonConst = DiscardedEventsMessage;
912 struct TypeDescr<DiscardedEventsMessage> : public DiscardedEventsMessageTypeDescr
917 struct TypeDescr<ConstDiscardedEventsMessage> : public DiscardedEventsMessageTypeDescr
921 template <typename LibObjT>
922 struct CommonDiscardedPacketsMessageSpec;
924 /* Functions specific to mutable discarded packets messages */
926 struct CommonDiscardedPacketsMessageSpec<bt_message> final
928 static bt_stream *stream(bt_message * const libObjPtr) noexcept
930 return bt_message_discarded_packets_borrow_stream(libObjPtr);
934 /* Functions specific to constant discarded packets messages */
936 struct CommonDiscardedPacketsMessageSpec<const bt_message> final
938 static const bt_stream *stream(const bt_message * const libObjPtr) noexcept
940 return bt_message_discarded_packets_borrow_stream_const(libObjPtr);
944 } /* namespace internal */
946 template <typename LibObjT>
947 class CommonDiscardedPacketsMessage final : public CommonMessage<LibObjT>
950 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
951 using _Stream = internal::DepStream<LibObjT>;
954 using typename CommonMessage<LibObjT>::LibObjPtr;
955 using Shared = SharedMessage<CommonDiscardedPacketsMessage<LibObjT>, LibObjT>;
957 explicit CommonDiscardedPacketsMessage(const LibObjPtr libObjPtr) noexcept :
958 _ThisCommonMessage {libObjPtr}
960 BT_ASSERT_DBG(this->isDiscardedPackets());
963 template <typename OtherLibObjT>
964 CommonDiscardedPacketsMessage(const CommonDiscardedPacketsMessage<OtherLibObjT> val) noexcept :
965 _ThisCommonMessage {val}
969 template <typename OtherLibObjT>
970 CommonDiscardedPacketsMessage<LibObjT>
971 operator=(const CommonDiscardedPacketsMessage<OtherLibObjT> val) noexcept
973 _ThisCommonMessage::operator=(val);
977 CommonDiscardedPacketsMessage<const bt_message> asConst() const noexcept
979 return CommonDiscardedPacketsMessage<const bt_message> {*this};
982 _Stream stream() const noexcept
985 internal::CommonDiscardedPacketsMessageSpec<LibObjT>::stream(this->libObjPtr())};
988 OptionalBorrowedObject<ConstClockClass> streamClassDefaultClockClass() const noexcept
990 return bt_message_discarded_packets_borrow_stream_class_default_clock_class_const(
994 ConstClockSnapshot beginningDefaultClockSnapshot() const noexcept
996 const auto libObjPtr =
997 bt_message_discarded_packets_borrow_beginning_default_clock_snapshot_const(
1000 return ConstClockSnapshot {libObjPtr};
1003 ConstClockSnapshot endDefaultClockSnapshot() const noexcept
1005 const auto libObjPtr =
1006 bt_message_discarded_packets_borrow_end_default_clock_snapshot_const(this->libObjPtr());
1008 return ConstClockSnapshot {libObjPtr};
1011 CommonDiscardedPacketsMessage count(const std::uint64_t count) const noexcept
1013 static_assert(!std::is_const<LibObjT>::value,
1014 "Not available with `bt2::ConstDiscardedPacketsMessage`.");
1016 bt_message_discarded_packets_set_count(this->libObjPtr(), count);
1020 bt2s::optional<std::uint64_t> count() const noexcept
1022 std::uint64_t count;
1024 if (bt_message_discarded_packets_get_count(this->libObjPtr(), &count)) {
1028 return bt2s::nullopt;
1031 Shared shared() const noexcept
1033 return Shared::createWithRef(*this);
1037 using DiscardedPacketsMessage = CommonDiscardedPacketsMessage<bt_message>;
1038 using ConstDiscardedPacketsMessage = CommonDiscardedPacketsMessage<const bt_message>;
1040 namespace internal {
1042 struct DiscardedPacketsMessageTypeDescr
1044 using Const = ConstDiscardedPacketsMessage;
1045 using NonConst = DiscardedPacketsMessage;
1049 struct TypeDescr<DiscardedPacketsMessage> : public DiscardedPacketsMessageTypeDescr
1054 struct TypeDescr<ConstDiscardedPacketsMessage> : public DiscardedPacketsMessageTypeDescr
1058 } /* namespace internal */
1060 template <typename LibObjT>
1061 class CommonMessageIteratorInactivityMessage final : public CommonMessage<LibObjT>
1064 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
1067 using typename CommonMessage<LibObjT>::LibObjPtr;
1068 using Shared = SharedMessage<CommonMessageIteratorInactivityMessage<LibObjT>, LibObjT>;
1070 explicit CommonMessageIteratorInactivityMessage(const LibObjPtr libObjPtr) noexcept :
1071 _ThisCommonMessage {libObjPtr}
1073 BT_ASSERT_DBG(this->isMessageIteratorInactivity());
1076 template <typename OtherLibObjT>
1077 CommonMessageIteratorInactivityMessage(
1078 const CommonMessageIteratorInactivityMessage<OtherLibObjT> val) noexcept :
1079 _ThisCommonMessage {val}
1083 template <typename OtherLibObjT>
1084 CommonMessageIteratorInactivityMessage<LibObjT>
1085 operator=(const CommonMessageIteratorInactivityMessage<OtherLibObjT> val) noexcept
1087 _ThisCommonMessage::operator=(val);
1091 CommonMessageIteratorInactivityMessage<const bt_message> asConst() const noexcept
1093 return CommonMessageIteratorInactivityMessage<const bt_message> {*this};
1096 ConstClockSnapshot clockSnapshot() const noexcept
1098 const auto libObjPtr =
1099 bt_message_message_iterator_inactivity_borrow_clock_snapshot_const(this->libObjPtr());
1101 return ConstClockSnapshot {libObjPtr};
1104 Shared shared() const noexcept
1106 return Shared::createWithRef(*this);
1110 using MessageIteratorInactivityMessage = CommonMessageIteratorInactivityMessage<bt_message>;
1111 using ConstMessageIteratorInactivityMessage =
1112 CommonMessageIteratorInactivityMessage<const bt_message>;
1114 namespace internal {
1116 struct MessageIteratorInactivityMessageTypeDescr
1118 using Const = ConstMessageIteratorInactivityMessage;
1119 using NonConst = MessageIteratorInactivityMessage;
1123 struct TypeDescr<MessageIteratorInactivityMessage> :
1124 public MessageIteratorInactivityMessageTypeDescr
1129 struct TypeDescr<ConstMessageIteratorInactivityMessage> :
1130 public MessageIteratorInactivityMessageTypeDescr
1134 } /* namespace internal */
1136 template <typename LibObjT>
1137 CommonStreamBeginningMessage<LibObjT> CommonMessage<LibObjT>::asStreamBeginning() const noexcept
1139 return CommonStreamBeginningMessage<LibObjT> {this->libObjPtr()};
1142 template <typename LibObjT>
1143 CommonStreamEndMessage<LibObjT> CommonMessage<LibObjT>::asStreamEnd() const noexcept
1145 return CommonStreamEndMessage<LibObjT> {this->libObjPtr()};
1148 template <typename LibObjT>
1149 CommonPacketBeginningMessage<LibObjT> CommonMessage<LibObjT>::asPacketBeginning() const noexcept
1151 return CommonPacketBeginningMessage<LibObjT> {this->libObjPtr()};
1154 template <typename LibObjT>
1155 CommonPacketEndMessage<LibObjT> CommonMessage<LibObjT>::asPacketEnd() const noexcept
1157 return CommonPacketEndMessage<LibObjT> {this->libObjPtr()};
1160 template <typename LibObjT>
1161 CommonEventMessage<LibObjT> CommonMessage<LibObjT>::asEvent() const noexcept
1163 return CommonEventMessage<LibObjT> {this->libObjPtr()};
1166 template <typename LibObjT>
1167 CommonDiscardedEventsMessage<LibObjT> CommonMessage<LibObjT>::asDiscardedEvents() const noexcept
1169 return CommonDiscardedEventsMessage<LibObjT> {this->libObjPtr()};
1172 template <typename LibObjT>
1173 CommonDiscardedPacketsMessage<LibObjT> CommonMessage<LibObjT>::asDiscardedPackets() const noexcept
1175 return CommonDiscardedPacketsMessage<LibObjT> {this->libObjPtr()};
1178 template <typename LibObjT>
1179 CommonMessageIteratorInactivityMessage<LibObjT>
1180 CommonMessage<LibObjT>::asMessageIteratorInactivity() const noexcept
1182 return CommonMessageIteratorInactivityMessage<LibObjT> {this->libObjPtr()};
1185 } /* namespace bt2 */
1187 #endif /* BABELTRACE_CPP_COMMON_BT2_MESSAGE_HPP */