bt2: remove unused imports
[babeltrace.git] / src / bindings / python / bt2 / bt2 / clock_class.py
1 # The MIT License (MIT)
2 #
3 # Copyright (c) 2017 Philippe Proulx <pproulx@efficios.com>
4 #
5 # Permission is hereby granted, free of charge, to any person obtaining a copy
6 # of this software and associated documentation files (the "Software"), to deal
7 # in the Software without restriction, including without limitation the rights
8 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 # copies of the Software, and to permit persons to whom the Software is
10 # furnished to do so, subject to the following conditions:
11 #
12 # The above copyright notice and this permission notice shall be included in
13 # all copies or substantial portions of the Software.
14 #
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 # THE SOFTWARE.
22
23 from bt2 import native_bt, object, utils
24 import uuid as uuidp
25
26
27 class ClockClassOffset:
28 def __init__(self, seconds=0, cycles=0):
29 utils._check_int64(seconds)
30 utils._check_int64(cycles)
31 self._seconds = seconds
32 self._cycles = cycles
33
34 @property
35 def seconds(self):
36 return self._seconds
37
38 @property
39 def cycles(self):
40 return self._cycles
41
42 def __eq__(self, other):
43 if not isinstance(other, self.__class__):
44 # not comparing apples to apples
45 return False
46
47 return (self.seconds, self.cycles) == (other.seconds, other.cycles)
48
49
50 class _ClockClass(object._SharedObject):
51 _get_ref = staticmethod(native_bt.clock_class_get_ref)
52 _put_ref = staticmethod(native_bt.clock_class_put_ref)
53
54 @property
55 def name(self):
56 return native_bt.clock_class_get_name(self._ptr)
57
58 def _name(self, name):
59 utils._check_str(name)
60 status = native_bt.clock_class_set_name(self._ptr, name)
61 utils._handle_func_status(status, "cannot set clock class object's name")
62
63 _name = property(fset=_name)
64
65 @property
66 def description(self):
67 return native_bt.clock_class_get_description(self._ptr)
68
69 def _description(self, description):
70 utils._check_str(description)
71 status = native_bt.clock_class_set_description(self._ptr, description)
72 utils._handle_func_status(status, "cannot set clock class object's description")
73
74 _description = property(fset=_description)
75
76 @property
77 def frequency(self):
78 return native_bt.clock_class_get_frequency(self._ptr)
79
80 def _frequency(self, frequency):
81 utils._check_uint64(frequency)
82 native_bt.clock_class_set_frequency(self._ptr, frequency)
83
84 _frequency = property(fset=_frequency)
85
86 @property
87 def precision(self):
88 precision = native_bt.clock_class_get_precision(self._ptr)
89 return precision
90
91 def _precision(self, precision):
92 utils._check_uint64(precision)
93 native_bt.clock_class_set_precision(self._ptr, precision)
94
95 _precision = property(fset=_precision)
96
97 @property
98 def offset(self):
99 offset_s, offset_cycles = native_bt.clock_class_get_offset(self._ptr)
100 return ClockClassOffset(offset_s, offset_cycles)
101
102 def _offset(self, offset):
103 utils._check_type(offset, ClockClassOffset)
104 native_bt.clock_class_set_offset(self._ptr, offset.seconds, offset.cycles)
105
106 _offset = property(fset=_offset)
107
108 @property
109 def origin_is_unix_epoch(self):
110 return native_bt.clock_class_origin_is_unix_epoch(self._ptr)
111
112 def _origin_is_unix_epoch(self, origin_is_unix_epoch):
113 utils._check_bool(origin_is_unix_epoch)
114 native_bt.clock_class_set_origin_is_unix_epoch(
115 self._ptr, int(origin_is_unix_epoch)
116 )
117
118 _origin_is_unix_epoch = property(fset=_origin_is_unix_epoch)
119
120 @property
121 def uuid(self):
122 uuid_bytes = native_bt.clock_class_get_uuid(self._ptr)
123
124 if uuid_bytes is None:
125 return
126
127 return uuidp.UUID(bytes=uuid_bytes)
128
129 def _uuid(self, uuid):
130 utils._check_type(uuid, uuidp.UUID)
131 native_bt.clock_class_set_uuid(self._ptr, uuid.bytes)
132
133 _uuid = property(fset=_uuid)
134
135 def cycles_to_ns_from_origin(self, cycles):
136 utils._check_uint64(cycles)
137 status, ns = native_bt.clock_class_cycles_to_ns_from_origin(self._ptr, cycles)
138 error_msg = "cannot convert clock value to nanoseconds from origin for given clock class"
139 utils._handle_func_status(status, error_msg)
140 return ns
This page took 0.033943 seconds and 5 git commands to generate.