X-Git-Url: https://git.efficios.com/?a=blobdiff_plain;f=src%2Fcpp-common%2Fbt2%2Fmessage.hpp;h=be9be1184587d23bc5f1c4e117d3e16b7803170c;hb=afe77d4f77220b7fa0a27cbe6e2aef34c6935174;hp=b335d8176394ab7896a7116acb1fc3b7b628e043;hpb=84cef782ca04a1d3932f8acd2ff5910ebbaa4797;p=babeltrace.git diff --git a/src/cpp-common/bt2/message.hpp b/src/cpp-common/bt2/message.hpp index b335d817..be9be118 100644 --- a/src/cpp-common/bt2/message.hpp +++ b/src/cpp-common/bt2/message.hpp @@ -19,7 +19,9 @@ #include "borrowed-object.hpp" #include "internal/utils.hpp" +#include "optional-borrowed-object.hpp" #include "shared-object.hpp" +#include "trace-ir.hpp" namespace bt2 { namespace internal { @@ -85,13 +87,13 @@ private: using typename BorrowedObject::_ThisBorrowedObject; protected: - using typename BorrowedObject::_LibObjPtr; using _ThisCommonMessage = CommonMessage; public: + using typename BorrowedObject::LibObjPtr; using Shared = SharedMessage, LibObjT>; - explicit CommonMessage(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr} + explicit CommonMessage(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr} { } @@ -228,14 +230,14 @@ template class CommonStreamBeginningMessage final : public CommonMessage { private: - using typename CommonMessage::_LibObjPtr; using typename CommonMessage::_ThisCommonMessage; using _Stream = internal::DepStream; public: + 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()); @@ -266,25 +268,32 @@ public: internal::CommonStreamBeginningMessageSpec::stream(this->libObjPtr())}; } - void defaultClockSnapshot(const std::uint64_t val) const noexcept + OptionalBorrowedObject streamClassDefaultClockClass() const noexcept + { + 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; } - bt2s::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 bt2s::nullopt; + return {}; } Shared shared() const noexcept @@ -343,14 +352,14 @@ template class CommonStreamEndMessage final : public CommonMessage { private: - using typename CommonMessage::_LibObjPtr; using typename CommonMessage::_ThisCommonMessage; using _Stream = internal::DepStream; public: + 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()); @@ -380,25 +389,32 @@ public: return _Stream {internal::CommonStreamEndMessageSpec::stream(this->libObjPtr())}; } - void defaultClockSnapshot(const std::uint64_t val) const noexcept + OptionalBorrowedObject streamClassDefaultClockClass() const noexcept + { + 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; } - bt2s::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 bt2s::nullopt; + return {}; } Shared shared() const noexcept @@ -457,14 +473,14 @@ template class CommonPacketBeginningMessage final : public CommonMessage { private: - using typename CommonMessage::_LibObjPtr; using typename CommonMessage::_ThisCommonMessage; using _Packet = internal::DepPacket; public: + 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()); @@ -495,12 +511,19 @@ public: internal::CommonPacketBeginningMessageSpec::packet(this->libObjPtr())}; } - void defaultClockSnapshot(const std::uint64_t val) const 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, "Not available with `bt2::ConstPacketBeginningMessage`."); bt_message_packet_beginning_set_default_clock_snapshot(this->libObjPtr(), val); + return *this; } ConstClockSnapshot defaultClockSnapshot() const noexcept @@ -567,14 +590,14 @@ template class CommonPacketEndMessage final : public CommonMessage { private: - using typename CommonMessage::_LibObjPtr; using typename CommonMessage::_ThisCommonMessage; using _Packet = internal::DepPacket; public: + 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()); @@ -604,12 +627,19 @@ public: return _Packet {internal::CommonPacketEndMessageSpec::packet(this->libObjPtr())}; } - void defaultClockSnapshot(const std::uint64_t val) const noexcept + OptionalBorrowedObject streamClassDefaultClockClass() const noexcept + { + 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 @@ -676,15 +706,14 @@ template class CommonEventMessage final : public CommonMessage { private: - using typename CommonMessage::_LibObjPtr; using typename CommonMessage::_ThisCommonMessage; using _Event = internal::DepType, CommonEvent>; public: + 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()); } @@ -712,14 +741,9 @@ public: return _Event {internal::CommonEventMessageSpec::event(this->libObjPtr())}; } - bt2s::optional streamClassDefaultClockClass() const noexcept + OptionalBorrowedObject streamClassDefaultClockClass() const noexcept { - if (const auto libClkClsPtr = - bt_message_event_borrow_stream_class_default_clock_class_const(this->libObjPtr())) { - return ConstClockClass {libClkClsPtr}; - } - - return bt2s::nullopt; + return bt_message_event_borrow_stream_class_default_clock_class_const(this->libObjPtr()); } ConstClockSnapshot defaultClockSnapshot() const noexcept @@ -786,14 +810,14 @@ template class CommonDiscardedEventsMessage final : public CommonMessage { private: - using typename CommonMessage::_LibObjPtr; using typename CommonMessage::_ThisCommonMessage; using _Stream = internal::DepStream; public: + 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()); @@ -824,6 +848,12 @@ public: 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 = @@ -841,20 +871,20 @@ public: return ConstClockSnapshot {libObjPtr}; } - void count(const std::uint64_t count) const noexcept + CommonDiscardedEventsMessage count(const std::uint64_t count) const noexcept { static_assert(!std::is_const::value, "Not available with `bt2::ConstDiscardedEventsMessage`."); bt_message_discarded_events_set_count(this->libObjPtr(), count); + return *this; } 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; } @@ -917,14 +947,14 @@ template class CommonDiscardedPacketsMessage final : public CommonMessage { private: - using typename CommonMessage::_LibObjPtr; using typename CommonMessage::_ThisCommonMessage; using _Stream = internal::DepStream; public: + 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()); @@ -955,6 +985,12 @@ public: 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 = @@ -972,20 +1008,20 @@ public: return ConstClockSnapshot {libObjPtr}; } - void count(const std::uint64_t count) const noexcept + CommonDiscardedPacketsMessage count(const std::uint64_t count) const noexcept { static_assert(!std::is_const::value, "Not available with `bt2::ConstDiscardedPacketsMessage`."); bt_message_discarded_packets_set_count(this->libObjPtr(), count); + return *this; } 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; } @@ -1025,13 +1061,13 @@ template class CommonMessageIteratorInactivityMessage final : public CommonMessage { private: - using typename CommonMessage::_LibObjPtr; using typename CommonMessage::_ThisCommonMessage; public: + 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()); @@ -1100,49 +1136,42 @@ 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 { - BT_ASSERT_DBG(this->isDiscardedPackets()); return CommonDiscardedPacketsMessage {this->libObjPtr()}; } @@ -1150,7 +1179,6 @@ template CommonMessageIteratorInactivityMessage CommonMessage::asMessageIteratorInactivity() const noexcept { - BT_ASSERT_DBG(this->isMessageIteratorInactivity()); return CommonMessageIteratorInactivityMessage {this->libObjPtr()}; }