Update project plugins's properties
[babeltrace.git] / src / bindings / python / bt2 / bt2 / stream_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 event_class as bt2_event_class
26from bt2 import trace_class as bt2_trace_class
27from bt2 import clock_class as bt2_clock_class
5783664e 28from bt2 import value as bt2_value
81447b5b 29import collections.abc
81447b5b
PP
30
31
f0a42b33 32class _StreamClassConst(object._SharedObject, collections.abc.Mapping):
fbbe9302
SM
33 _get_ref = staticmethod(native_bt.stream_class_get_ref)
34 _put_ref = staticmethod(native_bt.stream_class_put_ref)
f0a42b33
FD
35 _borrow_event_class_ptr_by_id = staticmethod(
36 native_bt.stream_class_borrow_event_class_by_id_const
37 )
38 _borrow_event_class_ptr_by_index = staticmethod(
39 native_bt.stream_class_borrow_event_class_by_index_const
40 )
41 _borrow_trace_class_ptr = staticmethod(
42 native_bt.stream_class_borrow_trace_class_const
43 )
44 _borrow_packet_context_field_class_ptr = staticmethod(
45 native_bt.stream_class_borrow_packet_context_field_class_const
46 )
47 _borrow_event_common_context_field_class_ptr = staticmethod(
48 native_bt.stream_class_borrow_event_common_context_field_class_const
49 )
50 _borrow_default_clock_class_ptr = staticmethod(
51 native_bt.stream_class_borrow_default_clock_class_const
52 )
2550c437
SM
53 _borrow_user_attributes_ptr = staticmethod(
54 native_bt.stream_class_borrow_user_attributes_const
55 )
f0a42b33
FD
56
57 _event_class_cls = property(lambda _: bt2_event_class._EventClassConst)
58 _trace_class_cls = property(lambda _: bt2_trace_class._TraceClassConst)
59 _clock_class_cls = property(lambda _: bt2_clock_class._ClockClassConst)
fbbe9302 60
81447b5b 61 def __getitem__(self, key):
811644b8 62 utils._check_int64(key)
f0a42b33 63 ec_ptr = self._borrow_event_class_ptr_by_id(self._ptr, key)
81447b5b
PP
64
65 if ec_ptr is None:
66 raise KeyError(key)
67
f0a42b33 68 return self._event_class_cls._create_from_ptr_and_get_ref(ec_ptr)
81447b5b
PP
69
70 def __len__(self):
50842bdc 71 count = native_bt.stream_class_get_event_class_count(self._ptr)
3cdfbaea 72 assert count >= 0
81447b5b
PP
73 return count
74
75 def __iter__(self):
3cdfbaea 76 for idx in range(len(self)):
f0a42b33 77 ec_ptr = self._borrow_event_class_ptr_by_index(self._ptr, idx)
3cdfbaea
SM
78 assert ec_ptr is not None
79
80 id = native_bt.event_class_get_id(ec_ptr)
81 assert id >= 0
82
83 yield id
81447b5b 84
f0a42b33
FD
85 @property
86 def trace_class(self):
87 tc_ptr = self._borrow_trace_class_ptr(self._ptr)
88
89 if tc_ptr is not None:
90 return self._trace_class_cls._create_from_ptr_and_get_ref(tc_ptr)
91
92 @property
93 def user_attributes(self):
2550c437 94 ptr = self._borrow_user_attributes_ptr(self._ptr)
f0a42b33
FD
95 assert ptr is not None
96 return bt2_value._create_from_ptr_and_get_ref(ptr)
97
98 @property
99 def name(self):
100 return native_bt.stream_class_get_name(self._ptr)
101
102 @property
103 def assigns_automatic_event_class_id(self):
104 return native_bt.stream_class_assigns_automatic_event_class_id(self._ptr)
105
106 @property
107 def assigns_automatic_stream_id(self):
108 return native_bt.stream_class_assigns_automatic_stream_id(self._ptr)
109
110 @property
111 def supports_packets(self):
112 return native_bt.stream_class_supports_packets(self._ptr)
113
114 @property
115 def packets_have_beginning_default_clock_snapshot(self):
116 return native_bt.stream_class_packets_have_beginning_default_clock_snapshot(
117 self._ptr
118 )
119
120 @property
121 def packets_have_end_default_clock_snapshot(self):
122 return native_bt.stream_class_packets_have_end_default_clock_snapshot(self._ptr)
123
124 @property
125 def supports_discarded_events(self):
126 return native_bt.stream_class_supports_discarded_events(self._ptr)
127
128 @property
129 def discarded_events_have_default_clock_snapshots(self):
130 return native_bt.stream_class_discarded_events_have_default_clock_snapshots(
131 self._ptr
132 )
133
134 @property
135 def supports_discarded_packets(self):
136 return native_bt.stream_class_supports_discarded_packets(self._ptr)
137
138 @property
139 def discarded_packets_have_default_clock_snapshots(self):
140 return native_bt.stream_class_discarded_packets_have_default_clock_snapshots(
141 self._ptr
142 )
143
144 @property
145 def id(self):
146 id = native_bt.stream_class_get_id(self._ptr)
147
148 if id < 0:
149 return
150
151 return id
152
153 @property
154 def packet_context_field_class(self):
155 fc_ptr = self._borrow_packet_context_field_class_ptr(self._ptr)
156
157 if fc_ptr is None:
158 return
159
160 return bt2_field_class._create_field_class_from_ptr_and_get_ref(fc_ptr)
161
162 @property
163 def event_common_context_field_class(self):
164 fc_ptr = self._borrow_event_common_context_field_class_ptr(self._ptr)
165
166 if fc_ptr is None:
167 return
168
169 return bt2_field_class._create_field_class_from_ptr_and_get_ref(fc_ptr)
170
171 @property
172 def default_clock_class(self):
173 cc_ptr = self._borrow_default_clock_class_ptr(self._ptr)
174 if cc_ptr is None:
175 return
176
177 return self._clock_class_cls._create_from_ptr_and_get_ref(cc_ptr)
178
179
180class _StreamClass(_StreamClassConst):
181 _get_ref = staticmethod(native_bt.stream_class_get_ref)
182 _put_ref = staticmethod(native_bt.stream_class_put_ref)
183 _borrow_event_class_ptr_by_id = staticmethod(
184 native_bt.stream_class_borrow_event_class_by_id
185 )
186 _borrow_event_class_ptr_by_index = staticmethod(
187 native_bt.stream_class_borrow_event_class_by_index
188 )
189 _borrow_trace_class_ptr = staticmethod(native_bt.stream_class_borrow_trace_class)
190 _borrow_packet_context_field_class_ptr = staticmethod(
191 native_bt.stream_class_borrow_packet_context_field_class
192 )
193 _borrow_event_common_context_field_class_ptr = staticmethod(
194 native_bt.stream_class_borrow_event_common_context_field_class
195 )
196 _borrow_default_clock_class_ptr = staticmethod(
197 native_bt.stream_class_borrow_default_clock_class
198 )
2550c437
SM
199 _borrow_user_attributes_ptr = staticmethod(
200 native_bt.stream_class_borrow_user_attributes
201 )
202
f0a42b33
FD
203 _event_class_cls = property(lambda s: bt2_event_class._EventClass)
204 _trace_class_cls = property(lambda s: bt2_trace_class._TraceClass)
205 _clock_class_cls = property(lambda s: bt2_clock_class._ClockClass)
206
cfbd7cf3
FD
207 def create_event_class(
208 self,
209 id=None,
210 name=None,
5783664e 211 user_attributes=None,
cfbd7cf3
FD
212 log_level=None,
213 emf_uri=None,
214 specific_context_field_class=None,
215 payload_field_class=None,
216 ):
3cdfbaea
SM
217 if self.assigns_automatic_event_class_id:
218 if id is not None:
cfbd7cf3
FD
219 raise ValueError(
220 'id provided, but stream class assigns automatic event class ids'
221 )
3cdfbaea
SM
222
223 ec_ptr = native_bt.event_class_create(self._ptr)
224 else:
225 if id is None:
cfbd7cf3
FD
226 raise ValueError(
227 'id not provided, but stream class does not assign automatic event class ids'
228 )
3cdfbaea
SM
229
230 utils._check_uint64(id)
231 ec_ptr = native_bt.event_class_create_with_id(self._ptr, id)
232
3fb99a22 233 event_class = bt2_event_class._EventClass._create_from_ptr(ec_ptr)
af4bbfc7
SM
234
235 if name is not None:
236 event_class._name = name
237
5783664e
PP
238 if user_attributes is not None:
239 event_class._user_attributes = user_attributes
240
af4bbfc7
SM
241 if log_level is not None:
242 event_class._log_level = log_level
243
244 if emf_uri is not None:
245 event_class._emf_uri = emf_uri
246
247 if specific_context_field_class is not None:
248 event_class._specific_context_field_class = specific_context_field_class
249
250 if payload_field_class is not None:
251 event_class._payload_field_class = payload_field_class
252
253 return event_class
81447b5b 254
5783664e
PP
255 def _user_attributes(self, user_attributes):
256 value = bt2_value.create_value(user_attributes)
257 utils._check_type(value, bt2_value.MapValue)
258 native_bt.stream_class_set_user_attributes(self._ptr, value._ptr)
259
260 _user_attributes = property(fset=_user_attributes)
261
3cdfbaea 262 def _name(self, name):
81447b5b 263 utils._check_str(name)
d24d5663 264 status = native_bt.stream_class_set_name(self._ptr, name)
cfbd7cf3 265 utils._handle_func_status(status, "cannot set stream class object's name")
81447b5b 266
3cdfbaea
SM
267 _name = property(fset=_name)
268
3cdfbaea
SM
269 def _assigns_automatic_event_class_id(self, auto_id):
270 utils._check_bool(auto_id)
cfbd7cf3
FD
271 return native_bt.stream_class_set_assigns_automatic_event_class_id(
272 self._ptr, auto_id
273 )
3cdfbaea
SM
274
275 _assigns_automatic_event_class_id = property(fset=_assigns_automatic_event_class_id)
276
8c2367b8
SM
277 def _assigns_automatic_stream_id(self, auto_id):
278 utils._check_bool(auto_id)
cfbd7cf3
FD
279 return native_bt.stream_class_set_assigns_automatic_stream_id(
280 self._ptr, auto_id
281 )
8c2367b8
SM
282
283 _assigns_automatic_stream_id = property(fset=_assigns_automatic_stream_id)
284
26fc5aed
PP
285 def _set_supports_packets(self, supports, with_begin_cs=False, with_end_cs=False):
286 utils._check_bool(supports)
287 utils._check_bool(with_begin_cs)
288 utils._check_bool(with_end_cs)
289
290 if not supports and (with_begin_cs or with_end_cs):
cfbd7cf3
FD
291 raise ValueError(
292 'cannot not support packets, but have default clock snapshots'
293 )
26fc5aed
PP
294
295 if not supports and self.packet_context_field_class is not None:
296 raise ValueError('stream class already has a packet context field class')
3cdfbaea 297
cfbd7cf3
FD
298 native_bt.stream_class_set_supports_packets(
299 self._ptr, supports, with_begin_cs, with_end_cs
300 )
3cdfbaea 301
2e90378a
PP
302 def _set_supports_discarded_events(self, supports, with_cs=False):
303 utils._check_bool(supports)
304 utils._check_bool(with_cs)
305
306 if not supports and with_cs:
cfbd7cf3
FD
307 raise ValueError(
308 'cannot not support discarded events, but have default clock snapshots'
309 )
2e90378a 310
cfbd7cf3
FD
311 native_bt.stream_class_set_supports_discarded_events(
312 self._ptr, supports, with_cs
313 )
2e90378a 314
f0a42b33 315 _supports_discarded_events = property(fset=_set_supports_discarded_events)
2e90378a
PP
316
317 def _set_supports_discarded_packets(self, supports, with_cs):
318 utils._check_bool(supports)
319 utils._check_bool(with_cs)
320
26fc5aed 321 if supports and not self.supports_packets:
cfbd7cf3
FD
322 raise ValueError(
323 'cannot support discarded packets, but not support packets'
324 )
26fc5aed 325
2e90378a 326 if not supports and with_cs:
cfbd7cf3
FD
327 raise ValueError(
328 'cannot not support discarded packets, but have default clock snapshots'
329 )
2e90378a 330
cfbd7cf3
FD
331 native_bt.stream_class_set_supports_discarded_packets(
332 self._ptr, supports, with_cs
333 )
2e90378a 334
f0a42b33 335 _supports_discarded_packets = property(fset=_set_supports_discarded_packets)
81447b5b 336
3cdfbaea 337 def _packet_context_field_class(self, packet_context_field_class):
b4f45851 338 if packet_context_field_class is not None:
cfbd7cf3 339 utils._check_type(
3fb99a22 340 packet_context_field_class, bt2_field_class._StructureFieldClass
cfbd7cf3 341 )
26fc5aed
PP
342
343 if not self.supports_packets:
344 raise ValueError('stream class does not support packets')
345
cfbd7cf3
FD
346 status = native_bt.stream_class_set_packet_context_field_class(
347 self._ptr, packet_context_field_class._ptr
348 )
349 utils._handle_func_status(
350 status, "cannot set stream class' packet context field class"
351 )
81447b5b 352
3cdfbaea 353 _packet_context_field_class = property(fset=_packet_context_field_class)
81447b5b 354
3cdfbaea
SM
355 def _event_common_context_field_class(self, event_common_context_field_class):
356 if event_common_context_field_class is not None:
cfbd7cf3 357 utils._check_type(
3fb99a22 358 event_common_context_field_class, bt2_field_class._StructureFieldClass
cfbd7cf3 359 )
81447b5b 360
3cdfbaea 361 set_context_fn = native_bt.stream_class_set_event_common_context_field_class
d24d5663 362 status = set_context_fn(self._ptr, event_common_context_field_class._ptr)
cfbd7cf3
FD
363 utils._handle_func_status(
364 status, "cannot set stream class' event context field type"
365 )
81447b5b 366
3cdfbaea 367 _event_common_context_field_class = property(fset=_event_common_context_field_class)
81447b5b 368
3cdfbaea 369 def _default_clock_class(self, clock_class):
3fb99a22 370 utils._check_type(clock_class, bt2_clock_class._ClockClass)
cfbd7cf3 371 native_bt.stream_class_set_default_clock_class(self._ptr, clock_class._ptr)
81447b5b 372
3cdfbaea 373 _default_clock_class = property(fset=_default_clock_class)
This page took 0.066203 seconds and 4 git commands to generate.