1 # The MIT License (MIT)
3 # Copyright (c) 2016-2017 Philippe Proulx <pproulx@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
23 from bt2
import native_bt
, object, utils
24 from bt2
import event_class
as bt2_event_class
25 from bt2
import packet
as bt2_packet
26 from bt2
import stream
as bt2_stream
27 from bt2
import field
as bt2_field
30 class _EventConst(object._UniqueObject
):
31 _borrow_class_ptr
= staticmethod(native_bt
.event_borrow_class_const
)
32 _borrow_packet_ptr
= staticmethod(native_bt
.event_borrow_packet_const
)
33 _borrow_stream_ptr
= staticmethod(native_bt
.event_borrow_stream_const
)
34 _borrow_common_context_field_ptr
= staticmethod(
35 native_bt
.event_borrow_common_context_field_const
37 _borrow_specific_context_field_ptr
= staticmethod(
38 native_bt
.event_borrow_specific_context_field_const
40 _borrow_payload_field_ptr
= staticmethod(native_bt
.event_borrow_payload_field_const
)
41 _create_field_from_ptr
= staticmethod(bt2_field
._create
_field
_from
_const
_ptr
)
43 _event_class_pycls
= property(lambda _
: bt2_event_class
._EventClassConst
)
44 _packet_pycls
= property(lambda _
: bt2_packet
._PacketConst
)
45 _stream_pycls
= property(lambda _
: bt2_stream
._StreamConst
)
49 event_class_ptr
= self
._borrow
_class
_ptr
(self
._ptr
)
50 assert event_class_ptr
is not None
51 return self
._event
_class
_pycls
._create
_from
_ptr
_and
_get
_ref
(event_class_ptr
)
63 packet_ptr
= self
._borrow
_packet
_ptr
(self
._ptr
)
65 if packet_ptr
is None:
68 return self
._packet
_pycls
._create
_from
_ptr
_and
_get
_ref
(packet_ptr
)
72 stream_ptr
= self
._borrow
_stream
_ptr
(self
._ptr
)
73 assert stream_ptr
is not None
74 return self
._stream
_pycls
._create
_from
_ptr
_and
_get
_ref
(stream_ptr
)
77 def common_context_field(self
):
78 field_ptr
= self
._borrow
_common
_context
_field
_ptr
(self
._ptr
)
83 return self
._create
_field
_from
_ptr
(
84 field_ptr
, self
._owner
_ptr
, self
._owner
_get
_ref
, self
._owner
_put
_ref
88 def specific_context_field(self
):
89 field_ptr
= self
._borrow
_specific
_context
_field
_ptr
(self
._ptr
)
94 return self
._create
_field
_from
_ptr
(
95 field_ptr
, self
._owner
_ptr
, self
._owner
_get
_ref
, self
._owner
_put
_ref
99 def payload_field(self
):
100 field_ptr
= self
._borrow
_payload
_field
_ptr
(self
._ptr
)
102 if field_ptr
is None:
105 return self
._create
_field
_from
_ptr
(
106 field_ptr
, self
._owner
_ptr
, self
._owner
_get
_ref
, self
._owner
_put
_ref
109 def __getitem__(self
, key
):
110 utils
._check
_str
(key
)
111 payload_field
= self
.payload_field
113 if payload_field
is not None and key
in payload_field
:
114 return payload_field
[key
]
116 specific_context_field
= self
.specific_context_field
118 if specific_context_field
is not None and key
in specific_context_field
:
119 return specific_context_field
[key
]
121 common_context_field
= self
.common_context_field
123 if common_context_field
is not None and key
in common_context_field
:
124 return common_context_field
[key
]
126 packet_context_field
= self
.packet
.context_field
128 if packet_context_field
is not None and key
in packet_context_field
:
129 return packet_context_field
[key
]
134 class _Event(_EventConst
):
135 _borrow_class_ptr
= staticmethod(native_bt
.event_borrow_class
)
136 _borrow_packet_ptr
= staticmethod(native_bt
.event_borrow_packet
)
137 _borrow_stream_ptr
= staticmethod(native_bt
.event_borrow_stream
)
138 _borrow_common_context_field_ptr
= staticmethod(
139 native_bt
.event_borrow_common_context_field
141 _borrow_specific_context_field_ptr
= staticmethod(
142 native_bt
.event_borrow_specific_context_field
144 _borrow_payload_field_ptr
= staticmethod(native_bt
.event_borrow_payload_field
)
145 _create_field_from_ptr
= staticmethod(bt2_field
._create
_field
_from
_ptr
)
147 _event_class_pycls
= property(lambda _
: bt2_event_class
._EventClass
)
148 _packet_pycls
= property(lambda _
: bt2_packet
._Packet
)
149 _stream_pycls
= property(lambda _
: bt2_stream
._Stream
)