cpp-common/bt2c/fmt.hpp: use `wise_enum::string_type` in `EnableIfIsWiseEnum` definition
[babeltrace.git] / src / bindings / python / bt2 / bt2 / event_class.py
CommitLineData
0235b0db 1# SPDX-License-Identifier: MIT
81447b5b 2#
811644b8 3# Copyright (c) 2017 Philippe Proulx <pproulx@efficios.com>
81447b5b 4
e5914347 5from bt2 import utils as bt2_utils
3fb99a22 6from bt2 import value as bt2_value
5995b304
SM
7from bt2 import object as bt2_object
8from bt2 import native_bt
9from bt2 import field_class as bt2_field_class
79935628
SM
10
11
12def _bt2_stream_class():
13 from bt2 import stream_class as bt2_stream_class
14
15 return bt2_stream_class
81447b5b
PP
16
17
811644b8 18class EventClassLogLevel:
50842bdc
PP
19 EMERGENCY = native_bt.EVENT_CLASS_LOG_LEVEL_EMERGENCY
20 ALERT = native_bt.EVENT_CLASS_LOG_LEVEL_ALERT
21 CRITICAL = native_bt.EVENT_CLASS_LOG_LEVEL_CRITICAL
22 ERROR = native_bt.EVENT_CLASS_LOG_LEVEL_ERROR
23 WARNING = native_bt.EVENT_CLASS_LOG_LEVEL_WARNING
24 NOTICE = native_bt.EVENT_CLASS_LOG_LEVEL_NOTICE
25 INFO = native_bt.EVENT_CLASS_LOG_LEVEL_INFO
26 DEBUG_SYSTEM = native_bt.EVENT_CLASS_LOG_LEVEL_DEBUG_SYSTEM
27 DEBUG_PROGRAM = native_bt.EVENT_CLASS_LOG_LEVEL_DEBUG_PROGRAM
28 DEBUG_PROCESS = native_bt.EVENT_CLASS_LOG_LEVEL_DEBUG_PROCESS
29 DEBUG_MODULE = native_bt.EVENT_CLASS_LOG_LEVEL_DEBUG_MODULE
30 DEBUG_UNIT = native_bt.EVENT_CLASS_LOG_LEVEL_DEBUG_UNIT
31 DEBUG_FUNCTION = native_bt.EVENT_CLASS_LOG_LEVEL_DEBUG_FUNCTION
32 DEBUG_LINE = native_bt.EVENT_CLASS_LOG_LEVEL_DEBUG_LINE
33 DEBUG = native_bt.EVENT_CLASS_LOG_LEVEL_DEBUG
81447b5b
PP
34
35
e5914347 36class _EventClassConst(bt2_object._SharedObject):
9dee90bd
SM
37 @staticmethod
38 def _get_ref(ptr):
39 native_bt.event_class_get_ref(ptr)
40
41 @staticmethod
42 def _put_ref(ptr):
43 native_bt.event_class_put_ref(ptr)
44
f0a42b33
FD
45 _borrow_stream_class_ptr = staticmethod(
46 native_bt.event_class_borrow_stream_class_const
47 )
48 _borrow_specific_context_field_class_ptr = staticmethod(
49 native_bt.event_class_borrow_specific_context_field_class_const
50 )
51 _borrow_payload_field_class_ptr = staticmethod(
52 native_bt.event_class_borrow_payload_field_class_const
53 )
54 _borrow_user_attributes_ptr = staticmethod(
55 native_bt.event_class_borrow_user_attributes_const
56 )
57 _create_field_class_from_ptr_and_get_ref = staticmethod(
58 bt2_field_class._create_field_class_from_const_ptr_and_get_ref
59 )
60 _create_value_from_ptr_and_get_ref = staticmethod(
61 bt2_value._create_from_const_ptr_and_get_ref
62 )
79935628 63 _stream_class_pycls = property(lambda s: _bt2_stream_class()._StreamClassConst)
3cdfbaea 64
81447b5b
PP
65 @property
66 def stream_class(self):
f0a42b33 67 sc_ptr = self._borrow_stream_class_ptr(self._ptr)
81447b5b
PP
68
69 if sc_ptr is not None:
f0a42b33 70 return self._stream_class_pycls._create_from_ptr_and_get_ref(sc_ptr)
81447b5b 71
5783664e
PP
72 @property
73 def user_attributes(self):
f0a42b33 74 ptr = self._borrow_user_attributes_ptr(self._ptr)
5783664e 75 assert ptr is not None
f0a42b33 76 return self._create_value_from_ptr_and_get_ref(ptr)
5783664e 77
81447b5b
PP
78 @property
79 def name(self):
50842bdc 80 return native_bt.event_class_get_name(self._ptr)
81447b5b
PP
81
82 @property
83 def id(self):
50842bdc 84 id = native_bt.event_class_get_id(self._ptr)
811644b8 85 return id if id >= 0 else None
81447b5b 86
811644b8
PP
87 @property
88 def log_level(self):
65531d55
SM
89 is_available, log_level = native_bt.event_class_get_log_level(self._ptr)
90
91 if is_available != native_bt.PROPERTY_AVAILABILITY_AVAILABLE:
92 return None
811644b8 93
65531d55
SM
94 return _EVENT_CLASS_LOG_LEVEL_TO_OBJ[log_level]
95
f0a42b33
FD
96 @property
97 def emf_uri(self):
98 return native_bt.event_class_get_emf_uri(self._ptr)
99
100 @property
101 def specific_context_field_class(self):
102 fc_ptr = self._borrow_specific_context_field_class_ptr(self._ptr)
103
104 if fc_ptr is None:
105 return
106
107 return self._create_field_class_from_ptr_and_get_ref(fc_ptr)
108
109 @property
110 def payload_field_class(self):
111 fc_ptr = self._borrow_payload_field_class_ptr(self._ptr)
112
113 if fc_ptr is None:
114 return
115
116 return self._create_field_class_from_ptr_and_get_ref(fc_ptr)
117
118
119class _EventClass(_EventClassConst):
120 _borrow_stream_class_ptr = staticmethod(native_bt.event_class_borrow_stream_class)
121 _borrow_specific_context_field_class_ptr = staticmethod(
122 native_bt.event_class_borrow_specific_context_field_class
123 )
124 _borrow_payload_field_class_ptr = staticmethod(
125 native_bt.event_class_borrow_payload_field_class
126 )
127 _borrow_user_attributes_ptr = staticmethod(
128 native_bt.event_class_borrow_user_attributes
129 )
130 _create_field_class_from_ptr_and_get_ref = staticmethod(
131 bt2_field_class._create_field_class_from_ptr_and_get_ref
132 )
133 _create_value_from_ptr_and_get_ref = staticmethod(
134 bt2_value._create_from_ptr_and_get_ref
135 )
79935628 136 _stream_class_pycls = property(lambda s: _bt2_stream_class()._StreamClass)
f0a42b33
FD
137
138 def _user_attributes(self, user_attributes):
139 value = bt2_value.create_value(user_attributes)
f0a42b33
FD
140 native_bt.event_class_set_user_attributes(self._ptr, value._ptr)
141
142 _user_attributes = property(fset=_user_attributes)
143
144 def _name(self, name):
f0a42b33
FD
145 return native_bt.event_class_set_name(self._ptr, name)
146
147 _name = property(fset=_name)
148
65531d55 149 def _log_level(self, log_level):
65531d55
SM
150 native_bt.event_class_set_log_level(self._ptr, log_level)
151
152 _log_level = property(fset=_log_level)
811644b8 153
65531d55 154 def _emf_uri(self, emf_uri):
d24d5663 155 status = native_bt.event_class_set_emf_uri(self._ptr, emf_uri)
e5914347 156 bt2_utils._handle_func_status(status, "cannot set event class object's EMF URI")
811644b8 157
65531d55
SM
158 _emf_uri = property(fset=_emf_uri)
159
65531d55 160 def _specific_context_field_class(self, context_field_class):
3321d9b0
SM
161 status = native_bt.event_class_set_specific_context_field_class(
162 self._ptr, context_field_class._ptr
163 )
e5914347 164 bt2_utils._handle_func_status(
3321d9b0
SM
165 status, "cannot set event class object's context field class"
166 )
81447b5b 167
65531d55 168 _specific_context_field_class = property(fset=_specific_context_field_class)
81447b5b 169
65531d55 170 def _payload_field_class(self, payload_field_class):
3321d9b0
SM
171 status = native_bt.event_class_set_payload_field_class(
172 self._ptr, payload_field_class._ptr
173 )
e5914347 174 bt2_utils._handle_func_status(
3321d9b0
SM
175 status, "cannot set event class object's payload field class"
176 )
177
178 _payload_field_class = property(fset=_payload_field_class)
179
180 @staticmethod
181 def _validate_create_params(
182 name,
183 user_attributes,
184 log_level,
185 emf_uri,
186 specific_context_field_class,
187 payload_field_class,
188 ):
189 if name is not None:
e5914347 190 bt2_utils._check_str(name)
3321d9b0
SM
191
192 if user_attributes is not None:
193 value = bt2_value.create_value(user_attributes)
e5914347 194 bt2_utils._check_type(value, bt2_value.MapValue)
3321d9b0
SM
195
196 if log_level is not None:
197 log_levels = (
198 EventClassLogLevel.EMERGENCY,
199 EventClassLogLevel.ALERT,
200 EventClassLogLevel.CRITICAL,
201 EventClassLogLevel.ERROR,
202 EventClassLogLevel.WARNING,
203 EventClassLogLevel.NOTICE,
204 EventClassLogLevel.INFO,
205 EventClassLogLevel.DEBUG_SYSTEM,
206 EventClassLogLevel.DEBUG_PROGRAM,
207 EventClassLogLevel.DEBUG_PROCESS,
208 EventClassLogLevel.DEBUG_MODULE,
209 EventClassLogLevel.DEBUG_UNIT,
210 EventClassLogLevel.DEBUG_FUNCTION,
211 EventClassLogLevel.DEBUG_LINE,
212 EventClassLogLevel.DEBUG,
cfbd7cf3 213 )
3321d9b0
SM
214
215 if log_level not in log_levels:
216 raise ValueError("'{}' is not a valid log level".format(log_level))
217
218 if emf_uri is not None:
e5914347 219 bt2_utils._check_str(emf_uri)
3321d9b0
SM
220
221 if specific_context_field_class is not None:
e5914347 222 bt2_utils._check_type(
3321d9b0 223 specific_context_field_class, bt2_field_class._StructureFieldClass
cfbd7cf3 224 )
65531d55 225
3321d9b0 226 if payload_field_class is not None:
e5914347
SM
227 bt2_utils._check_type(
228 payload_field_class, bt2_field_class._StructureFieldClass
229 )
65531d55
SM
230
231
232_EVENT_CLASS_LOG_LEVEL_TO_OBJ = {
233 native_bt.EVENT_CLASS_LOG_LEVEL_EMERGENCY: EventClassLogLevel.EMERGENCY,
234 native_bt.EVENT_CLASS_LOG_LEVEL_ALERT: EventClassLogLevel.ALERT,
235 native_bt.EVENT_CLASS_LOG_LEVEL_CRITICAL: EventClassLogLevel.CRITICAL,
236 native_bt.EVENT_CLASS_LOG_LEVEL_ERROR: EventClassLogLevel.ERROR,
237 native_bt.EVENT_CLASS_LOG_LEVEL_WARNING: EventClassLogLevel.WARNING,
238 native_bt.EVENT_CLASS_LOG_LEVEL_NOTICE: EventClassLogLevel.NOTICE,
239 native_bt.EVENT_CLASS_LOG_LEVEL_INFO: EventClassLogLevel.INFO,
240 native_bt.EVENT_CLASS_LOG_LEVEL_DEBUG_SYSTEM: EventClassLogLevel.DEBUG_SYSTEM,
241 native_bt.EVENT_CLASS_LOG_LEVEL_DEBUG_PROGRAM: EventClassLogLevel.DEBUG_PROGRAM,
242 native_bt.EVENT_CLASS_LOG_LEVEL_DEBUG_PROCESS: EventClassLogLevel.DEBUG_PROCESS,
243 native_bt.EVENT_CLASS_LOG_LEVEL_DEBUG_MODULE: EventClassLogLevel.DEBUG_MODULE,
244 native_bt.EVENT_CLASS_LOG_LEVEL_DEBUG_UNIT: EventClassLogLevel.DEBUG_UNIT,
245 native_bt.EVENT_CLASS_LOG_LEVEL_DEBUG_FUNCTION: EventClassLogLevel.DEBUG_FUNCTION,
246 native_bt.EVENT_CLASS_LOG_LEVEL_DEBUG_LINE: EventClassLogLevel.DEBUG_LINE,
247 native_bt.EVENT_CLASS_LOG_LEVEL_DEBUG: EventClassLogLevel.DEBUG,
248}
This page took 0.108069 seconds and 4 git commands to generate.