From 508053d4bbf1adfe3194c05192066f7947b55674 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Fri, 22 Jan 2021 09:23:02 -0500 Subject: [PATCH] Add C++ interface for the libbabeltrace2 `bt_message` API This patch adds C++ wrappers for Babeltrace 2 message objects. The class hierarchy is: Message StreamBeginningMessage StreamEndMessage PacketBeginningMessage PacketEndMessage EventMessage DiscardedEventsMessage DiscardedPacketsMessage MessageIteratorInactivityMessage ConstMessage ConstStreamBeginningMessage ConstStreamEndMessage ConstPacketBeginningMessage ConstPacketEndMessage ConstEventMessage ConstDiscardedEventsMessage ConstDiscardedPacketsMessage ConstMessageIteratorInactivityMessage Implicitly convert from a mutable field class to a constant field class with converting constructors and assignment operators. Those new template classes follow the approach of other wrappers in `src/cpp-common/bt2`. Signed-off-by: Philippe Proulx Change-Id: If01ac4b2bbf8eb1ea400f8e5e7c2003b4844b80f Reviewed-on: https://review.lttng.org/c/babeltrace/+/4735 --- src/cpp-common/bt2/message.hpp | 996 +++++++++++++++++++++++++++++++++ 1 file changed, 996 insertions(+) create mode 100644 src/cpp-common/bt2/message.hpp diff --git a/src/cpp-common/bt2/message.hpp b/src/cpp-common/bt2/message.hpp new file mode 100644 index 00000000..65404f3c --- /dev/null +++ b/src/cpp-common/bt2/message.hpp @@ -0,0 +1,996 @@ +/* + * Copyright (c) 2021 Philippe Proulx + * + * SPDX-License-Identifier: MIT + */ + +#ifndef BABELTRACE_CPP_COMMON_BT2_MESSAGE_HPP +#define BABELTRACE_CPP_COMMON_BT2_MESSAGE_HPP + +#include +#include +#include +#include + +#include "common/assert.h" +#include "common/common.h" +#include "internal/borrowed-obj.hpp" +#include "internal/shared-obj.hpp" +#include "internal/utils.hpp" +#include "cpp-common/optional.hpp" +#include "cpp-common/string_view.hpp" +#include "lib-error.hpp" + +namespace bt2 { + +namespace internal { + +struct MessageRefFuncs final +{ + static void get(const bt_message * const libObjPtr) + { + bt_message_get_ref(libObjPtr); + } + + static void put(const bt_message * const libObjPtr) + { + bt_message_put_ref(libObjPtr); + } +}; + +template +using SharedMessage = internal::SharedObj; + +} // namespace internal + +template +class CommonStreamBeginningMessage; + +template +class CommonStreamEndMessage; + +template +class CommonEventMessage; + +template +class CommonPacketBeginningMessage; + +template +class CommonPacketEndMessage; + +template +class CommonDiscardedEventsMessage; + +template +class CommonDiscardedPacketsMessage; + +template +class CommonMessageIteratorInactivityMessage; + +enum class MessageType +{ + STREAM_BEGINNING = BT_MESSAGE_TYPE_STREAM_BEGINNING, + STREAM_END = BT_MESSAGE_TYPE_STREAM_END, + EVENT = BT_MESSAGE_TYPE_EVENT, + PACKET_BEGINNING = BT_MESSAGE_TYPE_PACKET_BEGINNING, + PACKET_END = BT_MESSAGE_TYPE_PACKET_END, + DISCARDED_EVENTS = BT_MESSAGE_TYPE_DISCARDED_EVENTS, + DISCARDED_PACKETS = BT_MESSAGE_TYPE_DISCARDED_PACKETS, + MESSAGE_ITERATOR_INACTIVITY = BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY, +}; + +template +class CommonMessage : public internal::BorrowedObj +{ +private: + using typename internal::BorrowedObj::_ThisBorrowedObj; + +protected: + using typename internal::BorrowedObj::_LibObjPtr; + using _ThisCommonMessage = CommonMessage; + +public: + using Shared = internal::SharedMessage, LibObjT>; + + explicit CommonMessage(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr} + { + } + + template + CommonMessage(const CommonMessage& val) noexcept : _ThisBorrowedObj {val} + { + } + + template + _ThisCommonMessage& operator=(const CommonMessage& val) noexcept + { + _ThisBorrowedObj::operator=(val); + return *this; + } + + MessageType type() const noexcept + { + return static_cast(bt_message_get_type(this->_libObjPtr())); + } + + bool isStreamBeginning() const noexcept + { + return this->type() == MessageType::STREAM_BEGINNING; + } + + bool isStreamEnd() const noexcept + { + return this->type() == MessageType::STREAM_END; + } + + bool isEvent() const noexcept + { + return this->type() == MessageType::EVENT; + } + + bool isPacketBeginning() const noexcept + { + return this->type() == MessageType::PACKET_BEGINNING; + } + + bool isPacketEnd() const noexcept + { + return this->type() == MessageType::PACKET_END; + } + + bool isDiscardedEvents() const noexcept + { + return this->type() == MessageType::DISCARDED_EVENTS; + } + + bool isDiscardedPackets() const noexcept + { + return this->type() == MessageType::DISCARDED_PACKETS; + } + + bool isMessageIteratorInactivity() const noexcept + { + return this->type() == MessageType::MESSAGE_ITERATOR_INACTIVITY; + } + + Shared shared() const noexcept + { + return Shared {*this}; + } + + CommonStreamBeginningMessage asStreamBeginning() const noexcept; + CommonStreamEndMessage asStreamEnd() const noexcept; + CommonEventMessage asEvent() const noexcept; + CommonPacketBeginningMessage asPacketBeginning() const noexcept; + CommonPacketEndMessage asPacketEnd() const noexcept; + CommonDiscardedEventsMessage asDiscardedEvents() const noexcept; + CommonDiscardedPacketsMessage asDiscardedPackets() const noexcept; + CommonMessageIteratorInactivityMessage asMessageIteratorInactivity() const noexcept; +}; + +using Message = CommonMessage; +using ConstMessage = CommonMessage; + +namespace internal { + +template +struct CommonStreamBeginningMessageSpec; + +// Functions specific to mutable stream beginning messages +template <> +struct CommonStreamBeginningMessageSpec final +{ + static bt_stream *stream(bt_message * const libObjPtr) noexcept + { + return bt_message_stream_beginning_borrow_stream(libObjPtr); + } +}; + +// Functions specific to constant stream beginning messages +template <> +struct CommonStreamBeginningMessageSpec final +{ + static const bt_stream *stream(const bt_message * const libObjPtr) noexcept + { + return bt_message_stream_beginning_borrow_stream_const(libObjPtr); + } +}; + +} // namespace internal + +template +class CommonStreamBeginningMessage final : public CommonMessage +{ +private: + using typename CommonMessage::_LibObjPtr; + using typename CommonMessage::_ThisCommonMessage; + + using _Stream = + typename std::conditional::value, CommonStream, + CommonStream>::type; + +public: + using Shared = internal::SharedMessage, LibObjT>; + + explicit CommonStreamBeginningMessage(const _LibObjPtr libObjPtr) noexcept : + _ThisCommonMessage {libObjPtr} + { + BT_ASSERT_DBG(this->isStreamBeginning()); + } + + template + CommonStreamBeginningMessage(const CommonStreamBeginningMessage& val) noexcept : + _ThisCommonMessage {val} + { + } + + template + CommonStreamBeginningMessage& + operator=(const CommonStreamBeginningMessage& val) noexcept + { + _ThisCommonMessage::operator=(val); + return *this; + } + + ConstStream stream() const noexcept + { + return ConstStream {internal::CommonStreamBeginningMessageSpec::stream( + this->_libObjPtr())}; + } + + _Stream stream() noexcept + { + return _Stream { + internal::CommonStreamBeginningMessageSpec::stream(this->_libObjPtr())}; + } + + void defaultClockSnapshot(const std::uint64_t val) noexcept + { + static_assert(!std::is_const::value, "`LibObjT` must NOT be `const`."); + + bt_message_stream_beginning_set_default_clock_snapshot(this->_libObjPtr(), val); + } + + nonstd::optional defaultClockSnapshot() const noexcept + { + const bt_clock_snapshot *libObjPtr; + const auto state = bt_message_stream_beginning_borrow_default_clock_snapshot_const( + this->_libObjPtr(), &libObjPtr); + + if (state == BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN) { + return ConstClockSnapshot {libObjPtr}; + } + + return nonstd::nullopt; + } + + Shared shared() const noexcept + { + return Shared {*this}; + } +}; + +using StreamBeginningMessage = CommonStreamBeginningMessage; +using ConstStreamBeginningMessage = CommonStreamBeginningMessage; + +namespace internal { + +template +struct CommonStreamEndMessageSpec; + +// Functions specific to mutable stream end messages +template <> +struct CommonStreamEndMessageSpec final +{ + static bt_stream *stream(bt_message * const libObjPtr) noexcept + { + return bt_message_stream_end_borrow_stream(libObjPtr); + } +}; + +// Functions specific to constant stream end messages +template <> +struct CommonStreamEndMessageSpec final +{ + static const bt_stream *stream(const bt_message * const libObjPtr) noexcept + { + return bt_message_stream_end_borrow_stream_const(libObjPtr); + } +}; + +} // namespace internal + +template +class CommonStreamEndMessage final : public CommonMessage +{ +private: + using typename CommonMessage::_LibObjPtr; + using typename CommonMessage::_ThisCommonMessage; + + using _Stream = + typename std::conditional::value, CommonStream, + CommonStream>::type; + +public: + using Shared = internal::SharedMessage, LibObjT>; + + explicit CommonStreamEndMessage(const _LibObjPtr libObjPtr) noexcept : + _ThisCommonMessage {libObjPtr} + { + BT_ASSERT_DBG(this->isStreamEnd()); + } + + template + CommonStreamEndMessage(const CommonStreamEndMessage& val) noexcept : + _ThisCommonMessage {val} + { + } + + template + CommonStreamEndMessage& + operator=(const CommonStreamEndMessage& val) noexcept + { + _ThisCommonMessage::operator=(val); + return *this; + } + + ConstStream stream() const noexcept + { + return ConstStream { + internal::CommonStreamEndMessageSpec::stream(this->_libObjPtr())}; + } + + _Stream stream() noexcept + { + return _Stream {internal::CommonStreamEndMessageSpec::stream(this->_libObjPtr())}; + } + + void defaultClockSnapshot(const std::uint64_t val) noexcept + { + static_assert(!std::is_const::value, "`LibObjT` must NOT be `const`."); + + bt_message_stream_end_set_default_clock_snapshot(this->_libObjPtr(), val); + } + + nonstd::optional defaultClockSnapshot() const noexcept + { + const bt_clock_snapshot *libObjPtr; + const auto state = bt_message_stream_end_borrow_default_clock_snapshot_const( + this->_libObjPtr(), &libObjPtr); + + if (state == BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN) { + return ConstClockSnapshot {libObjPtr}; + } + + return nonstd::nullopt; + } + + Shared shared() const noexcept + { + return Shared {*this}; + } +}; + +using StreamEndMessage = CommonStreamEndMessage; +using ConstStreamEndMessage = CommonStreamEndMessage; + +namespace internal { + +template +struct CommonPacketBeginningMessageSpec; + +// Functions specific to mutable packet beginning messages +template <> +struct CommonPacketBeginningMessageSpec final +{ + static bt_packet *packet(bt_message * const libObjPtr) noexcept + { + return bt_message_packet_beginning_borrow_packet(libObjPtr); + } +}; + +// Functions specific to constant packet beginning messages +template <> +struct CommonPacketBeginningMessageSpec final +{ + static const bt_packet *packet(const bt_message * const libObjPtr) noexcept + { + return bt_message_packet_beginning_borrow_packet_const(libObjPtr); + } +}; + +} // namespace internal + +template +class CommonPacketBeginningMessage final : public CommonMessage +{ +private: + using typename CommonMessage::_LibObjPtr; + using typename CommonMessage::_ThisCommonMessage; + + using _Packet = + typename std::conditional::value, CommonPacket, + CommonPacket>::type; + +public: + using Shared = internal::SharedMessage, LibObjT>; + + explicit CommonPacketBeginningMessage(const _LibObjPtr libObjPtr) noexcept : + _ThisCommonMessage {libObjPtr} + { + BT_ASSERT_DBG(this->isPacketBeginning()); + } + + template + CommonPacketBeginningMessage(const CommonPacketBeginningMessage& val) noexcept : + _ThisCommonMessage {val} + { + } + + template + CommonPacketBeginningMessage& + operator=(const CommonPacketBeginningMessage& val) noexcept + { + _ThisCommonMessage::operator=(val); + return *this; + } + + ConstPacket packet() const noexcept + { + return ConstPacket {internal::CommonPacketBeginningMessageSpec::packet( + this->_libObjPtr())}; + } + + _Packet packet() noexcept + { + return _Packet { + internal::CommonPacketBeginningMessageSpec::packet(this->_libObjPtr())}; + } + + void defaultClockSnapshot(const std::uint64_t val) noexcept + { + static_assert(!std::is_const::value, "`LibObjT` must NOT be `const`."); + + bt_message_packet_beginning_set_default_clock_snapshot(this->_libObjPtr(), val); + } + + ConstClockSnapshot defaultClockSnapshot() const noexcept + { + const auto libObjPtr = + bt_message_packet_beginning_borrow_default_clock_snapshot_const(this->_libObjPtr()); + + return ConstClockSnapshot {libObjPtr}; + } + + Shared shared() const noexcept + { + return Shared {*this}; + } +}; + +using PacketBeginningMessage = CommonPacketBeginningMessage; +using ConstPacketBeginningMessage = CommonPacketBeginningMessage; + +namespace internal { + +template +struct CommonPacketEndMessageSpec; + +// Functions specific to mutable packet end messages +template <> +struct CommonPacketEndMessageSpec final +{ + static bt_packet *packet(bt_message * const libObjPtr) noexcept + { + return bt_message_packet_end_borrow_packet(libObjPtr); + } +}; + +// Functions specific to constant packet end messages +template <> +struct CommonPacketEndMessageSpec final +{ + static const bt_packet *packet(const bt_message * const libObjPtr) noexcept + { + return bt_message_packet_end_borrow_packet_const(libObjPtr); + } +}; + +} // namespace internal + +template +class CommonPacketEndMessage final : public CommonMessage +{ +private: + using typename CommonMessage::_LibObjPtr; + using typename CommonMessage::_ThisCommonMessage; + + using _Packet = + typename std::conditional::value, CommonPacket, + CommonPacket>::type; + +public: + using Shared = internal::SharedMessage, LibObjT>; + + explicit CommonPacketEndMessage(const _LibObjPtr libObjPtr) noexcept : + _ThisCommonMessage {libObjPtr} + { + BT_ASSERT_DBG(this->isPacketEnd()); + } + + template + CommonPacketEndMessage(const CommonPacketEndMessage& val) noexcept : + _ThisCommonMessage {val} + { + } + + template + CommonPacketEndMessage& + operator=(const CommonPacketEndMessage& val) noexcept + { + _ThisCommonMessage::operator=(val); + return *this; + } + + ConstPacket packet() const noexcept + { + return ConstPacket { + internal::CommonPacketEndMessageSpec::packet(this->_libObjPtr())}; + } + + _Packet packet() noexcept + { + return _Packet {internal::CommonPacketEndMessageSpec::packet(this->_libObjPtr())}; + } + + void defaultClockSnapshot(const std::uint64_t val) noexcept + { + static_assert(!std::is_const::value, "`LibObjT` must NOT be `const`."); + + bt_message_packet_end_set_default_clock_snapshot(this->_libObjPtr(), val); + } + + ConstClockSnapshot defaultClockSnapshot() const noexcept + { + const auto libObjPtr = + bt_message_packet_end_borrow_default_clock_snapshot_const(this->_libObjPtr()); + + return ConstClockSnapshot {libObjPtr}; + } + + Shared shared() const noexcept + { + return Shared {*this}; + } +}; + +using PacketEndMessage = CommonPacketEndMessage; +using ConstPacketEndMessage = CommonPacketEndMessage; + +namespace internal { + +template +struct CommonEventMessageSpec; + +// Functions specific to mutable event messages +template <> +struct CommonEventMessageSpec final +{ + static bt_event *event(bt_message * const libObjPtr) noexcept + { + return bt_message_event_borrow_event(libObjPtr); + } +}; + +// Functions specific to constant event messages +template <> +struct CommonEventMessageSpec final +{ + static const bt_event *event(const bt_message * const libObjPtr) noexcept + { + return bt_message_event_borrow_event_const(libObjPtr); + } +}; + +} // namespace internal + +template +class CommonEventMessage final : public CommonMessage +{ +private: + using typename CommonMessage::_LibObjPtr; + using typename CommonMessage::_ThisCommonMessage; + + using _Event = + typename std::conditional::value, CommonEvent, + CommonEvent>::type; + +public: + using Shared = internal::SharedMessage, LibObjT>; + + explicit CommonEventMessage(const _LibObjPtr libObjPtr) noexcept : + _ThisCommonMessage {libObjPtr} + { + BT_ASSERT_DBG(this->isEvent()); + } + + template + CommonEventMessage(const CommonEventMessage& val) noexcept : + _ThisCommonMessage {val} + { + } + + template + CommonEventMessage& operator=(const CommonEventMessage& val) noexcept + { + _ThisCommonMessage::operator=(val); + return *this; + } + + ConstEvent event() const noexcept + { + return ConstEvent { + internal::CommonEventMessageSpec::event(this->_libObjPtr())}; + } + + _Event event() noexcept + { + return _Event {internal::CommonEventMessageSpec::event(this->_libObjPtr())}; + } + + ConstClockSnapshot defaultClockSnapshot() const noexcept + { + const auto libObjPtr = + bt_message_event_borrow_default_clock_snapshot_const(this->_libObjPtr()); + + return ConstClockSnapshot {libObjPtr}; + } + + Shared shared() const noexcept + { + return Shared {*this}; + } +}; + +using EventMessage = CommonEventMessage; +using ConstEventMessage = CommonEventMessage; + +namespace internal { + +template +struct CommonDiscardedEventsMessageSpec; + +// Functions specific to mutable discarded events messages +template <> +struct CommonDiscardedEventsMessageSpec final +{ + static bt_stream *stream(bt_message * const libObjPtr) noexcept + { + return bt_message_discarded_events_borrow_stream(libObjPtr); + } +}; + +// Functions specific to constant discarded events messages +template <> +struct CommonDiscardedEventsMessageSpec final +{ + static const bt_stream *stream(const bt_message * const libObjPtr) noexcept + { + return bt_message_discarded_events_borrow_stream_const(libObjPtr); + } +}; + +} // namespace internal + +template +class CommonDiscardedEventsMessage final : public CommonMessage +{ +private: + using typename CommonMessage::_LibObjPtr; + using typename CommonMessage::_ThisCommonMessage; + + using _Stream = + typename std::conditional::value, CommonStream, + CommonStream>::type; + +public: + using Shared = internal::SharedMessage, LibObjT>; + + explicit CommonDiscardedEventsMessage(const _LibObjPtr libObjPtr) noexcept : + _ThisCommonMessage {libObjPtr} + { + BT_ASSERT_DBG(this->isDiscardedEvents()); + } + + template + CommonDiscardedEventsMessage(const CommonDiscardedEventsMessage& val) noexcept : + _ThisCommonMessage {val} + { + } + + template + CommonDiscardedEventsMessage& + operator=(const CommonDiscardedEventsMessage& val) noexcept + { + _ThisCommonMessage::operator=(val); + return *this; + } + + ConstStream stream() const noexcept + { + return ConstStream {internal::CommonDiscardedEventsMessageSpec::stream( + this->_libObjPtr())}; + } + + _Stream stream() noexcept + { + return _Stream { + internal::CommonDiscardedEventsMessageSpec::stream(this->_libObjPtr())}; + } + + ConstClockSnapshot beginningDefaultClockSnapshot() const noexcept + { + const auto libObjPtr = + bt_message_discarded_events_borrow_beginning_default_clock_snapshot_const( + this->_libObjPtr()); + + return ConstClockSnapshot {libObjPtr}; + } + + ConstClockSnapshot endDefaultClockSnapshot() const noexcept + { + const auto libObjPtr = + bt_message_discarded_events_borrow_end_default_clock_snapshot_const(this->_libObjPtr()); + + return ConstClockSnapshot {libObjPtr}; + } + + void count(const std::uint64_t count) noexcept + { + static_assert(!std::is_const::value, "`LibObjT` must NOT be `const`."); + + bt_message_discarded_events_set_count(this->_libObjPtr(), count); + } + + nonstd::optional count() const noexcept + { + std::uint64_t count; + const auto avail = bt_message_discarded_events_get_count(this->_libObjPtr(), &count); + + if (avail) { + return count; + } + + return nonstd::nullopt; + } + + Shared shared() const noexcept + { + return Shared {*this}; + } +}; + +using DiscardedEventsMessage = CommonDiscardedEventsMessage; +using ConstDiscardedEventsMessage = CommonDiscardedEventsMessage; + +namespace internal { + +template +struct CommonDiscardedPacketsMessageSpec; + +// Functions specific to mutable discarded packets messages +template <> +struct CommonDiscardedPacketsMessageSpec final +{ + static bt_stream *stream(bt_message * const libObjPtr) noexcept + { + return bt_message_discarded_packets_borrow_stream(libObjPtr); + } +}; + +// Functions specific to constant discarded packets messages +template <> +struct CommonDiscardedPacketsMessageSpec final +{ + static const bt_stream *stream(const bt_message * const libObjPtr) noexcept + { + return bt_message_discarded_packets_borrow_stream_const(libObjPtr); + } +}; + +} // namespace internal + +template +class CommonDiscardedPacketsMessage final : public CommonMessage +{ +private: + using typename CommonMessage::_LibObjPtr; + using typename CommonMessage::_ThisCommonMessage; + + using _Stream = + typename std::conditional::value, CommonStream, + CommonStream>::type; + +public: + using Shared = internal::SharedMessage, LibObjT>; + + explicit CommonDiscardedPacketsMessage(const _LibObjPtr libObjPtr) noexcept : + _ThisCommonMessage {libObjPtr} + { + BT_ASSERT_DBG(this->isDiscardedPackets()); + } + + template + CommonDiscardedPacketsMessage(const CommonDiscardedPacketsMessage& val) noexcept : + _ThisCommonMessage {val} + { + } + + template + CommonDiscardedPacketsMessage& + operator=(const CommonDiscardedPacketsMessage& val) noexcept + { + _ThisCommonMessage::operator=(val); + return *this; + } + + ConstStream stream() const noexcept + { + return ConstStream {internal::CommonDiscardedPacketsMessageSpec::stream( + this->_libObjPtr())}; + } + + _Stream stream() noexcept + { + return _Stream { + internal::CommonDiscardedPacketsMessageSpec::stream(this->_libObjPtr())}; + } + + ConstClockSnapshot beginningDefaultClockSnapshot() const noexcept + { + const auto libObjPtr = + bt_message_discarded_packets_borrow_beginning_default_clock_snapshot_const( + this->_libObjPtr()); + + return ConstClockSnapshot {libObjPtr}; + } + + ConstClockSnapshot endDefaultClockSnapshot() const noexcept + { + const auto libObjPtr = bt_message_discarded_packets_borrow_end_default_clock_snapshot_const( + this->_libObjPtr()); + + return ConstClockSnapshot {libObjPtr}; + } + + void count(const std::uint64_t count) noexcept + { + static_assert(!std::is_const::value, "`LibObjT` must NOT be `const`."); + + bt_message_discarded_packets_set_count(this->_libObjPtr(), count); + } + + nonstd::optional count() const noexcept + { + std::uint64_t count; + const auto avail = bt_message_discarded_packets_get_count(this->_libObjPtr(), &count); + + if (avail) { + return count; + } + + return nonstd::nullopt; + } + + Shared shared() const noexcept + { + return Shared {*this}; + } +}; + +using DiscardedPacketsMessage = CommonDiscardedPacketsMessage; +using ConstDiscardedPacketsMessage = CommonDiscardedPacketsMessage; + +template +class CommonMessageIteratorInactivityMessage final : public CommonMessage +{ +private: + using typename CommonMessage::_LibObjPtr; + using typename CommonMessage::_ThisCommonMessage; + +public: + using Shared = + internal::SharedMessage, LibObjT>; + + explicit CommonMessageIteratorInactivityMessage(const _LibObjPtr libObjPtr) noexcept : + _ThisCommonMessage {libObjPtr} + { + BT_ASSERT_DBG(this->isMessageIteratorInactivity()); + } + + template + CommonMessageIteratorInactivityMessage( + const CommonMessageIteratorInactivityMessage& val) noexcept : + _ThisCommonMessage {val} + { + } + + template + CommonMessageIteratorInactivityMessage& + operator=(const CommonMessageIteratorInactivityMessage& val) noexcept + { + _ThisCommonMessage::operator=(val); + return *this; + } + + ConstClockSnapshot clockSnapshot() const noexcept + { + const auto libObjPtr = + bt_message_message_iterator_inactivity_borrow_clock_snapshot_const(this->_libObjPtr()); + + return ConstClockSnapshot {libObjPtr}; + } + + Shared shared() const noexcept + { + return Shared {*this}; + } +}; + +using MessageIteratorInactivityMessage = CommonMessageIteratorInactivityMessage; +using ConstMessageIteratorInactivityMessage = + CommonMessageIteratorInactivityMessage; + +template +CommonStreamBeginningMessage CommonMessage::asStreamBeginning() const noexcept +{ + BT_ASSERT_DBG(this->isStreamBeginning()); + return CommonStreamBeginningMessage {this->_libObjPtr()}; +} + +template +CommonStreamEndMessage CommonMessage::asStreamEnd() const noexcept +{ + BT_ASSERT_DBG(this->isStreamEnd()); + return CommonStreamEndMessage {this->_libObjPtr()}; +} + +template +CommonPacketBeginningMessage CommonMessage::asPacketBeginning() const noexcept +{ + BT_ASSERT_DBG(this->isPacketBeginning()); + return CommonPacketBeginningMessage {this->_libObjPtr()}; +} + +template +CommonPacketEndMessage CommonMessage::asPacketEnd() const noexcept +{ + BT_ASSERT_DBG(this->isPacketEnd()); + return CommonPacketEndMessage {this->_libObjPtr()}; +} + +template +CommonEventMessage CommonMessage::asEvent() const noexcept +{ + BT_ASSERT_DBG(this->isEvent()); + return CommonEventMessage {this->_libObjPtr()}; +} + +template +CommonDiscardedEventsMessage CommonMessage::asDiscardedEvents() const noexcept +{ + BT_ASSERT_DBG(this->isDiscardedEvents()); + return CommonDiscardedEventsMessage {this->_libObjPtr()}; +} + +template +CommonMessageIteratorInactivityMessage +CommonMessage::asMessageIteratorInactivity() const noexcept +{ + BT_ASSERT_DBG(this->isMessageIteratorInactivity()); + return CommonMessageIteratorInactivityMessage {this->_libObjPtr()}; +} + +} // namespace bt2 + +#endif // BABELTRACE_CPP_COMMON_BT2_MESSAGE_HPP -- 2.34.1