Commit | Line | Data |
---|---|---|
0235b0db | 1 | # SPDX-License-Identifier: MIT |
79c39ab9 PP |
2 | # |
3 | # Copyright (c) 2017 Philippe Proulx <pproulx@efficios.com> | |
79c39ab9 | 4 | |
e5914347 SM |
5 | from bt2 import native_bt |
6 | from bt2 import object as bt2_object | |
7 | from bt2 import utils as bt2_utils | |
79c39ab9 | 8 | import numbers |
3fb99a22 | 9 | from bt2 import clock_class as bt2_clock_class |
be7bbff9 | 10 | import functools |
79c39ab9 PP |
11 | |
12 | ||
c6af194f | 13 | @functools.total_ordering |
e5914347 | 14 | class _ClockSnapshotConst(bt2_object._UniqueObject): |
79c39ab9 PP |
15 | @property |
16 | def clock_class(self): | |
be7bbff9 SM |
17 | cc_ptr = native_bt.clock_snapshot_borrow_clock_class_const(self._ptr) |
18 | assert cc_ptr is not None | |
eddea575 | 19 | return bt2_clock_class._ClockClassConst._create_from_ptr_and_get_ref(cc_ptr) |
79c39ab9 PP |
20 | |
21 | @property | |
2ae9f48c SM |
22 | def value(self): |
23 | return native_bt.clock_snapshot_get_value(self._ptr) | |
79c39ab9 PP |
24 | |
25 | @property | |
be7bbff9 | 26 | def ns_from_origin(self): |
d24d5663 | 27 | status, ns = native_bt.clock_snapshot_get_ns_from_origin(self._ptr) |
e5914347 | 28 | bt2_utils._handle_func_status( |
cfbd7cf3 FD |
29 | status, "cannot get clock snapshot's nanoseconds from origin" |
30 | ) | |
be7bbff9 | 31 | return ns |
79c39ab9 | 32 | |
be7bbff9 SM |
33 | def __eq__(self, other): |
34 | if not isinstance(other, numbers.Integral): | |
35 | return NotImplemented | |
79c39ab9 | 36 | |
be7bbff9 | 37 | return self.value == int(other) |
79c39ab9 | 38 | |
be7bbff9 SM |
39 | def __lt__(self, other): |
40 | if not isinstance(other, numbers.Integral): | |
41 | return NotImplemented | |
79c39ab9 | 42 | |
be7bbff9 | 43 | return self.value < int(other) |
9ec609ec SM |
44 | |
45 | ||
c6af194f | 46 | class _UnknownClockSnapshot: |
9ec609ec | 47 | pass |