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 import collections
.abc
25 import bt2
.clock_class
30 class _ClockClassIterator(collections
.abc
.Iterator
):
31 def __init__(self
, cc_prio_map
):
32 self
._cc
_prio
_map
= cc_prio_map
36 if self
._at
== len(self
._cc
_prio
_map
):
39 cc_ptr
= native_bt
.clock_class_priority_map_get_clock_class_by_index(self
._cc
_prio
_map
._ptr
,
42 clock_class
= bt2
.ClockClass
._create
_from
_ptr
(cc_ptr
)
47 class ClockClassPriorityMap(object._Object
, collections
.abc
.MutableMapping
):
48 def __init__(self
, clock_class_priorities
=None):
49 ptr
= native_bt
.clock_class_priority_map_create()
52 raise bt2
.CreationError('cannot create clock class priority map object')
56 if clock_class_priorities
is not None:
57 for clock_class
, priority
in clock_class_priorities
.items():
58 self
[clock_class
] = priority
60 def __getitem__(self
, key
):
61 utils
._check
_type
(key
, bt2
.ClockClass
)
62 ret
, prio
= native_bt
.clock_class_priority_map_get_clock_class_priority(self
._ptr
,
71 count
= native_bt
.clock_class_priority_map_get_clock_class_count(self
._ptr
)
75 def __delitem__(self
):
76 raise NotImplementedError
78 def __setitem__(self
, key
, value
):
79 utils
._check
_type
(key
, bt2
.ClockClass
)
80 utils
._check
_uint
64(value
)
81 ret
= native_bt
.clock_class_priority_map_add_clock_class(self
._ptr
,
84 utils
._handle
_ret
(ret
, "cannot set clock class's priority in clock class priority map object")
87 return _ClockClassIterator(self
)
90 def highest_priority_clock_class(self
):
91 cc_ptr
= native_bt
.clock_class_priority_map_get_highest_priority_clock_class(self
._ptr
)
96 return bt2
.ClockClass
._create
_from
_ptr
(cc_ptr
)
101 for clock_class
, prio
in self
.items():
102 prios
[clock_class
] = prio
106 def __eq__(self
, other
):
107 if type(other
) is not type(self
):
110 if self
.addr
== other
.addr
:
113 return self
._get
_prios
() == other
._get
_prios
()
115 def _copy(self
, cc_copy_func
):
116 cpy
= ClockClassPriorityMap()
118 for clock_class
, prio
in self
.items():
119 cpy
[cc_copy_func(clock_class
)] = prio
124 return self
._copy
(lambda obj
: obj
)
126 def __deepcopy__(self
, memo
):
127 cpy
= self
._copy
(copy
.deepcopy
)
This page took 0.032456 seconds and 4 git commands to generate.