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 | |
24 | import bt2.field_types | |
25 | import collections.abc | |
26 | import bt2.values | |
27 | import bt2.event | |
28 | import copy | |
29 | import bt2 | |
30 | ||
31 | ||
811644b8 PP |
32 | class EventClassLogLevel: |
33 | UNKNOWN = native_bt.CTF_EVENT_CLASS_LOG_LEVEL_UNKNOWN | |
34 | UNSPECIFIED = native_bt.CTF_EVENT_CLASS_LOG_LEVEL_UNSPECIFIED | |
35 | EMERGENCY = native_bt.CTF_EVENT_CLASS_LOG_LEVEL_EMERGENCY | |
36 | ALERT = native_bt.CTF_EVENT_CLASS_LOG_LEVEL_ALERT | |
37 | CRITICAL = native_bt.CTF_EVENT_CLASS_LOG_LEVEL_CRITICAL | |
38 | ERROR = native_bt.CTF_EVENT_CLASS_LOG_LEVEL_ERROR | |
39 | WARNING = native_bt.CTF_EVENT_CLASS_LOG_LEVEL_WARNING | |
40 | NOTICE = native_bt.CTF_EVENT_CLASS_LOG_LEVEL_NOTICE | |
41 | INFO = native_bt.CTF_EVENT_CLASS_LOG_LEVEL_INFO | |
42 | DEBUG_SYSTEM = native_bt.CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_SYSTEM | |
43 | DEBUG_PROGRAM = native_bt.CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_PROGRAM | |
44 | DEBUG_PROCESS = native_bt.CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_PROCESS | |
45 | DEBUG_MODULE = native_bt.CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_MODULE | |
46 | DEBUG_UNIT = native_bt.CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_UNIT | |
47 | DEBUG_FUNCTION = native_bt.CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_FUNCTION | |
48 | DEBUG_LINE = native_bt.CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_LINE | |
49 | DEBUG = native_bt.CTF_EVENT_CLASS_LOG_LEVEL_DEBUG | |
81447b5b PP |
50 | |
51 | ||
52 | class EventClass(object._Object): | |
811644b8 PP |
53 | def __init__(self, name, id=None, log_level=None, emf_uri=None, |
54 | context_field_type=None, payload_field_type=None): | |
81447b5b PP |
55 | utils._check_str(name) |
56 | ptr = native_bt.ctf_event_class_create(name) | |
57 | ||
58 | if ptr is None: | |
59 | raise bt2.CreationError('cannot create event class object') | |
60 | ||
61 | super().__init__(ptr) | |
62 | ||
63 | if id is not None: | |
64 | self.id = id | |
65 | ||
811644b8 PP |
66 | if log_level is not None: |
67 | self.log_level = log_level | |
68 | ||
69 | if emf_uri is not None: | |
70 | self.emf_uri = emf_uri | |
71 | ||
81447b5b PP |
72 | if context_field_type is not None: |
73 | self.context_field_type = context_field_type | |
74 | ||
75 | if payload_field_type is not None: | |
76 | self.payload_field_type = payload_field_type | |
77 | ||
81447b5b PP |
78 | @property |
79 | def stream_class(self): | |
80 | sc_ptr = native_bt.ctf_event_class_get_stream_class(self._ptr) | |
81 | ||
82 | if sc_ptr is not None: | |
83 | return bt2.StreamClass._create_from_ptr(sc_ptr) | |
84 | ||
81447b5b PP |
85 | @property |
86 | def name(self): | |
87 | return native_bt.ctf_event_class_get_name(self._ptr) | |
88 | ||
89 | @property | |
90 | def id(self): | |
91 | id = native_bt.ctf_event_class_get_id(self._ptr) | |
811644b8 | 92 | return id if id >= 0 else None |
81447b5b PP |
93 | |
94 | @id.setter | |
95 | def id(self, id): | |
96 | utils._check_int64(id) | |
97 | ret = native_bt.ctf_event_class_set_id(self._ptr, id) | |
98 | utils._handle_ret(ret, "cannot set event class object's ID") | |
99 | ||
811644b8 PP |
100 | @property |
101 | def log_level(self): | |
102 | log_level = native_bt.ctf_event_class_get_log_level(self._ptr) | |
103 | return log_level if log_level >= 0 else None | |
104 | ||
105 | @log_level.setter | |
106 | def log_level(self, log_level): | |
107 | log_levels = ( | |
108 | EventClassLogLevel.UNSPECIFIED, | |
109 | EventClassLogLevel.EMERGENCY, | |
110 | EventClassLogLevel.ALERT, | |
111 | EventClassLogLevel.CRITICAL, | |
112 | EventClassLogLevel.ERROR, | |
113 | EventClassLogLevel.WARNING, | |
114 | EventClassLogLevel.NOTICE, | |
115 | EventClassLogLevel.INFO, | |
116 | EventClassLogLevel.DEBUG_SYSTEM, | |
117 | EventClassLogLevel.DEBUG_PROGRAM, | |
118 | EventClassLogLevel.DEBUG_PROCESS, | |
119 | EventClassLogLevel.DEBUG_MODULE, | |
120 | EventClassLogLevel.DEBUG_UNIT, | |
121 | EventClassLogLevel.DEBUG_FUNCTION, | |
122 | EventClassLogLevel.DEBUG_LINE, | |
123 | EventClassLogLevel.DEBUG, | |
124 | ) | |
125 | ||
126 | if log_level not in log_levels: | |
127 | raise ValueError("'{}' is not a valid log level".format(log_level)) | |
128 | ||
129 | ret = native_bt.ctf_event_class_set_log_level(self._ptr, log_level) | |
130 | utils._handle_ret(ret, "cannot set event class object's log level") | |
131 | ||
132 | @property | |
133 | def emf_uri(self): | |
134 | return native_bt.ctf_event_class_get_emf_uri(self._ptr) | |
135 | ||
136 | @emf_uri.setter | |
137 | def emf_uri(self, emf_uri): | |
138 | utils._check_str(emf_uri) | |
139 | ret = native_bt.ctf_event_class_set_emf_uri(self._ptr, emf_uri) | |
140 | utils._handle_ret(ret, "cannot set event class object's EMF URI") | |
141 | ||
81447b5b PP |
142 | @property |
143 | def context_field_type(self): | |
144 | ft_ptr = native_bt.ctf_event_class_get_context_type(self._ptr) | |
145 | ||
146 | if ft_ptr is None: | |
147 | return | |
148 | ||
149 | return bt2.field_types._create_from_ptr(ft_ptr) | |
150 | ||
151 | @context_field_type.setter | |
152 | def context_field_type(self, context_field_type): | |
153 | context_field_type_ptr = None | |
154 | ||
155 | if context_field_type is not None: | |
156 | utils._check_type(context_field_type, bt2.field_types._FieldType) | |
157 | context_field_type_ptr = context_field_type._ptr | |
158 | ||
159 | ret = native_bt.ctf_event_class_set_context_type(self._ptr, context_field_type_ptr) | |
160 | utils._handle_ret(ret, "cannot set event class object's context field type") | |
161 | ||
162 | @property | |
163 | def payload_field_type(self): | |
164 | ft_ptr = native_bt.ctf_event_class_get_payload_type(self._ptr) | |
165 | ||
166 | if ft_ptr is None: | |
167 | return | |
168 | ||
169 | return bt2.field_types._create_from_ptr(ft_ptr) | |
170 | ||
171 | @payload_field_type.setter | |
172 | def payload_field_type(self, payload_field_type): | |
173 | payload_field_type_ptr = None | |
174 | ||
175 | if payload_field_type is not None: | |
176 | utils._check_type(payload_field_type, bt2.field_types._FieldType) | |
177 | payload_field_type_ptr = payload_field_type._ptr | |
178 | ||
179 | ret = native_bt.ctf_event_class_set_payload_type(self._ptr, payload_field_type_ptr) | |
180 | utils._handle_ret(ret, "cannot set event class object's payload field type") | |
181 | ||
182 | def __call__(self): | |
183 | event_ptr = native_bt.ctf_event_create(self._ptr) | |
184 | ||
185 | if event_ptr is None: | |
186 | raise bt2.CreationError('cannot create event field object') | |
187 | ||
188 | return bt2.event._create_from_ptr(event_ptr) | |
189 | ||
190 | def __eq__(self, other): | |
191 | if type(other) is not type(self): | |
192 | return False | |
193 | ||
194 | if self.addr == other.addr: | |
195 | return True | |
196 | ||
81447b5b | 197 | self_props = ( |
81447b5b PP |
198 | self.name, |
199 | self.id, | |
811644b8 PP |
200 | self.log_level, |
201 | self.emf_uri, | |
81447b5b PP |
202 | self.context_field_type, |
203 | self.payload_field_type | |
204 | ) | |
205 | other_props = ( | |
81447b5b PP |
206 | other.name, |
207 | other.id, | |
811644b8 PP |
208 | other.log_level, |
209 | other.emf_uri, | |
81447b5b PP |
210 | other.context_field_type, |
211 | other.payload_field_type | |
212 | ) | |
213 | return self_props == other_props | |
214 | ||
215 | def _copy(self, ft_copy_func): | |
216 | cpy = EventClass(self.name) | |
217 | cpy.id = self.id | |
218 | ||
811644b8 PP |
219 | if self.log_level is not None: |
220 | cpy.log_level = self.log_level | |
221 | ||
222 | if self.emf_uri is not None: | |
223 | cpy.emf_uri = self.emf_uri | |
81447b5b PP |
224 | |
225 | cpy.context_field_type = ft_copy_func(self.context_field_type) | |
226 | cpy.payload_field_type = ft_copy_func(self.payload_field_type) | |
227 | return cpy | |
228 | ||
229 | def __copy__(self): | |
230 | return self._copy(lambda ft: ft) | |
231 | ||
232 | def __deepcopy__(self, memo): | |
233 | cpy = self._copy(copy.deepcopy) | |
234 | memo[id(self)] = cpy | |
235 | return cpy |