python: make all _get_ref/_put_ref proper static methods
[babeltrace.git] / src / bindings / python / bt2 / bt2 / clock_class.py
CommitLineData
0235b0db 1# SPDX-License-Identifier: MIT
81447b5b 2#
811644b8 3# Copyright (c) 2017 Philippe Proulx <pproulx@efficios.com>
81447b5b
PP
4
5from bt2 import native_bt, object, utils
5783664e 6from bt2 import value as bt2_value
be7bbff9 7import uuid as uuidp
81447b5b 8
0b03f63e 9
81447b5b
PP
10class ClockClassOffset:
11 def __init__(self, seconds=0, cycles=0):
12 utils._check_int64(seconds)
13 utils._check_int64(cycles)
14 self._seconds = seconds
15 self._cycles = cycles
16
17 @property
18 def seconds(self):
19 return self._seconds
20
21 @property
22 def cycles(self):
23 return self._cycles
24
25 def __eq__(self, other):
26 if not isinstance(other, self.__class__):
27 # not comparing apples to apples
28 return False
29
30 return (self.seconds, self.cycles) == (other.seconds, other.cycles)
31
32
eddea575 33class _ClockClassConst(object._SharedObject):
9dee90bd
SM
34 @staticmethod
35 def _get_ref(ptr):
36 native_bt.clock_class_get_ref(ptr)
37
38 @staticmethod
39 def _put_ref(ptr):
40 native_bt.clock_class_put_ref(ptr)
41
eddea575
FD
42 _create_value_from_ptr_and_get_ref = staticmethod(
43 bt2_value._create_from_const_ptr_and_get_ref
44 )
2550c437
SM
45 _borrow_user_attributes_ptr = staticmethod(
46 native_bt.clock_class_borrow_user_attributes_const
47 )
3cdfbaea 48
5783664e
PP
49 @property
50 def user_attributes(self):
2550c437 51 ptr = self._borrow_user_attributes_ptr(self._ptr)
5783664e 52 assert ptr is not None
eddea575
FD
53 return self._create_value_from_ptr_and_get_ref(ptr)
54
55 @property
56 def name(self):
57 return native_bt.clock_class_get_name(self._ptr)
58
59 @property
60 def description(self):
61 return native_bt.clock_class_get_description(self._ptr)
62
63 @property
64 def frequency(self):
65 return native_bt.clock_class_get_frequency(self._ptr)
66
67 @property
68 def precision(self):
69 precision = native_bt.clock_class_get_precision(self._ptr)
70 return precision
71
72 @property
73 def offset(self):
74 offset_s, offset_cycles = native_bt.clock_class_get_offset(self._ptr)
75 return ClockClassOffset(offset_s, offset_cycles)
76
77 @property
78 def origin_is_unix_epoch(self):
79 return native_bt.clock_class_origin_is_unix_epoch(self._ptr)
80
81 @property
82 def uuid(self):
83 uuid_bytes = native_bt.clock_class_get_uuid(self._ptr)
84
85 if uuid_bytes is None:
86 return
87
88 return uuidp.UUID(bytes=uuid_bytes)
89
90 def cycles_to_ns_from_origin(self, cycles):
91 utils._check_uint64(cycles)
92 status, ns = native_bt.clock_class_cycles_to_ns_from_origin(self._ptr, cycles)
93 error_msg = "cannot convert clock value to nanoseconds from origin for given clock class"
94 utils._handle_func_status(status, error_msg)
95 return ns
96
97
98class _ClockClass(_ClockClassConst):
99 _create_value_from_ptr_and_get_ref = staticmethod(
100 bt2_value._create_from_ptr_and_get_ref
101 )
2550c437
SM
102 _borrow_user_attributes_ptr = staticmethod(
103 native_bt.clock_class_borrow_user_attributes
104 )
5783664e
PP
105
106 def _user_attributes(self, user_attributes):
107 value = bt2_value.create_value(user_attributes)
108 utils._check_type(value, bt2_value.MapValue)
109 native_bt.clock_class_set_user_attributes(self._ptr, value._ptr)
110
111 _user_attributes = property(fset=_user_attributes)
112
be7bbff9 113 def _name(self, name):
81447b5b 114 utils._check_str(name)
d24d5663 115 status = native_bt.clock_class_set_name(self._ptr, name)
cfbd7cf3 116 utils._handle_func_status(status, "cannot set clock class object's name")
81447b5b 117
be7bbff9
SM
118 _name = property(fset=_name)
119
be7bbff9 120 def _description(self, description):
81447b5b 121 utils._check_str(description)
d24d5663 122 status = native_bt.clock_class_set_description(self._ptr, description)
cfbd7cf3 123 utils._handle_func_status(status, "cannot set clock class object's description")
81447b5b 124
be7bbff9
SM
125 _description = property(fset=_description)
126
be7bbff9 127 def _frequency(self, frequency):
81447b5b 128 utils._check_uint64(frequency)
be7bbff9
SM
129 native_bt.clock_class_set_frequency(self._ptr, frequency)
130
131 _frequency = property(fset=_frequency)
81447b5b 132
be7bbff9 133 def _precision(self, precision):
81447b5b 134 utils._check_uint64(precision)
be7bbff9
SM
135 native_bt.clock_class_set_precision(self._ptr, precision)
136
137 _precision = property(fset=_precision)
81447b5b 138
be7bbff9 139 def _offset(self, offset):
81447b5b 140 utils._check_type(offset, ClockClassOffset)
be7bbff9
SM
141 native_bt.clock_class_set_offset(self._ptr, offset.seconds, offset.cycles)
142
143 _offset = property(fset=_offset)
81447b5b 144
be7bbff9
SM
145 def _origin_is_unix_epoch(self, origin_is_unix_epoch):
146 utils._check_bool(origin_is_unix_epoch)
cfbd7cf3
FD
147 native_bt.clock_class_set_origin_is_unix_epoch(
148 self._ptr, int(origin_is_unix_epoch)
149 )
be7bbff9
SM
150
151 _origin_is_unix_epoch = property(fset=_origin_is_unix_epoch)
81447b5b 152
be7bbff9 153 def _uuid(self, uuid):
81447b5b 154 utils._check_type(uuid, uuidp.UUID)
be7bbff9
SM
155 native_bt.clock_class_set_uuid(self._ptr, uuid.bytes)
156
157 _uuid = property(fset=_uuid)
This page took 0.08039 seconds and 4 git commands to generate.