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 field_class
as bt2_field_class
25 from bt2
import value
as bt2_value
28 def _bt2_stream_class():
29 from bt2
import stream_class
as bt2_stream_class
31 return bt2_stream_class
34 class EventClassLogLevel
:
35 EMERGENCY
= native_bt
.EVENT_CLASS_LOG_LEVEL_EMERGENCY
36 ALERT
= native_bt
.EVENT_CLASS_LOG_LEVEL_ALERT
37 CRITICAL
= native_bt
.EVENT_CLASS_LOG_LEVEL_CRITICAL
38 ERROR
= native_bt
.EVENT_CLASS_LOG_LEVEL_ERROR
39 WARNING
= native_bt
.EVENT_CLASS_LOG_LEVEL_WARNING
40 NOTICE
= native_bt
.EVENT_CLASS_LOG_LEVEL_NOTICE
41 INFO
= native_bt
.EVENT_CLASS_LOG_LEVEL_INFO
42 DEBUG_SYSTEM
= native_bt
.EVENT_CLASS_LOG_LEVEL_DEBUG_SYSTEM
43 DEBUG_PROGRAM
= native_bt
.EVENT_CLASS_LOG_LEVEL_DEBUG_PROGRAM
44 DEBUG_PROCESS
= native_bt
.EVENT_CLASS_LOG_LEVEL_DEBUG_PROCESS
45 DEBUG_MODULE
= native_bt
.EVENT_CLASS_LOG_LEVEL_DEBUG_MODULE
46 DEBUG_UNIT
= native_bt
.EVENT_CLASS_LOG_LEVEL_DEBUG_UNIT
47 DEBUG_FUNCTION
= native_bt
.EVENT_CLASS_LOG_LEVEL_DEBUG_FUNCTION
48 DEBUG_LINE
= native_bt
.EVENT_CLASS_LOG_LEVEL_DEBUG_LINE
49 DEBUG
= native_bt
.EVENT_CLASS_LOG_LEVEL_DEBUG
52 class _EventClassConst(object._SharedObject
):
53 _get_ref
= staticmethod(native_bt
.event_class_get_ref
)
54 _put_ref
= staticmethod(native_bt
.event_class_put_ref
)
55 _borrow_stream_class_ptr
= staticmethod(
56 native_bt
.event_class_borrow_stream_class_const
58 _borrow_specific_context_field_class_ptr
= staticmethod(
59 native_bt
.event_class_borrow_specific_context_field_class_const
61 _borrow_payload_field_class_ptr
= staticmethod(
62 native_bt
.event_class_borrow_payload_field_class_const
64 _borrow_user_attributes_ptr
= staticmethod(
65 native_bt
.event_class_borrow_user_attributes_const
67 _create_field_class_from_ptr_and_get_ref
= staticmethod(
68 bt2_field_class
._create
_field
_class
_from
_const
_ptr
_and
_get
_ref
70 _create_value_from_ptr_and_get_ref
= staticmethod(
71 bt2_value
._create
_from
_const
_ptr
_and
_get
_ref
73 _stream_class_pycls
= property(lambda s
: _bt2_stream_class()._StreamClassConst
)
76 def stream_class(self
):
77 sc_ptr
= self
._borrow
_stream
_class
_ptr
(self
._ptr
)
79 if sc_ptr
is not None:
80 return self
._stream
_class
_pycls
._create
_from
_ptr
_and
_get
_ref
(sc_ptr
)
83 def user_attributes(self
):
84 ptr
= self
._borrow
_user
_attributes
_ptr
(self
._ptr
)
85 assert ptr
is not None
86 return self
._create
_value
_from
_ptr
_and
_get
_ref
(ptr
)
90 return native_bt
.event_class_get_name(self
._ptr
)
94 id = native_bt
.event_class_get_id(self
._ptr
)
95 return id if id >= 0 else None
99 is_available
, log_level
= native_bt
.event_class_get_log_level(self
._ptr
)
101 if is_available
!= native_bt
.PROPERTY_AVAILABILITY_AVAILABLE
:
104 return _EVENT_CLASS_LOG_LEVEL_TO_OBJ
[log_level
]
108 return native_bt
.event_class_get_emf_uri(self
._ptr
)
111 def specific_context_field_class(self
):
112 fc_ptr
= self
._borrow
_specific
_context
_field
_class
_ptr
(self
._ptr
)
117 return self
._create
_field
_class
_from
_ptr
_and
_get
_ref
(fc_ptr
)
120 def payload_field_class(self
):
121 fc_ptr
= self
._borrow
_payload
_field
_class
_ptr
(self
._ptr
)
126 return self
._create
_field
_class
_from
_ptr
_and
_get
_ref
(fc_ptr
)
129 class _EventClass(_EventClassConst
):
130 _borrow_stream_class_ptr
= staticmethod(native_bt
.event_class_borrow_stream_class
)
131 _borrow_specific_context_field_class_ptr
= staticmethod(
132 native_bt
.event_class_borrow_specific_context_field_class
134 _borrow_payload_field_class_ptr
= staticmethod(
135 native_bt
.event_class_borrow_payload_field_class
137 _borrow_user_attributes_ptr
= staticmethod(
138 native_bt
.event_class_borrow_user_attributes
140 _create_field_class_from_ptr_and_get_ref
= staticmethod(
141 bt2_field_class
._create
_field
_class
_from
_ptr
_and
_get
_ref
143 _create_value_from_ptr_and_get_ref
= staticmethod(
144 bt2_value
._create
_from
_ptr
_and
_get
_ref
146 _stream_class_pycls
= property(lambda s
: _bt2_stream_class()._StreamClass
)
148 def _user_attributes(self
, user_attributes
):
149 value
= bt2_value
.create_value(user_attributes
)
150 utils
._check
_type
(value
, bt2_value
.MapValue
)
151 native_bt
.event_class_set_user_attributes(self
._ptr
, value
._ptr
)
153 _user_attributes
= property(fset
=_user_attributes
)
155 def _name(self
, name
):
156 utils
._check
_str
(name
)
157 return native_bt
.event_class_set_name(self
._ptr
, name
)
159 _name
= property(fset
=_name
)
161 def _log_level(self
, log_level
):
163 EventClassLogLevel
.EMERGENCY
,
164 EventClassLogLevel
.ALERT
,
165 EventClassLogLevel
.CRITICAL
,
166 EventClassLogLevel
.ERROR
,
167 EventClassLogLevel
.WARNING
,
168 EventClassLogLevel
.NOTICE
,
169 EventClassLogLevel
.INFO
,
170 EventClassLogLevel
.DEBUG_SYSTEM
,
171 EventClassLogLevel
.DEBUG_PROGRAM
,
172 EventClassLogLevel
.DEBUG_PROCESS
,
173 EventClassLogLevel
.DEBUG_MODULE
,
174 EventClassLogLevel
.DEBUG_UNIT
,
175 EventClassLogLevel
.DEBUG_FUNCTION
,
176 EventClassLogLevel
.DEBUG_LINE
,
177 EventClassLogLevel
.DEBUG
,
180 if log_level
not in log_levels
:
181 raise ValueError("'{}' is not a valid log level".format(log_level
))
183 native_bt
.event_class_set_log_level(self
._ptr
, log_level
)
185 _log_level
= property(fset
=_log_level
)
187 def _emf_uri(self
, emf_uri
):
188 utils
._check
_str
(emf_uri
)
189 status
= native_bt
.event_class_set_emf_uri(self
._ptr
, emf_uri
)
190 utils
._handle
_func
_status
(status
, "cannot set event class object's EMF URI")
192 _emf_uri
= property(fset
=_emf_uri
)
194 def _specific_context_field_class(self
, context_field_class
):
195 if context_field_class
is not None:
196 utils
._check
_type
(context_field_class
, bt2_field_class
._StructureFieldClass
)
197 status
= native_bt
.event_class_set_specific_context_field_class(
198 self
._ptr
, context_field_class
._ptr
200 utils
._handle
_func
_status
(
201 status
, "cannot set event class object's context field class"
204 _specific_context_field_class
= property(fset
=_specific_context_field_class
)
206 def _payload_field_class(self
, payload_field_class
):
207 if payload_field_class
is not None:
208 utils
._check
_type
(payload_field_class
, bt2_field_class
._StructureFieldClass
)
209 status
= native_bt
.event_class_set_payload_field_class(
210 self
._ptr
, payload_field_class
._ptr
212 utils
._handle
_func
_status
(
213 status
, "cannot set event class object's payload field class"
216 _payload_field_class
= property(fset
=_payload_field_class
)
219 _EVENT_CLASS_LOG_LEVEL_TO_OBJ
= {
220 native_bt
.EVENT_CLASS_LOG_LEVEL_EMERGENCY
: EventClassLogLevel
.EMERGENCY
,
221 native_bt
.EVENT_CLASS_LOG_LEVEL_ALERT
: EventClassLogLevel
.ALERT
,
222 native_bt
.EVENT_CLASS_LOG_LEVEL_CRITICAL
: EventClassLogLevel
.CRITICAL
,
223 native_bt
.EVENT_CLASS_LOG_LEVEL_ERROR
: EventClassLogLevel
.ERROR
,
224 native_bt
.EVENT_CLASS_LOG_LEVEL_WARNING
: EventClassLogLevel
.WARNING
,
225 native_bt
.EVENT_CLASS_LOG_LEVEL_NOTICE
: EventClassLogLevel
.NOTICE
,
226 native_bt
.EVENT_CLASS_LOG_LEVEL_INFO
: EventClassLogLevel
.INFO
,
227 native_bt
.EVENT_CLASS_LOG_LEVEL_DEBUG_SYSTEM
: EventClassLogLevel
.DEBUG_SYSTEM
,
228 native_bt
.EVENT_CLASS_LOG_LEVEL_DEBUG_PROGRAM
: EventClassLogLevel
.DEBUG_PROGRAM
,
229 native_bt
.EVENT_CLASS_LOG_LEVEL_DEBUG_PROCESS
: EventClassLogLevel
.DEBUG_PROCESS
,
230 native_bt
.EVENT_CLASS_LOG_LEVEL_DEBUG_MODULE
: EventClassLogLevel
.DEBUG_MODULE
,
231 native_bt
.EVENT_CLASS_LOG_LEVEL_DEBUG_UNIT
: EventClassLogLevel
.DEBUG_UNIT
,
232 native_bt
.EVENT_CLASS_LOG_LEVEL_DEBUG_FUNCTION
: EventClassLogLevel
.DEBUG_FUNCTION
,
233 native_bt
.EVENT_CLASS_LOG_LEVEL_DEBUG_LINE
: EventClassLogLevel
.DEBUG_LINE
,
234 native_bt
.EVENT_CLASS_LOG_LEVEL_DEBUG
: EventClassLogLevel
.DEBUG
,