X-Git-Url: https://git.efficios.com/?a=blobdiff_plain;f=src%2Fcpp-common%2Fbt2%2Fmessage.hpp;h=be9be1184587d23bc5f1c4e117d3e16b7803170c;hb=afe77d4f77220b7fa0a27cbe6e2aef34c6935174;hp=bc83c4b2181cbe9645bf5e9d1d9ab41ea2bfea08;hpb=45e0ded5cd688d00bd39feace0720cba4e63a298;p=babeltrace.git diff --git a/src/cpp-common/bt2/message.hpp b/src/cpp-common/bt2/message.hpp index bc83c4b2..be9be118 100644 --- a/src/cpp-common/bt2/message.hpp +++ b/src/cpp-common/bt2/message.hpp @@ -7,41 +7,43 @@ #ifndef BABELTRACE_CPP_COMMON_BT2_MESSAGE_HPP #define BABELTRACE_CPP_COMMON_BT2_MESSAGE_HPP -#include #include -#include +#include + #include #include "common/assert.h" -#include "common/common.h" -#include "internal/borrowed-obj.hpp" -#include "internal/shared-obj.hpp" +#include "cpp-common/bt2/clock-snapshot.hpp" +#include "cpp-common/bt2/trace-ir.hpp" +#include "cpp-common/bt2s/optional.hpp" + +#include "borrowed-object.hpp" #include "internal/utils.hpp" -#include "cpp-common/optional.hpp" -#include "cpp-common/string_view.hpp" -#include "lib-error.hpp" +#include "optional-borrowed-object.hpp" +#include "shared-object.hpp" +#include "trace-ir.hpp" namespace bt2 { namespace internal { struct MessageRefFuncs final { - static void get(const bt_message * const libObjPtr) + static void get(const bt_message * const libObjPtr) noexcept { bt_message_get_ref(libObjPtr); } - static void put(const bt_message * const libObjPtr) + static void put(const bt_message * const libObjPtr) noexcept { bt_message_put_ref(libObjPtr); } }; -template -using SharedMessage = internal::SharedObj; - } /* namespace internal */ +template +using SharedMessage = SharedObject; + template class CommonStreamBeginningMessage; @@ -79,34 +81,39 @@ enum class MessageType }; template -class CommonMessage : public internal::BorrowedObj +class CommonMessage : public BorrowedObject { private: - using typename internal::BorrowedObj::_ThisBorrowedObj; + using typename BorrowedObject::_ThisBorrowedObject; protected: - using typename internal::BorrowedObj::_LibObjPtr; using _ThisCommonMessage = CommonMessage; public: - using Shared = internal::SharedMessage, LibObjT>; + using typename BorrowedObject::LibObjPtr; + using Shared = SharedMessage, LibObjT>; - explicit CommonMessage(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr} + explicit CommonMessage(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr} { } template - CommonMessage(const CommonMessage& val) noexcept : _ThisBorrowedObj {val} + CommonMessage(const CommonMessage val) noexcept : _ThisBorrowedObject {val} { } template - _ThisCommonMessage& operator=(const CommonMessage& val) noexcept + _ThisCommonMessage operator=(const CommonMessage val) noexcept { - _ThisBorrowedObj::operator=(val); + _ThisBorrowedObject::operator=(val); return *this; } + CommonMessage asConst() const noexcept + { + return CommonMessage {*this}; + } + MessageType type() const noexcept { return static_cast(bt_message_get_type(this->libObjPtr())); @@ -223,66 +230,70 @@ template class CommonStreamBeginningMessage final : public CommonMessage { private: - using typename CommonMessage::_LibObjPtr; using typename CommonMessage::_ThisCommonMessage; - - using _Stream = - typename std::conditional::value, CommonStream, - CommonStream>::type; + using _Stream = internal::DepStream; public: - using Shared = internal::SharedMessage, LibObjT>; + using typename CommonMessage::LibObjPtr; + using Shared = SharedMessage, LibObjT>; - explicit CommonStreamBeginningMessage(const _LibObjPtr libObjPtr) noexcept : + explicit CommonStreamBeginningMessage(const LibObjPtr libObjPtr) noexcept : _ThisCommonMessage {libObjPtr} { BT_ASSERT_DBG(this->isStreamBeginning()); } template - CommonStreamBeginningMessage(const CommonStreamBeginningMessage& val) noexcept : + CommonStreamBeginningMessage(const CommonStreamBeginningMessage val) noexcept : _ThisCommonMessage {val} { } template - CommonStreamBeginningMessage& - operator=(const CommonStreamBeginningMessage& val) noexcept + CommonStreamBeginningMessage + operator=(const CommonStreamBeginningMessage val) noexcept { _ThisCommonMessage::operator=(val); return *this; } - ConstStream stream() const noexcept + CommonStreamBeginningMessage asConst() const noexcept { - return ConstStream {internal::CommonStreamBeginningMessageSpec::stream( - this->libObjPtr())}; + return CommonStreamBeginningMessage {*this}; } - _Stream stream() noexcept + _Stream stream() const noexcept { return _Stream { internal::CommonStreamBeginningMessageSpec::stream(this->libObjPtr())}; } - void defaultClockSnapshot(const std::uint64_t val) noexcept + OptionalBorrowedObject streamClassDefaultClockClass() const noexcept { - static_assert(!std::is_const::value, "`LibObjT` must NOT be `const`."); + return bt_message_stream_beginning_borrow_stream_class_default_clock_class_const( + this->libObjPtr()); + } + + CommonStreamBeginningMessage defaultClockSnapshot(const std::uint64_t val) const noexcept + { + static_assert(!std::is_const::value, + "Not available with `bt2::ConstStreamBeginningMessage`."); bt_message_stream_beginning_set_default_clock_snapshot(this->libObjPtr(), val); + return *this; } - nonstd::optional defaultClockSnapshot() const noexcept + OptionalBorrowedObject 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 libObjPtr; } - return nonstd::nullopt; + return {}; } Shared shared() const noexcept @@ -341,65 +352,69 @@ template class CommonStreamEndMessage final : public CommonMessage { private: - using typename CommonMessage::_LibObjPtr; using typename CommonMessage::_ThisCommonMessage; - - using _Stream = - typename std::conditional::value, CommonStream, - CommonStream>::type; + using _Stream = internal::DepStream; public: - using Shared = internal::SharedMessage, LibObjT>; + using typename CommonMessage::LibObjPtr; + using Shared = SharedMessage, LibObjT>; - explicit CommonStreamEndMessage(const _LibObjPtr libObjPtr) noexcept : + explicit CommonStreamEndMessage(const LibObjPtr libObjPtr) noexcept : _ThisCommonMessage {libObjPtr} { BT_ASSERT_DBG(this->isStreamEnd()); } template - CommonStreamEndMessage(const CommonStreamEndMessage& val) noexcept : + CommonStreamEndMessage(const CommonStreamEndMessage val) noexcept : _ThisCommonMessage {val} { } template - CommonStreamEndMessage& - operator=(const CommonStreamEndMessage& val) noexcept + CommonStreamEndMessage + operator=(const CommonStreamEndMessage val) noexcept { _ThisCommonMessage::operator=(val); return *this; } - ConstStream stream() const noexcept + CommonStreamEndMessage asConst() const noexcept { - return ConstStream { - internal::CommonStreamEndMessageSpec::stream(this->libObjPtr())}; + return CommonStreamEndMessage {*this}; } - _Stream stream() noexcept + _Stream stream() const noexcept { return _Stream {internal::CommonStreamEndMessageSpec::stream(this->libObjPtr())}; } - void defaultClockSnapshot(const std::uint64_t val) noexcept + OptionalBorrowedObject streamClassDefaultClockClass() const noexcept { - static_assert(!std::is_const::value, "`LibObjT` must NOT be `const`."); + return bt_message_stream_end_borrow_stream_class_default_clock_class_const( + this->libObjPtr()); + } + + CommonStreamEndMessage defaultClockSnapshot(const std::uint64_t val) const noexcept + { + static_assert(!std::is_const::value, + "Not available with `bt2::ConstStreamEndMessage`."); bt_message_stream_end_set_default_clock_snapshot(this->libObjPtr(), val); + return *this; } - nonstd::optional defaultClockSnapshot() const noexcept + OptionalBorrowedObject 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 libObjPtr; } - return nonstd::nullopt; + return {}; } Shared shared() const noexcept @@ -458,53 +473,57 @@ template class CommonPacketBeginningMessage final : public CommonMessage { private: - using typename CommonMessage::_LibObjPtr; using typename CommonMessage::_ThisCommonMessage; - - using _Packet = - typename std::conditional::value, CommonPacket, - CommonPacket>::type; + using _Packet = internal::DepPacket; public: - using Shared = internal::SharedMessage, LibObjT>; + using typename CommonMessage::LibObjPtr; + using Shared = SharedMessage, LibObjT>; - explicit CommonPacketBeginningMessage(const _LibObjPtr libObjPtr) noexcept : + explicit CommonPacketBeginningMessage(const LibObjPtr libObjPtr) noexcept : _ThisCommonMessage {libObjPtr} { BT_ASSERT_DBG(this->isPacketBeginning()); } template - CommonPacketBeginningMessage(const CommonPacketBeginningMessage& val) noexcept : + CommonPacketBeginningMessage(const CommonPacketBeginningMessage val) noexcept : _ThisCommonMessage {val} { } template - CommonPacketBeginningMessage& - operator=(const CommonPacketBeginningMessage& val) noexcept + CommonPacketBeginningMessage + operator=(const CommonPacketBeginningMessage val) noexcept { _ThisCommonMessage::operator=(val); return *this; } - ConstPacket packet() const noexcept + CommonPacketBeginningMessage asConst() const noexcept { - return ConstPacket {internal::CommonPacketBeginningMessageSpec::packet( - this->libObjPtr())}; + return CommonPacketBeginningMessage {*this}; } - _Packet packet() noexcept + _Packet packet() const noexcept { return _Packet { internal::CommonPacketBeginningMessageSpec::packet(this->libObjPtr())}; } - void defaultClockSnapshot(const std::uint64_t val) noexcept + OptionalBorrowedObject streamClassDefaultClockClass() const noexcept + { + return bt_message_packet_beginning_borrow_stream_class_default_clock_class_const( + this->libObjPtr()); + } + + CommonPacketBeginningMessage defaultClockSnapshot(const std::uint64_t val) const noexcept { - static_assert(!std::is_const::value, "`LibObjT` must NOT be `const`."); + static_assert(!std::is_const::value, + "Not available with `bt2::ConstPacketBeginningMessage`."); bt_message_packet_beginning_set_default_clock_snapshot(this->libObjPtr(), val); + return *this; } ConstClockSnapshot defaultClockSnapshot() const noexcept @@ -571,52 +590,56 @@ template class CommonPacketEndMessage final : public CommonMessage { private: - using typename CommonMessage::_LibObjPtr; using typename CommonMessage::_ThisCommonMessage; - - using _Packet = - typename std::conditional::value, CommonPacket, - CommonPacket>::type; + using _Packet = internal::DepPacket; public: - using Shared = internal::SharedMessage, LibObjT>; + using typename CommonMessage::LibObjPtr; + using Shared = SharedMessage, LibObjT>; - explicit CommonPacketEndMessage(const _LibObjPtr libObjPtr) noexcept : + explicit CommonPacketEndMessage(const LibObjPtr libObjPtr) noexcept : _ThisCommonMessage {libObjPtr} { BT_ASSERT_DBG(this->isPacketEnd()); } template - CommonPacketEndMessage(const CommonPacketEndMessage& val) noexcept : + CommonPacketEndMessage(const CommonPacketEndMessage val) noexcept : _ThisCommonMessage {val} { } template - CommonPacketEndMessage& - operator=(const CommonPacketEndMessage& val) noexcept + CommonPacketEndMessage + operator=(const CommonPacketEndMessage val) noexcept { _ThisCommonMessage::operator=(val); return *this; } - ConstPacket packet() const noexcept + CommonPacketEndMessage asConst() const noexcept { - return ConstPacket { - internal::CommonPacketEndMessageSpec::packet(this->libObjPtr())}; + return CommonPacketEndMessage {*this}; } - _Packet packet() noexcept + _Packet packet() const noexcept { return _Packet {internal::CommonPacketEndMessageSpec::packet(this->libObjPtr())}; } - void defaultClockSnapshot(const std::uint64_t val) noexcept + OptionalBorrowedObject streamClassDefaultClockClass() const noexcept { - static_assert(!std::is_const::value, "`LibObjT` must NOT be `const`."); + return bt_message_packet_end_borrow_stream_class_default_clock_class_const( + this->libObjPtr()); + } + + CommonPacketEndMessage defaultClockSnapshot(const std::uint64_t val) const noexcept + { + static_assert(!std::is_const::value, + "Not available with `bt2::ConstPacketEndMessage`."); bt_message_packet_end_set_default_clock_snapshot(this->libObjPtr(), val); + return *this; } ConstClockSnapshot defaultClockSnapshot() const noexcept @@ -683,46 +706,46 @@ template class CommonEventMessage final : public CommonMessage { private: - using typename CommonMessage::_LibObjPtr; using typename CommonMessage::_ThisCommonMessage; - - using _Event = - typename std::conditional::value, CommonEvent, - CommonEvent>::type; + using _Event = internal::DepType, CommonEvent>; public: - using Shared = internal::SharedMessage, LibObjT>; + using typename CommonMessage::LibObjPtr; + using Shared = SharedMessage, LibObjT>; - explicit CommonEventMessage(const _LibObjPtr libObjPtr) noexcept : - _ThisCommonMessage {libObjPtr} + explicit CommonEventMessage(const LibObjPtr libObjPtr) noexcept : _ThisCommonMessage {libObjPtr} { BT_ASSERT_DBG(this->isEvent()); } template - CommonEventMessage(const CommonEventMessage& val) noexcept : + CommonEventMessage(const CommonEventMessage val) noexcept : _ThisCommonMessage {val} { } template - CommonEventMessage& operator=(const CommonEventMessage& val) noexcept + CommonEventMessage operator=(const CommonEventMessage val) noexcept { _ThisCommonMessage::operator=(val); return *this; } - ConstEvent event() const noexcept + CommonEventMessage asConst() const noexcept { - return ConstEvent { - internal::CommonEventMessageSpec::event(this->libObjPtr())}; + return CommonEventMessage {*this}; } - _Event event() noexcept + _Event event() const noexcept { return _Event {internal::CommonEventMessageSpec::event(this->libObjPtr())}; } + OptionalBorrowedObject streamClassDefaultClockClass() const noexcept + { + return bt_message_event_borrow_stream_class_default_clock_class_const(this->libObjPtr()); + } + ConstClockSnapshot defaultClockSnapshot() const noexcept { const auto libObjPtr = @@ -787,48 +810,50 @@ template class CommonDiscardedEventsMessage final : public CommonMessage { private: - using typename CommonMessage::_LibObjPtr; using typename CommonMessage::_ThisCommonMessage; - - using _Stream = - typename std::conditional::value, CommonStream, - CommonStream>::type; + using _Stream = internal::DepStream; public: - using Shared = internal::SharedMessage, LibObjT>; + using typename CommonMessage::LibObjPtr; + using Shared = SharedMessage, LibObjT>; - explicit CommonDiscardedEventsMessage(const _LibObjPtr libObjPtr) noexcept : + explicit CommonDiscardedEventsMessage(const LibObjPtr libObjPtr) noexcept : _ThisCommonMessage {libObjPtr} { BT_ASSERT_DBG(this->isDiscardedEvents()); } template - CommonDiscardedEventsMessage(const CommonDiscardedEventsMessage& val) noexcept : + CommonDiscardedEventsMessage(const CommonDiscardedEventsMessage val) noexcept : _ThisCommonMessage {val} { } template - CommonDiscardedEventsMessage& - operator=(const CommonDiscardedEventsMessage& val) noexcept + CommonDiscardedEventsMessage + operator=(const CommonDiscardedEventsMessage val) noexcept { _ThisCommonMessage::operator=(val); return *this; } - ConstStream stream() const noexcept + CommonDiscardedEventsMessage asConst() const noexcept { - return ConstStream {internal::CommonDiscardedEventsMessageSpec::stream( - this->libObjPtr())}; + return CommonDiscardedEventsMessage {*this}; } - _Stream stream() noexcept + _Stream stream() const noexcept { return _Stream { internal::CommonDiscardedEventsMessageSpec::stream(this->libObjPtr())}; } + OptionalBorrowedObject streamClassDefaultClockClass() const noexcept + { + return bt_message_discarded_events_borrow_stream_class_default_clock_class_const( + this->libObjPtr()); + } + ConstClockSnapshot beginningDefaultClockSnapshot() const noexcept { const auto libObjPtr = @@ -846,23 +871,24 @@ public: return ConstClockSnapshot {libObjPtr}; } - void count(const std::uint64_t count) noexcept + CommonDiscardedEventsMessage count(const std::uint64_t count) const noexcept { - static_assert(!std::is_const::value, "`LibObjT` must NOT be `const`."); + static_assert(!std::is_const::value, + "Not available with `bt2::ConstDiscardedEventsMessage`."); bt_message_discarded_events_set_count(this->libObjPtr(), count); + return *this; } - nonstd::optional count() const noexcept + bt2s::optional count() const noexcept { std::uint64_t count; - const auto avail = bt_message_discarded_events_get_count(this->libObjPtr(), &count); - if (avail) { + if (bt_message_discarded_events_get_count(this->libObjPtr(), &count)) { return count; } - return nonstd::nullopt; + return bt2s::nullopt; } Shared shared() const noexcept @@ -921,48 +947,50 @@ template class CommonDiscardedPacketsMessage final : public CommonMessage { private: - using typename CommonMessage::_LibObjPtr; using typename CommonMessage::_ThisCommonMessage; - - using _Stream = - typename std::conditional::value, CommonStream, - CommonStream>::type; + using _Stream = internal::DepStream; public: - using Shared = internal::SharedMessage, LibObjT>; + using typename CommonMessage::LibObjPtr; + using Shared = SharedMessage, LibObjT>; - explicit CommonDiscardedPacketsMessage(const _LibObjPtr libObjPtr) noexcept : + explicit CommonDiscardedPacketsMessage(const LibObjPtr libObjPtr) noexcept : _ThisCommonMessage {libObjPtr} { BT_ASSERT_DBG(this->isDiscardedPackets()); } template - CommonDiscardedPacketsMessage(const CommonDiscardedPacketsMessage& val) noexcept : + CommonDiscardedPacketsMessage(const CommonDiscardedPacketsMessage val) noexcept : _ThisCommonMessage {val} { } template - CommonDiscardedPacketsMessage& - operator=(const CommonDiscardedPacketsMessage& val) noexcept + CommonDiscardedPacketsMessage + operator=(const CommonDiscardedPacketsMessage val) noexcept { _ThisCommonMessage::operator=(val); return *this; } - ConstStream stream() const noexcept + CommonDiscardedPacketsMessage asConst() const noexcept { - return ConstStream {internal::CommonDiscardedPacketsMessageSpec::stream( - this->libObjPtr())}; + return CommonDiscardedPacketsMessage {*this}; } - _Stream stream() noexcept + _Stream stream() const noexcept { return _Stream { internal::CommonDiscardedPacketsMessageSpec::stream(this->libObjPtr())}; } + OptionalBorrowedObject streamClassDefaultClockClass() const noexcept + { + return bt_message_discarded_packets_borrow_stream_class_default_clock_class_const( + this->libObjPtr()); + } + ConstClockSnapshot beginningDefaultClockSnapshot() const noexcept { const auto libObjPtr = @@ -980,23 +1008,24 @@ public: return ConstClockSnapshot {libObjPtr}; } - void count(const std::uint64_t count) noexcept + CommonDiscardedPacketsMessage count(const std::uint64_t count) const noexcept { - static_assert(!std::is_const::value, "`LibObjT` must NOT be `const`."); + static_assert(!std::is_const::value, + "Not available with `bt2::ConstDiscardedPacketsMessage`."); bt_message_discarded_packets_set_count(this->libObjPtr(), count); + return *this; } - nonstd::optional count() const noexcept + bt2s::optional count() const noexcept { std::uint64_t count; - const auto avail = bt_message_discarded_packets_get_count(this->libObjPtr(), &count); - if (avail) { + if (bt_message_discarded_packets_get_count(this->libObjPtr(), &count)) { return count; } - return nonstd::nullopt; + return bt2s::nullopt; } Shared shared() const noexcept @@ -1032,14 +1061,13 @@ template class CommonMessageIteratorInactivityMessage final : public CommonMessage { private: - using typename CommonMessage::_LibObjPtr; using typename CommonMessage::_ThisCommonMessage; public: - using Shared = - internal::SharedMessage, LibObjT>; + using typename CommonMessage::LibObjPtr; + using Shared = SharedMessage, LibObjT>; - explicit CommonMessageIteratorInactivityMessage(const _LibObjPtr libObjPtr) noexcept : + explicit CommonMessageIteratorInactivityMessage(const LibObjPtr libObjPtr) noexcept : _ThisCommonMessage {libObjPtr} { BT_ASSERT_DBG(this->isMessageIteratorInactivity()); @@ -1047,19 +1075,24 @@ public: template CommonMessageIteratorInactivityMessage( - const CommonMessageIteratorInactivityMessage& val) noexcept : + const CommonMessageIteratorInactivityMessage val) noexcept : _ThisCommonMessage {val} { } template - CommonMessageIteratorInactivityMessage& - operator=(const CommonMessageIteratorInactivityMessage& val) noexcept + CommonMessageIteratorInactivityMessage + operator=(const CommonMessageIteratorInactivityMessage val) noexcept { _ThisCommonMessage::operator=(val); return *this; } + CommonMessageIteratorInactivityMessage asConst() const noexcept + { + return CommonMessageIteratorInactivityMessage {*this}; + } + ConstClockSnapshot clockSnapshot() const noexcept { const auto libObjPtr = @@ -1103,50 +1136,49 @@ struct TypeDescr : 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 +CommonDiscardedPacketsMessage CommonMessage::asDiscardedPackets() const noexcept +{ + return CommonDiscardedPacketsMessage {this->libObjPtr()}; +} + template CommonMessageIteratorInactivityMessage CommonMessage::asMessageIteratorInactivity() const noexcept { - BT_ASSERT_DBG(this->isMessageIteratorInactivity()); return CommonMessageIteratorInactivityMessage {this->libObjPtr()}; }