1 # The MIT License (MIT)
3 # Copyright (c) 2016 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
28 class ClockClassOffset
:
29 def __init__(self
, seconds
=0, cycles
=0):
30 utils
._check
_int
64(seconds
)
31 utils
._check
_int
64(cycles
)
32 self
._seconds
= seconds
43 def __eq__(self
, other
):
44 if not isinstance(other
, self
.__class
__):
45 # not comparing apples to apples
48 return (self
.seconds
, self
.cycles
) == (other
.seconds
, other
.cycles
)
51 class ClockClass(object._Object
):
52 def __init__(self
, name
, description
=None, frequency
=None, precision
=None,
53 offset
=None, is_absolute
=None, uuid
=None):
54 utils
._check
_str
(name
)
55 ptr
= native_bt
.ctf_clock_class_create(name
)
58 raise bt2
.CreationError('cannot create clock class object')
62 if description
is not None:
63 self
.description
= description
65 if frequency
is not None:
66 self
.frequency
= frequency
68 if precision
is not None:
69 self
.precision
= precision
71 if offset
is not None:
74 if is_absolute
is not None:
75 self
.is_absolute
= is_absolute
80 def __eq__(self
, other
):
81 if type(self
) is not type(other
):
82 # not comparing apples to apples
103 return self_props
== other_props
106 return ClockClass(name
=self
.name
, description
=self
.description
,
107 frequency
=self
.frequency
, precision
=self
.precision
,
108 offset
=self
.offset
, is_absolute
=self
.is_absolute
,
111 def __deepcopy__(self
, memo
):
112 cpy
= self
.__copy
__()
118 name
= native_bt
.ctf_clock_class_get_name(self
._ptr
)
119 utils
._handle
_ptr
(name
, "cannot get clock class object's name")
123 def name(self
, name
):
124 utils
._check
_str
(name
)
125 ret
= native_bt
.ctf_clock_class_set_name(self
._ptr
, name
)
126 utils
._handle
_ret
(ret
, "cannot set clock class object's name")
129 def description(self
):
130 description
= native_bt
.ctf_clock_class_get_description(self
._ptr
)
134 def description(self
, description
):
135 utils
._check
_str
(description
)
136 ret
= native_bt
.ctf_clock_class_set_description(self
._ptr
, description
)
137 utils
._handle
_ret
(ret
, "cannot set clock class object's description")
141 frequency
= native_bt
.ctf_clock_class_get_frequency(self
._ptr
)
143 if utils
._is
_m
1ull(frequency
):
144 raise bt2
.Error("cannot get clock class object's frequency")
149 def frequency(self
, frequency
):
150 utils
._check
_uint
64(frequency
)
151 ret
= native_bt
.ctf_clock_class_set_frequency(self
._ptr
, frequency
)
152 utils
._handle
_ret
(ret
, "cannot set clock class object's frequency")
156 precision
= native_bt
.ctf_clock_class_get_precision(self
._ptr
)
158 if utils
._is
_m
1ull(precision
):
159 raise bt2
.Error("cannot get clock class object's precision")
164 def precision(self
, precision
):
165 utils
._check
_uint
64(precision
)
166 ret
= native_bt
.ctf_clock_class_set_precision(self
._ptr
, precision
)
167 utils
._handle
_ret
(ret
, "cannot set clock class object's precision")
171 ret
, offset_s
= native_bt
.ctf_clock_class_get_offset_s(self
._ptr
)
172 utils
._handle
_ret
(ret
, "cannot get clock class object's offset (seconds)")
173 ret
, offset_cycles
= native_bt
.ctf_clock_class_get_offset_cycles(self
._ptr
)
174 utils
._handle
_ret
(ret
, "cannot get clock class object's offset (cycles)")
175 return ClockClassOffset(offset_s
, offset_cycles
)
178 def offset(self
, offset
):
179 utils
._check
_type
(offset
, ClockClassOffset
)
180 ret
= native_bt
.ctf_clock_class_set_offset_s(self
._ptr
, offset
.seconds
)
181 utils
._handle
_ret
(ret
, "cannot set clock class object's offset (seconds)")
182 ret
= native_bt
.ctf_clock_class_set_offset_cycles(self
._ptr
, offset
.cycles
)
183 utils
._handle
_ret
(ret
, "cannot set clock class object's offset (cycles)")
186 def is_absolute(self
):
187 is_absolute
= native_bt
.ctf_clock_class_get_is_absolute(self
._ptr
)
188 utils
._handle
_ret
(is_absolute
, "cannot get clock class object's absoluteness")
189 return is_absolute
> 0
192 def is_absolute(self
, is_absolute
):
193 utils
._check
_bool
(is_absolute
)
194 ret
= native_bt
.ctf_clock_class_set_is_absolute(self
._ptr
, int(is_absolute
))
195 utils
._handle
_ret
(ret
, "cannot set clock class object's absoluteness")
199 uuid_bytes
= native_bt
.ctf_clock_class_get_uuid(self
._ptr
)
201 if uuid_bytes
is None:
202 raise bt2
.Error("cannot get clock class object's UUID")
204 return uuidp
.UUID(bytes
=uuid_bytes
)
207 def uuid(self
, uuid
):
208 utils
._check
_type
(uuid
, uuidp
.UUID
)
209 ret
= native_bt
.ctf_clock_class_set_uuid(self
._ptr
, uuid
.bytes
)
210 utils
._handle
_ret
(ret
, "cannot set clock class object's UUID")
212 def create_clock_value(self
, cycles
):
213 return _ClockValue(self
._ptr
, cycles
)
216 def _create_clock_value_from_ptr(ptr
):
217 clock_value
= _ClockValue
._create
_from
_ptr
(ptr
)
221 class _ClockValue(object._Object
):
222 def __init__(self
, clock_class_ptr
, cycles
):
223 utils
._check
_uint
64(cycles
)
224 ptr
= native_bt
.ctf_clock_value_create(clock_class_ptr
, cycles
)
227 raise bt2
.CreationError('cannot create clock value object')
229 super().__init
__(ptr
)
232 def clock_class(self
):
233 ptr
= native_bt
.ctf_clock_value_get_class(self
._ptr
)
234 utils
._handle
_ptr
(ptr
, "cannot get clock value object's clock class object")
235 return ClockClass
._create
_from
_ptr
(ptr
)
239 ret
, cycles
= native_bt
.ctf_clock_value_get_value(self
._ptr
)
240 utils
._handle
_ret
(ret
, "cannot get clock value object's cycles")
244 def ns_from_epoch(self
):
245 ret
, ns
= native_bt
.ctf_clock_value_get_value_ns_from_epoch(self
._ptr
)
246 utils
._handle
_ret
(ret
, "cannot get clock value object's nanoseconds from Epoch")
249 def __eq__(self
, other
):
250 if not isinstance(other
, self
.__class
__):
251 # not comparing apples to apples
254 if self
.addr
== other
.addr
:
257 self_props
= self
.clock_class
.addr
, self
.cycles
258 other_props
= other
.clock_class
.addr
, other
.cycles
259 return self_props
== other_props
262 return self
.clock_class
.create_clock_value(self
.cycles
)
264 def __deepcopy__(self
, memo
):
265 cpy
= self
.__copy
__()
This page took 0.054798 seconds and 4 git commands to generate.