Commit | Line | Data |
---|---|---|
81447b5b PP |
1 | # The MIT License (MIT) |
2 | # | |
f6a5e476 | 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 | ||
23 | from bt2 import native_bt, object, utils | |
c946c9de PP |
24 | from bt2 import field_class as bt2_field_class |
25 | from bt2 import value as bt2_value | |
c946c9de | 26 | from bt2 import stream_class as bt2_stream_class |
81447b5b PP |
27 | |
28 | ||
f6a5e476 | 29 | class EventClassLogLevel: |
839d52a5 PP |
30 | EMERGENCY = native_bt.EVENT_CLASS_LOG_LEVEL_EMERGENCY |
31 | ALERT = native_bt.EVENT_CLASS_LOG_LEVEL_ALERT | |
32 | CRITICAL = native_bt.EVENT_CLASS_LOG_LEVEL_CRITICAL | |
33 | ERROR = native_bt.EVENT_CLASS_LOG_LEVEL_ERROR | |
34 | WARNING = native_bt.EVENT_CLASS_LOG_LEVEL_WARNING | |
35 | NOTICE = native_bt.EVENT_CLASS_LOG_LEVEL_NOTICE | |
36 | INFO = native_bt.EVENT_CLASS_LOG_LEVEL_INFO | |
37 | DEBUG_SYSTEM = native_bt.EVENT_CLASS_LOG_LEVEL_DEBUG_SYSTEM | |
38 | DEBUG_PROGRAM = native_bt.EVENT_CLASS_LOG_LEVEL_DEBUG_PROGRAM | |
39 | DEBUG_PROCESS = native_bt.EVENT_CLASS_LOG_LEVEL_DEBUG_PROCESS | |
40 | DEBUG_MODULE = native_bt.EVENT_CLASS_LOG_LEVEL_DEBUG_MODULE | |
41 | DEBUG_UNIT = native_bt.EVENT_CLASS_LOG_LEVEL_DEBUG_UNIT | |
42 | DEBUG_FUNCTION = native_bt.EVENT_CLASS_LOG_LEVEL_DEBUG_FUNCTION | |
43 | DEBUG_LINE = native_bt.EVENT_CLASS_LOG_LEVEL_DEBUG_LINE | |
44 | DEBUG = native_bt.EVENT_CLASS_LOG_LEVEL_DEBUG | |
81447b5b PP |
45 | |
46 | ||
78668ecd | 47 | class _EventClass(object._SharedObject): |
060aee52 SM |
48 | _get_ref = staticmethod(native_bt.event_class_get_ref) |
49 | _put_ref = staticmethod(native_bt.event_class_put_ref) | |
50 | ||
81447b5b PP |
51 | @property |
52 | def stream_class(self): | |
52c65bda | 53 | sc_ptr = native_bt.event_class_borrow_stream_class(self._ptr) |
81447b5b PP |
54 | |
55 | if sc_ptr is not None: | |
c946c9de | 56 | return bt2_stream_class._StreamClass._create_from_ptr_and_get_ref(sc_ptr) |
81447b5b | 57 | |
b2df5780 PP |
58 | @property |
59 | def user_attributes(self): | |
60 | ptr = native_bt.event_class_borrow_user_attributes(self._ptr) | |
61 | assert ptr is not None | |
62 | return bt2_value._create_from_ptr_and_get_ref(ptr) | |
63 | ||
64 | def _user_attributes(self, user_attributes): | |
65 | value = bt2_value.create_value(user_attributes) | |
66 | utils._check_type(value, bt2_value.MapValue) | |
67 | native_bt.event_class_set_user_attributes(self._ptr, value._ptr) | |
68 | ||
69 | _user_attributes = property(fset=_user_attributes) | |
70 | ||
81447b5b PP |
71 | @property |
72 | def name(self): | |
839d52a5 | 73 | return native_bt.event_class_get_name(self._ptr) |
81447b5b | 74 | |
52c65bda SM |
75 | def _name(self, name): |
76 | utils._check_str(name) | |
77 | return native_bt.event_class_set_name(self._ptr, name) | |
78 | ||
79 | _name = property(fset=_name) | |
80 | ||
81447b5b PP |
81 | @property |
82 | def id(self): | |
839d52a5 | 83 | id = native_bt.event_class_get_id(self._ptr) |
f6a5e476 | 84 | return id if id >= 0 else None |
81447b5b | 85 | |
f6a5e476 PP |
86 | @property |
87 | def log_level(self): | |
52c65bda SM |
88 | is_available, log_level = native_bt.event_class_get_log_level(self._ptr) |
89 | ||
90 | if is_available != native_bt.PROPERTY_AVAILABILITY_AVAILABLE: | |
91 | return None | |
f6a5e476 | 92 | |
52c65bda SM |
93 | return _EVENT_CLASS_LOG_LEVEL_TO_OBJ[log_level] |
94 | ||
95 | def _log_level(self, log_level): | |
f6a5e476 | 96 | log_levels = ( |
f6a5e476 PP |
97 | EventClassLogLevel.EMERGENCY, |
98 | EventClassLogLevel.ALERT, | |
99 | EventClassLogLevel.CRITICAL, | |
100 | EventClassLogLevel.ERROR, | |
101 | EventClassLogLevel.WARNING, | |
102 | EventClassLogLevel.NOTICE, | |
103 | EventClassLogLevel.INFO, | |
104 | EventClassLogLevel.DEBUG_SYSTEM, | |
105 | EventClassLogLevel.DEBUG_PROGRAM, | |
106 | EventClassLogLevel.DEBUG_PROCESS, | |
107 | EventClassLogLevel.DEBUG_MODULE, | |
108 | EventClassLogLevel.DEBUG_UNIT, | |
109 | EventClassLogLevel.DEBUG_FUNCTION, | |
110 | EventClassLogLevel.DEBUG_LINE, | |
111 | EventClassLogLevel.DEBUG, | |
112 | ) | |
113 | ||
114 | if log_level not in log_levels: | |
115 | raise ValueError("'{}' is not a valid log level".format(log_level)) | |
116 | ||
52c65bda SM |
117 | native_bt.event_class_set_log_level(self._ptr, log_level) |
118 | ||
119 | _log_level = property(fset=_log_level) | |
f6a5e476 PP |
120 | |
121 | @property | |
122 | def emf_uri(self): | |
839d52a5 | 123 | return native_bt.event_class_get_emf_uri(self._ptr) |
f6a5e476 | 124 | |
52c65bda | 125 | def _emf_uri(self, emf_uri): |
f6a5e476 | 126 | utils._check_str(emf_uri) |
fb25b9e3 | 127 | status = native_bt.event_class_set_emf_uri(self._ptr, emf_uri) |
61d96b89 | 128 | utils._handle_func_status(status, "cannot set event class object's EMF URI") |
f6a5e476 | 129 | |
52c65bda SM |
130 | _emf_uri = property(fset=_emf_uri) |
131 | ||
81447b5b | 132 | @property |
52c65bda | 133 | def specific_context_field_class(self): |
61d96b89 FD |
134 | fc_ptr = native_bt.event_class_borrow_specific_context_field_class_const( |
135 | self._ptr | |
136 | ) | |
81447b5b | 137 | |
32656995 | 138 | if fc_ptr is None: |
81447b5b PP |
139 | return |
140 | ||
c946c9de | 141 | return bt2_field_class._create_field_class_from_ptr_and_get_ref(fc_ptr) |
81447b5b | 142 | |
52c65bda | 143 | def _specific_context_field_class(self, context_field_class): |
32656995 | 144 | if context_field_class is not None: |
c946c9de | 145 | utils._check_type(context_field_class, bt2_field_class._StructureFieldClass) |
61d96b89 FD |
146 | status = native_bt.event_class_set_specific_context_field_class( |
147 | self._ptr, context_field_class._ptr | |
148 | ) | |
149 | utils._handle_func_status( | |
150 | status, "cannot set event class object's context field class" | |
151 | ) | |
81447b5b | 152 | |
52c65bda | 153 | _specific_context_field_class = property(fset=_specific_context_field_class) |
81447b5b PP |
154 | |
155 | @property | |
32656995 | 156 | def payload_field_class(self): |
52c65bda | 157 | fc_ptr = native_bt.event_class_borrow_payload_field_class_const(self._ptr) |
81447b5b | 158 | |
32656995 | 159 | if fc_ptr is None: |
81447b5b PP |
160 | return |
161 | ||
c946c9de | 162 | return bt2_field_class._create_field_class_from_ptr_and_get_ref(fc_ptr) |
81447b5b | 163 | |
52c65bda | 164 | def _payload_field_class(self, payload_field_class): |
32656995 | 165 | if payload_field_class is not None: |
c946c9de | 166 | utils._check_type(payload_field_class, bt2_field_class._StructureFieldClass) |
61d96b89 FD |
167 | status = native_bt.event_class_set_payload_field_class( |
168 | self._ptr, payload_field_class._ptr | |
169 | ) | |
170 | utils._handle_func_status( | |
171 | status, "cannot set event class object's payload field class" | |
172 | ) | |
52c65bda SM |
173 | |
174 | _payload_field_class = property(fset=_payload_field_class) | |
175 | ||
176 | ||
177 | _EVENT_CLASS_LOG_LEVEL_TO_OBJ = { | |
178 | native_bt.EVENT_CLASS_LOG_LEVEL_EMERGENCY: EventClassLogLevel.EMERGENCY, | |
179 | native_bt.EVENT_CLASS_LOG_LEVEL_ALERT: EventClassLogLevel.ALERT, | |
180 | native_bt.EVENT_CLASS_LOG_LEVEL_CRITICAL: EventClassLogLevel.CRITICAL, | |
181 | native_bt.EVENT_CLASS_LOG_LEVEL_ERROR: EventClassLogLevel.ERROR, | |
182 | native_bt.EVENT_CLASS_LOG_LEVEL_WARNING: EventClassLogLevel.WARNING, | |
183 | native_bt.EVENT_CLASS_LOG_LEVEL_NOTICE: EventClassLogLevel.NOTICE, | |
184 | native_bt.EVENT_CLASS_LOG_LEVEL_INFO: EventClassLogLevel.INFO, | |
185 | native_bt.EVENT_CLASS_LOG_LEVEL_DEBUG_SYSTEM: EventClassLogLevel.DEBUG_SYSTEM, | |
186 | native_bt.EVENT_CLASS_LOG_LEVEL_DEBUG_PROGRAM: EventClassLogLevel.DEBUG_PROGRAM, | |
187 | native_bt.EVENT_CLASS_LOG_LEVEL_DEBUG_PROCESS: EventClassLogLevel.DEBUG_PROCESS, | |
188 | native_bt.EVENT_CLASS_LOG_LEVEL_DEBUG_MODULE: EventClassLogLevel.DEBUG_MODULE, | |
189 | native_bt.EVENT_CLASS_LOG_LEVEL_DEBUG_UNIT: EventClassLogLevel.DEBUG_UNIT, | |
190 | native_bt.EVENT_CLASS_LOG_LEVEL_DEBUG_FUNCTION: EventClassLogLevel.DEBUG_FUNCTION, | |
191 | native_bt.EVENT_CLASS_LOG_LEVEL_DEBUG_LINE: EventClassLogLevel.DEBUG_LINE, | |
192 | native_bt.EVENT_CLASS_LOG_LEVEL_DEBUG: EventClassLogLevel.DEBUG, | |
193 | } |