1 # SPDX-License-Identifier: MIT
3 # Copyright (c) 2018 Francis Deslauriers <francis.deslauriers@efficios.com>
6 from bt2
import native_bt
, object
10 PACKET_CONTEXT
= native_bt
.FIELD_PATH_SCOPE_PACKET_CONTEXT
11 EVENT_COMMON_CONTEXT
= native_bt
.FIELD_PATH_SCOPE_EVENT_COMMON_CONTEXT
12 EVENT_SPECIFIC_CONTEXT
= native_bt
.FIELD_PATH_SCOPE_EVENT_SPECIFIC_CONTEXT
13 EVENT_PAYLOAD
= native_bt
.FIELD_PATH_SCOPE_EVENT_PAYLOAD
20 class _IndexFieldPathItem(_FieldPathItem
):
21 def __init__(self
, index
):
29 class _CurrentArrayElementFieldPathItem(_FieldPathItem
):
33 class _CurrentOptionContentFieldPathItem(_FieldPathItem
):
37 class _FieldPathConst(object._SharedObject
, collections
.abc
.Iterable
):
38 _get_ref
= staticmethod(native_bt
.field_path_get_ref
)
39 _put_ref
= staticmethod(native_bt
.field_path_put_ref
)
43 scope
= native_bt
.field_path_get_root_scope(self
._ptr
)
44 return _SCOPE_TO_OBJ
[scope
]
47 return native_bt
.field_path_get_item_count(self
._ptr
)
50 for idx
in range(len(self
)):
51 item_ptr
= native_bt
.field_path_borrow_item_by_index_const(self
._ptr
, idx
)
52 assert item_ptr
is not None
53 item_type
= native_bt
.field_path_item_get_type(item_ptr
)
54 if item_type
== native_bt
.FIELD_PATH_ITEM_TYPE_INDEX
:
55 idx
= native_bt
.field_path_item_index_get_index(item_ptr
)
56 yield _IndexFieldPathItem(idx
)
57 elif item_type
== native_bt
.FIELD_PATH_ITEM_TYPE_CURRENT_ARRAY_ELEMENT
:
58 yield _CurrentArrayElementFieldPathItem()
59 elif item_type
== native_bt
.FIELD_PATH_ITEM_TYPE_CURRENT_OPTION_CONTENT
:
60 yield _CurrentOptionContentFieldPathItem()
66 native_bt
.FIELD_PATH_SCOPE_PACKET_CONTEXT
: FieldPathScope
.PACKET_CONTEXT
,
67 native_bt
.FIELD_PATH_SCOPE_EVENT_COMMON_CONTEXT
: FieldPathScope
.EVENT_COMMON_CONTEXT
,
68 native_bt
.FIELD_PATH_SCOPE_EVENT_SPECIFIC_CONTEXT
: FieldPathScope
.EVENT_SPECIFIC_CONTEXT
,
69 native_bt
.FIELD_PATH_SCOPE_EVENT_PAYLOAD
: FieldPathScope
.EVENT_PAYLOAD
,