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"
28 struct MessageRefFuncs final
30 static void get(const bt_message * const libObjPtr) noexcept
32 bt_message_get_ref(libObjPtr);
35 static void put(const bt_message * const libObjPtr) noexcept
37 bt_message_put_ref(libObjPtr);
41 } /* namespace internal */
43 template <typename ObjT, typename LibObjT>
44 using SharedMessage = SharedObject<ObjT, LibObjT, internal::MessageRefFuncs>;
46 template <typename LibObjT>
47 class CommonStreamBeginningMessage;
49 template <typename LibObjT>
50 class CommonStreamEndMessage;
52 template <typename LibObjT>
53 class CommonEventMessage;
55 template <typename LibObjT>
56 class CommonPacketBeginningMessage;
58 template <typename LibObjT>
59 class CommonPacketEndMessage;
61 template <typename LibObjT>
62 class CommonDiscardedEventsMessage;
64 template <typename LibObjT>
65 class CommonDiscardedPacketsMessage;
67 template <typename LibObjT>
68 class CommonMessageIteratorInactivityMessage;
70 enum class MessageType
72 STREAM_BEGINNING = BT_MESSAGE_TYPE_STREAM_BEGINNING,
73 STREAM_END = BT_MESSAGE_TYPE_STREAM_END,
74 EVENT = BT_MESSAGE_TYPE_EVENT,
75 PACKET_BEGINNING = BT_MESSAGE_TYPE_PACKET_BEGINNING,
76 PACKET_END = BT_MESSAGE_TYPE_PACKET_END,
77 DISCARDED_EVENTS = BT_MESSAGE_TYPE_DISCARDED_EVENTS,
78 DISCARDED_PACKETS = BT_MESSAGE_TYPE_DISCARDED_PACKETS,
79 MESSAGE_ITERATOR_INACTIVITY = BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY,
82 template <typename LibObjT>
83 class CommonMessage : public BorrowedObject<LibObjT>
86 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
89 using _ThisCommonMessage = CommonMessage<LibObjT>;
92 using typename BorrowedObject<LibObjT>::LibObjPtr;
93 using Shared = SharedMessage<CommonMessage<LibObjT>, LibObjT>;
95 explicit CommonMessage(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
99 template <typename OtherLibObjT>
100 CommonMessage(const CommonMessage<OtherLibObjT> val) noexcept : _ThisBorrowedObject {val}
104 template <typename OtherLibObjT>
105 _ThisCommonMessage operator=(const CommonMessage<OtherLibObjT> val) noexcept
107 _ThisBorrowedObject::operator=(val);
111 CommonMessage<const bt_message> asConst() const noexcept
113 return CommonMessage<const bt_message> {*this};
116 MessageType type() const noexcept
118 return static_cast<MessageType>(bt_message_get_type(this->libObjPtr()));
121 bool isStreamBeginning() const noexcept
123 return this->type() == MessageType::STREAM_BEGINNING;
126 bool isStreamEnd() const noexcept
128 return this->type() == MessageType::STREAM_END;
131 bool isEvent() const noexcept
133 return this->type() == MessageType::EVENT;
136 bool isPacketBeginning() const noexcept
138 return this->type() == MessageType::PACKET_BEGINNING;
141 bool isPacketEnd() const noexcept
143 return this->type() == MessageType::PACKET_END;
146 bool isDiscardedEvents() const noexcept
148 return this->type() == MessageType::DISCARDED_EVENTS;
151 bool isDiscardedPackets() const noexcept
153 return this->type() == MessageType::DISCARDED_PACKETS;
156 bool isMessageIteratorInactivity() const noexcept
158 return this->type() == MessageType::MESSAGE_ITERATOR_INACTIVITY;
161 Shared shared() const noexcept
163 return Shared::createWithRef(*this);
166 template <typename MessageT>
167 MessageT as() const noexcept
169 return MessageT {this->libObjPtr()};
172 CommonStreamBeginningMessage<LibObjT> asStreamBeginning() const noexcept;
173 CommonStreamEndMessage<LibObjT> asStreamEnd() const noexcept;
174 CommonEventMessage<LibObjT> asEvent() const noexcept;
175 CommonPacketBeginningMessage<LibObjT> asPacketBeginning() const noexcept;
176 CommonPacketEndMessage<LibObjT> asPacketEnd() const noexcept;
177 CommonDiscardedEventsMessage<LibObjT> asDiscardedEvents() const noexcept;
178 CommonDiscardedPacketsMessage<LibObjT> asDiscardedPackets() const noexcept;
179 CommonMessageIteratorInactivityMessage<LibObjT> asMessageIteratorInactivity() const noexcept;
182 using Message = CommonMessage<bt_message>;
183 using ConstMessage = CommonMessage<const bt_message>;
187 struct MessageTypeDescr
189 using Const = ConstMessage;
190 using NonConst = Message;
194 struct TypeDescr<Message> : public MessageTypeDescr
199 struct TypeDescr<ConstMessage> : public MessageTypeDescr
203 template <typename LibObjT>
204 struct CommonStreamBeginningMessageSpec;
206 /* Functions specific to mutable stream beginning messages */
208 struct CommonStreamBeginningMessageSpec<bt_message> final
210 static bt_stream *stream(bt_message * const libObjPtr) noexcept
212 return bt_message_stream_beginning_borrow_stream(libObjPtr);
216 /* Functions specific to constant stream beginning messages */
218 struct CommonStreamBeginningMessageSpec<const bt_message> final
220 static const bt_stream *stream(const bt_message * const libObjPtr) noexcept
222 return bt_message_stream_beginning_borrow_stream_const(libObjPtr);
226 } /* namespace internal */
228 template <typename LibObjT>
229 class CommonStreamBeginningMessage final : public CommonMessage<LibObjT>
232 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
233 using _Stream = internal::DepStream<LibObjT>;
236 using typename CommonMessage<LibObjT>::LibObjPtr;
237 using Shared = SharedMessage<CommonStreamBeginningMessage<LibObjT>, LibObjT>;
239 explicit CommonStreamBeginningMessage(const LibObjPtr libObjPtr) noexcept :
240 _ThisCommonMessage {libObjPtr}
242 BT_ASSERT_DBG(this->isStreamBeginning());
245 template <typename OtherLibObjT>
246 CommonStreamBeginningMessage(const CommonStreamBeginningMessage<OtherLibObjT> val) noexcept :
247 _ThisCommonMessage {val}
251 template <typename OtherLibObjT>
252 CommonStreamBeginningMessage<LibObjT>
253 operator=(const CommonStreamBeginningMessage<OtherLibObjT> val) noexcept
255 _ThisCommonMessage::operator=(val);
259 CommonStreamBeginningMessage<const bt_message> asConst() const noexcept
261 return CommonStreamBeginningMessage<const bt_message> {*this};
264 _Stream stream() const noexcept
267 internal::CommonStreamBeginningMessageSpec<LibObjT>::stream(this->libObjPtr())};
270 void defaultClockSnapshot(const std::uint64_t val) const noexcept
272 static_assert(!std::is_const<LibObjT>::value,
273 "Not available with `bt2::ConstStreamBeginningMessage`.");
275 bt_message_stream_beginning_set_default_clock_snapshot(this->libObjPtr(), val);
278 OptionalBorrowedObject<ConstClockSnapshot> defaultClockSnapshot() const noexcept
280 const bt_clock_snapshot *libObjPtr;
281 const auto state = bt_message_stream_beginning_borrow_default_clock_snapshot_const(
282 this->libObjPtr(), &libObjPtr);
284 if (state == BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN) {
291 Shared shared() const noexcept
293 return Shared::createWithRef(*this);
297 using StreamBeginningMessage = CommonStreamBeginningMessage<bt_message>;
298 using ConstStreamBeginningMessage = CommonStreamBeginningMessage<const bt_message>;
302 struct StreamBeginningMessageTypeDescr
304 using Const = ConstStreamBeginningMessage;
305 using NonConst = StreamBeginningMessage;
309 struct TypeDescr<StreamBeginningMessage> : public StreamBeginningMessageTypeDescr
314 struct TypeDescr<ConstStreamBeginningMessage> : public StreamBeginningMessageTypeDescr
318 template <typename LibObjT>
319 struct CommonStreamEndMessageSpec;
321 /* Functions specific to mutable stream end messages */
323 struct CommonStreamEndMessageSpec<bt_message> final
325 static bt_stream *stream(bt_message * const libObjPtr) noexcept
327 return bt_message_stream_end_borrow_stream(libObjPtr);
331 /* Functions specific to constant stream end messages */
333 struct CommonStreamEndMessageSpec<const bt_message> final
335 static const bt_stream *stream(const bt_message * const libObjPtr) noexcept
337 return bt_message_stream_end_borrow_stream_const(libObjPtr);
341 } /* namespace internal */
343 template <typename LibObjT>
344 class CommonStreamEndMessage final : public CommonMessage<LibObjT>
347 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
348 using _Stream = internal::DepStream<LibObjT>;
351 using typename CommonMessage<LibObjT>::LibObjPtr;
352 using Shared = SharedMessage<CommonStreamEndMessage<LibObjT>, LibObjT>;
354 explicit CommonStreamEndMessage(const LibObjPtr libObjPtr) noexcept :
355 _ThisCommonMessage {libObjPtr}
357 BT_ASSERT_DBG(this->isStreamEnd());
360 template <typename OtherLibObjT>
361 CommonStreamEndMessage(const CommonStreamEndMessage<OtherLibObjT> val) noexcept :
362 _ThisCommonMessage {val}
366 template <typename OtherLibObjT>
367 CommonStreamEndMessage<LibObjT>
368 operator=(const CommonStreamEndMessage<OtherLibObjT> val) noexcept
370 _ThisCommonMessage::operator=(val);
374 CommonStreamEndMessage<const bt_message> asConst() const noexcept
376 return CommonStreamEndMessage<const bt_message> {*this};
379 _Stream stream() const noexcept
381 return _Stream {internal::CommonStreamEndMessageSpec<LibObjT>::stream(this->libObjPtr())};
384 void defaultClockSnapshot(const std::uint64_t val) const noexcept
386 static_assert(!std::is_const<LibObjT>::value,
387 "Not available with `bt2::ConstStreamEndMessage`.");
389 bt_message_stream_end_set_default_clock_snapshot(this->libObjPtr(), val);
392 OptionalBorrowedObject<ConstClockSnapshot> defaultClockSnapshot() const noexcept
394 const bt_clock_snapshot *libObjPtr;
395 const auto state = bt_message_stream_end_borrow_default_clock_snapshot_const(
396 this->libObjPtr(), &libObjPtr);
398 if (state == BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN) {
405 Shared shared() const noexcept
407 return Shared::createWithRef(*this);
411 using StreamEndMessage = CommonStreamEndMessage<bt_message>;
412 using ConstStreamEndMessage = CommonStreamEndMessage<const bt_message>;
416 struct StreamEndMessageTypeDescr
418 using Const = ConstStreamEndMessage;
419 using NonConst = StreamEndMessage;
423 struct TypeDescr<StreamEndMessage> : public StreamEndMessageTypeDescr
428 struct TypeDescr<ConstStreamEndMessage> : public StreamEndMessageTypeDescr
432 template <typename LibObjT>
433 struct CommonPacketBeginningMessageSpec;
435 /* Functions specific to mutable packet beginning messages */
437 struct CommonPacketBeginningMessageSpec<bt_message> final
439 static bt_packet *packet(bt_message * const libObjPtr) noexcept
441 return bt_message_packet_beginning_borrow_packet(libObjPtr);
445 /* Functions specific to constant packet beginning messages */
447 struct CommonPacketBeginningMessageSpec<const bt_message> final
449 static const bt_packet *packet(const bt_message * const libObjPtr) noexcept
451 return bt_message_packet_beginning_borrow_packet_const(libObjPtr);
455 } /* namespace internal */
457 template <typename LibObjT>
458 class CommonPacketBeginningMessage final : public CommonMessage<LibObjT>
461 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
462 using _Packet = internal::DepPacket<LibObjT>;
465 using typename CommonMessage<LibObjT>::LibObjPtr;
466 using Shared = SharedMessage<CommonPacketBeginningMessage<LibObjT>, LibObjT>;
468 explicit CommonPacketBeginningMessage(const LibObjPtr libObjPtr) noexcept :
469 _ThisCommonMessage {libObjPtr}
471 BT_ASSERT_DBG(this->isPacketBeginning());
474 template <typename OtherLibObjT>
475 CommonPacketBeginningMessage(const CommonPacketBeginningMessage<OtherLibObjT> val) noexcept :
476 _ThisCommonMessage {val}
480 template <typename OtherLibObjT>
481 CommonPacketBeginningMessage<LibObjT>
482 operator=(const CommonPacketBeginningMessage<OtherLibObjT> val) noexcept
484 _ThisCommonMessage::operator=(val);
488 CommonPacketBeginningMessage<const bt_message> asConst() const noexcept
490 return CommonPacketBeginningMessage<const bt_message> {*this};
493 _Packet packet() const noexcept
496 internal::CommonPacketBeginningMessageSpec<LibObjT>::packet(this->libObjPtr())};
499 void defaultClockSnapshot(const std::uint64_t val) const noexcept
501 static_assert(!std::is_const<LibObjT>::value,
502 "Not available with `bt2::ConstPacketBeginningMessage`.");
504 bt_message_packet_beginning_set_default_clock_snapshot(this->libObjPtr(), val);
507 ConstClockSnapshot defaultClockSnapshot() const noexcept
509 const auto libObjPtr =
510 bt_message_packet_beginning_borrow_default_clock_snapshot_const(this->libObjPtr());
512 return ConstClockSnapshot {libObjPtr};
515 Shared shared() const noexcept
517 return Shared::createWithRef(*this);
521 using PacketBeginningMessage = CommonPacketBeginningMessage<bt_message>;
522 using ConstPacketBeginningMessage = CommonPacketBeginningMessage<const bt_message>;
526 struct PacketBeginningMessageTypeDescr
528 using Const = ConstPacketBeginningMessage;
529 using NonConst = PacketBeginningMessage;
533 struct TypeDescr<PacketBeginningMessage> : public PacketBeginningMessageTypeDescr
538 struct TypeDescr<ConstPacketBeginningMessage> : public PacketBeginningMessageTypeDescr
542 template <typename LibObjT>
543 struct CommonPacketEndMessageSpec;
545 /* Functions specific to mutable packet end messages */
547 struct CommonPacketEndMessageSpec<bt_message> final
549 static bt_packet *packet(bt_message * const libObjPtr) noexcept
551 return bt_message_packet_end_borrow_packet(libObjPtr);
555 /* Functions specific to constant packet end messages */
557 struct CommonPacketEndMessageSpec<const bt_message> final
559 static const bt_packet *packet(const bt_message * const libObjPtr) noexcept
561 return bt_message_packet_end_borrow_packet_const(libObjPtr);
565 } /* namespace internal */
567 template <typename LibObjT>
568 class CommonPacketEndMessage final : public CommonMessage<LibObjT>
571 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
572 using _Packet = internal::DepPacket<LibObjT>;
575 using typename CommonMessage<LibObjT>::LibObjPtr;
576 using Shared = SharedMessage<CommonPacketEndMessage<LibObjT>, LibObjT>;
578 explicit CommonPacketEndMessage(const LibObjPtr libObjPtr) noexcept :
579 _ThisCommonMessage {libObjPtr}
581 BT_ASSERT_DBG(this->isPacketEnd());
584 template <typename OtherLibObjT>
585 CommonPacketEndMessage(const CommonPacketEndMessage<OtherLibObjT> val) noexcept :
586 _ThisCommonMessage {val}
590 template <typename OtherLibObjT>
591 CommonPacketEndMessage<LibObjT>
592 operator=(const CommonPacketEndMessage<OtherLibObjT> val) noexcept
594 _ThisCommonMessage::operator=(val);
598 CommonPacketEndMessage<const bt_message> asConst() const noexcept
600 return CommonPacketEndMessage<const bt_message> {*this};
603 _Packet packet() const noexcept
605 return _Packet {internal::CommonPacketEndMessageSpec<LibObjT>::packet(this->libObjPtr())};
608 void defaultClockSnapshot(const std::uint64_t val) const noexcept
610 static_assert(!std::is_const<LibObjT>::value,
611 "Not available with `bt2::ConstPacketEndMessage`.");
613 bt_message_packet_end_set_default_clock_snapshot(this->libObjPtr(), val);
616 ConstClockSnapshot defaultClockSnapshot() const noexcept
618 const auto libObjPtr =
619 bt_message_packet_end_borrow_default_clock_snapshot_const(this->libObjPtr());
621 return ConstClockSnapshot {libObjPtr};
624 Shared shared() const noexcept
626 return Shared::createWithRef(*this);
630 using PacketEndMessage = CommonPacketEndMessage<bt_message>;
631 using ConstPacketEndMessage = CommonPacketEndMessage<const bt_message>;
635 struct PacketEndMessageTypeDescr
637 using Const = ConstPacketEndMessage;
638 using NonConst = PacketEndMessage;
642 struct TypeDescr<PacketEndMessage> : public PacketEndMessageTypeDescr
647 struct TypeDescr<ConstPacketEndMessage> : public PacketEndMessageTypeDescr
651 template <typename LibObjT>
652 struct CommonEventMessageSpec;
654 /* Functions specific to mutable event messages */
656 struct CommonEventMessageSpec<bt_message> final
658 static bt_event *event(bt_message * const libObjPtr) noexcept
660 return bt_message_event_borrow_event(libObjPtr);
664 /* Functions specific to constant event messages */
666 struct CommonEventMessageSpec<const bt_message> final
668 static const bt_event *event(const bt_message * const libObjPtr) noexcept
670 return bt_message_event_borrow_event_const(libObjPtr);
674 } /* namespace internal */
676 template <typename LibObjT>
677 class CommonEventMessage final : public CommonMessage<LibObjT>
680 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
681 using _Event = internal::DepType<LibObjT, CommonEvent<bt_event>, CommonEvent<const bt_event>>;
684 using typename CommonMessage<LibObjT>::LibObjPtr;
685 using Shared = SharedMessage<CommonEventMessage<LibObjT>, LibObjT>;
687 explicit CommonEventMessage(const LibObjPtr libObjPtr) noexcept : _ThisCommonMessage {libObjPtr}
689 BT_ASSERT_DBG(this->isEvent());
692 template <typename OtherLibObjT>
693 CommonEventMessage(const CommonEventMessage<OtherLibObjT> val) noexcept :
694 _ThisCommonMessage {val}
698 template <typename OtherLibObjT>
699 CommonEventMessage<LibObjT> operator=(const CommonEventMessage<OtherLibObjT> val) noexcept
701 _ThisCommonMessage::operator=(val);
705 CommonEventMessage<const bt_message> asConst() const noexcept
707 return CommonEventMessage<const bt_message> {*this};
710 _Event event() const noexcept
712 return _Event {internal::CommonEventMessageSpec<LibObjT>::event(this->libObjPtr())};
715 OptionalBorrowedObject<ConstClockClass> streamClassDefaultClockClass() const noexcept
717 return bt_message_event_borrow_stream_class_default_clock_class_const(this->libObjPtr());
720 ConstClockSnapshot defaultClockSnapshot() const noexcept
722 const auto libObjPtr =
723 bt_message_event_borrow_default_clock_snapshot_const(this->libObjPtr());
725 return ConstClockSnapshot {libObjPtr};
728 Shared shared() const noexcept
730 return Shared::createWithRef(*this);
734 using EventMessage = CommonEventMessage<bt_message>;
735 using ConstEventMessage = CommonEventMessage<const bt_message>;
739 struct EventMessageTypeDescr
741 using Const = ConstEventMessage;
742 using NonConst = EventMessage;
746 struct TypeDescr<EventMessage> : public EventMessageTypeDescr
751 struct TypeDescr<ConstEventMessage> : public EventMessageTypeDescr
755 template <typename LibObjT>
756 struct CommonDiscardedEventsMessageSpec;
758 /* Functions specific to mutable discarded events messages */
760 struct CommonDiscardedEventsMessageSpec<bt_message> final
762 static bt_stream *stream(bt_message * const libObjPtr) noexcept
764 return bt_message_discarded_events_borrow_stream(libObjPtr);
768 /* Functions specific to constant discarded events messages */
770 struct CommonDiscardedEventsMessageSpec<const bt_message> final
772 static const bt_stream *stream(const bt_message * const libObjPtr) noexcept
774 return bt_message_discarded_events_borrow_stream_const(libObjPtr);
778 } /* namespace internal */
780 template <typename LibObjT>
781 class CommonDiscardedEventsMessage final : public CommonMessage<LibObjT>
784 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
785 using _Stream = internal::DepStream<LibObjT>;
788 using typename CommonMessage<LibObjT>::LibObjPtr;
789 using Shared = SharedMessage<CommonDiscardedEventsMessage<LibObjT>, LibObjT>;
791 explicit CommonDiscardedEventsMessage(const LibObjPtr libObjPtr) noexcept :
792 _ThisCommonMessage {libObjPtr}
794 BT_ASSERT_DBG(this->isDiscardedEvents());
797 template <typename OtherLibObjT>
798 CommonDiscardedEventsMessage(const CommonDiscardedEventsMessage<OtherLibObjT> val) noexcept :
799 _ThisCommonMessage {val}
803 template <typename OtherLibObjT>
804 CommonDiscardedEventsMessage<LibObjT>
805 operator=(const CommonDiscardedEventsMessage<OtherLibObjT> val) noexcept
807 _ThisCommonMessage::operator=(val);
811 CommonDiscardedEventsMessage<const bt_message> asConst() const noexcept
813 return CommonDiscardedEventsMessage<const bt_message> {*this};
816 _Stream stream() const noexcept
819 internal::CommonDiscardedEventsMessageSpec<LibObjT>::stream(this->libObjPtr())};
822 ConstClockSnapshot beginningDefaultClockSnapshot() const noexcept
824 const auto libObjPtr =
825 bt_message_discarded_events_borrow_beginning_default_clock_snapshot_const(
828 return ConstClockSnapshot {libObjPtr};
831 ConstClockSnapshot endDefaultClockSnapshot() const noexcept
833 const auto libObjPtr =
834 bt_message_discarded_events_borrow_end_default_clock_snapshot_const(this->libObjPtr());
836 return ConstClockSnapshot {libObjPtr};
839 void count(const std::uint64_t count) const noexcept
841 static_assert(!std::is_const<LibObjT>::value,
842 "Not available with `bt2::ConstDiscardedEventsMessage`.");
844 bt_message_discarded_events_set_count(this->libObjPtr(), count);
847 bt2s::optional<std::uint64_t> count() const noexcept
851 if (bt_message_discarded_events_get_count(this->libObjPtr(), &count)) {
855 return bt2s::nullopt;
858 Shared shared() const noexcept
860 return Shared::createWithRef(*this);
864 using DiscardedEventsMessage = CommonDiscardedEventsMessage<bt_message>;
865 using ConstDiscardedEventsMessage = CommonDiscardedEventsMessage<const bt_message>;
869 struct DiscardedEventsMessageTypeDescr
871 using Const = ConstDiscardedEventsMessage;
872 using NonConst = DiscardedEventsMessage;
876 struct TypeDescr<DiscardedEventsMessage> : public DiscardedEventsMessageTypeDescr
881 struct TypeDescr<ConstDiscardedEventsMessage> : public DiscardedEventsMessageTypeDescr
885 template <typename LibObjT>
886 struct CommonDiscardedPacketsMessageSpec;
888 /* Functions specific to mutable discarded packets messages */
890 struct CommonDiscardedPacketsMessageSpec<bt_message> final
892 static bt_stream *stream(bt_message * const libObjPtr) noexcept
894 return bt_message_discarded_packets_borrow_stream(libObjPtr);
898 /* Functions specific to constant discarded packets messages */
900 struct CommonDiscardedPacketsMessageSpec<const bt_message> final
902 static const bt_stream *stream(const bt_message * const libObjPtr) noexcept
904 return bt_message_discarded_packets_borrow_stream_const(libObjPtr);
908 } /* namespace internal */
910 template <typename LibObjT>
911 class CommonDiscardedPacketsMessage final : public CommonMessage<LibObjT>
914 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
915 using _Stream = internal::DepStream<LibObjT>;
918 using typename CommonMessage<LibObjT>::LibObjPtr;
919 using Shared = SharedMessage<CommonDiscardedPacketsMessage<LibObjT>, LibObjT>;
921 explicit CommonDiscardedPacketsMessage(const LibObjPtr libObjPtr) noexcept :
922 _ThisCommonMessage {libObjPtr}
924 BT_ASSERT_DBG(this->isDiscardedPackets());
927 template <typename OtherLibObjT>
928 CommonDiscardedPacketsMessage(const CommonDiscardedPacketsMessage<OtherLibObjT> val) noexcept :
929 _ThisCommonMessage {val}
933 template <typename OtherLibObjT>
934 CommonDiscardedPacketsMessage<LibObjT>
935 operator=(const CommonDiscardedPacketsMessage<OtherLibObjT> val) noexcept
937 _ThisCommonMessage::operator=(val);
941 CommonDiscardedPacketsMessage<const bt_message> asConst() const noexcept
943 return CommonDiscardedPacketsMessage<const bt_message> {*this};
946 _Stream stream() const noexcept
949 internal::CommonDiscardedPacketsMessageSpec<LibObjT>::stream(this->libObjPtr())};
952 ConstClockSnapshot beginningDefaultClockSnapshot() const noexcept
954 const auto libObjPtr =
955 bt_message_discarded_packets_borrow_beginning_default_clock_snapshot_const(
958 return ConstClockSnapshot {libObjPtr};
961 ConstClockSnapshot endDefaultClockSnapshot() const noexcept
963 const auto libObjPtr =
964 bt_message_discarded_packets_borrow_end_default_clock_snapshot_const(this->libObjPtr());
966 return ConstClockSnapshot {libObjPtr};
969 void count(const std::uint64_t count) const noexcept
971 static_assert(!std::is_const<LibObjT>::value,
972 "Not available with `bt2::ConstDiscardedPacketsMessage`.");
974 bt_message_discarded_packets_set_count(this->libObjPtr(), count);
977 bt2s::optional<std::uint64_t> count() const noexcept
981 if (bt_message_discarded_packets_get_count(this->libObjPtr(), &count)) {
985 return bt2s::nullopt;
988 Shared shared() const noexcept
990 return Shared::createWithRef(*this);
994 using DiscardedPacketsMessage = CommonDiscardedPacketsMessage<bt_message>;
995 using ConstDiscardedPacketsMessage = CommonDiscardedPacketsMessage<const bt_message>;
999 struct DiscardedPacketsMessageTypeDescr
1001 using Const = ConstDiscardedPacketsMessage;
1002 using NonConst = DiscardedPacketsMessage;
1006 struct TypeDescr<DiscardedPacketsMessage> : public DiscardedPacketsMessageTypeDescr
1011 struct TypeDescr<ConstDiscardedPacketsMessage> : public DiscardedPacketsMessageTypeDescr
1015 } /* namespace internal */
1017 template <typename LibObjT>
1018 class CommonMessageIteratorInactivityMessage final : public CommonMessage<LibObjT>
1021 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
1024 using typename CommonMessage<LibObjT>::LibObjPtr;
1025 using Shared = SharedMessage<CommonMessageIteratorInactivityMessage<LibObjT>, LibObjT>;
1027 explicit CommonMessageIteratorInactivityMessage(const LibObjPtr libObjPtr) noexcept :
1028 _ThisCommonMessage {libObjPtr}
1030 BT_ASSERT_DBG(this->isMessageIteratorInactivity());
1033 template <typename OtherLibObjT>
1034 CommonMessageIteratorInactivityMessage(
1035 const CommonMessageIteratorInactivityMessage<OtherLibObjT> val) noexcept :
1036 _ThisCommonMessage {val}
1040 template <typename OtherLibObjT>
1041 CommonMessageIteratorInactivityMessage<LibObjT>
1042 operator=(const CommonMessageIteratorInactivityMessage<OtherLibObjT> val) noexcept
1044 _ThisCommonMessage::operator=(val);
1048 CommonMessageIteratorInactivityMessage<const bt_message> asConst() const noexcept
1050 return CommonMessageIteratorInactivityMessage<const bt_message> {*this};
1053 ConstClockSnapshot clockSnapshot() const noexcept
1055 const auto libObjPtr =
1056 bt_message_message_iterator_inactivity_borrow_clock_snapshot_const(this->libObjPtr());
1058 return ConstClockSnapshot {libObjPtr};
1061 Shared shared() const noexcept
1063 return Shared::createWithRef(*this);
1067 using MessageIteratorInactivityMessage = CommonMessageIteratorInactivityMessage<bt_message>;
1068 using ConstMessageIteratorInactivityMessage =
1069 CommonMessageIteratorInactivityMessage<const bt_message>;
1071 namespace internal {
1073 struct MessageIteratorInactivityMessageTypeDescr
1075 using Const = ConstMessageIteratorInactivityMessage;
1076 using NonConst = MessageIteratorInactivityMessage;
1080 struct TypeDescr<MessageIteratorInactivityMessage> :
1081 public MessageIteratorInactivityMessageTypeDescr
1086 struct TypeDescr<ConstMessageIteratorInactivityMessage> :
1087 public MessageIteratorInactivityMessageTypeDescr
1091 } /* namespace internal */
1093 template <typename LibObjT>
1094 CommonStreamBeginningMessage<LibObjT> CommonMessage<LibObjT>::asStreamBeginning() const noexcept
1096 BT_ASSERT_DBG(this->isStreamBeginning());
1097 return CommonStreamBeginningMessage<LibObjT> {this->libObjPtr()};
1100 template <typename LibObjT>
1101 CommonStreamEndMessage<LibObjT> CommonMessage<LibObjT>::asStreamEnd() const noexcept
1103 BT_ASSERT_DBG(this->isStreamEnd());
1104 return CommonStreamEndMessage<LibObjT> {this->libObjPtr()};
1107 template <typename LibObjT>
1108 CommonPacketBeginningMessage<LibObjT> CommonMessage<LibObjT>::asPacketBeginning() const noexcept
1110 BT_ASSERT_DBG(this->isPacketBeginning());
1111 return CommonPacketBeginningMessage<LibObjT> {this->libObjPtr()};
1114 template <typename LibObjT>
1115 CommonPacketEndMessage<LibObjT> CommonMessage<LibObjT>::asPacketEnd() const noexcept
1117 BT_ASSERT_DBG(this->isPacketEnd());
1118 return CommonPacketEndMessage<LibObjT> {this->libObjPtr()};
1121 template <typename LibObjT>
1122 CommonEventMessage<LibObjT> CommonMessage<LibObjT>::asEvent() const noexcept
1124 BT_ASSERT_DBG(this->isEvent());
1125 return CommonEventMessage<LibObjT> {this->libObjPtr()};
1128 template <typename LibObjT>
1129 CommonDiscardedEventsMessage<LibObjT> CommonMessage<LibObjT>::asDiscardedEvents() const noexcept
1131 BT_ASSERT_DBG(this->isDiscardedEvents());
1132 return CommonDiscardedEventsMessage<LibObjT> {this->libObjPtr()};
1135 template <typename LibObjT>
1136 CommonDiscardedPacketsMessage<LibObjT> CommonMessage<LibObjT>::asDiscardedPackets() const noexcept
1138 BT_ASSERT_DBG(this->isDiscardedPackets());
1139 return CommonDiscardedPacketsMessage<LibObjT> {this->libObjPtr()};
1142 template <typename LibObjT>
1143 CommonMessageIteratorInactivityMessage<LibObjT>
1144 CommonMessage<LibObjT>::asMessageIteratorInactivity() const noexcept
1146 BT_ASSERT_DBG(this->isMessageIteratorInactivity());
1147 return CommonMessageIteratorInactivityMessage<LibObjT> {this->libObjPtr()};
1150 } /* namespace bt2 */
1152 #endif /* BABELTRACE_CPP_COMMON_BT2_MESSAGE_HPP */