393f7ed883ec94f651355b7250d02601b190ff1f
1 # SPDX-License-Identifier: MIT
3 # Copyright (c) 2017 Philippe Proulx <pproulx@efficios.com>
6 from bt2
import logging
as bt2_logging
7 from bt2
import native_bt
11 if not isinstance(o
, bool):
12 raise TypeError("'{}' is not a 'bool' object".format(o
.__class
__.__name
__))
16 if not isinstance(o
, int):
17 raise TypeError("'{}' is not an 'int' object".format(o
.__class
__.__name
__))
21 if not isinstance(o
, float):
22 raise TypeError("'{}' is not a 'float' object".format(o
.__class
__.__name
__))
26 if not isinstance(o
, str):
27 raise TypeError("'{}' is not a 'str' object".format(o
.__class
__.__name
__))
30 def _check_type(o
, expected_type
):
31 if not isinstance(o
, expected_type
):
33 "'{}' is not a '{}' object".format(o
.__class
__.__name
__, expected_type
)
37 def _is_in_int64_range(v
):
38 assert isinstance(v
, int)
39 return v
>= -(2**63) and v
<= (2**63 - 1)
43 if not isinstance(v
, int):
46 return _is_in_int64_range(v
)
49 def _is_in_uint64_range(v
):
50 assert isinstance(v
, int)
51 return v
>= 0 and v
<= (2**64 - 1)
55 if not isinstance(v
, int):
58 return _is_in_uint64_range(v
)
61 def _check_int64(v
, msg
=None):
64 if not _is_in_int64_range(v
):
66 msg
= "expecting a signed 64-bit integral value"
68 msg
+= " (got {})".format(v
)
72 def _check_uint64(v
, msg
=None):
75 if not _is_in_uint64_range(v
):
77 msg
= "expecting an unsigned 64-bit integral value"
79 msg
+= " (got {})".format(v
)
84 return v
== 18446744073709551615
88 return v
!= 0 and ((v
& (v
- 1)) == 0)
91 def _check_alignment(a
):
95 raise ValueError("{} is not a power of two".format(a
))
98 def _check_log_level(log_level
):
102 bt2_logging
.LoggingLevel
.TRACE
,
103 bt2_logging
.LoggingLevel
.DEBUG
,
104 bt2_logging
.LoggingLevel
.INFO
,
105 bt2_logging
.LoggingLevel
.WARNING
,
106 bt2_logging
.LoggingLevel
.ERROR
,
107 bt2_logging
.LoggingLevel
.FATAL
,
108 bt2_logging
.LoggingLevel
.NONE
,
111 if log_level
not in log_levels
:
112 raise ValueError("'{}' is not a valid logging level".format(log_level
))
115 def _handle_func_status(status
, msg
=None):
116 if status
== native_bt
.__BT
_FUNC
_STATUS
_OK
:
120 if status
== native_bt
.__BT
_FUNC
_STATUS
_ERROR
:
121 assert msg
is not None
122 raise bt2
._Error(msg
)
123 elif status
== native_bt
.__BT
_FUNC
_STATUS
_MEMORY
_ERROR
:
124 assert msg
is not None
125 raise bt2
._MemoryError(msg
)
126 elif status
== native_bt
.__BT
_FUNC
_STATUS
_END
:
131 elif status
== native_bt
.__BT
_FUNC
_STATUS
_AGAIN
:
135 raise bt2
.TryAgain(msg
)
136 elif status
== native_bt
.__BT
_FUNC
_STATUS
_OVERFLOW
_ERROR
:
138 raise bt2
._OverflowError
140 raise bt2
._OverflowError(msg
)
141 elif status
== native_bt
.__BT
_FUNC
_STATUS
_UNKNOWN
_OBJECT
:
143 raise bt2
.UnknownObject
145 raise bt2
.UnknownObject(msg
)
150 class _ListenerHandle
:
151 def __init__(self
, addr
):
153 self
._listener
_id
= None
155 def _set_listener_id(self
, listener_id
):
156 self
._listener
_id
= listener_id
158 def _invalidate(self
):
159 self
._listener
_id
= None
This page took 0.032038 seconds and 4 git commands to generate.