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