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
26 from bt2
import event
as bt2_event
27 from bt2
import stream_class
as bt2_stream_class
31 class EventClassLogLevel
:
32 EMERGENCY
= native_bt
.EVENT_CLASS_LOG_LEVEL_EMERGENCY
33 ALERT
= native_bt
.EVENT_CLASS_LOG_LEVEL_ALERT
34 CRITICAL
= native_bt
.EVENT_CLASS_LOG_LEVEL_CRITICAL
35 ERROR
= native_bt
.EVENT_CLASS_LOG_LEVEL_ERROR
36 WARNING
= native_bt
.EVENT_CLASS_LOG_LEVEL_WARNING
37 NOTICE
= native_bt
.EVENT_CLASS_LOG_LEVEL_NOTICE
38 INFO
= native_bt
.EVENT_CLASS_LOG_LEVEL_INFO
39 DEBUG_SYSTEM
= native_bt
.EVENT_CLASS_LOG_LEVEL_DEBUG_SYSTEM
40 DEBUG_PROGRAM
= native_bt
.EVENT_CLASS_LOG_LEVEL_DEBUG_PROGRAM
41 DEBUG_PROCESS
= native_bt
.EVENT_CLASS_LOG_LEVEL_DEBUG_PROCESS
42 DEBUG_MODULE
= native_bt
.EVENT_CLASS_LOG_LEVEL_DEBUG_MODULE
43 DEBUG_UNIT
= native_bt
.EVENT_CLASS_LOG_LEVEL_DEBUG_UNIT
44 DEBUG_FUNCTION
= native_bt
.EVENT_CLASS_LOG_LEVEL_DEBUG_FUNCTION
45 DEBUG_LINE
= native_bt
.EVENT_CLASS_LOG_LEVEL_DEBUG_LINE
46 DEBUG
= native_bt
.EVENT_CLASS_LOG_LEVEL_DEBUG
49 class _EventClass(object._SharedObject
):
50 _get_ref
= staticmethod(native_bt
.event_class_get_ref
)
51 _put_ref
= staticmethod(native_bt
.event_class_put_ref
)
54 def stream_class(self
):
55 sc_ptr
= native_bt
.event_class_borrow_stream_class(self
._ptr
)
57 if sc_ptr
is not None:
58 return bt2_stream_class
._StreamClass
._create
_from
_ptr
_and
_get
_ref
(sc_ptr
)
61 def user_attributes(self
):
62 ptr
= native_bt
.event_class_borrow_user_attributes(self
._ptr
)
63 assert ptr
is not None
64 return bt2_value
._create
_from
_ptr
_and
_get
_ref
(ptr
)
66 def _user_attributes(self
, user_attributes
):
67 value
= bt2_value
.create_value(user_attributes
)
68 utils
._check
_type
(value
, bt2_value
.MapValue
)
69 native_bt
.event_class_set_user_attributes(self
._ptr
, value
._ptr
)
71 _user_attributes
= property(fset
=_user_attributes
)
75 return native_bt
.event_class_get_name(self
._ptr
)
77 def _name(self
, name
):
78 utils
._check
_str
(name
)
79 return native_bt
.event_class_set_name(self
._ptr
, name
)
81 _name
= property(fset
=_name
)
85 id = native_bt
.event_class_get_id(self
._ptr
)
86 return id if id >= 0 else None
90 is_available
, log_level
= native_bt
.event_class_get_log_level(self
._ptr
)
92 if is_available
!= native_bt
.PROPERTY_AVAILABILITY_AVAILABLE
:
95 return _EVENT_CLASS_LOG_LEVEL_TO_OBJ
[log_level
]
97 def _log_level(self
, log_level
):
99 EventClassLogLevel
.EMERGENCY
,
100 EventClassLogLevel
.ALERT
,
101 EventClassLogLevel
.CRITICAL
,
102 EventClassLogLevel
.ERROR
,
103 EventClassLogLevel
.WARNING
,
104 EventClassLogLevel
.NOTICE
,
105 EventClassLogLevel
.INFO
,
106 EventClassLogLevel
.DEBUG_SYSTEM
,
107 EventClassLogLevel
.DEBUG_PROGRAM
,
108 EventClassLogLevel
.DEBUG_PROCESS
,
109 EventClassLogLevel
.DEBUG_MODULE
,
110 EventClassLogLevel
.DEBUG_UNIT
,
111 EventClassLogLevel
.DEBUG_FUNCTION
,
112 EventClassLogLevel
.DEBUG_LINE
,
113 EventClassLogLevel
.DEBUG
,
116 if log_level
not in log_levels
:
117 raise ValueError("'{}' is not a valid log level".format(log_level
))
119 native_bt
.event_class_set_log_level(self
._ptr
, log_level
)
121 _log_level
= property(fset
=_log_level
)
125 return native_bt
.event_class_get_emf_uri(self
._ptr
)
127 def _emf_uri(self
, emf_uri
):
128 utils
._check
_str
(emf_uri
)
129 status
= native_bt
.event_class_set_emf_uri(self
._ptr
, emf_uri
)
130 utils
._handle
_func
_status
(status
, "cannot set event class object's EMF URI")
132 _emf_uri
= property(fset
=_emf_uri
)
135 def specific_context_field_class(self
):
136 fc_ptr
= native_bt
.event_class_borrow_specific_context_field_class_const(
143 return bt2_field_class
._create
_field
_class
_from
_ptr
_and
_get
_ref
(fc_ptr
)
145 def _specific_context_field_class(self
, context_field_class
):
146 if context_field_class
is not None:
147 utils
._check
_type
(context_field_class
, bt2_field_class
._StructureFieldClass
)
148 status
= native_bt
.event_class_set_specific_context_field_class(
149 self
._ptr
, context_field_class
._ptr
151 utils
._handle
_func
_status
(
152 status
, "cannot set event class object's context field class"
155 _specific_context_field_class
= property(fset
=_specific_context_field_class
)
158 def payload_field_class(self
):
159 fc_ptr
= native_bt
.event_class_borrow_payload_field_class_const(self
._ptr
)
164 return bt2_field_class
._create
_field
_class
_from
_ptr
_and
_get
_ref
(fc_ptr
)
166 def _payload_field_class(self
, payload_field_class
):
167 if payload_field_class
is not None:
168 utils
._check
_type
(payload_field_class
, bt2_field_class
._StructureFieldClass
)
169 status
= native_bt
.event_class_set_payload_field_class(
170 self
._ptr
, payload_field_class
._ptr
172 utils
._handle
_func
_status
(
173 status
, "cannot set event class object's payload field class"
176 _payload_field_class
= property(fset
=_payload_field_class
)
179 _EVENT_CLASS_LOG_LEVEL_TO_OBJ
= {
180 native_bt
.EVENT_CLASS_LOG_LEVEL_EMERGENCY
: EventClassLogLevel
.EMERGENCY
,
181 native_bt
.EVENT_CLASS_LOG_LEVEL_ALERT
: EventClassLogLevel
.ALERT
,
182 native_bt
.EVENT_CLASS_LOG_LEVEL_CRITICAL
: EventClassLogLevel
.CRITICAL
,
183 native_bt
.EVENT_CLASS_LOG_LEVEL_ERROR
: EventClassLogLevel
.ERROR
,
184 native_bt
.EVENT_CLASS_LOG_LEVEL_WARNING
: EventClassLogLevel
.WARNING
,
185 native_bt
.EVENT_CLASS_LOG_LEVEL_NOTICE
: EventClassLogLevel
.NOTICE
,
186 native_bt
.EVENT_CLASS_LOG_LEVEL_INFO
: EventClassLogLevel
.INFO
,
187 native_bt
.EVENT_CLASS_LOG_LEVEL_DEBUG_SYSTEM
: EventClassLogLevel
.DEBUG_SYSTEM
,
188 native_bt
.EVENT_CLASS_LOG_LEVEL_DEBUG_PROGRAM
: EventClassLogLevel
.DEBUG_PROGRAM
,
189 native_bt
.EVENT_CLASS_LOG_LEVEL_DEBUG_PROCESS
: EventClassLogLevel
.DEBUG_PROCESS
,
190 native_bt
.EVENT_CLASS_LOG_LEVEL_DEBUG_MODULE
: EventClassLogLevel
.DEBUG_MODULE
,
191 native_bt
.EVENT_CLASS_LOG_LEVEL_DEBUG_UNIT
: EventClassLogLevel
.DEBUG_UNIT
,
192 native_bt
.EVENT_CLASS_LOG_LEVEL_DEBUG_FUNCTION
: EventClassLogLevel
.DEBUG_FUNCTION
,
193 native_bt
.EVENT_CLASS_LOG_LEVEL_DEBUG_LINE
: EventClassLogLevel
.DEBUG_LINE
,
194 native_bt
.EVENT_CLASS_LOG_LEVEL_DEBUG
: EventClassLogLevel
.DEBUG
,