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
24 from bt2
import value
as bt2_value
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._SharedObject
):
52 _get_ref
= staticmethod(native_bt
.clock_class_get_ref
)
53 _put_ref
= staticmethod(native_bt
.clock_class_put_ref
)
56 def user_attributes(self
):
57 ptr
= native_bt
.clock_class_borrow_user_attributes(self
._ptr
)
58 assert ptr
is not None
59 return bt2_value
._create
_from
_ptr
_and
_get
_ref
(ptr
)
61 def _user_attributes(self
, user_attributes
):
62 value
= bt2_value
.create_value(user_attributes
)
63 utils
._check
_type
(value
, bt2_value
.MapValue
)
64 native_bt
.clock_class_set_user_attributes(self
._ptr
, value
._ptr
)
66 _user_attributes
= property(fset
=_user_attributes
)
70 return native_bt
.clock_class_get_name(self
._ptr
)
72 def _name(self
, name
):
73 utils
._check
_str
(name
)
74 status
= native_bt
.clock_class_set_name(self
._ptr
, name
)
75 utils
._handle
_func
_status
(status
, "cannot set clock class object's name")
77 _name
= property(fset
=_name
)
80 def description(self
):
81 return native_bt
.clock_class_get_description(self
._ptr
)
83 def _description(self
, description
):
84 utils
._check
_str
(description
)
85 status
= native_bt
.clock_class_set_description(self
._ptr
, description
)
86 utils
._handle
_func
_status
(status
, "cannot set clock class object's description")
88 _description
= property(fset
=_description
)
92 return native_bt
.clock_class_get_frequency(self
._ptr
)
94 def _frequency(self
, frequency
):
95 utils
._check
_uint
64(frequency
)
96 native_bt
.clock_class_set_frequency(self
._ptr
, frequency
)
98 _frequency
= property(fset
=_frequency
)
102 precision
= native_bt
.clock_class_get_precision(self
._ptr
)
105 def _precision(self
, precision
):
106 utils
._check
_uint
64(precision
)
107 native_bt
.clock_class_set_precision(self
._ptr
, precision
)
109 _precision
= property(fset
=_precision
)
113 offset_s
, offset_cycles
= native_bt
.clock_class_get_offset(self
._ptr
)
114 return ClockClassOffset(offset_s
, offset_cycles
)
116 def _offset(self
, offset
):
117 utils
._check
_type
(offset
, ClockClassOffset
)
118 native_bt
.clock_class_set_offset(self
._ptr
, offset
.seconds
, offset
.cycles
)
120 _offset
= property(fset
=_offset
)
123 def origin_is_unix_epoch(self
):
124 return native_bt
.clock_class_origin_is_unix_epoch(self
._ptr
)
126 def _origin_is_unix_epoch(self
, origin_is_unix_epoch
):
127 utils
._check
_bool
(origin_is_unix_epoch
)
128 native_bt
.clock_class_set_origin_is_unix_epoch(
129 self
._ptr
, int(origin_is_unix_epoch
)
132 _origin_is_unix_epoch
= property(fset
=_origin_is_unix_epoch
)
136 uuid_bytes
= native_bt
.clock_class_get_uuid(self
._ptr
)
138 if uuid_bytes
is None:
141 return uuidp
.UUID(bytes
=uuid_bytes
)
143 def _uuid(self
, uuid
):
144 utils
._check
_type
(uuid
, uuidp
.UUID
)
145 native_bt
.clock_class_set_uuid(self
._ptr
, uuid
.bytes
)
147 _uuid
= property(fset
=_uuid
)
149 def cycles_to_ns_from_origin(self
, cycles
):
150 utils
._check
_uint
64(cycles
)
151 status
, ns
= native_bt
.clock_class_cycles_to_ns_from_origin(self
._ptr
, cycles
)
152 error_msg
= "cannot convert clock value to nanoseconds from origin for given clock class"
153 utils
._handle
_func
_status
(status
, error_msg
)
This page took 0.031927 seconds and 4 git commands to generate.