cpp-common/bt2c/fmt.hpp: use `wise_enum::string_type` in `EnableIfIsWiseEnum` definition
[babeltrace.git] / src / bindings / python / bt2 / bt2 / event_class.py
1 # SPDX-License-Identifier: MIT
2 #
3 # Copyright (c) 2017 Philippe Proulx <pproulx@efficios.com>
4
5 from bt2 import utils as bt2_utils
6 from bt2 import value as bt2_value
7 from bt2 import object as bt2_object
8 from bt2 import native_bt
9 from bt2 import field_class as bt2_field_class
10
11
12 def _bt2_stream_class():
13 from bt2 import stream_class as bt2_stream_class
14
15 return bt2_stream_class
16
17
18 class EventClassLogLevel:
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
34
35
36 class _EventClassConst(bt2_object._SharedObject):
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
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 )
63 _stream_class_pycls = property(lambda s: _bt2_stream_class()._StreamClassConst)
64
65 @property
66 def stream_class(self):
67 sc_ptr = self._borrow_stream_class_ptr(self._ptr)
68
69 if sc_ptr is not None:
70 return self._stream_class_pycls._create_from_ptr_and_get_ref(sc_ptr)
71
72 @property
73 def user_attributes(self):
74 ptr = self._borrow_user_attributes_ptr(self._ptr)
75 assert ptr is not None
76 return self._create_value_from_ptr_and_get_ref(ptr)
77
78 @property
79 def name(self):
80 return native_bt.event_class_get_name(self._ptr)
81
82 @property
83 def id(self):
84 id = native_bt.event_class_get_id(self._ptr)
85 return id if id >= 0 else None
86
87 @property
88 def log_level(self):
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
93
94 return _EVENT_CLASS_LOG_LEVEL_TO_OBJ[log_level]
95
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
119 class _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 )
136 _stream_class_pycls = property(lambda s: _bt2_stream_class()._StreamClass)
137
138 def _user_attributes(self, user_attributes):
139 value = bt2_value.create_value(user_attributes)
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):
145 return native_bt.event_class_set_name(self._ptr, name)
146
147 _name = property(fset=_name)
148
149 def _log_level(self, log_level):
150 native_bt.event_class_set_log_level(self._ptr, log_level)
151
152 _log_level = property(fset=_log_level)
153
154 def _emf_uri(self, emf_uri):
155 status = native_bt.event_class_set_emf_uri(self._ptr, emf_uri)
156 bt2_utils._handle_func_status(status, "cannot set event class object's EMF URI")
157
158 _emf_uri = property(fset=_emf_uri)
159
160 def _specific_context_field_class(self, context_field_class):
161 status = native_bt.event_class_set_specific_context_field_class(
162 self._ptr, context_field_class._ptr
163 )
164 bt2_utils._handle_func_status(
165 status, "cannot set event class object's context field class"
166 )
167
168 _specific_context_field_class = property(fset=_specific_context_field_class)
169
170 def _payload_field_class(self, payload_field_class):
171 status = native_bt.event_class_set_payload_field_class(
172 self._ptr, payload_field_class._ptr
173 )
174 bt2_utils._handle_func_status(
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:
190 bt2_utils._check_str(name)
191
192 if user_attributes is not None:
193 value = bt2_value.create_value(user_attributes)
194 bt2_utils._check_type(value, bt2_value.MapValue)
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,
213 )
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:
219 bt2_utils._check_str(emf_uri)
220
221 if specific_context_field_class is not None:
222 bt2_utils._check_type(
223 specific_context_field_class, bt2_field_class._StructureFieldClass
224 )
225
226 if payload_field_class is not None:
227 bt2_utils._check_type(
228 payload_field_class, bt2_field_class._StructureFieldClass
229 )
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.033989 seconds and 4 git commands to generate.