Add C++ interface for the libbabeltrace2 `bt_clock_snapshot` API
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 17 Dec 2020 13:52:40 +0000 (08:52 -0500)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Fri, 28 Jan 2022 16:22:26 +0000 (11:22 -0500)
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 <eeppeliteloop@gmail.com>
Change-Id: Id462b88b1575cddf50ae250f22dda71d7b27733c
Reviewed-on: https://review.lttng.org/c/babeltrace/+/4603

src/cpp-common/bt2/clock-snapshot.hpp [new file with mode: 0644]

diff --git a/src/cpp-common/bt2/clock-snapshot.hpp b/src/cpp-common/bt2/clock-snapshot.hpp
new file mode 100644 (file)
index 0000000..26ec9e8
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2020 Philippe Proulx <pproulx@efficios.com>
+ *
+ * SPDX-License-Identifier: MIT
+ */
+
+#ifndef BABELTRACE_CPP_COMMON_BT2_CLOCK_SNAPSHOT_HPP
+#define BABELTRACE_CPP_COMMON_BT2_CLOCK_SNAPSHOT_HPP
+
+#include <cstdint>
+#include <babeltrace2/babeltrace.h>
+
+#include "internal/borrowed-obj.hpp"
+#include "lib-error.hpp"
+
+namespace bt2 {
+
+class ConstClockSnapshot final : public internal::BorrowedObj<const bt_clock_snapshot>
+{
+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
This page took 0.024906 seconds and 4 git commands to generate.