1 # SPDX-License-Identifier: MIT
3 # Copyright (c) 2017 Philippe Proulx <pproulx@efficios.com>
5 from bt2
import native_bt
, object, utils
7 from bt2
import field_path
as bt2_field_path
8 from bt2
import integer_range_set
as bt2_integer_range_set
9 from bt2
import value
as bt2_value
13 def _create_field_class_from_ptr_and_get_ref_template(type_map
, ptr
):
14 typeid
= native_bt
.field_class_get_type(ptr
)
15 return type_map
[typeid
]._create
_from
_ptr
_and
_get
_ref
(ptr
)
18 def _create_field_class_from_ptr_and_get_ref(ptr
):
19 return _create_field_class_from_ptr_and_get_ref_template(
20 _FIELD_CLASS_TYPE_TO_OBJ
, ptr
24 def _create_field_class_from_const_ptr_and_get_ref(ptr
):
25 return _create_field_class_from_ptr_and_get_ref_template(
26 _FIELD_CLASS_TYPE_TO_CONST_OBJ
, ptr
30 class IntegerDisplayBase
:
31 BINARY
= native_bt
.FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_BINARY
32 OCTAL
= native_bt
.FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_OCTAL
33 DECIMAL
= native_bt
.FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
34 HEXADECIMAL
= native_bt
.FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_HEXADECIMAL
37 class _FieldClassConst(object._SharedObject
):
38 _get_ref
= staticmethod(native_bt
.field_class_get_ref
)
39 _put_ref
= staticmethod(native_bt
.field_class_put_ref
)
40 _borrow_user_attributes_ptr
= staticmethod(
41 native_bt
.field_class_borrow_user_attributes_const
43 _create_value_from_ptr_and_get_ref
= staticmethod(
44 bt2_value
._create
_from
_const
_ptr
_and
_get
_ref
47 def _check_create_status(self
, ptr
):
49 raise bt2
._MemoryError(
50 'cannot create {} field class object'.format(self
._NAME
.lower())
54 def user_attributes(self
):
55 ptr
= self
._borrow
_user
_attributes
_ptr
(self
._ptr
)
56 assert ptr
is not None
57 return self
._create
_value
_from
_ptr
_and
_get
_ref
(ptr
)
60 class _FieldClass(_FieldClassConst
):
61 _borrow_user_attributes_ptr
= staticmethod(
62 native_bt
.field_class_borrow_user_attributes
64 _create_value_from_ptr_and_get_ref
= staticmethod(
65 bt2_value
._create
_from
_ptr
_and
_get
_ref
68 def _user_attributes(self
, user_attributes
):
69 value
= bt2_value
.create_value(user_attributes
)
70 utils
._check
_type
(value
, bt2_value
.MapValue
)
71 native_bt
.field_class_set_user_attributes(self
._ptr
, value
._ptr
)
73 _user_attributes
= property(fset
=_user_attributes
)
76 class _BoolFieldClassConst(_FieldClassConst
):
77 _NAME
= 'Const boolean'
80 class _BoolFieldClass(_BoolFieldClassConst
, _FieldClass
):
84 class _BitArrayFieldClassConst(_FieldClassConst
):
85 _NAME
= 'Const bit array'
89 length
= native_bt
.field_class_bit_array_get_length(self
._ptr
)
94 class _BitArrayFieldClass(_BitArrayFieldClassConst
, _FieldClass
):
98 class _IntegerFieldClassConst(_FieldClassConst
):
100 def field_value_range(self
):
101 size
= native_bt
.field_class_integer_get_field_value_range(self
._ptr
)
106 def preferred_display_base(self
):
107 base
= native_bt
.field_class_integer_get_preferred_display_base(self
._ptr
)
112 class _IntegerFieldClass(_FieldClass
, _IntegerFieldClassConst
):
113 def _field_value_range(self
, size
):
114 if size
< 1 or size
> 64:
115 raise ValueError("Value is outside valid range [1, 64] ({})".format(size
))
116 native_bt
.field_class_integer_set_field_value_range(self
._ptr
, size
)
118 _field_value_range
= property(fset
=_field_value_range
)
120 def _preferred_display_base(self
, base
):
121 utils
._check
_uint
64(base
)
124 IntegerDisplayBase
.BINARY
,
125 IntegerDisplayBase
.OCTAL
,
126 IntegerDisplayBase
.DECIMAL
,
127 IntegerDisplayBase
.HEXADECIMAL
,
129 raise ValueError("Display base is not a valid IntegerDisplayBase value")
131 native_bt
.field_class_integer_set_preferred_display_base(self
._ptr
, base
)
133 _preferred_display_base
= property(fset
=_preferred_display_base
)
136 class _UnsignedIntegerFieldClassConst(_IntegerFieldClassConst
, _FieldClassConst
):
137 _NAME
= 'Const unsigned integer'
140 class _UnsignedIntegerFieldClass(
141 _UnsignedIntegerFieldClassConst
, _IntegerFieldClass
, _FieldClass
143 _NAME
= 'Unsigned integer'
146 class _SignedIntegerFieldClassConst(_IntegerFieldClassConst
, _FieldClassConst
):
147 _NAME
= 'Const signed integer'
150 class _SignedIntegerFieldClass(
151 _SignedIntegerFieldClassConst
, _IntegerFieldClass
, _FieldClass
153 _NAME
= 'Signed integer'
156 class _RealFieldClassConst(_FieldClassConst
):
160 class _SinglePrecisionRealFieldClassConst(_RealFieldClassConst
):
161 _NAME
= 'Const single-precision real'
164 class _DoublePrecisionRealFieldClassConst(_RealFieldClassConst
):
165 _NAME
= 'Const double-precision real'
168 class _RealFieldClass(_FieldClass
, _RealFieldClassConst
):
172 class _SinglePrecisionRealFieldClass(_RealFieldClass
):
173 _NAME
= 'Single-precision real'
176 class _DoublePrecisionRealFieldClass(_RealFieldClass
):
177 _NAME
= 'Double-precision real'
180 # an enumeration field class mapping does not have a reference count, so
181 # we copy the properties here to avoid eventual memory access errors.
182 class _EnumerationFieldClassMapping
:
183 def __init__(self
, mapping_ptr
):
184 base_mapping_ptr
= self
._as
_enumeration
_field
_class
_mapping
_ptr
(mapping_ptr
)
185 self
._label
= native_bt
.field_class_enumeration_mapping_get_label(
188 assert self
._label
is not None
189 ranges_ptr
= self
._mapping
_borrow
_ranges
_ptr
(mapping_ptr
)
190 assert ranges_ptr
is not None
191 self
._ranges
= self
._range
_set
_pycls
._create
_from
_ptr
_and
_get
_ref
(ranges_ptr
)
202 class _UnsignedEnumerationFieldClassMappingConst(_EnumerationFieldClassMapping
):
203 _range_set_pycls
= bt2_integer_range_set
._UnsignedIntegerRangeSetConst
204 _as_enumeration_field_class_mapping_ptr
= staticmethod(
205 native_bt
.field_class_enumeration_unsigned_mapping_as_mapping_const
207 _mapping_borrow_ranges_ptr
= staticmethod(
208 native_bt
.field_class_enumeration_unsigned_mapping_borrow_ranges_const
212 class _SignedEnumerationFieldClassMappingConst(_EnumerationFieldClassMapping
):
213 _range_set_pycls
= bt2_integer_range_set
._SignedIntegerRangeSetConst
214 _as_enumeration_field_class_mapping_ptr
= staticmethod(
215 native_bt
.field_class_enumeration_signed_mapping_as_mapping_const
217 _mapping_borrow_ranges_ptr
= staticmethod(
218 native_bt
.field_class_enumeration_signed_mapping_borrow_ranges_const
222 class _EnumerationFieldClassConst(_IntegerFieldClassConst
, collections
.abc
.Mapping
):
224 count
= native_bt
.field_class_enumeration_get_mapping_count(self
._ptr
)
228 def mappings_for_value(self
, value
):
229 self
._check
_int
_type
(value
)
231 status
, labels
= self
._get
_mapping
_labels
_for
_value
(self
._ptr
, value
)
232 utils
._handle
_func
_status
(
233 status
, 'cannot get mapping labels for value {}'.format(value
)
235 return [self
[label
] for label
in labels
]
238 for idx
in range(len(self
)):
239 mapping_ptr
= self
._borrow
_mapping
_ptr
_by
_index
(self
._ptr
, idx
)
240 yield self
._mapping
_pycls
(mapping_ptr
).label
242 def __getitem__(self
, label
):
243 utils
._check
_str
(label
)
244 mapping_ptr
= self
._borrow
_mapping
_ptr
_by
_label
(self
._ptr
, label
)
246 if mapping_ptr
is None:
247 raise KeyError(label
)
249 return self
._mapping
_pycls
(mapping_ptr
)
252 class _EnumerationFieldClass(_EnumerationFieldClassConst
, _IntegerFieldClass
):
253 def add_mapping(self
, label
, ranges
):
254 utils
._check
_str
(label
)
255 utils
._check
_type
(ranges
, self
._range
_set
_pycls
)
258 raise ValueError("duplicate mapping label '{}'".format(label
))
260 status
= self
._add
_mapping
(self
._ptr
, label
, ranges
._ptr
)
261 utils
._handle
_func
_status
(
262 status
, 'cannot add mapping to enumeration field class object'
265 def __iadd__(self
, mappings
):
266 for label
, ranges
in mappings
:
267 self
.add_mapping(label
, ranges
)
272 class _UnsignedEnumerationFieldClassConst(
273 _EnumerationFieldClassConst
, _UnsignedIntegerFieldClassConst
275 _NAME
= 'Const unsigned enumeration'
276 _borrow_mapping_ptr_by_label
= staticmethod(
277 native_bt
.field_class_enumeration_unsigned_borrow_mapping_by_label_const
279 _borrow_mapping_ptr_by_index
= staticmethod(
280 native_bt
.field_class_enumeration_unsigned_borrow_mapping_by_index_const
282 _mapping_pycls
= property(lambda _
: _UnsignedEnumerationFieldClassMappingConst
)
283 _get_mapping_labels_for_value
= staticmethod(
284 native_bt
.field_class_enumeration_unsigned_get_mapping_labels_for_value
286 _check_int_type
= staticmethod(utils
._check
_uint
64)
289 class _UnsignedEnumerationFieldClass(
290 _UnsignedEnumerationFieldClassConst
,
291 _EnumerationFieldClass
,
292 _UnsignedIntegerFieldClass
,
294 _NAME
= 'Unsigned enumeration'
295 _range_set_pycls
= bt2_integer_range_set
.UnsignedIntegerRangeSet
296 _add_mapping
= staticmethod(native_bt
.field_class_enumeration_unsigned_add_mapping
)
299 class _SignedEnumerationFieldClassConst(
300 _EnumerationFieldClassConst
, _SignedIntegerFieldClassConst
302 _NAME
= 'Const signed enumeration'
303 _borrow_mapping_ptr_by_label
= staticmethod(
304 native_bt
.field_class_enumeration_signed_borrow_mapping_by_label_const
306 _borrow_mapping_ptr_by_index
= staticmethod(
307 native_bt
.field_class_enumeration_signed_borrow_mapping_by_index_const
309 _mapping_pycls
= property(lambda _
: _SignedEnumerationFieldClassMappingConst
)
310 _get_mapping_labels_for_value
= staticmethod(
311 native_bt
.field_class_enumeration_signed_get_mapping_labels_for_value
313 _check_int_type
= staticmethod(utils
._check
_int
64)
316 class _SignedEnumerationFieldClass(
317 _SignedEnumerationFieldClassConst
, _EnumerationFieldClass
, _SignedIntegerFieldClass
319 _NAME
= 'Signed enumeration'
320 _range_set_pycls
= bt2_integer_range_set
.SignedIntegerRangeSet
321 _add_mapping
= staticmethod(native_bt
.field_class_enumeration_signed_add_mapping
)
324 class _StringFieldClassConst(_FieldClassConst
):
325 _NAME
= 'Const string'
328 class _StringFieldClass(_StringFieldClassConst
, _FieldClass
):
332 class _StructureFieldClassMemberConst
:
333 _create_field_class_from_ptr_and_get_ref
= staticmethod(
334 _create_field_class_from_const_ptr_and_get_ref
336 _borrow_field_class_ptr
= staticmethod(
337 native_bt
.field_class_structure_member_borrow_field_class_const
339 _borrow_user_attributes_ptr
= staticmethod(
340 native_bt
.field_class_structure_member_borrow_user_attributes_const
342 _create_value_from_ptr_and_get_ref
= staticmethod(
343 bt2_value
._create
_from
_const
_ptr
_and
_get
_ref
346 def __init__(self
, owning_struct_fc
, member_ptr
):
347 # this field class owns the member; keeping it here maintains
348 # the member alive as members are not shared objects
349 self
._owning
_struct
_fc
= owning_struct_fc
350 self
._ptr
= member_ptr
354 name
= native_bt
.field_class_structure_member_get_name(self
._ptr
)
355 assert name
is not None
359 def field_class(self
):
360 fc_ptr
= self
._borrow
_field
_class
_ptr
(self
._ptr
)
361 assert fc_ptr
is not None
362 return self
._create
_field
_class
_from
_ptr
_and
_get
_ref
(fc_ptr
)
365 def user_attributes(self
):
366 ptr
= self
._borrow
_user
_attributes
_ptr
(self
._ptr
)
367 assert ptr
is not None
368 return self
._create
_value
_from
_ptr
_and
_get
_ref
(ptr
)
371 class _StructureFieldClassMember(_StructureFieldClassMemberConst
):
372 _borrow_field_class_ptr
= staticmethod(
373 native_bt
.field_class_structure_member_borrow_field_class
375 _borrow_user_attributes_ptr
= staticmethod(
376 native_bt
.field_class_structure_member_borrow_user_attributes
378 _create_field_class_from_ptr_and_get_ref
= staticmethod(
379 _create_field_class_from_ptr_and_get_ref
381 _create_value_from_ptr_and_get_ref
= staticmethod(
382 bt2_value
._create
_from
_ptr
_and
_get
_ref
385 def _user_attributes(self
, user_attributes
):
386 value
= bt2_value
.create_value(user_attributes
)
387 utils
._check
_type
(value
, bt2_value
.MapValue
)
388 native_bt
.field_class_structure_member_set_user_attributes(
389 self
._ptr
, value
._ptr
392 _user_attributes
= property(fset
=_user_attributes
)
395 class _StructureFieldClassConst(_FieldClassConst
, collections
.abc
.Mapping
):
396 _NAME
= 'Const structure'
397 _borrow_member_ptr_by_index
= staticmethod(
398 native_bt
.field_class_structure_borrow_member_by_index_const
400 _borrow_member_ptr_by_name
= staticmethod(
401 native_bt
.field_class_structure_borrow_member_by_name_const
403 _structure_member_field_class_pycls
= property(
404 lambda _
: _StructureFieldClassMemberConst
408 count
= native_bt
.field_class_structure_get_member_count(self
._ptr
)
412 def __getitem__(self
, key
):
413 if not isinstance(key
, str):
415 "key must be a 'str' object, got '{}'".format(key
.__class
__.__name
__)
418 member_ptr
= self
._borrow
_member
_ptr
_by
_name
(self
._ptr
, key
)
420 if member_ptr
is None:
423 return self
._structure
_member
_field
_class
_pycls
(self
, member_ptr
)
426 for idx
in range(len(self
)):
427 member_ptr
= self
._borrow
_member
_ptr
_by
_index
(self
._ptr
, idx
)
428 assert member_ptr
is not None
429 yield native_bt
.field_class_structure_member_get_name(member_ptr
)
431 def member_at_index(self
, index
):
432 utils
._check
_uint
64(index
)
434 if index
>= len(self
):
437 member_ptr
= self
._borrow
_member
_ptr
_by
_index
(self
._ptr
, index
)
438 assert member_ptr
is not None
439 return self
._structure
_member
_field
_class
_pycls
(self
, member_ptr
)
442 class _StructureFieldClass(_StructureFieldClassConst
, _FieldClass
):
444 _borrow_member_by_index
= staticmethod(
445 native_bt
.field_class_structure_borrow_member_by_index
447 _borrow_member_ptr_by_name
= staticmethod(
448 native_bt
.field_class_structure_borrow_member_by_name
450 _structure_member_field_class_pycls
= property(lambda _
: _StructureFieldClassMember
)
452 def append_member(self
, name
, field_class
, user_attributes
=None):
453 utils
._check
_str
(name
)
454 utils
._check
_type
(field_class
, _FieldClass
)
457 raise ValueError("duplicate member name '{}'".format(name
))
459 user_attributes_value
= None
461 if user_attributes
is not None:
462 # check now that user attributes are valid
463 user_attributes_value
= bt2
.create_value(user_attributes
)
465 status
= native_bt
.field_class_structure_append_member(
466 self
._ptr
, name
, field_class
._ptr
468 utils
._handle
_func
_status
(
469 status
, 'cannot append member to structure field class object'
472 if user_attributes
is not None:
473 self
[name
]._user
_attributes
= user_attributes_value
475 def __iadd__(self
, members
):
476 for name
, field_class
in members
:
477 self
.append_member(name
, field_class
)
482 class _OptionFieldClassConst(_FieldClassConst
):
483 _NAME
= 'Const option'
484 _create_field_class_from_ptr_and_get_ref
= staticmethod(
485 _create_field_class_from_const_ptr_and_get_ref
487 _borrow_field_class_ptr
= staticmethod(
488 native_bt
.field_class_option_borrow_field_class_const
492 def field_class(self
):
493 elem_fc_ptr
= self
._borrow
_field
_class
_ptr
(self
._ptr
)
494 return self
._create
_field
_class
_from
_ptr
_and
_get
_ref
(elem_fc_ptr
)
497 class _OptionWithSelectorFieldClassConst(_OptionFieldClassConst
):
498 _NAME
= 'Const option (with selector)'
501 def selector_field_path(self
):
502 ptr
= native_bt
.field_class_option_with_selector_field_borrow_selector_field_path_const(
508 return bt2_field_path
._FieldPathConst
._create
_from
_ptr
_and
_get
_ref
(ptr
)
511 class _OptionWithBoolSelectorFieldClassConst(_OptionWithSelectorFieldClassConst
):
512 _NAME
= 'Const option (with boolean selector)'
515 def selector_is_reversed(self
):
517 native_bt
.field_class_option_with_selector_field_bool_selector_is_reversed(
523 class _OptionWithIntegerSelectorFieldClassConst(_OptionWithSelectorFieldClassConst
):
524 _NAME
= 'Const option (with integer selector)'
528 range_set_ptr
= self
._borrow
_selector
_ranges
_ptr
(self
._ptr
)
529 assert range_set_ptr
is not None
530 return self
._range
_set
_pycls
._create
_from
_ptr
_and
_get
_ref
(range_set_ptr
)
533 class _OptionWithUnsignedIntegerSelectorFieldClassConst(
534 _OptionWithIntegerSelectorFieldClassConst
536 _NAME
= 'Const option (with unsigned integer selector)'
537 _range_set_pycls
= bt2_integer_range_set
._UnsignedIntegerRangeSetConst
538 _borrow_selector_ranges_ptr
= staticmethod(
539 native_bt
.field_class_option_with_selector_field_integer_unsigned_borrow_selector_ranges_const
543 class _OptionWithSignedIntegerSelectorFieldClassConst(
544 _OptionWithIntegerSelectorFieldClassConst
546 _NAME
= 'Const option (with signed integer selector)'
547 _range_set_pycls
= bt2_integer_range_set
._SignedIntegerRangeSetConst
548 _borrow_selector_ranges_ptr
= staticmethod(
549 native_bt
.field_class_option_with_selector_field_integer_signed_borrow_selector_ranges_const
553 class _OptionFieldClass(_OptionFieldClassConst
, _FieldClass
):
555 _borrow_field_class_ptr
= staticmethod(
556 native_bt
.field_class_option_borrow_field_class
558 _create_field_class_from_ptr_and_get_ref
= staticmethod(
559 _create_field_class_from_ptr_and_get_ref
563 class _OptionWithSelectorFieldClass(
564 _OptionWithSelectorFieldClassConst
, _OptionFieldClass
566 _NAME
= 'Option (with selector)'
569 class _OptionWithBoolSelectorFieldClass(
570 _OptionWithBoolSelectorFieldClassConst
, _OptionWithSelectorFieldClass
572 _NAME
= 'Option (with boolean selector)'
574 def _selector_is_reversed(self
, selector_is_reversed
):
575 utils
._check
_bool
(selector_is_reversed
)
576 native_bt
.field_class_option_with_selector_field_bool_set_selector_is_reversed(
577 self
._ptr
, selector_is_reversed
580 _selector_is_reversed
= property(fset
=_selector_is_reversed
)
583 class _OptionWithIntegerSelectorFieldClass(
584 _OptionWithIntegerSelectorFieldClassConst
, _OptionWithSelectorFieldClass
586 _NAME
= 'Option (with integer selector)'
589 class _OptionWithUnsignedIntegerSelectorFieldClass(
590 _OptionWithUnsignedIntegerSelectorFieldClassConst
,
591 _OptionWithIntegerSelectorFieldClass
,
593 _NAME
= 'Option (with unsigned integer selector)'
596 class _OptionWithSignedIntegerSelectorFieldClass(
597 _OptionWithSignedIntegerSelectorFieldClassConst
,
598 _OptionWithIntegerSelectorFieldClass
,
600 _NAME
= 'Option (with signed integer selector)'
603 class _VariantFieldClassOptionConst
:
604 _create_field_class_from_ptr_and_get_ref
= staticmethod(
605 _create_field_class_from_const_ptr_and_get_ref
607 _borrow_field_class_ptr
= staticmethod(
608 native_bt
.field_class_variant_option_borrow_field_class_const
610 _borrow_user_attributes_ptr
= staticmethod(
611 native_bt
.field_class_variant_option_borrow_user_attributes_const
613 _create_value_from_ptr_and_get_ref
= staticmethod(
614 bt2_value
._create
_from
_const
_ptr
_and
_get
_ref
617 def __init__(self
, owning_var_fc
, option_ptr
):
618 # this field class owns the option; keeping it here maintains
619 # the option alive as options are not shared objects
620 self
._owning
_var
_fc
= owning_var_fc
621 self
._ptr
= option_ptr
625 name
= native_bt
.field_class_variant_option_get_name(self
._ptr
)
626 assert name
is not None
630 def field_class(self
):
631 fc_ptr
= self
._borrow
_field
_class
_ptr
(self
._ptr
)
632 assert fc_ptr
is not None
633 return self
._create
_field
_class
_from
_ptr
_and
_get
_ref
(fc_ptr
)
636 def user_attributes(self
):
637 ptr
= self
._borrow
_user
_attributes
_ptr
(self
._ptr
)
638 assert ptr
is not None
639 return self
._create
_value
_from
_ptr
_and
_get
_ref
(ptr
)
642 class _VariantFieldClassOption(_VariantFieldClassOptionConst
):
643 _create_field_class_from_ptr_and_get_ref
= staticmethod(
644 _create_field_class_from_ptr_and_get_ref
646 _borrow_field_class_ptr
= staticmethod(
647 native_bt
.field_class_variant_option_borrow_field_class
649 _borrow_user_attributes_ptr
= staticmethod(
650 native_bt
.field_class_variant_option_borrow_user_attributes
652 _create_value_from_ptr_and_get_ref
= staticmethod(
653 bt2_value
._create
_from
_ptr
_and
_get
_ref
656 def _user_attributes(self
, user_attributes
):
657 value
= bt2_value
.create_value(user_attributes
)
658 utils
._check
_type
(value
, bt2_value
.MapValue
)
659 native_bt
.field_class_variant_option_set_user_attributes(self
._ptr
, value
._ptr
)
661 _user_attributes
= property(fset
=_user_attributes
)
664 class _VariantFieldClassWithIntegerSelectorOptionConst(_VariantFieldClassOptionConst
):
665 def __init__(self
, owning_var_fc
, spec_opt_ptr
):
666 self
._spec
_ptr
= spec_opt_ptr
667 super().__init
__(owning_var_fc
, self
._as
_option
_ptr
(spec_opt_ptr
))
671 range_set_ptr
= self
._borrow
_ranges
_ptr
(self
._spec
_ptr
)
672 assert range_set_ptr
is not None
673 return self
._range
_set
_pycls
._create
_from
_ptr
_and
_get
_ref
(range_set_ptr
)
676 class _VariantFieldClassWithIntegerSelectorOption(
677 _VariantFieldClassWithIntegerSelectorOptionConst
, _VariantFieldClassOption
682 class _VariantFieldClassWithSignedIntegerSelectorOptionConst(
683 _VariantFieldClassWithIntegerSelectorOptionConst
685 _as_option_ptr
= staticmethod(
686 native_bt
.field_class_variant_with_selector_field_integer_signed_option_as_option_const
688 _borrow_ranges_ptr
= staticmethod(
689 native_bt
.field_class_variant_with_selector_field_integer_signed_option_borrow_ranges_const
691 _range_set_pycls
= bt2_integer_range_set
._SignedIntegerRangeSetConst
694 class _VariantFieldClassWithSignedIntegerSelectorOption(
695 _VariantFieldClassWithSignedIntegerSelectorOptionConst
,
696 _VariantFieldClassWithIntegerSelectorOption
,
701 class _VariantFieldClassWithUnsignedIntegerSelectorOptionConst(
702 _VariantFieldClassWithIntegerSelectorOptionConst
704 _as_option_ptr
= staticmethod(
705 native_bt
.field_class_variant_with_selector_field_integer_unsigned_option_as_option_const
707 _borrow_ranges_ptr
= staticmethod(
708 native_bt
.field_class_variant_with_selector_field_integer_unsigned_option_borrow_ranges_const
710 _range_set_pycls
= bt2_integer_range_set
._UnsignedIntegerRangeSetConst
713 class _VariantFieldClassWithUnsignedIntegerSelectorOption(
714 _VariantFieldClassWithUnsignedIntegerSelectorOptionConst
,
715 _VariantFieldClassWithIntegerSelectorOption
,
720 class _VariantFieldClassConst(_FieldClassConst
, collections
.abc
.Mapping
):
721 _NAME
= 'Const variant'
722 _borrow_option_ptr_by_name
= staticmethod(
723 native_bt
.field_class_variant_borrow_option_by_name_const
725 _borrow_option_ptr_by_index
= staticmethod(
726 native_bt
.field_class_variant_borrow_option_by_index_const
728 _variant_option_pycls
= _VariantFieldClassOptionConst
731 def _as_option_ptr(opt_ptr
):
734 def _create_option_from_ptr(self
, opt_ptr
):
735 return self
._variant
_option
_pycls
(self
, opt_ptr
)
738 count
= native_bt
.field_class_variant_get_option_count(self
._ptr
)
742 def __getitem__(self
, key
):
743 if not isinstance(key
, str):
745 "key must be a 'str' object, got '{}'".format(key
.__class
__.__name
__)
748 opt_ptr
= self
._borrow
_option
_ptr
_by
_name
(self
._ptr
, key
)
753 return self
._create
_option
_from
_ptr
(opt_ptr
)
756 for idx
in range(len(self
)):
757 opt_ptr
= self
._borrow
_option
_ptr
_by
_index
(self
._ptr
, idx
)
758 assert opt_ptr
is not None
759 base_opt_ptr
= self
._as
_option
_ptr
(opt_ptr
)
760 yield native_bt
.field_class_variant_option_get_name(base_opt_ptr
)
762 def option_at_index(self
, index
):
763 utils
._check
_uint
64(index
)
765 if index
>= len(self
):
768 opt_ptr
= self
._borrow
_option
_ptr
_by
_index
(self
._ptr
, index
)
769 assert opt_ptr
is not None
770 return self
._create
_option
_from
_ptr
(opt_ptr
)
773 class _VariantFieldClass(_VariantFieldClassConst
, _FieldClass
, collections
.abc
.Mapping
):
775 _borrow_option_ptr_by_name
= staticmethod(
776 native_bt
.field_class_variant_borrow_option_by_name
778 _borrow_option_ptr_by_index
= staticmethod(
779 native_bt
.field_class_variant_borrow_option_by_index
781 _variant_option_pycls
= _VariantFieldClassOption
784 class _VariantFieldClassWithoutSelectorConst(_VariantFieldClassConst
):
785 _NAME
= 'Const variant (without selector)'
788 class _VariantFieldClassWithoutSelector(
789 _VariantFieldClassWithoutSelectorConst
, _VariantFieldClass
791 _NAME
= 'Variant (without selector)'
793 def append_option(self
, name
, field_class
, user_attributes
=None):
794 utils
._check
_str
(name
)
795 utils
._check
_type
(field_class
, _FieldClass
)
798 raise ValueError("duplicate option name '{}'".format(name
))
800 user_attributes_value
= None
802 if user_attributes
is not None:
803 # check now that user attributes are valid
804 user_attributes_value
= bt2
.create_value(user_attributes
)
806 status
= native_bt
.field_class_variant_without_selector_append_option(
807 self
._ptr
, name
, field_class
._ptr
809 utils
._handle
_func
_status
(
810 status
, 'cannot append option to variant field class object'
813 if user_attributes
is not None:
814 self
[name
]._user
_attributes
= user_attributes_value
816 def __iadd__(self
, options
):
817 for name
, field_class
in options
:
818 self
.append_option(name
, field_class
)
823 class _VariantFieldClassWithIntegerSelectorConst(_VariantFieldClassConst
):
824 _NAME
= 'Const variant (with selector)'
827 def selector_field_path(self
):
828 ptr
= native_bt
.field_class_variant_with_selector_field_borrow_selector_field_path_const(
835 return bt2_field_path
._FieldPathConst
._create
_from
_ptr
_and
_get
_ref
(ptr
)
838 class _VariantFieldClassWithIntegerSelector(
839 _VariantFieldClassWithIntegerSelectorConst
, _VariantFieldClass
841 _NAME
= 'Variant (with selector)'
843 def append_option(self
, name
, field_class
, ranges
, user_attributes
=None):
844 utils
._check
_str
(name
)
845 utils
._check
_type
(field_class
, _FieldClass
)
846 utils
._check
_type
(ranges
, self
._variant
_option
_pycls
._range
_set
_pycls
)
849 raise ValueError("duplicate option name '{}'".format(name
))
852 raise ValueError('range set is empty')
854 user_attributes_value
= None
856 if user_attributes
is not None:
857 # check now that user attributes are valid
858 user_attributes_value
= bt2
.create_value(user_attributes
)
860 # TODO: check overlaps (precondition of self._append_option())
862 status
= self
._append
_option
(self
._ptr
, name
, field_class
._ptr
, ranges
._ptr
)
863 utils
._handle
_func
_status
(
864 status
, 'cannot append option to variant field class object'
867 if user_attributes
is not None:
868 self
[name
]._user
_attributes
= user_attributes_value
870 def __iadd__(self
, options
):
871 for name
, field_class
, ranges
in options
:
872 self
.append_option(name
, field_class
, ranges
)
877 class _VariantFieldClassWithUnsignedIntegerSelectorConst(
878 _VariantFieldClassWithIntegerSelectorConst
880 _NAME
= 'Const variant (with unsigned integer selector)'
881 _borrow_option_ptr_by_name
= staticmethod(
882 native_bt
.field_class_variant_with_selector_field_integer_unsigned_borrow_option_by_name_const
884 _borrow_option_ptr_by_index
= staticmethod(
885 native_bt
.field_class_variant_with_selector_field_integer_unsigned_borrow_option_by_index_const
887 _variant_option_pycls
= _VariantFieldClassWithUnsignedIntegerSelectorOptionConst
888 _as_option_ptr
= staticmethod(_variant_option_pycls
._as
_option
_ptr
)
891 class _VariantFieldClassWithUnsignedIntegerSelector(
892 _VariantFieldClassWithUnsignedIntegerSelectorConst
,
893 _VariantFieldClassWithIntegerSelector
,
895 _NAME
= 'Variant (with unsigned integer selector)'
896 _variant_option_pycls
= _VariantFieldClassWithUnsignedIntegerSelectorOption
897 _as_option_ptr
= staticmethod(_variant_option_pycls
._as
_option
_ptr
)
898 _append_option
= staticmethod(
899 native_bt
.field_class_variant_with_selector_field_integer_unsigned_append_option
903 class _VariantFieldClassWithSignedIntegerSelectorConst(
904 _VariantFieldClassWithIntegerSelectorConst
906 _NAME
= 'Const variant (with signed integer selector)'
907 _borrow_option_ptr_by_name
= staticmethod(
908 native_bt
.field_class_variant_with_selector_field_integer_signed_borrow_option_by_name_const
910 _borrow_option_ptr_by_index
= staticmethod(
911 native_bt
.field_class_variant_with_selector_field_integer_signed_borrow_option_by_index_const
913 _variant_option_pycls
= _VariantFieldClassWithSignedIntegerSelectorOptionConst
914 _as_option_ptr
= staticmethod(_variant_option_pycls
._as
_option
_ptr
)
917 class _VariantFieldClassWithSignedIntegerSelector(
918 _VariantFieldClassWithSignedIntegerSelectorConst
,
919 _VariantFieldClassWithIntegerSelector
,
921 _NAME
= 'Variant (with signed integer selector)'
922 _variant_option_pycls
= _VariantFieldClassWithSignedIntegerSelectorOption
923 _as_option_ptr
= staticmethod(_variant_option_pycls
._as
_option
_ptr
)
924 _append_option
= staticmethod(
925 native_bt
.field_class_variant_with_selector_field_integer_signed_append_option
929 class _ArrayFieldClassConst(_FieldClassConst
):
930 _create_field_class_from_ptr_and_get_ref
= staticmethod(
931 _create_field_class_from_const_ptr_and_get_ref
933 _borrow_element_field_class
= staticmethod(
934 native_bt
.field_class_array_borrow_element_field_class_const
938 def element_field_class(self
):
939 elem_fc_ptr
= self
._borrow
_element
_field
_class
(self
._ptr
)
940 return self
._create
_field
_class
_from
_ptr
_and
_get
_ref
(elem_fc_ptr
)
943 class _ArrayFieldClass(_ArrayFieldClassConst
, _FieldClass
):
944 _create_field_class_from_ptr_and_get_ref
= staticmethod(
945 _create_field_class_from_ptr_and_get_ref
947 _borrow_element_field_class
= staticmethod(
948 native_bt
.field_class_array_borrow_element_field_class
952 class _StaticArrayFieldClassConst(_ArrayFieldClassConst
):
953 _NAME
= 'Const static array'
957 return native_bt
.field_class_array_static_get_length(self
._ptr
)
960 class _StaticArrayFieldClass(_StaticArrayFieldClassConst
, _ArrayFieldClass
):
961 _NAME
= 'Static array'
964 class _DynamicArrayFieldClassConst(_ArrayFieldClassConst
):
965 _NAME
= 'Const dynamic array'
968 class _DynamicArrayWithLengthFieldFieldClassConst(_DynamicArrayFieldClassConst
):
969 _NAME
= 'Const dynamic array (with length field)'
972 def length_field_path(self
):
973 ptr
= native_bt
.field_class_array_dynamic_with_length_field_borrow_length_field_path_const(
979 return bt2_field_path
._FieldPathConst
._create
_from
_ptr
_and
_get
_ref
(ptr
)
982 class _DynamicArrayFieldClass(_DynamicArrayFieldClassConst
, _ArrayFieldClass
):
983 _NAME
= 'Dynamic array'
986 class _DynamicArrayWithLengthFieldFieldClass(
987 _DynamicArrayWithLengthFieldFieldClassConst
, _DynamicArrayFieldClass
989 _NAME
= 'Dynamic array (with length field)'
992 _FIELD_CLASS_TYPE_TO_CONST_OBJ
= {
993 native_bt
.FIELD_CLASS_TYPE_BOOL
: _BoolFieldClassConst
,
994 native_bt
.FIELD_CLASS_TYPE_BIT_ARRAY
: _BitArrayFieldClassConst
,
995 native_bt
.FIELD_CLASS_TYPE_UNSIGNED_INTEGER
: _UnsignedIntegerFieldClassConst
,
996 native_bt
.FIELD_CLASS_TYPE_SIGNED_INTEGER
: _SignedIntegerFieldClassConst
,
997 native_bt
.FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL
: _SinglePrecisionRealFieldClassConst
,
998 native_bt
.FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL
: _DoublePrecisionRealFieldClassConst
,
999 native_bt
.FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
: _UnsignedEnumerationFieldClassConst
,
1000 native_bt
.FIELD_CLASS_TYPE_SIGNED_ENUMERATION
: _SignedEnumerationFieldClassConst
,
1001 native_bt
.FIELD_CLASS_TYPE_STRING
: _StringFieldClassConst
,
1002 native_bt
.FIELD_CLASS_TYPE_STRUCTURE
: _StructureFieldClassConst
,
1003 native_bt
.FIELD_CLASS_TYPE_STATIC_ARRAY
: _StaticArrayFieldClassConst
,
1004 native_bt
.FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD
: _DynamicArrayFieldClassConst
,
1005 native_bt
.FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD
: _DynamicArrayWithLengthFieldFieldClassConst
,
1006 native_bt
.FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD
: _OptionFieldClassConst
,
1007 native_bt
.FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD
: _OptionWithBoolSelectorFieldClassConst
,
1008 native_bt
.FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
: _OptionWithUnsignedIntegerSelectorFieldClassConst
,
1009 native_bt
.FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD
: _OptionWithSignedIntegerSelectorFieldClassConst
,
1010 native_bt
.FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD
: _VariantFieldClassWithoutSelectorConst
,
1011 native_bt
.FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
: _VariantFieldClassWithUnsignedIntegerSelectorConst
,
1012 native_bt
.FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
: _VariantFieldClassWithSignedIntegerSelectorConst
,
1015 _FIELD_CLASS_TYPE_TO_OBJ
= {
1016 native_bt
.FIELD_CLASS_TYPE_BOOL
: _BoolFieldClass
,
1017 native_bt
.FIELD_CLASS_TYPE_BIT_ARRAY
: _BitArrayFieldClass
,
1018 native_bt
.FIELD_CLASS_TYPE_UNSIGNED_INTEGER
: _UnsignedIntegerFieldClass
,
1019 native_bt
.FIELD_CLASS_TYPE_SIGNED_INTEGER
: _SignedIntegerFieldClass
,
1020 native_bt
.FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL
: _SinglePrecisionRealFieldClass
,
1021 native_bt
.FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL
: _DoublePrecisionRealFieldClass
,
1022 native_bt
.FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
: _UnsignedEnumerationFieldClass
,
1023 native_bt
.FIELD_CLASS_TYPE_SIGNED_ENUMERATION
: _SignedEnumerationFieldClass
,
1024 native_bt
.FIELD_CLASS_TYPE_STRING
: _StringFieldClass
,
1025 native_bt
.FIELD_CLASS_TYPE_STRUCTURE
: _StructureFieldClass
,
1026 native_bt
.FIELD_CLASS_TYPE_STATIC_ARRAY
: _StaticArrayFieldClass
,
1027 native_bt
.FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD
: _DynamicArrayFieldClass
,
1028 native_bt
.FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD
: _DynamicArrayWithLengthFieldFieldClass
,
1029 native_bt
.FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD
: _OptionFieldClass
,
1030 native_bt
.FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD
: _OptionWithBoolSelectorFieldClass
,
1031 native_bt
.FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
: _OptionWithUnsignedIntegerSelectorFieldClass
,
1032 native_bt
.FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD
: _OptionWithSignedIntegerSelectorFieldClass
,
1033 native_bt
.FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD
: _VariantFieldClassWithoutSelector
,
1034 native_bt
.FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
: _VariantFieldClassWithUnsignedIntegerSelector
,
1035 native_bt
.FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
: _VariantFieldClassWithSignedIntegerSelector
,