1 # SPDX-License-Identifier: MIT
3 # Copyright (c) 2017 Philippe Proulx <pproulx@efficios.com>
5 from bt2
import native_bt
6 from bt2
import object as bt2_object
7 from bt2
import utils
as bt2_utils
8 from bt2
import field_class
as bt2_field_class
9 from bt2
import event_class
as bt2_event_class
10 from bt2
import clock_class
as bt2_clock_class
11 from bt2
import value
as bt2_value
12 import collections
.abc
15 def _bt2_trace_class():
16 from bt2
import trace_class
as bt2_trace_class
18 return bt2_trace_class
21 class _StreamClassConst(bt2_object
._SharedObject
, collections
.abc
.Mapping
):
24 native_bt
.stream_class_get_ref(ptr
)
28 native_bt
.stream_class_put_ref(ptr
)
30 _borrow_event_class_ptr_by_id
= staticmethod(
31 native_bt
.stream_class_borrow_event_class_by_id_const
33 _borrow_event_class_ptr_by_index
= staticmethod(
34 native_bt
.stream_class_borrow_event_class_by_index_const
36 _borrow_trace_class_ptr
= staticmethod(
37 native_bt
.stream_class_borrow_trace_class_const
39 _borrow_packet_context_field_class_ptr
= staticmethod(
40 native_bt
.stream_class_borrow_packet_context_field_class_const
42 _borrow_event_common_context_field_class_ptr
= staticmethod(
43 native_bt
.stream_class_borrow_event_common_context_field_class_const
45 _borrow_default_clock_class_ptr
= staticmethod(
46 native_bt
.stream_class_borrow_default_clock_class_const
48 _borrow_user_attributes_ptr
= staticmethod(
49 native_bt
.stream_class_borrow_user_attributes_const
52 _event_class_cls
= property(lambda _
: bt2_event_class
._EventClassConst
)
53 _trace_class_cls
= property(lambda _
: _bt2_trace_class()._TraceClassConst
)
54 _clock_class_cls
= property(lambda _
: bt2_clock_class
._ClockClassConst
)
56 def __getitem__(self
, key
):
57 bt2_utils
._check
_int
64(key
)
58 ec_ptr
= self
._borrow
_event
_class
_ptr
_by
_id
(self
._ptr
, key
)
63 return self
._event
_class
_cls
._create
_from
_ptr
_and
_get
_ref
(ec_ptr
)
66 count
= native_bt
.stream_class_get_event_class_count(self
._ptr
)
71 for idx
in range(len(self
)):
72 ec_ptr
= self
._borrow
_event
_class
_ptr
_by
_index
(self
._ptr
, idx
)
73 assert ec_ptr
is not None
75 id = native_bt
.event_class_get_id(ec_ptr
)
81 def trace_class(self
):
82 tc_ptr
= self
._borrow
_trace
_class
_ptr
(self
._ptr
)
84 if tc_ptr
is not None:
85 return self
._trace
_class
_cls
._create
_from
_ptr
_and
_get
_ref
(tc_ptr
)
88 def user_attributes(self
):
89 ptr
= self
._borrow
_user
_attributes
_ptr
(self
._ptr
)
90 assert ptr
is not None
91 return bt2_value
._create
_from
_ptr
_and
_get
_ref
(ptr
)
95 return native_bt
.stream_class_get_name(self
._ptr
)
98 def assigns_automatic_event_class_id(self
):
99 return native_bt
.stream_class_assigns_automatic_event_class_id(self
._ptr
)
102 def assigns_automatic_stream_id(self
):
103 return native_bt
.stream_class_assigns_automatic_stream_id(self
._ptr
)
106 def supports_packets(self
):
107 return native_bt
.stream_class_supports_packets(self
._ptr
)
110 def packets_have_beginning_default_clock_snapshot(self
):
111 return native_bt
.stream_class_packets_have_beginning_default_clock_snapshot(
116 def packets_have_end_default_clock_snapshot(self
):
117 return native_bt
.stream_class_packets_have_end_default_clock_snapshot(self
._ptr
)
120 def supports_discarded_events(self
):
121 return native_bt
.stream_class_supports_discarded_events(self
._ptr
)
124 def discarded_events_have_default_clock_snapshots(self
):
125 return native_bt
.stream_class_discarded_events_have_default_clock_snapshots(
130 def supports_discarded_packets(self
):
131 return native_bt
.stream_class_supports_discarded_packets(self
._ptr
)
134 def discarded_packets_have_default_clock_snapshots(self
):
135 return native_bt
.stream_class_discarded_packets_have_default_clock_snapshots(
141 id = native_bt
.stream_class_get_id(self
._ptr
)
149 def packet_context_field_class(self
):
150 fc_ptr
= self
._borrow
_packet
_context
_field
_class
_ptr
(self
._ptr
)
155 return bt2_field_class
._create
_field
_class
_from
_ptr
_and
_get
_ref
(fc_ptr
)
158 def event_common_context_field_class(self
):
159 fc_ptr
= self
._borrow
_event
_common
_context
_field
_class
_ptr
(self
._ptr
)
164 return bt2_field_class
._create
_field
_class
_from
_ptr
_and
_get
_ref
(fc_ptr
)
167 def default_clock_class(self
):
168 cc_ptr
= self
._borrow
_default
_clock
_class
_ptr
(self
._ptr
)
172 return self
._clock
_class
_cls
._create
_from
_ptr
_and
_get
_ref
(cc_ptr
)
175 class _StreamClass(_StreamClassConst
):
178 native_bt
.stream_class_get_ref(ptr
)
182 native_bt
.stream_class_put_ref(ptr
)
184 _borrow_event_class_ptr_by_id
= staticmethod(
185 native_bt
.stream_class_borrow_event_class_by_id
187 _borrow_event_class_ptr_by_index
= staticmethod(
188 native_bt
.stream_class_borrow_event_class_by_index
190 _borrow_trace_class_ptr
= staticmethod(native_bt
.stream_class_borrow_trace_class
)
191 _borrow_packet_context_field_class_ptr
= staticmethod(
192 native_bt
.stream_class_borrow_packet_context_field_class
194 _borrow_event_common_context_field_class_ptr
= staticmethod(
195 native_bt
.stream_class_borrow_event_common_context_field_class
197 _borrow_default_clock_class_ptr
= staticmethod(
198 native_bt
.stream_class_borrow_default_clock_class
200 _borrow_user_attributes_ptr
= staticmethod(
201 native_bt
.stream_class_borrow_user_attributes
204 _event_class_cls
= property(lambda s
: bt2_event_class
._EventClass
)
205 _trace_class_cls
= property(lambda s
: _bt2_trace_class()._TraceClass
)
206 _clock_class_cls
= property(lambda s
: bt2_clock_class
._ClockClass
)
208 def create_event_class(
212 user_attributes
=None,
215 specific_context_field_class
=None,
216 payload_field_class
=None,
218 # Validate parameters before we create the object.
219 bt2_event_class
._EventClass
._validate
_create
_params
(
224 specific_context_field_class
,
228 if self
.assigns_automatic_event_class_id
:
231 "id provided, but stream class assigns automatic event class ids"
234 ec_ptr
= native_bt
.event_class_create(self
._ptr
)
238 "id not provided, but stream class does not assign automatic event class ids"
241 bt2_utils
._check
_uint
64(id)
242 ec_ptr
= native_bt
.event_class_create_with_id(self
._ptr
, id)
244 event_class
= bt2_event_class
._EventClass
._create
_from
_ptr
(ec_ptr
)
247 event_class
._name
= name
249 if user_attributes
is not None:
250 event_class
._user
_attributes
= user_attributes
252 if log_level
is not None:
253 event_class
._log
_level
= log_level
255 if emf_uri
is not None:
256 event_class
._emf
_uri
= emf_uri
258 if specific_context_field_class
is not None:
259 event_class
._specific
_context
_field
_class
= specific_context_field_class
261 if payload_field_class
is not None:
262 event_class
._payload
_field
_class
= payload_field_class
266 def _user_attributes(self
, user_attributes
):
267 value
= bt2_value
.create_value(user_attributes
)
268 native_bt
.stream_class_set_user_attributes(self
._ptr
, value
._ptr
)
270 _user_attributes
= property(fset
=_user_attributes
)
272 def _name(self
, name
):
273 status
= native_bt
.stream_class_set_name(self
._ptr
, name
)
274 bt2_utils
._handle
_func
_status
(status
, "cannot set stream class object's name")
276 _name
= property(fset
=_name
)
278 def _assigns_automatic_event_class_id(self
, auto_id
):
279 native_bt
.stream_class_set_assigns_automatic_event_class_id(self
._ptr
, auto_id
)
281 _assigns_automatic_event_class_id
= property(fset
=_assigns_automatic_event_class_id
)
283 def _assigns_automatic_stream_id(self
, auto_id
):
284 native_bt
.stream_class_set_assigns_automatic_stream_id(self
._ptr
, auto_id
)
286 _assigns_automatic_stream_id
= property(fset
=_assigns_automatic_stream_id
)
288 def _set_supports_packets(self
, supports
, with_begin_cs
=False, with_end_cs
=False):
289 native_bt
.stream_class_set_supports_packets(
290 self
._ptr
, supports
, with_begin_cs
, with_end_cs
293 def _set_supports_discarded_events(self
, supports
, with_cs
=False):
294 native_bt
.stream_class_set_supports_discarded_events(
295 self
._ptr
, supports
, with_cs
298 _supports_discarded_events
= property(fset
=_set_supports_discarded_events
)
300 def _set_supports_discarded_packets(self
, supports
, with_cs
):
301 native_bt
.stream_class_set_supports_discarded_packets(
302 self
._ptr
, supports
, with_cs
305 _supports_discarded_packets
= property(fset
=_set_supports_discarded_packets
)
307 def _packet_context_field_class(self
, packet_context_field_class
):
308 status
= native_bt
.stream_class_set_packet_context_field_class(
309 self
._ptr
, packet_context_field_class
._ptr
311 bt2_utils
._handle
_func
_status
(
312 status
, "cannot set stream class' packet context field class"
315 _packet_context_field_class
= property(fset
=_packet_context_field_class
)
317 def _event_common_context_field_class(self
, event_common_context_field_class
):
318 set_context_fn
= native_bt
.stream_class_set_event_common_context_field_class
319 status
= set_context_fn(self
._ptr
, event_common_context_field_class
._ptr
)
320 bt2_utils
._handle
_func
_status
(
321 status
, "cannot set stream class' event context field type"
324 _event_common_context_field_class
= property(fset
=_event_common_context_field_class
)
326 def _default_clock_class(self
, clock_class
):
327 native_bt
.stream_class_set_default_clock_class(self
._ptr
, clock_class
._ptr
)
329 _default_clock_class
= property(fset
=_default_clock_class
)
332 def _validate_create_params(
336 packet_context_field_class
,
337 event_common_context_field_class
,
339 assigns_automatic_event_class_id
,
340 assigns_automatic_stream_id
,
342 packets_have_beginning_default_clock_snapshot
,
343 packets_have_end_default_clock_snapshot
,
344 supports_discarded_events
,
345 discarded_events_have_default_clock_snapshots
,
346 supports_discarded_packets
,
347 discarded_packets_have_default_clock_snapshots
,
351 bt2_utils
._check
_str
(name
)
354 if user_attributes
is not None:
355 value
= bt2_value
.create_value(user_attributes
)
356 bt2_utils
._check
_type
(value
, bt2_value
.MapValue
)
358 # Packet context field class
359 if packet_context_field_class
is not None:
360 if not supports_packets
:
362 "cannot have a packet context field class without supporting packets"
365 bt2_utils
._check
_type
(
366 packet_context_field_class
, bt2_field_class
._StructureFieldClass
369 # Event common context field class
370 if event_common_context_field_class
is not None:
371 bt2_utils
._check
_type
(
372 event_common_context_field_class
, bt2_field_class
._StructureFieldClass
375 # Default clock class
376 if default_clock_class
is not None:
377 bt2_utils
._check
_type
(default_clock_class
, bt2_clock_class
._ClockClass
)
379 # Assigns automatic event class id
380 bt2_utils
._check
_bool
(assigns_automatic_event_class_id
)
382 # Assigns automatic stream id
383 bt2_utils
._check
_bool
(assigns_automatic_stream_id
)
386 bt2_utils
._check
_bool
(supports_packets
)
387 bt2_utils
._check
_bool
(packets_have_beginning_default_clock_snapshot
)
388 bt2_utils
._check
_bool
(packets_have_end_default_clock_snapshot
)
390 if not supports_packets
:
391 if packets_have_beginning_default_clock_snapshot
:
393 "cannot not support packets, but have packet beginning default clock snapshot"
395 if packets_have_end_default_clock_snapshot
:
397 "cannot not support packets, but have packet end default clock snapshots"
401 bt2_utils
._check
_bool
(supports_discarded_events
)
402 bt2_utils
._check
_bool
(discarded_events_have_default_clock_snapshots
)
404 if discarded_events_have_default_clock_snapshots
:
405 if not supports_discarded_events
:
407 "cannot not support discarded events, but have default clock snapshots for discarded event messages"
410 if default_clock_class
is None:
412 "cannot have no default clock class, but have default clock snapshots for discarded event messages"
416 bt2_utils
._check
_bool
(supports_discarded_packets
)
417 bt2_utils
._check
_bool
(discarded_packets_have_default_clock_snapshots
)
419 if supports_discarded_packets
and not supports_packets
:
421 "cannot support discarded packets, but not support packets"
424 if discarded_packets_have_default_clock_snapshots
:
425 if not supports_discarded_packets
:
427 "cannot not support discarded packets, but have default clock snapshots for discarded packet messages"
430 if default_clock_class
is None:
432 "cannot have no default clock class, but have default clock snapshots for discarded packet messages"