1 # SPDX-License-Identifier: MIT
3 # Copyright (c) 2017 Philippe Proulx <pproulx@efficios.com>
5 from bt2
import native_bt
, object, utils
6 from bt2
import field_class
as bt2_field_class
7 from bt2
import event_class
as bt2_event_class
8 from bt2
import clock_class
as bt2_clock_class
9 from bt2
import value
as bt2_value
10 import collections
.abc
13 def _bt2_trace_class():
14 from bt2
import trace_class
as bt2_trace_class
16 return bt2_trace_class
19 class _StreamClassConst(object._SharedObject
, collections
.abc
.Mapping
):
22 native_bt
.stream_class_get_ref(ptr
)
26 native_bt
.stream_class_put_ref(ptr
)
28 _borrow_event_class_ptr_by_id
= staticmethod(
29 native_bt
.stream_class_borrow_event_class_by_id_const
31 _borrow_event_class_ptr_by_index
= staticmethod(
32 native_bt
.stream_class_borrow_event_class_by_index_const
34 _borrow_trace_class_ptr
= staticmethod(
35 native_bt
.stream_class_borrow_trace_class_const
37 _borrow_packet_context_field_class_ptr
= staticmethod(
38 native_bt
.stream_class_borrow_packet_context_field_class_const
40 _borrow_event_common_context_field_class_ptr
= staticmethod(
41 native_bt
.stream_class_borrow_event_common_context_field_class_const
43 _borrow_default_clock_class_ptr
= staticmethod(
44 native_bt
.stream_class_borrow_default_clock_class_const
46 _borrow_user_attributes_ptr
= staticmethod(
47 native_bt
.stream_class_borrow_user_attributes_const
50 _event_class_cls
= property(lambda _
: bt2_event_class
._EventClassConst
)
51 _trace_class_cls
= property(lambda _
: _bt2_trace_class()._TraceClassConst
)
52 _clock_class_cls
= property(lambda _
: bt2_clock_class
._ClockClassConst
)
54 def __getitem__(self
, key
):
55 utils
._check
_int
64(key
)
56 ec_ptr
= self
._borrow
_event
_class
_ptr
_by
_id
(self
._ptr
, key
)
61 return self
._event
_class
_cls
._create
_from
_ptr
_and
_get
_ref
(ec_ptr
)
64 count
= native_bt
.stream_class_get_event_class_count(self
._ptr
)
69 for idx
in range(len(self
)):
70 ec_ptr
= self
._borrow
_event
_class
_ptr
_by
_index
(self
._ptr
, idx
)
71 assert ec_ptr
is not None
73 id = native_bt
.event_class_get_id(ec_ptr
)
79 def trace_class(self
):
80 tc_ptr
= self
._borrow
_trace
_class
_ptr
(self
._ptr
)
82 if tc_ptr
is not None:
83 return self
._trace
_class
_cls
._create
_from
_ptr
_and
_get
_ref
(tc_ptr
)
86 def user_attributes(self
):
87 ptr
= self
._borrow
_user
_attributes
_ptr
(self
._ptr
)
88 assert ptr
is not None
89 return bt2_value
._create
_from
_ptr
_and
_get
_ref
(ptr
)
93 return native_bt
.stream_class_get_name(self
._ptr
)
96 def assigns_automatic_event_class_id(self
):
97 return native_bt
.stream_class_assigns_automatic_event_class_id(self
._ptr
)
100 def assigns_automatic_stream_id(self
):
101 return native_bt
.stream_class_assigns_automatic_stream_id(self
._ptr
)
104 def supports_packets(self
):
105 return native_bt
.stream_class_supports_packets(self
._ptr
)
108 def packets_have_beginning_default_clock_snapshot(self
):
109 return native_bt
.stream_class_packets_have_beginning_default_clock_snapshot(
114 def packets_have_end_default_clock_snapshot(self
):
115 return native_bt
.stream_class_packets_have_end_default_clock_snapshot(self
._ptr
)
118 def supports_discarded_events(self
):
119 return native_bt
.stream_class_supports_discarded_events(self
._ptr
)
122 def discarded_events_have_default_clock_snapshots(self
):
123 return native_bt
.stream_class_discarded_events_have_default_clock_snapshots(
128 def supports_discarded_packets(self
):
129 return native_bt
.stream_class_supports_discarded_packets(self
._ptr
)
132 def discarded_packets_have_default_clock_snapshots(self
):
133 return native_bt
.stream_class_discarded_packets_have_default_clock_snapshots(
139 id = native_bt
.stream_class_get_id(self
._ptr
)
147 def packet_context_field_class(self
):
148 fc_ptr
= self
._borrow
_packet
_context
_field
_class
_ptr
(self
._ptr
)
153 return bt2_field_class
._create
_field
_class
_from
_ptr
_and
_get
_ref
(fc_ptr
)
156 def event_common_context_field_class(self
):
157 fc_ptr
= self
._borrow
_event
_common
_context
_field
_class
_ptr
(self
._ptr
)
162 return bt2_field_class
._create
_field
_class
_from
_ptr
_and
_get
_ref
(fc_ptr
)
165 def default_clock_class(self
):
166 cc_ptr
= self
._borrow
_default
_clock
_class
_ptr
(self
._ptr
)
170 return self
._clock
_class
_cls
._create
_from
_ptr
_and
_get
_ref
(cc_ptr
)
173 class _StreamClass(_StreamClassConst
):
176 native_bt
.stream_class_get_ref(ptr
)
180 native_bt
.stream_class_put_ref(ptr
)
182 _borrow_event_class_ptr_by_id
= staticmethod(
183 native_bt
.stream_class_borrow_event_class_by_id
185 _borrow_event_class_ptr_by_index
= staticmethod(
186 native_bt
.stream_class_borrow_event_class_by_index
188 _borrow_trace_class_ptr
= staticmethod(native_bt
.stream_class_borrow_trace_class
)
189 _borrow_packet_context_field_class_ptr
= staticmethod(
190 native_bt
.stream_class_borrow_packet_context_field_class
192 _borrow_event_common_context_field_class_ptr
= staticmethod(
193 native_bt
.stream_class_borrow_event_common_context_field_class
195 _borrow_default_clock_class_ptr
= staticmethod(
196 native_bt
.stream_class_borrow_default_clock_class
198 _borrow_user_attributes_ptr
= staticmethod(
199 native_bt
.stream_class_borrow_user_attributes
202 _event_class_cls
= property(lambda s
: bt2_event_class
._EventClass
)
203 _trace_class_cls
= property(lambda s
: _bt2_trace_class()._TraceClass
)
204 _clock_class_cls
= property(lambda s
: bt2_clock_class
._ClockClass
)
206 def create_event_class(
210 user_attributes
=None,
213 specific_context_field_class
=None,
214 payload_field_class
=None,
216 # Validate parameters before we create the object.
217 bt2_event_class
._EventClass
._validate
_create
_params
(
222 specific_context_field_class
,
226 if self
.assigns_automatic_event_class_id
:
229 "id provided, but stream class assigns automatic event class ids"
232 ec_ptr
= native_bt
.event_class_create(self
._ptr
)
236 "id not provided, but stream class does not assign automatic event class ids"
239 utils
._check
_uint
64(id)
240 ec_ptr
= native_bt
.event_class_create_with_id(self
._ptr
, id)
242 event_class
= bt2_event_class
._EventClass
._create
_from
_ptr
(ec_ptr
)
245 event_class
._name
= name
247 if user_attributes
is not None:
248 event_class
._user
_attributes
= user_attributes
250 if log_level
is not None:
251 event_class
._log
_level
= log_level
253 if emf_uri
is not None:
254 event_class
._emf
_uri
= emf_uri
256 if specific_context_field_class
is not None:
257 event_class
._specific
_context
_field
_class
= specific_context_field_class
259 if payload_field_class
is not None:
260 event_class
._payload
_field
_class
= payload_field_class
264 def _user_attributes(self
, user_attributes
):
265 value
= bt2_value
.create_value(user_attributes
)
266 native_bt
.stream_class_set_user_attributes(self
._ptr
, value
._ptr
)
268 _user_attributes
= property(fset
=_user_attributes
)
270 def _name(self
, name
):
271 status
= native_bt
.stream_class_set_name(self
._ptr
, name
)
272 utils
._handle
_func
_status
(status
, "cannot set stream class object's name")
274 _name
= property(fset
=_name
)
276 def _assigns_automatic_event_class_id(self
, auto_id
):
277 native_bt
.stream_class_set_assigns_automatic_event_class_id(self
._ptr
, auto_id
)
279 _assigns_automatic_event_class_id
= property(fset
=_assigns_automatic_event_class_id
)
281 def _assigns_automatic_stream_id(self
, auto_id
):
282 native_bt
.stream_class_set_assigns_automatic_stream_id(self
._ptr
, auto_id
)
284 _assigns_automatic_stream_id
= property(fset
=_assigns_automatic_stream_id
)
286 def _set_supports_packets(self
, supports
, with_begin_cs
=False, with_end_cs
=False):
287 native_bt
.stream_class_set_supports_packets(
288 self
._ptr
, supports
, with_begin_cs
, with_end_cs
291 def _set_supports_discarded_events(self
, supports
, with_cs
=False):
292 native_bt
.stream_class_set_supports_discarded_events(
293 self
._ptr
, supports
, with_cs
296 _supports_discarded_events
= property(fset
=_set_supports_discarded_events
)
298 def _set_supports_discarded_packets(self
, supports
, with_cs
):
299 native_bt
.stream_class_set_supports_discarded_packets(
300 self
._ptr
, supports
, with_cs
303 _supports_discarded_packets
= property(fset
=_set_supports_discarded_packets
)
305 def _packet_context_field_class(self
, packet_context_field_class
):
306 status
= native_bt
.stream_class_set_packet_context_field_class(
307 self
._ptr
, packet_context_field_class
._ptr
309 utils
._handle
_func
_status
(
310 status
, "cannot set stream class' packet context field class"
313 _packet_context_field_class
= property(fset
=_packet_context_field_class
)
315 def _event_common_context_field_class(self
, event_common_context_field_class
):
316 set_context_fn
= native_bt
.stream_class_set_event_common_context_field_class
317 status
= set_context_fn(self
._ptr
, event_common_context_field_class
._ptr
)
318 utils
._handle
_func
_status
(
319 status
, "cannot set stream class' event context field type"
322 _event_common_context_field_class
= property(fset
=_event_common_context_field_class
)
324 def _default_clock_class(self
, clock_class
):
325 native_bt
.stream_class_set_default_clock_class(self
._ptr
, clock_class
._ptr
)
327 _default_clock_class
= property(fset
=_default_clock_class
)
330 def _validate_create_params(
334 packet_context_field_class
,
335 event_common_context_field_class
,
337 assigns_automatic_event_class_id
,
338 assigns_automatic_stream_id
,
340 packets_have_beginning_default_clock_snapshot
,
341 packets_have_end_default_clock_snapshot
,
342 supports_discarded_events
,
343 discarded_events_have_default_clock_snapshots
,
344 supports_discarded_packets
,
345 discarded_packets_have_default_clock_snapshots
,
349 utils
._check
_str
(name
)
352 if user_attributes
is not None:
353 value
= bt2_value
.create_value(user_attributes
)
354 utils
._check
_type
(value
, bt2_value
.MapValue
)
356 # Packet context field class
357 if packet_context_field_class
is not None:
358 if not supports_packets
:
360 "cannot have a packet context field class without supporting packets"
364 packet_context_field_class
, bt2_field_class
._StructureFieldClass
367 # Event common context field class
368 if event_common_context_field_class
is not None:
370 event_common_context_field_class
, bt2_field_class
._StructureFieldClass
373 # Default clock class
374 if default_clock_class
is not None:
375 utils
._check
_type
(default_clock_class
, bt2_clock_class
._ClockClass
)
377 # Assigns automatic event class id
378 utils
._check
_bool
(assigns_automatic_event_class_id
)
380 # Assigns automatic stream id
381 utils
._check
_bool
(assigns_automatic_stream_id
)
384 utils
._check
_bool
(supports_packets
)
385 utils
._check
_bool
(packets_have_beginning_default_clock_snapshot
)
386 utils
._check
_bool
(packets_have_end_default_clock_snapshot
)
388 if not supports_packets
:
389 if packets_have_beginning_default_clock_snapshot
:
391 "cannot not support packets, but have packet beginning default clock snapshot"
393 if packets_have_end_default_clock_snapshot
:
395 "cannot not support packets, but have packet end default clock snapshots"
399 utils
._check
_bool
(supports_discarded_events
)
400 utils
._check
_bool
(discarded_events_have_default_clock_snapshots
)
402 if discarded_events_have_default_clock_snapshots
:
403 if not supports_discarded_events
:
405 "cannot not support discarded events, but have default clock snapshots for discarded event messages"
408 if default_clock_class
is None:
410 "cannot have no default clock class, but have default clock snapshots for discarded event messages"
414 utils
._check
_bool
(supports_discarded_packets
)
415 utils
._check
_bool
(discarded_packets_have_default_clock_snapshots
)
417 if supports_discarded_packets
and not supports_packets
:
419 "cannot support discarded packets, but not support packets"
422 if discarded_packets_have_default_clock_snapshots
:
423 if not supports_discarded_packets
:
425 "cannot not support discarded packets, but have default clock snapshots for discarded packet messages"
428 if default_clock_class
is None:
430 "cannot have no default clock class, but have default clock snapshots for discarded packet messages"