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