fc6d24ce79d8b9c4915238b87ed3f7205c97b63f
1 # SPDX-License-Identifier: MIT
3 # Copyright (c) 2017 Philippe Proulx <pproulx@efficios.com>
6 from bt2
import error
as bt2_error
7 from bt2
import logging
as bt2_logging
8 from bt2
import native_bt
11 class UnknownObject(Exception):
13 Raised when a component class handles a query for an object it doesn't
20 class _OverflowError(bt2_error
._Error
, OverflowError):
24 class TryAgain(Exception):
28 class Stop(StopIteration):
33 if not isinstance(o
, bool):
34 raise TypeError("'{}' is not a 'bool' object".format(o
.__class
__.__name
__))
38 if not isinstance(o
, int):
39 raise TypeError("'{}' is not an 'int' object".format(o
.__class
__.__name
__))
43 if not isinstance(o
, float):
44 raise TypeError("'{}' is not a 'float' object".format(o
.__class
__.__name
__))
48 if not isinstance(o
, str):
49 raise TypeError("'{}' is not a 'str' object".format(o
.__class
__.__name
__))
52 def _check_type(o
, expected_type
):
53 if not isinstance(o
, expected_type
):
55 "'{}' is not a '{}' object".format(o
.__class
__.__name
__, expected_type
)
59 def _is_in_int64_range(v
):
60 assert isinstance(v
, int)
61 return v
>= -(2**63) and v
<= (2**63 - 1)
65 if not isinstance(v
, int):
68 return _is_in_int64_range(v
)
71 def _is_in_uint64_range(v
):
72 assert isinstance(v
, int)
73 return v
>= 0 and v
<= (2**64 - 1)
77 if not isinstance(v
, int):
80 return _is_in_uint64_range(v
)
83 def _check_int64(v
, msg
=None):
86 if not _is_in_int64_range(v
):
88 msg
= "expecting a signed 64-bit integral value"
90 msg
+= " (got {})".format(v
)
94 def _check_uint64(v
, msg
=None):
97 if not _is_in_uint64_range(v
):
99 msg
= "expecting an unsigned 64-bit integral value"
101 msg
+= " (got {})".format(v
)
102 raise ValueError(msg
)
106 return v
== 18446744073709551615
110 return v
!= 0 and ((v
& (v
- 1)) == 0)
113 def _check_alignment(a
):
117 raise ValueError("{} is not a power of two".format(a
))
120 def _check_log_level(log_level
):
121 _check_int(log_level
)
124 bt2_logging
.LoggingLevel
.TRACE
,
125 bt2_logging
.LoggingLevel
.DEBUG
,
126 bt2_logging
.LoggingLevel
.INFO
,
127 bt2_logging
.LoggingLevel
.WARNING
,
128 bt2_logging
.LoggingLevel
.ERROR
,
129 bt2_logging
.LoggingLevel
.FATAL
,
130 bt2_logging
.LoggingLevel
.NONE
,
133 if log_level
not in log_levels
:
134 raise ValueError("'{}' is not a valid logging level".format(log_level
))
137 def _handle_func_status(status
, msg
=None):
138 if status
== native_bt
.__BT
_FUNC
_STATUS
_OK
:
142 if status
== native_bt
.__BT
_FUNC
_STATUS
_ERROR
:
143 assert msg
is not None
144 raise bt2_error
._Error
(msg
)
145 elif status
== native_bt
.__BT
_FUNC
_STATUS
_MEMORY
_ERROR
:
146 assert msg
is not None
147 raise bt2_error
._MemoryError
(msg
)
148 elif status
== native_bt
.__BT
_FUNC
_STATUS
_END
:
153 elif status
== native_bt
.__BT
_FUNC
_STATUS
_AGAIN
:
158 elif status
== native_bt
.__BT
_FUNC
_STATUS
_OVERFLOW
_ERROR
:
159 raise _OverflowError(msg
)
160 elif status
== native_bt
.__BT
_FUNC
_STATUS
_UNKNOWN
_OBJECT
:
164 raise UnknownObject(msg
)
169 class _ListenerHandle
:
170 def __init__(self
, addr
):
172 self
._listener
_id
= None
174 def _set_listener_id(self
, listener_id
):
175 self
._listener
_id
= listener_id
177 def _invalidate(self
):
178 self
._listener
_id
= None
This page took 0.034957 seconds and 5 git commands to generate.