Commit | Line | Data |
---|---|---|
3aafc165 PP |
1 | /* |
2 | * Copyright (c) 2020 Philippe Proulx <pproulx@efficios.com> | |
3 | * | |
4 | * SPDX-License-Identifier: MIT | |
5 | */ | |
6 | ||
7 | #ifndef BABELTRACE_CPP_COMMON_BT2_CLOCK_SNAPSHOT_HPP | |
8 | #define BABELTRACE_CPP_COMMON_BT2_CLOCK_SNAPSHOT_HPP | |
9 | ||
10 | #include <cstdint> | |
11 | #include <babeltrace2/babeltrace.h> | |
12 | ||
13 | #include "internal/borrowed-obj.hpp" | |
39278ebc | 14 | #include "exc.hpp" |
3aafc165 PP |
15 | |
16 | namespace bt2 { | |
17 | ||
18 | class ConstClockSnapshot final : public internal::BorrowedObj<const bt_clock_snapshot> | |
19 | { | |
20 | public: | |
21 | explicit ConstClockSnapshot(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr} | |
22 | { | |
23 | } | |
24 | ||
25 | ConstClockSnapshot(const ConstClockSnapshot& clkSnapshot) noexcept : | |
26 | _ThisBorrowedObj {clkSnapshot} | |
27 | { | |
28 | } | |
29 | ||
30 | ConstClockSnapshot& operator=(const ConstClockSnapshot& clkSnapshot) noexcept | |
31 | { | |
32 | _ThisBorrowedObj::operator=(clkSnapshot); | |
33 | return *this; | |
34 | } | |
35 | ||
36 | std::uint64_t value() const noexcept | |
37 | { | |
341a67c4 | 38 | return bt_clock_snapshot_get_value(this->libObjPtr()); |
3aafc165 PP |
39 | } |
40 | ||
41 | operator std::uint64_t() const noexcept | |
42 | { | |
43 | return this->value(); | |
44 | } | |
45 | ||
46 | std::int64_t nsFromOrigin() const | |
47 | { | |
48 | std::int64_t nsFromOrigin; | |
341a67c4 | 49 | const auto status = bt_clock_snapshot_get_ns_from_origin(this->libObjPtr(), &nsFromOrigin); |
3aafc165 PP |
50 | |
51 | if (status == BT_CLOCK_SNAPSHOT_GET_NS_FROM_ORIGIN_STATUS_OVERFLOW_ERROR) { | |
39278ebc | 52 | throw OverflowError {}; |
3aafc165 PP |
53 | } |
54 | ||
55 | return nsFromOrigin; | |
56 | } | |
57 | }; | |
58 | ||
b5f55e9f | 59 | } /* namespace bt2 */ |
3aafc165 | 60 | |
b5f55e9f | 61 | #endif /* BABELTRACE_CPP_COMMON_BT2_CLOCK_SNAPSHOT_HPP */ |