bt2: clean available `bt2` package names
[babeltrace.git] / src / bindings / python / bt2 / bt2 / event_class.py
CommitLineData
81447b5b
PP
1# The MIT License (MIT)
2#
811644b8 3# Copyright (c) 2017 Philippe Proulx <pproulx@efficios.com>
81447b5b
PP
4#
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:
11#
12# The above copyright notice and this permission notice shall be included in
13# all copies or substantial portions of the Software.
14#
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
21# THE SOFTWARE.
22
23from bt2 import native_bt, object, utils
3fb99a22
PP
24from bt2 import field_class as bt2_field_class
25from bt2 import value as bt2_value
26from bt2 import event as bt2_event
27from bt2 import stream_class as bt2_stream_class
81447b5b
PP
28import bt2
29
30
811644b8 31class EventClassLogLevel:
50842bdc
PP
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
81447b5b
PP
47
48
2c6f8520 49class _EventClass(object._SharedObject):
3cdfbaea
SM
50 _get_ref = staticmethod(native_bt.event_class_get_ref)
51 _put_ref = staticmethod(native_bt.event_class_put_ref)
52
81447b5b
PP
53 @property
54 def stream_class(self):
65531d55 55 sc_ptr = native_bt.event_class_borrow_stream_class(self._ptr)
81447b5b
PP
56
57 if sc_ptr is not None:
3fb99a22 58 return bt2_stream_class._StreamClass._create_from_ptr_and_get_ref(sc_ptr)
81447b5b 59
81447b5b
PP
60 @property
61 def name(self):
50842bdc 62 return native_bt.event_class_get_name(self._ptr)
81447b5b 63
65531d55
SM
64 def _name(self, name):
65 utils._check_str(name)
66 return native_bt.event_class_set_name(self._ptr, name)
67
68 _name = property(fset=_name)
69
81447b5b
PP
70 @property
71 def id(self):
50842bdc 72 id = native_bt.event_class_get_id(self._ptr)
811644b8 73 return id if id >= 0 else None
81447b5b 74
811644b8
PP
75 @property
76 def log_level(self):
65531d55
SM
77 is_available, log_level = native_bt.event_class_get_log_level(self._ptr)
78
79 if is_available != native_bt.PROPERTY_AVAILABILITY_AVAILABLE:
80 return None
811644b8 81
65531d55
SM
82 return _EVENT_CLASS_LOG_LEVEL_TO_OBJ[log_level]
83
84 def _log_level(self, log_level):
811644b8 85 log_levels = (
811644b8
PP
86 EventClassLogLevel.EMERGENCY,
87 EventClassLogLevel.ALERT,
88 EventClassLogLevel.CRITICAL,
89 EventClassLogLevel.ERROR,
90 EventClassLogLevel.WARNING,
91 EventClassLogLevel.NOTICE,
92 EventClassLogLevel.INFO,
93 EventClassLogLevel.DEBUG_SYSTEM,
94 EventClassLogLevel.DEBUG_PROGRAM,
95 EventClassLogLevel.DEBUG_PROCESS,
96 EventClassLogLevel.DEBUG_MODULE,
97 EventClassLogLevel.DEBUG_UNIT,
98 EventClassLogLevel.DEBUG_FUNCTION,
99 EventClassLogLevel.DEBUG_LINE,
100 EventClassLogLevel.DEBUG,
101 )
102
103 if log_level not in log_levels:
104 raise ValueError("'{}' is not a valid log level".format(log_level))
105
65531d55
SM
106 native_bt.event_class_set_log_level(self._ptr, log_level)
107
108 _log_level = property(fset=_log_level)
811644b8
PP
109
110 @property
111 def emf_uri(self):
50842bdc 112 return native_bt.event_class_get_emf_uri(self._ptr)
811644b8 113
65531d55 114 def _emf_uri(self, emf_uri):
811644b8 115 utils._check_str(emf_uri)
d24d5663 116 status = native_bt.event_class_set_emf_uri(self._ptr, emf_uri)
cfbd7cf3 117 utils._handle_func_status(status, "cannot set event class object's EMF URI")
811644b8 118
65531d55
SM
119 _emf_uri = property(fset=_emf_uri)
120
81447b5b 121 @property
65531d55 122 def specific_context_field_class(self):
cfbd7cf3
FD
123 fc_ptr = native_bt.event_class_borrow_specific_context_field_class_const(
124 self._ptr
125 )
81447b5b 126
b4f45851 127 if fc_ptr is None:
81447b5b
PP
128 return
129
3fb99a22 130 return bt2_field_class._create_field_class_from_ptr_and_get_ref(fc_ptr)
81447b5b 131
65531d55 132 def _specific_context_field_class(self, context_field_class):
b4f45851 133 if context_field_class is not None:
3fb99a22 134 utils._check_type(context_field_class, bt2_field_class._StructureFieldClass)
cfbd7cf3
FD
135 status = native_bt.event_class_set_specific_context_field_class(
136 self._ptr, context_field_class._ptr
137 )
138 utils._handle_func_status(
139 status, "cannot set event class object's context field class"
140 )
81447b5b 141
65531d55 142 _specific_context_field_class = property(fset=_specific_context_field_class)
81447b5b
PP
143
144 @property
b4f45851 145 def payload_field_class(self):
65531d55 146 fc_ptr = native_bt.event_class_borrow_payload_field_class_const(self._ptr)
81447b5b 147
b4f45851 148 if fc_ptr is None:
81447b5b
PP
149 return
150
3fb99a22 151 return bt2_field_class._create_field_class_from_ptr_and_get_ref(fc_ptr)
81447b5b 152
65531d55 153 def _payload_field_class(self, payload_field_class):
b4f45851 154 if payload_field_class is not None:
3fb99a22 155 utils._check_type(payload_field_class, bt2_field_class._StructureFieldClass)
cfbd7cf3
FD
156 status = native_bt.event_class_set_payload_field_class(
157 self._ptr, payload_field_class._ptr
158 )
159 utils._handle_func_status(
160 status, "cannot set event class object's payload field class"
161 )
65531d55
SM
162
163 _payload_field_class = property(fset=_payload_field_class)
164
165
166_EVENT_CLASS_LOG_LEVEL_TO_OBJ = {
167 native_bt.EVENT_CLASS_LOG_LEVEL_EMERGENCY: EventClassLogLevel.EMERGENCY,
168 native_bt.EVENT_CLASS_LOG_LEVEL_ALERT: EventClassLogLevel.ALERT,
169 native_bt.EVENT_CLASS_LOG_LEVEL_CRITICAL: EventClassLogLevel.CRITICAL,
170 native_bt.EVENT_CLASS_LOG_LEVEL_ERROR: EventClassLogLevel.ERROR,
171 native_bt.EVENT_CLASS_LOG_LEVEL_WARNING: EventClassLogLevel.WARNING,
172 native_bt.EVENT_CLASS_LOG_LEVEL_NOTICE: EventClassLogLevel.NOTICE,
173 native_bt.EVENT_CLASS_LOG_LEVEL_INFO: EventClassLogLevel.INFO,
174 native_bt.EVENT_CLASS_LOG_LEVEL_DEBUG_SYSTEM: EventClassLogLevel.DEBUG_SYSTEM,
175 native_bt.EVENT_CLASS_LOG_LEVEL_DEBUG_PROGRAM: EventClassLogLevel.DEBUG_PROGRAM,
176 native_bt.EVENT_CLASS_LOG_LEVEL_DEBUG_PROCESS: EventClassLogLevel.DEBUG_PROCESS,
177 native_bt.EVENT_CLASS_LOG_LEVEL_DEBUG_MODULE: EventClassLogLevel.DEBUG_MODULE,
178 native_bt.EVENT_CLASS_LOG_LEVEL_DEBUG_UNIT: EventClassLogLevel.DEBUG_UNIT,
179 native_bt.EVENT_CLASS_LOG_LEVEL_DEBUG_FUNCTION: EventClassLogLevel.DEBUG_FUNCTION,
180 native_bt.EVENT_CLASS_LOG_LEVEL_DEBUG_LINE: EventClassLogLevel.DEBUG_LINE,
181 native_bt.EVENT_CLASS_LOG_LEVEL_DEBUG: EventClassLogLevel.DEBUG,
182}
This page took 0.052005 seconds and 4 git commands to generate.