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> | |
c802cacb | 11 | |
3aafc165 PP |
12 | #include <babeltrace2/babeltrace.h> |
13 | ||
0d218157 | 14 | #include "borrowed-object.hpp" |
39278ebc | 15 | #include "exc.hpp" |
3aafc165 PP |
16 | |
17 | namespace bt2 { | |
18 | ||
0d218157 | 19 | class ConstClockSnapshot final : public BorrowedObject<const bt_clock_snapshot> |
3aafc165 PP |
20 | { |
21 | public: | |
0d218157 PP |
22 | explicit ConstClockSnapshot(const _LibObjPtr libObjPtr) noexcept : |
23 | _ThisBorrowedObject {libObjPtr} | |
3aafc165 PP |
24 | { |
25 | } | |
26 | ||
27 | ConstClockSnapshot(const ConstClockSnapshot& clkSnapshot) noexcept : | |
0d218157 | 28 | _ThisBorrowedObject {clkSnapshot} |
3aafc165 PP |
29 | { |
30 | } | |
31 | ||
32 | ConstClockSnapshot& operator=(const ConstClockSnapshot& clkSnapshot) noexcept | |
33 | { | |
0d218157 | 34 | _ThisBorrowedObject::operator=(clkSnapshot); |
3aafc165 PP |
35 | return *this; |
36 | } | |
37 | ||
38 | std::uint64_t value() const noexcept | |
39 | { | |
341a67c4 | 40 | return bt_clock_snapshot_get_value(this->libObjPtr()); |
3aafc165 PP |
41 | } |
42 | ||
43 | operator std::uint64_t() const noexcept | |
44 | { | |
45 | return this->value(); | |
46 | } | |
47 | ||
48 | std::int64_t nsFromOrigin() const | |
49 | { | |
50 | std::int64_t nsFromOrigin; | |
341a67c4 | 51 | const auto status = bt_clock_snapshot_get_ns_from_origin(this->libObjPtr(), &nsFromOrigin); |
3aafc165 PP |
52 | |
53 | if (status == BT_CLOCK_SNAPSHOT_GET_NS_FROM_ORIGIN_STATUS_OVERFLOW_ERROR) { | |
39278ebc | 54 | throw OverflowError {}; |
3aafc165 PP |
55 | } |
56 | ||
57 | return nsFromOrigin; | |
58 | } | |
59 | }; | |
60 | ||
b5f55e9f | 61 | } /* namespace bt2 */ |
3aafc165 | 62 | |
b5f55e9f | 63 | #endif /* BABELTRACE_CPP_COMMON_BT2_CLOCK_SNAPSHOT_HPP */ |