1 # The MIT License (MIT)
3 # Copyright (c) 2017 Philippe Proulx <pproulx@efficios.com>
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:
12 # The above copyright notice and this permission notice shall be included in
13 # all copies or substantial portions of the Software.
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
23 from bt2
import native_bt
, object, utils
29 class ClockClassOffset
:
30 def __init__(self
, seconds
=0, cycles
=0):
31 utils
._check
_int
64(seconds
)
32 utils
._check
_int
64(cycles
)
33 self
._seconds
= seconds
45 return hash((self
.seconds
, self
.cycles
))
47 def __eq__(self
, other
):
48 if not isinstance(other
, self
.__class
__):
49 # not comparing apples to apples
52 return (self
.seconds
, self
.cycles
) == (other
.seconds
, other
.cycles
)
55 class ClockClass(object._Object
):
56 def __init__(self
, name
, frequency
, description
=None, precision
=None,
57 offset
=None, is_absolute
=None, uuid
=None):
58 utils
._check
_str
(name
)
59 utils
._check
_uint
64(frequency
)
60 ptr
= native_bt
.ctf_clock_class_create(name
, frequency
)
63 raise bt2
.CreationError('cannot create clock class object')
67 if description
is not None:
68 self
.description
= description
70 if frequency
is not None:
71 self
.frequency
= frequency
73 if precision
is not None:
74 self
.precision
= precision
76 if offset
is not None:
79 if is_absolute
is not None:
80 self
.is_absolute
= is_absolute
85 def __eq__(self
, other
):
86 if type(self
) is not type(other
):
87 # not comparing apples to apples
108 return self_props
== other_props
111 return ClockClass(name
=self
.name
, description
=self
.description
,
112 frequency
=self
.frequency
, precision
=self
.precision
,
113 offset
=self
.offset
, is_absolute
=self
.is_absolute
,
116 def __deepcopy__(self
, memo
):
117 cpy
= self
.__copy
__()
134 name
= native_bt
.ctf_clock_class_get_name(self
._ptr
)
135 assert(name
is not None)
139 def name(self
, name
):
140 utils
._check
_str
(name
)
141 ret
= native_bt
.ctf_clock_class_set_name(self
._ptr
, name
)
142 utils
._handle
_ret
(ret
, "cannot set clock class object's name")
145 def description(self
):
146 return native_bt
.ctf_clock_class_get_description(self
._ptr
)
149 def description(self
, description
):
150 utils
._check
_str
(description
)
151 ret
= native_bt
.ctf_clock_class_set_description(self
._ptr
, description
)
152 utils
._handle
_ret
(ret
, "cannot set clock class object's description")
156 frequency
= native_bt
.ctf_clock_class_get_frequency(self
._ptr
)
157 assert(frequency
>= 1)
161 def frequency(self
, frequency
):
162 utils
._check
_uint
64(frequency
)
163 ret
= native_bt
.ctf_clock_class_set_frequency(self
._ptr
, frequency
)
164 utils
._handle
_ret
(ret
, "cannot set clock class object's frequency")
168 precision
= native_bt
.ctf_clock_class_get_precision(self
._ptr
)
169 assert(precision
>= 0)
173 def precision(self
, precision
):
174 utils
._check
_uint
64(precision
)
175 ret
= native_bt
.ctf_clock_class_set_precision(self
._ptr
, precision
)
176 utils
._handle
_ret
(ret
, "cannot set clock class object's precision")
180 ret
, offset_s
= native_bt
.ctf_clock_class_get_offset_s(self
._ptr
)
182 ret
, offset_cycles
= native_bt
.ctf_clock_class_get_offset_cycles(self
._ptr
)
184 return ClockClassOffset(offset_s
, offset_cycles
)
187 def offset(self
, offset
):
188 utils
._check
_type
(offset
, ClockClassOffset
)
189 ret
= native_bt
.ctf_clock_class_set_offset_s(self
._ptr
, offset
.seconds
)
190 utils
._handle
_ret
(ret
, "cannot set clock class object's offset (seconds)")
191 ret
= native_bt
.ctf_clock_class_set_offset_cycles(self
._ptr
, offset
.cycles
)
192 utils
._handle
_ret
(ret
, "cannot set clock class object's offset (cycles)")
195 def is_absolute(self
):
196 is_absolute
= native_bt
.ctf_clock_class_is_absolute(self
._ptr
)
197 assert(is_absolute
>= 0)
198 return is_absolute
> 0
201 def is_absolute(self
, is_absolute
):
202 utils
._check
_bool
(is_absolute
)
203 ret
= native_bt
.ctf_clock_class_set_is_absolute(self
._ptr
, int(is_absolute
))
204 utils
._handle
_ret
(ret
, "cannot set clock class object's absoluteness")
208 uuid_bytes
= native_bt
.ctf_clock_class_get_uuid(self
._ptr
)
210 if uuid_bytes
is None:
213 return uuidp
.UUID(bytes
=uuid_bytes
)
216 def uuid(self
, uuid
):
217 utils
._check
_type
(uuid
, uuidp
.UUID
)
218 ret
= native_bt
.ctf_clock_class_set_uuid(self
._ptr
, uuid
.bytes
)
219 utils
._handle
_ret
(ret
, "cannot set clock class object's UUID")
221 def __call__(self
, cycles
):
222 return _ClockValue(self
._ptr
, cycles
)
This page took 0.035064 seconds and 5 git commands to generate.