From: Philippe Proulx Date: Wed, 17 Apr 2024 19:28:23 +0000 (-0400) Subject: cpp-common/bt2/clock-class.hpp: adapt to latest libbabeltrace2 API X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=9fdc823585a93a34e58691ae57b79af7e691911f;p=babeltrace.git cpp-common/bt2/clock-class.hpp: adapt to latest libbabeltrace2 API Read anything related to the origin with the new origin() method which returns a clock origin view from which you may get the namespace, name, UID, and whether or not it's unknown or the Unix epoch. Signed-off-by: Philippe Proulx Change-Id: Ib44547fd60580ab9aea3c0cb3492542749d3a5da Reviewed-on: https://review.lttng.org/c/babeltrace/+/12729 --- diff --git a/src/clock-correlation-validator/clock-correlation-validator.cpp b/src/clock-correlation-validator/clock-correlation-validator.cpp index 4bb1a725..b5c9c21b 100644 --- a/src/clock-correlation-validator/clock-correlation-validator.cpp +++ b/src/clock-correlation-validator/clock-correlation-validator.cpp @@ -41,7 +41,7 @@ void ClockCorrelationValidator::_validate(const bt2::ConstMessage msg) */ if (!clockCls) { _mExpectation = PropsExpectation::None; - } else if (clockCls->originIsUnixEpoch()) { + } else if (clockCls->origin().isUnixEpoch()) { _mExpectation = PropsExpectation::OriginUnix; } else if (const auto uuid = clockCls->uuid()) { _mExpectation = PropsExpectation::OriginOtherUuid; @@ -73,7 +73,7 @@ void ClockCorrelationValidator::_validate(const bt2::ConstMessage msg) streamCls}; } - if (!clockCls->originIsUnixEpoch()) { + if (!clockCls->origin().isUnixEpoch()) { throw ClockCorrelationError {ClockCorrelationError::Type::ExpectingOriginUnixGotOther, bt2s::nullopt, *clockCls, @@ -93,7 +93,7 @@ void ClockCorrelationValidator::_validate(const bt2::ConstMessage msg) streamCls}; } - if (clockCls->originIsUnixEpoch()) { + if (clockCls->origin().isUnixEpoch()) { throw ClockCorrelationError {ClockCorrelationError::Type::ExpectingOriginUuidGotUnix, bt2s::nullopt, *clockCls, diff --git a/src/cpp-common/bt2/clock-class.hpp b/src/cpp-common/bt2/clock-class.hpp index 5b80890d..76af9e4c 100644 --- a/src/cpp-common/bt2/clock-class.hpp +++ b/src/cpp-common/bt2/clock-class.hpp @@ -66,7 +66,7 @@ struct CommonClockClassSpec final class ClockOffset final { public: - explicit ClockOffset(const std::int64_t seconds, const std::uint64_t cycles) : + explicit ClockOffset(const std::int64_t seconds, const std::uint64_t cycles) noexcept : _mSeconds {seconds}, _mCycles {cycles} { } @@ -86,6 +86,8 @@ private: std::uint64_t _mCycles; }; +class ClockOriginView; + template class CommonClockClass final : public BorrowedObject { @@ -158,9 +160,36 @@ public: return *this; } - std::uint64_t precision() const noexcept + bt2s::optional precision() const noexcept + { + std::uint64_t prec; + + if (bt_clock_class_get_opt_precision(this->libObjPtr(), &prec) == + BT_PROPERTY_AVAILABILITY_NOT_AVAILABLE) { + return bt2s::nullopt; + } + + return prec; + } + + CommonClockClass accuracy(const std::uint64_t accuracy) const noexcept { - return bt_clock_class_get_precision(this->libObjPtr()); + static_assert(!std::is_const::value, "Not available with `bt2::ConstClockClass`."); + + bt_clock_class_set_accuracy(this->libObjPtr(), accuracy); + return *this; + } + + bt2s::optional accuracy() const noexcept + { + std::uint64_t accuracy; + + if (bt_clock_class_get_accuracy(this->libObjPtr(), &accuracy) == + BT_PROPERTY_AVAILABILITY_NOT_AVAILABLE) { + return bt2s::nullopt; + } + + return accuracy; } CommonClockClass originIsUnixEpoch(const bool originIsUnixEpoch) const noexcept @@ -172,9 +201,52 @@ public: return *this; } - bool originIsUnixEpoch() const noexcept + CommonClockClass setOriginIsUnixEpoch() const noexcept + { + static_assert(!std::is_const::value, "Not available with `bt2::ConstClockClass`."); + + bt_clock_class_set_origin_unix_epoch(this->libObjPtr()); + return *this; + } + + CommonClockClass setOriginIsUnknown() const noexcept + { + static_assert(!std::is_const::value, "Not available with `bt2::ConstClockClass`."); + + bt_clock_class_set_origin_unknown(this->libObjPtr()); + return *this; + } + + CommonClockClass origin(const bt2c::CStringView nameSpace, const bt2c::CStringView name, + const bt2c::CStringView uid) const + { + static_assert(!std::is_const::value, "Not available with `bt2::ConstClockClass`."); + + if (bt_clock_class_set_origin(this->libObjPtr(), nameSpace, name, uid) == + BT_CLOCK_CLASS_SET_ORIGIN_STATUS_MEMORY_ERROR) { + throw MemoryError {}; + } + + return *this; + } + + ClockOriginView origin() const noexcept; + + CommonClockClass nameSpace(const bt2c::CStringView nameSpace) const + { + static_assert(!std::is_const::value, "Not available with `bt2::ConstClockClass`."); + + if (bt_clock_class_set_namespace(this->libObjPtr(), nameSpace) == + BT_CLOCK_CLASS_SET_NAMESPACE_STATUS_MEMORY_ERROR) { + throw MemoryError {}; + } + + return *this; + } + + bt2c::CStringView nameSpace() const noexcept { - return static_cast(bt_clock_class_origin_is_unix_epoch(this->libObjPtr())); + return bt_clock_class_get_namespace(this->libObjPtr()); } CommonClockClass name(const bt2c::CStringView name) const @@ -195,6 +267,29 @@ public: return bt_clock_class_get_name(this->libObjPtr()); } + CommonClockClass uid(const bt2c::CStringView uid) const + { + static_assert(!std::is_const::value, "Not available with `bt2::ConstClockClass`."); + + if (bt_clock_class_set_uid(this->libObjPtr(), uid) == + BT_CLOCK_CLASS_SET_UID_STATUS_MEMORY_ERROR) { + throw MemoryError {}; + } + + return *this; + } + + bt2c::CStringView uid() const noexcept + { + return bt_clock_class_get_uid(this->libObjPtr()); + } + + bool hasSameIdentity(const CommonClockClass other) const noexcept + { + return static_cast( + bt_clock_class_has_same_identity(this->libObjPtr(), other.libObjPtr())); + } + CommonClockClass description(const bt2c::CStringView description) const { static_assert(!std::is_const::value, "Not available with `bt2::ConstClockClass`."); @@ -288,6 +383,49 @@ struct TypeDescr : public ClockClassTypeDescr }; } /* namespace internal */ + +class ClockOriginView final +{ +public: + explicit ClockOriginView(const ConstClockClass clockClass) noexcept : _mClkCls {clockClass} + { + } + + bt2c::CStringView nameSpace() const noexcept + { + return bt_clock_class_get_origin_namespace(_mClkCls.libObjPtr()); + } + + bt2c::CStringView name() const noexcept + { + return bt_clock_class_get_origin_name(_mClkCls.libObjPtr()); + } + + bt2c::CStringView uid() const noexcept + { + return bt_clock_class_get_origin_uid(_mClkCls.libObjPtr()); + } + + bool isUnknown() const noexcept + { + return bt_clock_class_origin_is_unknown(_mClkCls.libObjPtr()); + } + + bool isUnixEpoch() const noexcept + { + return bt_clock_class_origin_is_unix_epoch(_mClkCls.libObjPtr()); + } + +private: + ConstClockClass _mClkCls; +}; + +template +ClockOriginView CommonClockClass::origin() const noexcept +{ + return ClockOriginView {*this}; +} + } /* namespace bt2 */ #endif /* BABELTRACE_CPP_COMMON_BT2_CLOCK_CLASS_HPP */