sink.text.details: print user attributes
[babeltrace.git] / src / bindings / python / bt2 / bt2 / clock_class.py
CommitLineData
81447b5b
PP
1# The MIT License (MIT)
2#
811644b8 3# Copyright (c) 2017 Philippe Proulx <pproulx@efficios.com>
81447b5b
PP
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
23from bt2 import native_bt, object, utils
be7bbff9 24import uuid as uuidp
81447b5b 25
0b03f63e 26
81447b5b
PP
27class 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
be7bbff9 50class _ClockClass(object._SharedObject):
3cdfbaea
SM
51 _get_ref = staticmethod(native_bt.clock_class_get_ref)
52 _put_ref = staticmethod(native_bt.clock_class_put_ref)
53
81447b5b
PP
54 @property
55 def name(self):
be7bbff9 56 return native_bt.clock_class_get_name(self._ptr)
81447b5b 57
be7bbff9 58 def _name(self, name):
81447b5b 59 utils._check_str(name)
d24d5663 60 status = native_bt.clock_class_set_name(self._ptr, name)
cfbd7cf3 61 utils._handle_func_status(status, "cannot set clock class object's name")
81447b5b 62
be7bbff9
SM
63 _name = property(fset=_name)
64
81447b5b
PP
65 @property
66 def description(self):
50842bdc 67 return native_bt.clock_class_get_description(self._ptr)
81447b5b 68
be7bbff9 69 def _description(self, description):
81447b5b 70 utils._check_str(description)
d24d5663 71 status = native_bt.clock_class_set_description(self._ptr, description)
cfbd7cf3 72 utils._handle_func_status(status, "cannot set clock class object's description")
81447b5b 73
be7bbff9
SM
74 _description = property(fset=_description)
75
81447b5b
PP
76 @property
77 def frequency(self):
be7bbff9 78 return native_bt.clock_class_get_frequency(self._ptr)
81447b5b 79
be7bbff9 80 def _frequency(self, frequency):
81447b5b 81 utils._check_uint64(frequency)
be7bbff9
SM
82 native_bt.clock_class_set_frequency(self._ptr, frequency)
83
84 _frequency = property(fset=_frequency)
81447b5b
PP
85
86 @property
87 def precision(self):
50842bdc 88 precision = native_bt.clock_class_get_precision(self._ptr)
81447b5b
PP
89 return precision
90
be7bbff9 91 def _precision(self, precision):
81447b5b 92 utils._check_uint64(precision)
be7bbff9
SM
93 native_bt.clock_class_set_precision(self._ptr, precision)
94
95 _precision = property(fset=_precision)
81447b5b
PP
96
97 @property
98 def offset(self):
be7bbff9 99 offset_s, offset_cycles = native_bt.clock_class_get_offset(self._ptr)
81447b5b
PP
100 return ClockClassOffset(offset_s, offset_cycles)
101
be7bbff9 102 def _offset(self, offset):
81447b5b 103 utils._check_type(offset, ClockClassOffset)
be7bbff9
SM
104 native_bt.clock_class_set_offset(self._ptr, offset.seconds, offset.cycles)
105
106 _offset = property(fset=_offset)
81447b5b
PP
107
108 @property
be7bbff9
SM
109 def origin_is_unix_epoch(self):
110 return native_bt.clock_class_origin_is_unix_epoch(self._ptr)
81447b5b 111
be7bbff9
SM
112 def _origin_is_unix_epoch(self, origin_is_unix_epoch):
113 utils._check_bool(origin_is_unix_epoch)
cfbd7cf3
FD
114 native_bt.clock_class_set_origin_is_unix_epoch(
115 self._ptr, int(origin_is_unix_epoch)
116 )
be7bbff9
SM
117
118 _origin_is_unix_epoch = property(fset=_origin_is_unix_epoch)
81447b5b
PP
119
120 @property
121 def uuid(self):
50842bdc 122 uuid_bytes = native_bt.clock_class_get_uuid(self._ptr)
81447b5b
PP
123
124 if uuid_bytes is None:
811644b8 125 return
81447b5b
PP
126
127 return uuidp.UUID(bytes=uuid_bytes)
128
be7bbff9 129 def _uuid(self, uuid):
81447b5b 130 utils._check_type(uuid, uuidp.UUID)
be7bbff9
SM
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)
d24d5663 137 status, ns = native_bt.clock_class_cycles_to_ns_from_origin(self._ptr, cycles)
be7bbff9 138 error_msg = "cannot convert clock value to nanoseconds from origin for given clock class"
d24d5663 139 utils._handle_func_status(status, error_msg)
be7bbff9 140 return ns
This page took 0.051207 seconds and 4 git commands to generate.