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
10 #include <type_traits>
13 #include <babeltrace2/babeltrace.h>
15 #include "common/assert.h"
16 #include "common/common.h"
17 #include "internal/borrowed-obj.hpp"
18 #include "internal/shared-obj.hpp"
19 #include "internal/utils.hpp"
20 #include "cpp-common/optional.hpp"
21 #include "cpp-common/string_view.hpp"
27 struct MessageRefFuncs final
29 static void get(const bt_message * const libObjPtr)
31 bt_message_get_ref(libObjPtr);
34 static void put(const bt_message * const libObjPtr)
36 bt_message_put_ref(libObjPtr);
40 template <typename ObjT, typename LibObjT>
41 using SharedMessage = internal::SharedObj<ObjT, LibObjT, internal::MessageRefFuncs>;
43 } /* namespace internal */
45 template <typename LibObjT>
46 class CommonStreamBeginningMessage;
48 template <typename LibObjT>
49 class CommonStreamEndMessage;
51 template <typename LibObjT>
52 class CommonEventMessage;
54 template <typename LibObjT>
55 class CommonPacketBeginningMessage;
57 template <typename LibObjT>
58 class CommonPacketEndMessage;
60 template <typename LibObjT>
61 class CommonDiscardedEventsMessage;
63 template <typename LibObjT>
64 class CommonDiscardedPacketsMessage;
66 template <typename LibObjT>
67 class CommonMessageIteratorInactivityMessage;
69 enum class MessageType
71 STREAM_BEGINNING = BT_MESSAGE_TYPE_STREAM_BEGINNING,
72 STREAM_END = BT_MESSAGE_TYPE_STREAM_END,
73 EVENT = BT_MESSAGE_TYPE_EVENT,
74 PACKET_BEGINNING = BT_MESSAGE_TYPE_PACKET_BEGINNING,
75 PACKET_END = BT_MESSAGE_TYPE_PACKET_END,
76 DISCARDED_EVENTS = BT_MESSAGE_TYPE_DISCARDED_EVENTS,
77 DISCARDED_PACKETS = BT_MESSAGE_TYPE_DISCARDED_PACKETS,
78 MESSAGE_ITERATOR_INACTIVITY = BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY,
81 template <typename LibObjT>
82 class CommonMessage : public internal::BorrowedObj<LibObjT>
85 using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
88 using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
89 using _ThisCommonMessage = CommonMessage<LibObjT>;
92 using Shared = internal::SharedMessage<CommonMessage<LibObjT>, LibObjT>;
94 explicit CommonMessage(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr}
98 template <typename OtherLibObjT>
99 CommonMessage(const CommonMessage<OtherLibObjT> val) noexcept : _ThisBorrowedObj {val}
103 template <typename OtherLibObjT>
104 _ThisCommonMessage& operator=(const CommonMessage<OtherLibObjT> val) noexcept
106 _ThisBorrowedObj::operator=(val);
110 MessageType type() const noexcept
112 return static_cast<MessageType>(bt_message_get_type(this->libObjPtr()));
115 bool isStreamBeginning() const noexcept
117 return this->type() == MessageType::STREAM_BEGINNING;
120 bool isStreamEnd() const noexcept
122 return this->type() == MessageType::STREAM_END;
125 bool isEvent() const noexcept
127 return this->type() == MessageType::EVENT;
130 bool isPacketBeginning() const noexcept
132 return this->type() == MessageType::PACKET_BEGINNING;
135 bool isPacketEnd() const noexcept
137 return this->type() == MessageType::PACKET_END;
140 bool isDiscardedEvents() const noexcept
142 return this->type() == MessageType::DISCARDED_EVENTS;
145 bool isDiscardedPackets() const noexcept
147 return this->type() == MessageType::DISCARDED_PACKETS;
150 bool isMessageIteratorInactivity() const noexcept
152 return this->type() == MessageType::MESSAGE_ITERATOR_INACTIVITY;
155 Shared shared() const noexcept
157 return Shared::createWithRef(*this);
160 template <typename MessageT>
161 MessageT as() const noexcept
163 return MessageT {this->libObjPtr()};
166 CommonStreamBeginningMessage<LibObjT> asStreamBeginning() const noexcept;
167 CommonStreamEndMessage<LibObjT> asStreamEnd() const noexcept;
168 CommonEventMessage<LibObjT> asEvent() const noexcept;
169 CommonPacketBeginningMessage<LibObjT> asPacketBeginning() const noexcept;
170 CommonPacketEndMessage<LibObjT> asPacketEnd() const noexcept;
171 CommonDiscardedEventsMessage<LibObjT> asDiscardedEvents() const noexcept;
172 CommonDiscardedPacketsMessage<LibObjT> asDiscardedPackets() const noexcept;
173 CommonMessageIteratorInactivityMessage<LibObjT> asMessageIteratorInactivity() const noexcept;
176 using Message = CommonMessage<bt_message>;
177 using ConstMessage = CommonMessage<const bt_message>;
181 struct MessageTypeDescr
183 using Const = ConstMessage;
184 using NonConst = Message;
188 struct TypeDescr<Message> : public MessageTypeDescr
193 struct TypeDescr<ConstMessage> : public MessageTypeDescr
197 template <typename LibObjT>
198 struct CommonStreamBeginningMessageSpec;
200 /* Functions specific to mutable stream beginning messages */
202 struct CommonStreamBeginningMessageSpec<bt_message> final
204 static bt_stream *stream(bt_message * const libObjPtr) noexcept
206 return bt_message_stream_beginning_borrow_stream(libObjPtr);
210 /* Functions specific to constant stream beginning messages */
212 struct CommonStreamBeginningMessageSpec<const bt_message> final
214 static const bt_stream *stream(const bt_message * const libObjPtr) noexcept
216 return bt_message_stream_beginning_borrow_stream_const(libObjPtr);
220 } /* namespace internal */
222 template <typename LibObjT>
223 class CommonStreamBeginningMessage final : public CommonMessage<LibObjT>
226 using typename CommonMessage<LibObjT>::_LibObjPtr;
227 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
230 typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>,
231 CommonStream<bt_stream>>::type;
234 using Shared = internal::SharedMessage<CommonStreamBeginningMessage<LibObjT>, LibObjT>;
236 explicit CommonStreamBeginningMessage(const _LibObjPtr libObjPtr) noexcept :
237 _ThisCommonMessage {libObjPtr}
239 BT_ASSERT_DBG(this->isStreamBeginning());
242 template <typename OtherLibObjT>
243 CommonStreamBeginningMessage(const CommonStreamBeginningMessage<OtherLibObjT> val) noexcept :
244 _ThisCommonMessage {val}
248 template <typename OtherLibObjT>
249 CommonStreamBeginningMessage<LibObjT>&
250 operator=(const CommonStreamBeginningMessage<OtherLibObjT> val) noexcept
252 _ThisCommonMessage::operator=(val);
256 ConstStream stream() const noexcept
258 return ConstStream {internal::CommonStreamBeginningMessageSpec<const bt_message>::stream(
262 _Stream stream() noexcept
265 internal::CommonStreamBeginningMessageSpec<LibObjT>::stream(this->libObjPtr())};
268 void defaultClockSnapshot(const std::uint64_t val) noexcept
270 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
272 bt_message_stream_beginning_set_default_clock_snapshot(this->libObjPtr(), val);
275 nonstd::optional<ConstClockSnapshot> defaultClockSnapshot() const noexcept
277 const bt_clock_snapshot *libObjPtr;
278 const auto state = bt_message_stream_beginning_borrow_default_clock_snapshot_const(
279 this->libObjPtr(), &libObjPtr);
281 if (state == BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN) {
282 return ConstClockSnapshot {libObjPtr};
285 return nonstd::nullopt;
288 Shared shared() const noexcept
290 return Shared::createWithRef(*this);
294 using StreamBeginningMessage = CommonStreamBeginningMessage<bt_message>;
295 using ConstStreamBeginningMessage = CommonStreamBeginningMessage<const bt_message>;
299 struct StreamBeginningMessageTypeDescr
301 using Const = ConstStreamBeginningMessage;
302 using NonConst = StreamBeginningMessage;
306 struct TypeDescr<StreamBeginningMessage> : public StreamBeginningMessageTypeDescr
311 struct TypeDescr<ConstStreamBeginningMessage> : public StreamBeginningMessageTypeDescr
315 template <typename LibObjT>
316 struct CommonStreamEndMessageSpec;
318 /* Functions specific to mutable stream end messages */
320 struct CommonStreamEndMessageSpec<bt_message> final
322 static bt_stream *stream(bt_message * const libObjPtr) noexcept
324 return bt_message_stream_end_borrow_stream(libObjPtr);
328 /* Functions specific to constant stream end messages */
330 struct CommonStreamEndMessageSpec<const bt_message> final
332 static const bt_stream *stream(const bt_message * const libObjPtr) noexcept
334 return bt_message_stream_end_borrow_stream_const(libObjPtr);
338 } /* namespace internal */
340 template <typename LibObjT>
341 class CommonStreamEndMessage final : public CommonMessage<LibObjT>
344 using typename CommonMessage<LibObjT>::_LibObjPtr;
345 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
348 typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>,
349 CommonStream<bt_stream>>::type;
352 using Shared = internal::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 ConstStream stream() const noexcept
377 internal::CommonStreamEndMessageSpec<const bt_message>::stream(this->libObjPtr())};
380 _Stream stream() noexcept
382 return _Stream {internal::CommonStreamEndMessageSpec<LibObjT>::stream(this->libObjPtr())};
385 void defaultClockSnapshot(const std::uint64_t val) noexcept
387 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
389 bt_message_stream_end_set_default_clock_snapshot(this->libObjPtr(), val);
392 nonstd::optional<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) {
399 return ConstClockSnapshot {libObjPtr};
402 return nonstd::nullopt;
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>::_LibObjPtr;
462 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
465 typename std::conditional<std::is_const<LibObjT>::value, CommonPacket<const bt_packet>,
466 CommonPacket<bt_packet>>::type;
469 using Shared = internal::SharedMessage<CommonPacketBeginningMessage<LibObjT>, LibObjT>;
471 explicit CommonPacketBeginningMessage(const _LibObjPtr libObjPtr) noexcept :
472 _ThisCommonMessage {libObjPtr}
474 BT_ASSERT_DBG(this->isPacketBeginning());
477 template <typename OtherLibObjT>
478 CommonPacketBeginningMessage(const CommonPacketBeginningMessage<OtherLibObjT> val) noexcept :
479 _ThisCommonMessage {val}
483 template <typename OtherLibObjT>
484 CommonPacketBeginningMessage<LibObjT>&
485 operator=(const CommonPacketBeginningMessage<OtherLibObjT> val) noexcept
487 _ThisCommonMessage::operator=(val);
491 ConstPacket packet() const noexcept
493 return ConstPacket {internal::CommonPacketBeginningMessageSpec<const bt_message>::packet(
497 _Packet packet() noexcept
500 internal::CommonPacketBeginningMessageSpec<LibObjT>::packet(this->libObjPtr())};
503 void defaultClockSnapshot(const std::uint64_t val) noexcept
505 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
507 bt_message_packet_beginning_set_default_clock_snapshot(this->libObjPtr(), val);
510 ConstClockSnapshot defaultClockSnapshot() const noexcept
512 const auto libObjPtr =
513 bt_message_packet_beginning_borrow_default_clock_snapshot_const(this->libObjPtr());
515 return ConstClockSnapshot {libObjPtr};
518 Shared shared() const noexcept
520 return Shared::createWithRef(*this);
524 using PacketBeginningMessage = CommonPacketBeginningMessage<bt_message>;
525 using ConstPacketBeginningMessage = CommonPacketBeginningMessage<const bt_message>;
529 struct PacketBeginningMessageTypeDescr
531 using Const = ConstPacketBeginningMessage;
532 using NonConst = PacketBeginningMessage;
536 struct TypeDescr<PacketBeginningMessage> : public PacketBeginningMessageTypeDescr
541 struct TypeDescr<ConstPacketBeginningMessage> : public PacketBeginningMessageTypeDescr
545 template <typename LibObjT>
546 struct CommonPacketEndMessageSpec;
548 /* Functions specific to mutable packet end messages */
550 struct CommonPacketEndMessageSpec<bt_message> final
552 static bt_packet *packet(bt_message * const libObjPtr) noexcept
554 return bt_message_packet_end_borrow_packet(libObjPtr);
558 /* Functions specific to constant packet end messages */
560 struct CommonPacketEndMessageSpec<const bt_message> final
562 static const bt_packet *packet(const bt_message * const libObjPtr) noexcept
564 return bt_message_packet_end_borrow_packet_const(libObjPtr);
568 } /* namespace internal */
570 template <typename LibObjT>
571 class CommonPacketEndMessage final : public CommonMessage<LibObjT>
574 using typename CommonMessage<LibObjT>::_LibObjPtr;
575 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
578 typename std::conditional<std::is_const<LibObjT>::value, CommonPacket<const bt_packet>,
579 CommonPacket<bt_packet>>::type;
582 using Shared = internal::SharedMessage<CommonPacketEndMessage<LibObjT>, LibObjT>;
584 explicit CommonPacketEndMessage(const _LibObjPtr libObjPtr) noexcept :
585 _ThisCommonMessage {libObjPtr}
587 BT_ASSERT_DBG(this->isPacketEnd());
590 template <typename OtherLibObjT>
591 CommonPacketEndMessage(const CommonPacketEndMessage<OtherLibObjT> val) noexcept :
592 _ThisCommonMessage {val}
596 template <typename OtherLibObjT>
597 CommonPacketEndMessage<LibObjT>&
598 operator=(const CommonPacketEndMessage<OtherLibObjT> val) noexcept
600 _ThisCommonMessage::operator=(val);
604 ConstPacket packet() const noexcept
607 internal::CommonPacketEndMessageSpec<const bt_message>::packet(this->libObjPtr())};
610 _Packet packet() noexcept
612 return _Packet {internal::CommonPacketEndMessageSpec<LibObjT>::packet(this->libObjPtr())};
615 void defaultClockSnapshot(const std::uint64_t val) noexcept
617 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
619 bt_message_packet_end_set_default_clock_snapshot(this->libObjPtr(), val);
622 ConstClockSnapshot defaultClockSnapshot() const noexcept
624 const auto libObjPtr =
625 bt_message_packet_end_borrow_default_clock_snapshot_const(this->libObjPtr());
627 return ConstClockSnapshot {libObjPtr};
630 Shared shared() const noexcept
632 return Shared::createWithRef(*this);
636 using PacketEndMessage = CommonPacketEndMessage<bt_message>;
637 using ConstPacketEndMessage = CommonPacketEndMessage<const bt_message>;
641 struct PacketEndMessageTypeDescr
643 using Const = ConstPacketEndMessage;
644 using NonConst = PacketEndMessage;
648 struct TypeDescr<PacketEndMessage> : public PacketEndMessageTypeDescr
653 struct TypeDescr<ConstPacketEndMessage> : public PacketEndMessageTypeDescr
657 template <typename LibObjT>
658 struct CommonEventMessageSpec;
660 /* Functions specific to mutable event messages */
662 struct CommonEventMessageSpec<bt_message> final
664 static bt_event *event(bt_message * const libObjPtr) noexcept
666 return bt_message_event_borrow_event(libObjPtr);
670 /* Functions specific to constant event messages */
672 struct CommonEventMessageSpec<const bt_message> final
674 static const bt_event *event(const bt_message * const libObjPtr) noexcept
676 return bt_message_event_borrow_event_const(libObjPtr);
680 } /* namespace internal */
682 template <typename LibObjT>
683 class CommonEventMessage final : public CommonMessage<LibObjT>
686 using typename CommonMessage<LibObjT>::_LibObjPtr;
687 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
690 typename std::conditional<std::is_const<LibObjT>::value, CommonEvent<const bt_event>,
691 CommonEvent<bt_event>>::type;
694 using Shared = internal::SharedMessage<CommonEventMessage<LibObjT>, LibObjT>;
696 explicit CommonEventMessage(const _LibObjPtr libObjPtr) noexcept :
697 _ThisCommonMessage {libObjPtr}
699 BT_ASSERT_DBG(this->isEvent());
702 template <typename OtherLibObjT>
703 CommonEventMessage(const CommonEventMessage<OtherLibObjT> val) noexcept :
704 _ThisCommonMessage {val}
708 template <typename OtherLibObjT>
709 CommonEventMessage<LibObjT>& operator=(const CommonEventMessage<OtherLibObjT> val) noexcept
711 _ThisCommonMessage::operator=(val);
715 ConstEvent event() const noexcept
718 internal::CommonEventMessageSpec<const bt_message>::event(this->libObjPtr())};
721 _Event event() noexcept
723 return _Event {internal::CommonEventMessageSpec<LibObjT>::event(this->libObjPtr())};
726 ConstClockSnapshot defaultClockSnapshot() const noexcept
728 const auto libObjPtr =
729 bt_message_event_borrow_default_clock_snapshot_const(this->libObjPtr());
731 return ConstClockSnapshot {libObjPtr};
734 Shared shared() const noexcept
736 return Shared::createWithRef(*this);
740 using EventMessage = CommonEventMessage<bt_message>;
741 using ConstEventMessage = CommonEventMessage<const bt_message>;
745 struct EventMessageTypeDescr
747 using Const = ConstEventMessage;
748 using NonConst = EventMessage;
752 struct TypeDescr<EventMessage> : public EventMessageTypeDescr
757 struct TypeDescr<ConstEventMessage> : public EventMessageTypeDescr
761 template <typename LibObjT>
762 struct CommonDiscardedEventsMessageSpec;
764 /* Functions specific to mutable discarded events messages */
766 struct CommonDiscardedEventsMessageSpec<bt_message> final
768 static bt_stream *stream(bt_message * const libObjPtr) noexcept
770 return bt_message_discarded_events_borrow_stream(libObjPtr);
774 /* Functions specific to constant discarded events messages */
776 struct CommonDiscardedEventsMessageSpec<const bt_message> final
778 static const bt_stream *stream(const bt_message * const libObjPtr) noexcept
780 return bt_message_discarded_events_borrow_stream_const(libObjPtr);
784 } /* namespace internal */
786 template <typename LibObjT>
787 class CommonDiscardedEventsMessage final : public CommonMessage<LibObjT>
790 using typename CommonMessage<LibObjT>::_LibObjPtr;
791 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
794 typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>,
795 CommonStream<bt_stream>>::type;
798 using Shared = internal::SharedMessage<CommonDiscardedEventsMessage<LibObjT>, LibObjT>;
800 explicit CommonDiscardedEventsMessage(const _LibObjPtr libObjPtr) noexcept :
801 _ThisCommonMessage {libObjPtr}
803 BT_ASSERT_DBG(this->isDiscardedEvents());
806 template <typename OtherLibObjT>
807 CommonDiscardedEventsMessage(const CommonDiscardedEventsMessage<OtherLibObjT> val) noexcept :
808 _ThisCommonMessage {val}
812 template <typename OtherLibObjT>
813 CommonDiscardedEventsMessage<LibObjT>&
814 operator=(const CommonDiscardedEventsMessage<OtherLibObjT> val) noexcept
816 _ThisCommonMessage::operator=(val);
820 ConstStream stream() const noexcept
822 return ConstStream {internal::CommonDiscardedEventsMessageSpec<const bt_message>::stream(
826 _Stream stream() noexcept
829 internal::CommonDiscardedEventsMessageSpec<LibObjT>::stream(this->libObjPtr())};
832 ConstClockSnapshot beginningDefaultClockSnapshot() const noexcept
834 const auto libObjPtr =
835 bt_message_discarded_events_borrow_beginning_default_clock_snapshot_const(
838 return ConstClockSnapshot {libObjPtr};
841 ConstClockSnapshot endDefaultClockSnapshot() const noexcept
843 const auto libObjPtr =
844 bt_message_discarded_events_borrow_end_default_clock_snapshot_const(this->libObjPtr());
846 return ConstClockSnapshot {libObjPtr};
849 void count(const std::uint64_t count) noexcept
851 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
853 bt_message_discarded_events_set_count(this->libObjPtr(), count);
856 nonstd::optional<std::uint64_t> count() const noexcept
859 const auto avail = bt_message_discarded_events_get_count(this->libObjPtr(), &count);
865 return nonstd::nullopt;
868 Shared shared() const noexcept
870 return Shared::createWithRef(*this);
874 using DiscardedEventsMessage = CommonDiscardedEventsMessage<bt_message>;
875 using ConstDiscardedEventsMessage = CommonDiscardedEventsMessage<const bt_message>;
879 struct DiscardedEventsMessageTypeDescr
881 using Const = ConstDiscardedEventsMessage;
882 using NonConst = DiscardedEventsMessage;
886 struct TypeDescr<DiscardedEventsMessage> : public DiscardedEventsMessageTypeDescr
891 struct TypeDescr<ConstDiscardedEventsMessage> : public DiscardedEventsMessageTypeDescr
895 template <typename LibObjT>
896 struct CommonDiscardedPacketsMessageSpec;
898 /* Functions specific to mutable discarded packets messages */
900 struct CommonDiscardedPacketsMessageSpec<bt_message> final
902 static bt_stream *stream(bt_message * const libObjPtr) noexcept
904 return bt_message_discarded_packets_borrow_stream(libObjPtr);
908 /* Functions specific to constant discarded packets messages */
910 struct CommonDiscardedPacketsMessageSpec<const bt_message> final
912 static const bt_stream *stream(const bt_message * const libObjPtr) noexcept
914 return bt_message_discarded_packets_borrow_stream_const(libObjPtr);
918 } /* namespace internal */
920 template <typename LibObjT>
921 class CommonDiscardedPacketsMessage final : public CommonMessage<LibObjT>
924 using typename CommonMessage<LibObjT>::_LibObjPtr;
925 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
928 typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>,
929 CommonStream<bt_stream>>::type;
932 using Shared = internal::SharedMessage<CommonDiscardedPacketsMessage<LibObjT>, LibObjT>;
934 explicit CommonDiscardedPacketsMessage(const _LibObjPtr libObjPtr) noexcept :
935 _ThisCommonMessage {libObjPtr}
937 BT_ASSERT_DBG(this->isDiscardedPackets());
940 template <typename OtherLibObjT>
941 CommonDiscardedPacketsMessage(const CommonDiscardedPacketsMessage<OtherLibObjT> val) noexcept :
942 _ThisCommonMessage {val}
946 template <typename OtherLibObjT>
947 CommonDiscardedPacketsMessage<LibObjT>&
948 operator=(const CommonDiscardedPacketsMessage<OtherLibObjT> val) noexcept
950 _ThisCommonMessage::operator=(val);
954 ConstStream stream() const noexcept
956 return ConstStream {internal::CommonDiscardedPacketsMessageSpec<const bt_message>::stream(
960 _Stream stream() noexcept
963 internal::CommonDiscardedPacketsMessageSpec<LibObjT>::stream(this->libObjPtr())};
966 ConstClockSnapshot beginningDefaultClockSnapshot() const noexcept
968 const auto libObjPtr =
969 bt_message_discarded_packets_borrow_beginning_default_clock_snapshot_const(
972 return ConstClockSnapshot {libObjPtr};
975 ConstClockSnapshot endDefaultClockSnapshot() const noexcept
977 const auto libObjPtr =
978 bt_message_discarded_packets_borrow_end_default_clock_snapshot_const(this->libObjPtr());
980 return ConstClockSnapshot {libObjPtr};
983 void count(const std::uint64_t count) noexcept
985 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
987 bt_message_discarded_packets_set_count(this->libObjPtr(), count);
990 nonstd::optional<std::uint64_t> count() const noexcept
993 const auto avail = bt_message_discarded_packets_get_count(this->libObjPtr(), &count);
999 return nonstd::nullopt;
1002 Shared shared() const noexcept
1004 return Shared::createWithRef(*this);
1008 using DiscardedPacketsMessage = CommonDiscardedPacketsMessage<bt_message>;
1009 using ConstDiscardedPacketsMessage = CommonDiscardedPacketsMessage<const bt_message>;
1011 namespace internal {
1013 struct DiscardedPacketsMessageTypeDescr
1015 using Const = ConstDiscardedPacketsMessage;
1016 using NonConst = DiscardedPacketsMessage;
1020 struct TypeDescr<DiscardedPacketsMessage> : public DiscardedPacketsMessageTypeDescr
1025 struct TypeDescr<ConstDiscardedPacketsMessage> : public DiscardedPacketsMessageTypeDescr
1029 } /* namespace internal */
1031 template <typename LibObjT>
1032 class CommonMessageIteratorInactivityMessage final : public CommonMessage<LibObjT>
1035 using typename CommonMessage<LibObjT>::_LibObjPtr;
1036 using typename CommonMessage<LibObjT>::_ThisCommonMessage;
1040 internal::SharedMessage<CommonMessageIteratorInactivityMessage<LibObjT>, LibObjT>;
1042 explicit CommonMessageIteratorInactivityMessage(const _LibObjPtr libObjPtr) noexcept :
1043 _ThisCommonMessage {libObjPtr}
1045 BT_ASSERT_DBG(this->isMessageIteratorInactivity());
1048 template <typename OtherLibObjT>
1049 CommonMessageIteratorInactivityMessage(
1050 const CommonMessageIteratorInactivityMessage<OtherLibObjT> val) noexcept :
1051 _ThisCommonMessage {val}
1055 template <typename OtherLibObjT>
1056 CommonMessageIteratorInactivityMessage<LibObjT>&
1057 operator=(const CommonMessageIteratorInactivityMessage<OtherLibObjT> val) noexcept
1059 _ThisCommonMessage::operator=(val);
1063 ConstClockSnapshot clockSnapshot() const noexcept
1065 const auto libObjPtr =
1066 bt_message_message_iterator_inactivity_borrow_clock_snapshot_const(this->libObjPtr());
1068 return ConstClockSnapshot {libObjPtr};
1071 Shared shared() const noexcept
1073 return Shared::createWithRef(*this);
1077 using MessageIteratorInactivityMessage = CommonMessageIteratorInactivityMessage<bt_message>;
1078 using ConstMessageIteratorInactivityMessage =
1079 CommonMessageIteratorInactivityMessage<const bt_message>;
1081 namespace internal {
1083 struct MessageIteratorInactivityMessageTypeDescr
1085 using Const = ConstMessageIteratorInactivityMessage;
1086 using NonConst = MessageIteratorInactivityMessage;
1090 struct TypeDescr<MessageIteratorInactivityMessage> :
1091 public MessageIteratorInactivityMessageTypeDescr
1096 struct TypeDescr<ConstMessageIteratorInactivityMessage> :
1097 public MessageIteratorInactivityMessageTypeDescr
1101 } /* namespace internal */
1103 template <typename LibObjT>
1104 CommonStreamBeginningMessage<LibObjT> CommonMessage<LibObjT>::asStreamBeginning() const noexcept
1106 BT_ASSERT_DBG(this->isStreamBeginning());
1107 return CommonStreamBeginningMessage<LibObjT> {this->libObjPtr()};
1110 template <typename LibObjT>
1111 CommonStreamEndMessage<LibObjT> CommonMessage<LibObjT>::asStreamEnd() const noexcept
1113 BT_ASSERT_DBG(this->isStreamEnd());
1114 return CommonStreamEndMessage<LibObjT> {this->libObjPtr()};
1117 template <typename LibObjT>
1118 CommonPacketBeginningMessage<LibObjT> CommonMessage<LibObjT>::asPacketBeginning() const noexcept
1120 BT_ASSERT_DBG(this->isPacketBeginning());
1121 return CommonPacketBeginningMessage<LibObjT> {this->libObjPtr()};
1124 template <typename LibObjT>
1125 CommonPacketEndMessage<LibObjT> CommonMessage<LibObjT>::asPacketEnd() const noexcept
1127 BT_ASSERT_DBG(this->isPacketEnd());
1128 return CommonPacketEndMessage<LibObjT> {this->libObjPtr()};
1131 template <typename LibObjT>
1132 CommonEventMessage<LibObjT> CommonMessage<LibObjT>::asEvent() const noexcept
1134 BT_ASSERT_DBG(this->isEvent());
1135 return CommonEventMessage<LibObjT> {this->libObjPtr()};
1138 template <typename LibObjT>
1139 CommonDiscardedEventsMessage<LibObjT> CommonMessage<LibObjT>::asDiscardedEvents() const noexcept
1141 BT_ASSERT_DBG(this->isDiscardedEvents());
1142 return CommonDiscardedEventsMessage<LibObjT> {this->libObjPtr()};
1145 template <typename LibObjT>
1146 CommonDiscardedPacketsMessage<LibObjT> CommonMessage<LibObjT>::asDiscardedPackets() const noexcept
1148 BT_ASSERT_DBG(this->isDiscardedPackets());
1149 return CommonDiscardedPacketsMessage<LibObjT> {this->libObjPtr()};
1152 template <typename LibObjT>
1153 CommonMessageIteratorInactivityMessage<LibObjT>
1154 CommonMessage<LibObjT>::asMessageIteratorInactivity() const noexcept
1156 BT_ASSERT_DBG(this->isMessageIteratorInactivity());
1157 return CommonMessageIteratorInactivityMessage<LibObjT> {this->libObjPtr()};
1160 } /* namespace bt2 */
1162 #endif /* BABELTRACE_CPP_COMMON_BT2_MESSAGE_HPP */