From 3aafc1652f91618c0ae7e485bcf50212ca4e112f Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Thu, 17 Dec 2020 08:52:40 -0500 Subject: [PATCH] Add C++ interface for the libbabeltrace2 `bt_clock_snapshot` API This patch adds C++ wrappers for Babeltrace 2 clock snapshot objects. The new available class is `bt2::ClockSnapshot`. This new class follows the approach of other wrappers in `src/cpp-common/bt2`. You can't create such objects: they are what various message methods (not part of `src/cpp-common/bt2` yet) return. Signed-off-by: Philippe Proulx Change-Id: Id462b88b1575cddf50ae250f22dda71d7b27733c Reviewed-on: https://review.lttng.org/c/babeltrace/+/4603 --- src/cpp-common/bt2/clock-snapshot.hpp | 61 +++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src/cpp-common/bt2/clock-snapshot.hpp diff --git a/src/cpp-common/bt2/clock-snapshot.hpp b/src/cpp-common/bt2/clock-snapshot.hpp new file mode 100644 index 00000000..26ec9e83 --- /dev/null +++ b/src/cpp-common/bt2/clock-snapshot.hpp @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2020 Philippe Proulx + * + * SPDX-License-Identifier: MIT + */ + +#ifndef BABELTRACE_CPP_COMMON_BT2_CLOCK_SNAPSHOT_HPP +#define BABELTRACE_CPP_COMMON_BT2_CLOCK_SNAPSHOT_HPP + +#include +#include + +#include "internal/borrowed-obj.hpp" +#include "lib-error.hpp" + +namespace bt2 { + +class ConstClockSnapshot final : public internal::BorrowedObj +{ +public: + explicit ConstClockSnapshot(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr} + { + } + + ConstClockSnapshot(const ConstClockSnapshot& clkSnapshot) noexcept : + _ThisBorrowedObj {clkSnapshot} + { + } + + ConstClockSnapshot& operator=(const ConstClockSnapshot& clkSnapshot) noexcept + { + _ThisBorrowedObj::operator=(clkSnapshot); + return *this; + } + + std::uint64_t value() const noexcept + { + return bt_clock_snapshot_get_value(this->_libObjPtr()); + } + + operator std::uint64_t() const noexcept + { + return this->value(); + } + + std::int64_t nsFromOrigin() const + { + std::int64_t nsFromOrigin; + const auto status = bt_clock_snapshot_get_ns_from_origin(this->_libObjPtr(), &nsFromOrigin); + + if (status == BT_CLOCK_SNAPSHOT_GET_NS_FROM_ORIGIN_STATUS_OVERFLOW_ERROR) { + throw LibOverflowError {}; + } + + return nsFromOrigin; + } +}; + +} // namespace bt2 + +#endif // BABELTRACE_CPP_COMMON_BT2_CLOCK_SNAPSHOT_HPP -- 2.34.1