1 # SPDX-License-Identifier: MIT
3 # Copyright (c) 2017 Philippe Proulx <pproulx@efficios.com>
5 from bt2
import native_bt
, object, utils
6 from bt2
import field_class
as bt2_field_class
7 from bt2
import value
as bt2_value
10 def _bt2_stream_class():
11 from bt2
import stream_class
as bt2_stream_class
13 return bt2_stream_class
16 class EventClassLogLevel
:
17 EMERGENCY
= native_bt
.EVENT_CLASS_LOG_LEVEL_EMERGENCY
18 ALERT
= native_bt
.EVENT_CLASS_LOG_LEVEL_ALERT
19 CRITICAL
= native_bt
.EVENT_CLASS_LOG_LEVEL_CRITICAL
20 ERROR
= native_bt
.EVENT_CLASS_LOG_LEVEL_ERROR
21 WARNING
= native_bt
.EVENT_CLASS_LOG_LEVEL_WARNING
22 NOTICE
= native_bt
.EVENT_CLASS_LOG_LEVEL_NOTICE
23 INFO
= native_bt
.EVENT_CLASS_LOG_LEVEL_INFO
24 DEBUG_SYSTEM
= native_bt
.EVENT_CLASS_LOG_LEVEL_DEBUG_SYSTEM
25 DEBUG_PROGRAM
= native_bt
.EVENT_CLASS_LOG_LEVEL_DEBUG_PROGRAM
26 DEBUG_PROCESS
= native_bt
.EVENT_CLASS_LOG_LEVEL_DEBUG_PROCESS
27 DEBUG_MODULE
= native_bt
.EVENT_CLASS_LOG_LEVEL_DEBUG_MODULE
28 DEBUG_UNIT
= native_bt
.EVENT_CLASS_LOG_LEVEL_DEBUG_UNIT
29 DEBUG_FUNCTION
= native_bt
.EVENT_CLASS_LOG_LEVEL_DEBUG_FUNCTION
30 DEBUG_LINE
= native_bt
.EVENT_CLASS_LOG_LEVEL_DEBUG_LINE
31 DEBUG
= native_bt
.EVENT_CLASS_LOG_LEVEL_DEBUG
34 class _EventClassConst(object._SharedObject
):
35 _get_ref
= staticmethod(native_bt
.event_class_get_ref
)
36 _put_ref
= staticmethod(native_bt
.event_class_put_ref
)
37 _borrow_stream_class_ptr
= staticmethod(
38 native_bt
.event_class_borrow_stream_class_const
40 _borrow_specific_context_field_class_ptr
= staticmethod(
41 native_bt
.event_class_borrow_specific_context_field_class_const
43 _borrow_payload_field_class_ptr
= staticmethod(
44 native_bt
.event_class_borrow_payload_field_class_const
46 _borrow_user_attributes_ptr
= staticmethod(
47 native_bt
.event_class_borrow_user_attributes_const
49 _create_field_class_from_ptr_and_get_ref
= staticmethod(
50 bt2_field_class
._create
_field
_class
_from
_const
_ptr
_and
_get
_ref
52 _create_value_from_ptr_and_get_ref
= staticmethod(
53 bt2_value
._create
_from
_const
_ptr
_and
_get
_ref
55 _stream_class_pycls
= property(lambda s
: _bt2_stream_class()._StreamClassConst
)
58 def stream_class(self
):
59 sc_ptr
= self
._borrow
_stream
_class
_ptr
(self
._ptr
)
61 if sc_ptr
is not None:
62 return self
._stream
_class
_pycls
._create
_from
_ptr
_and
_get
_ref
(sc_ptr
)
65 def user_attributes(self
):
66 ptr
= self
._borrow
_user
_attributes
_ptr
(self
._ptr
)
67 assert ptr
is not None
68 return self
._create
_value
_from
_ptr
_and
_get
_ref
(ptr
)
72 return native_bt
.event_class_get_name(self
._ptr
)
76 id = native_bt
.event_class_get_id(self
._ptr
)
77 return id if id >= 0 else None
81 is_available
, log_level
= native_bt
.event_class_get_log_level(self
._ptr
)
83 if is_available
!= native_bt
.PROPERTY_AVAILABILITY_AVAILABLE
:
86 return _EVENT_CLASS_LOG_LEVEL_TO_OBJ
[log_level
]
90 return native_bt
.event_class_get_emf_uri(self
._ptr
)
93 def specific_context_field_class(self
):
94 fc_ptr
= self
._borrow
_specific
_context
_field
_class
_ptr
(self
._ptr
)
99 return self
._create
_field
_class
_from
_ptr
_and
_get
_ref
(fc_ptr
)
102 def payload_field_class(self
):
103 fc_ptr
= self
._borrow
_payload
_field
_class
_ptr
(self
._ptr
)
108 return self
._create
_field
_class
_from
_ptr
_and
_get
_ref
(fc_ptr
)
111 class _EventClass(_EventClassConst
):
112 _borrow_stream_class_ptr
= staticmethod(native_bt
.event_class_borrow_stream_class
)
113 _borrow_specific_context_field_class_ptr
= staticmethod(
114 native_bt
.event_class_borrow_specific_context_field_class
116 _borrow_payload_field_class_ptr
= staticmethod(
117 native_bt
.event_class_borrow_payload_field_class
119 _borrow_user_attributes_ptr
= staticmethod(
120 native_bt
.event_class_borrow_user_attributes
122 _create_field_class_from_ptr_and_get_ref
= staticmethod(
123 bt2_field_class
._create
_field
_class
_from
_ptr
_and
_get
_ref
125 _create_value_from_ptr_and_get_ref
= staticmethod(
126 bt2_value
._create
_from
_ptr
_and
_get
_ref
128 _stream_class_pycls
= property(lambda s
: _bt2_stream_class()._StreamClass
)
130 def _user_attributes(self
, user_attributes
):
131 value
= bt2_value
.create_value(user_attributes
)
132 native_bt
.event_class_set_user_attributes(self
._ptr
, value
._ptr
)
134 _user_attributes
= property(fset
=_user_attributes
)
136 def _name(self
, name
):
137 return native_bt
.event_class_set_name(self
._ptr
, name
)
139 _name
= property(fset
=_name
)
141 def _log_level(self
, log_level
):
142 native_bt
.event_class_set_log_level(self
._ptr
, log_level
)
144 _log_level
= property(fset
=_log_level
)
146 def _emf_uri(self
, emf_uri
):
147 status
= native_bt
.event_class_set_emf_uri(self
._ptr
, emf_uri
)
148 utils
._handle
_func
_status
(status
, "cannot set event class object's EMF URI")
150 _emf_uri
= property(fset
=_emf_uri
)
152 def _specific_context_field_class(self
, context_field_class
):
153 status
= native_bt
.event_class_set_specific_context_field_class(
154 self
._ptr
, context_field_class
._ptr
156 utils
._handle
_func
_status
(
157 status
, "cannot set event class object's context field class"
160 _specific_context_field_class
= property(fset
=_specific_context_field_class
)
162 def _payload_field_class(self
, payload_field_class
):
163 status
= native_bt
.event_class_set_payload_field_class(
164 self
._ptr
, payload_field_class
._ptr
166 utils
._handle
_func
_status
(
167 status
, "cannot set event class object's payload field class"
170 _payload_field_class
= property(fset
=_payload_field_class
)
173 def _validate_create_params(
178 specific_context_field_class
,
182 utils
._check
_str
(name
)
184 if user_attributes
is not None:
185 value
= bt2_value
.create_value(user_attributes
)
186 utils
._check
_type
(value
, bt2_value
.MapValue
)
188 if log_level
is not None:
190 EventClassLogLevel
.EMERGENCY
,
191 EventClassLogLevel
.ALERT
,
192 EventClassLogLevel
.CRITICAL
,
193 EventClassLogLevel
.ERROR
,
194 EventClassLogLevel
.WARNING
,
195 EventClassLogLevel
.NOTICE
,
196 EventClassLogLevel
.INFO
,
197 EventClassLogLevel
.DEBUG_SYSTEM
,
198 EventClassLogLevel
.DEBUG_PROGRAM
,
199 EventClassLogLevel
.DEBUG_PROCESS
,
200 EventClassLogLevel
.DEBUG_MODULE
,
201 EventClassLogLevel
.DEBUG_UNIT
,
202 EventClassLogLevel
.DEBUG_FUNCTION
,
203 EventClassLogLevel
.DEBUG_LINE
,
204 EventClassLogLevel
.DEBUG
,
207 if log_level
not in log_levels
:
208 raise ValueError("'{}' is not a valid log level".format(log_level
))
210 if emf_uri
is not None:
211 utils
._check
_str
(emf_uri
)
213 if specific_context_field_class
is not None:
215 specific_context_field_class
, bt2_field_class
._StructureFieldClass
218 if payload_field_class
is not None:
219 utils
._check
_type
(payload_field_class
, bt2_field_class
._StructureFieldClass
)
222 _EVENT_CLASS_LOG_LEVEL_TO_OBJ
= {
223 native_bt
.EVENT_CLASS_LOG_LEVEL_EMERGENCY
: EventClassLogLevel
.EMERGENCY
,
224 native_bt
.EVENT_CLASS_LOG_LEVEL_ALERT
: EventClassLogLevel
.ALERT
,
225 native_bt
.EVENT_CLASS_LOG_LEVEL_CRITICAL
: EventClassLogLevel
.CRITICAL
,
226 native_bt
.EVENT_CLASS_LOG_LEVEL_ERROR
: EventClassLogLevel
.ERROR
,
227 native_bt
.EVENT_CLASS_LOG_LEVEL_WARNING
: EventClassLogLevel
.WARNING
,
228 native_bt
.EVENT_CLASS_LOG_LEVEL_NOTICE
: EventClassLogLevel
.NOTICE
,
229 native_bt
.EVENT_CLASS_LOG_LEVEL_INFO
: EventClassLogLevel
.INFO
,
230 native_bt
.EVENT_CLASS_LOG_LEVEL_DEBUG_SYSTEM
: EventClassLogLevel
.DEBUG_SYSTEM
,
231 native_bt
.EVENT_CLASS_LOG_LEVEL_DEBUG_PROGRAM
: EventClassLogLevel
.DEBUG_PROGRAM
,
232 native_bt
.EVENT_CLASS_LOG_LEVEL_DEBUG_PROCESS
: EventClassLogLevel
.DEBUG_PROCESS
,
233 native_bt
.EVENT_CLASS_LOG_LEVEL_DEBUG_MODULE
: EventClassLogLevel
.DEBUG_MODULE
,
234 native_bt
.EVENT_CLASS_LOG_LEVEL_DEBUG_UNIT
: EventClassLogLevel
.DEBUG_UNIT
,
235 native_bt
.EVENT_CLASS_LOG_LEVEL_DEBUG_FUNCTION
: EventClassLogLevel
.DEBUG_FUNCTION
,
236 native_bt
.EVENT_CLASS_LOG_LEVEL_DEBUG_LINE
: EventClassLogLevel
.DEBUG_LINE
,
237 native_bt
.EVENT_CLASS_LOG_LEVEL_DEBUG
: EventClassLogLevel
.DEBUG
,