1 # The MIT License (MIT)
3 # Copyright (c) 2018 Francis Deslauriers <francis.deslauriers@efficios.com>
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:
12 # The above copyright notice and this permission notice shall be included in
13 # all copies or substantial portions of the Software.
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
24 from bt2
import native_bt
, object
28 PACKET_CONTEXT
= native_bt
.FIELD_PATH_SCOPE_PACKET_CONTEXT
29 EVENT_COMMON_CONTEXT
= native_bt
.FIELD_PATH_SCOPE_EVENT_COMMON_CONTEXT
30 EVENT_SPECIFIC_CONTEXT
= native_bt
.FIELD_PATH_SCOPE_EVENT_SPECIFIC_CONTEXT
31 EVENT_PAYLOAD
= native_bt
.FIELD_PATH_SCOPE_EVENT_PAYLOAD
38 class _IndexFieldPathItem(_FieldPathItem
):
39 def __init__(self
, index
):
47 class _CurrentArrayElementFieldPathItem(_FieldPathItem
):
51 class _CurrentOptionContentFieldPathItem(_FieldPathItem
):
55 class _FieldPathConst(object._SharedObject
, collections
.abc
.Iterable
):
56 _get_ref
= staticmethod(native_bt
.field_path_get_ref
)
57 _put_ref
= staticmethod(native_bt
.field_path_put_ref
)
61 scope
= native_bt
.field_path_get_root_scope(self
._ptr
)
62 return _SCOPE_TO_OBJ
[scope
]
65 return native_bt
.field_path_get_item_count(self
._ptr
)
68 for idx
in range(len(self
)):
69 item_ptr
= native_bt
.field_path_borrow_item_by_index_const(self
._ptr
, idx
)
70 assert item_ptr
is not None
71 item_type
= native_bt
.field_path_item_get_type(item_ptr
)
72 if item_type
== native_bt
.FIELD_PATH_ITEM_TYPE_INDEX
:
73 idx
= native_bt
.field_path_item_index_get_index(item_ptr
)
74 yield _IndexFieldPathItem(idx
)
75 elif item_type
== native_bt
.FIELD_PATH_ITEM_TYPE_CURRENT_ARRAY_ELEMENT
:
76 yield _CurrentArrayElementFieldPathItem()
77 elif item_type
== native_bt
.FIELD_PATH_ITEM_TYPE_CURRENT_OPTION_CONTENT
:
78 yield _CurrentOptionContentFieldPathItem()
84 native_bt
.FIELD_PATH_SCOPE_PACKET_CONTEXT
: FieldPathScope
.PACKET_CONTEXT
,
85 native_bt
.FIELD_PATH_SCOPE_EVENT_COMMON_CONTEXT
: FieldPathScope
.EVENT_COMMON_CONTEXT
,
86 native_bt
.FIELD_PATH_SCOPE_EVENT_SPECIFIC_CONTEXT
: FieldPathScope
.EVENT_SPECIFIC_CONTEXT
,
87 native_bt
.FIELD_PATH_SCOPE_EVENT_PAYLOAD
: FieldPathScope
.EVENT_PAYLOAD
,