Commit | Line | Data |
---|---|---|
0235b0db | 1 | # SPDX-License-Identifier: MIT |
81447b5b | 2 | # |
811644b8 | 3 | # Copyright (c) 2017 Philippe Proulx <pproulx@efficios.com> |
81447b5b PP |
4 | |
5 | from bt2 import native_bt, object, utils | |
3fb99a22 PP |
6 | from bt2 import field_class as bt2_field_class |
7 | from bt2 import value as bt2_value | |
79935628 SM |
8 | |
9 | ||
10 | def _bt2_stream_class(): | |
11 | from bt2 import stream_class as bt2_stream_class | |
12 | ||
13 | return bt2_stream_class | |
81447b5b PP |
14 | |
15 | ||
811644b8 | 16 | class EventClassLogLevel: |
50842bdc PP |
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 | |
81447b5b PP |
32 | |
33 | ||
f0a42b33 | 34 | class _EventClassConst(object._SharedObject): |
3cdfbaea SM |
35 | _get_ref = staticmethod(native_bt.event_class_get_ref) |
36 | _put_ref = staticmethod(native_bt.event_class_put_ref) | |
f0a42b33 FD |
37 | _borrow_stream_class_ptr = staticmethod( |
38 | native_bt.event_class_borrow_stream_class_const | |
39 | ) | |
40 | _borrow_specific_context_field_class_ptr = staticmethod( | |
41 | native_bt.event_class_borrow_specific_context_field_class_const | |
42 | ) | |
43 | _borrow_payload_field_class_ptr = staticmethod( | |
44 | native_bt.event_class_borrow_payload_field_class_const | |
45 | ) | |
46 | _borrow_user_attributes_ptr = staticmethod( | |
47 | native_bt.event_class_borrow_user_attributes_const | |
48 | ) | |
49 | _create_field_class_from_ptr_and_get_ref = staticmethod( | |
50 | bt2_field_class._create_field_class_from_const_ptr_and_get_ref | |
51 | ) | |
52 | _create_value_from_ptr_and_get_ref = staticmethod( | |
53 | bt2_value._create_from_const_ptr_and_get_ref | |
54 | ) | |
79935628 | 55 | _stream_class_pycls = property(lambda s: _bt2_stream_class()._StreamClassConst) |
3cdfbaea | 56 | |
81447b5b PP |
57 | @property |
58 | def stream_class(self): | |
f0a42b33 | 59 | sc_ptr = self._borrow_stream_class_ptr(self._ptr) |
81447b5b PP |
60 | |
61 | if sc_ptr is not None: | |
f0a42b33 | 62 | return self._stream_class_pycls._create_from_ptr_and_get_ref(sc_ptr) |
81447b5b | 63 | |
5783664e PP |
64 | @property |
65 | def user_attributes(self): | |
f0a42b33 | 66 | ptr = self._borrow_user_attributes_ptr(self._ptr) |
5783664e | 67 | assert ptr is not None |
f0a42b33 | 68 | return self._create_value_from_ptr_and_get_ref(ptr) |
5783664e | 69 | |
81447b5b PP |
70 | @property |
71 | def name(self): | |
50842bdc | 72 | return native_bt.event_class_get_name(self._ptr) |
81447b5b PP |
73 | |
74 | @property | |
75 | def id(self): | |
50842bdc | 76 | id = native_bt.event_class_get_id(self._ptr) |
811644b8 | 77 | return id if id >= 0 else None |
81447b5b | 78 | |
811644b8 PP |
79 | @property |
80 | def log_level(self): | |
65531d55 SM |
81 | is_available, log_level = native_bt.event_class_get_log_level(self._ptr) |
82 | ||
83 | if is_available != native_bt.PROPERTY_AVAILABILITY_AVAILABLE: | |
84 | return None | |
811644b8 | 85 | |
65531d55 SM |
86 | return _EVENT_CLASS_LOG_LEVEL_TO_OBJ[log_level] |
87 | ||
f0a42b33 FD |
88 | @property |
89 | def emf_uri(self): | |
90 | return native_bt.event_class_get_emf_uri(self._ptr) | |
91 | ||
92 | @property | |
93 | def specific_context_field_class(self): | |
94 | fc_ptr = self._borrow_specific_context_field_class_ptr(self._ptr) | |
95 | ||
96 | if fc_ptr is None: | |
97 | return | |
98 | ||
99 | return self._create_field_class_from_ptr_and_get_ref(fc_ptr) | |
100 | ||
101 | @property | |
102 | def payload_field_class(self): | |
103 | fc_ptr = self._borrow_payload_field_class_ptr(self._ptr) | |
104 | ||
105 | if fc_ptr is None: | |
106 | return | |
107 | ||
108 | return self._create_field_class_from_ptr_and_get_ref(fc_ptr) | |
109 | ||
110 | ||
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 | |
115 | ) | |
116 | _borrow_payload_field_class_ptr = staticmethod( | |
117 | native_bt.event_class_borrow_payload_field_class | |
118 | ) | |
119 | _borrow_user_attributes_ptr = staticmethod( | |
120 | native_bt.event_class_borrow_user_attributes | |
121 | ) | |
122 | _create_field_class_from_ptr_and_get_ref = staticmethod( | |
123 | bt2_field_class._create_field_class_from_ptr_and_get_ref | |
124 | ) | |
125 | _create_value_from_ptr_and_get_ref = staticmethod( | |
126 | bt2_value._create_from_ptr_and_get_ref | |
127 | ) | |
79935628 | 128 | _stream_class_pycls = property(lambda s: _bt2_stream_class()._StreamClass) |
f0a42b33 FD |
129 | |
130 | def _user_attributes(self, user_attributes): | |
131 | value = bt2_value.create_value(user_attributes) | |
f0a42b33 FD |
132 | native_bt.event_class_set_user_attributes(self._ptr, value._ptr) |
133 | ||
134 | _user_attributes = property(fset=_user_attributes) | |
135 | ||
136 | def _name(self, name): | |
f0a42b33 FD |
137 | return native_bt.event_class_set_name(self._ptr, name) |
138 | ||
139 | _name = property(fset=_name) | |
140 | ||
65531d55 | 141 | def _log_level(self, log_level): |
65531d55 SM |
142 | native_bt.event_class_set_log_level(self._ptr, log_level) |
143 | ||
144 | _log_level = property(fset=_log_level) | |
811644b8 | 145 | |
65531d55 | 146 | def _emf_uri(self, emf_uri): |
d24d5663 | 147 | status = native_bt.event_class_set_emf_uri(self._ptr, emf_uri) |
cfbd7cf3 | 148 | utils._handle_func_status(status, "cannot set event class object's EMF URI") |
811644b8 | 149 | |
65531d55 SM |
150 | _emf_uri = property(fset=_emf_uri) |
151 | ||
65531d55 | 152 | def _specific_context_field_class(self, context_field_class): |
3321d9b0 SM |
153 | status = native_bt.event_class_set_specific_context_field_class( |
154 | self._ptr, context_field_class._ptr | |
155 | ) | |
156 | utils._handle_func_status( | |
157 | status, "cannot set event class object's context field class" | |
158 | ) | |
81447b5b | 159 | |
65531d55 | 160 | _specific_context_field_class = property(fset=_specific_context_field_class) |
81447b5b | 161 | |
65531d55 | 162 | def _payload_field_class(self, payload_field_class): |
3321d9b0 SM |
163 | status = native_bt.event_class_set_payload_field_class( |
164 | self._ptr, payload_field_class._ptr | |
165 | ) | |
166 | utils._handle_func_status( | |
167 | status, "cannot set event class object's payload field class" | |
168 | ) | |
169 | ||
170 | _payload_field_class = property(fset=_payload_field_class) | |
171 | ||
172 | @staticmethod | |
173 | def _validate_create_params( | |
174 | name, | |
175 | user_attributes, | |
176 | log_level, | |
177 | emf_uri, | |
178 | specific_context_field_class, | |
179 | payload_field_class, | |
180 | ): | |
181 | if name is not None: | |
182 | utils._check_str(name) | |
183 | ||
184 | if user_attributes is not None: | |
185 | value = bt2_value.create_value(user_attributes) | |
186 | utils._check_type(value, bt2_value.MapValue) | |
187 | ||
188 | if log_level is not None: | |
189 | log_levels = ( | |
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, | |
cfbd7cf3 | 205 | ) |
3321d9b0 SM |
206 | |
207 | if log_level not in log_levels: | |
208 | raise ValueError("'{}' is not a valid log level".format(log_level)) | |
209 | ||
210 | if emf_uri is not None: | |
211 | utils._check_str(emf_uri) | |
212 | ||
213 | if specific_context_field_class is not None: | |
214 | utils._check_type( | |
215 | specific_context_field_class, bt2_field_class._StructureFieldClass | |
cfbd7cf3 | 216 | ) |
65531d55 | 217 | |
3321d9b0 SM |
218 | if payload_field_class is not None: |
219 | utils._check_type(payload_field_class, bt2_field_class._StructureFieldClass) | |
65531d55 SM |
220 | |
221 | ||
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, | |
238 | } |