bt2: Add `_Clock*Const` classes and adapt tests
[babeltrace.git] / src / bindings / python / bt2 / bt2 / event.py
CommitLineData
81447b5b
PP
1# The MIT License (MIT)
2#
3# Copyright (c) 2016-2017 Philippe Proulx <pproulx@efficios.com>
4#
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:
11#
12# The above copyright notice and this permission notice shall be included in
13# all copies or substantial portions of the Software.
14#
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
21# THE SOFTWARE.
22
23from bt2 import native_bt, object, utils
3fb99a22
PP
24from bt2 import event_class as bt2_event_class
25from bt2 import packet as bt2_packet
26from bt2 import stream as bt2_stream
27from bt2 import field as bt2_field
81447b5b
PP
28
29
78288f58 30class _Event(object._UniqueObject):
81447b5b 31 @property
e8ac1aae 32 def cls(self):
2ae9f48c
SM
33 event_class_ptr = native_bt.event_borrow_class(self._ptr)
34 assert event_class_ptr is not None
3fb99a22 35 return bt2_event_class._EventClass._create_from_ptr_and_get_ref(event_class_ptr)
81447b5b
PP
36
37 @property
38 def name(self):
e8ac1aae 39 return self.cls.name
81447b5b
PP
40
41 @property
42 def id(self):
e8ac1aae 43 return self.cls.id
81447b5b
PP
44
45 @property
46 def packet(self):
2ae9f48c 47 packet_ptr = native_bt.event_borrow_packet(self._ptr)
26fc5aed
PP
48
49 if packet_ptr is None:
50 return
51
3fb99a22 52 return bt2_packet._Packet._create_from_ptr_and_get_ref(packet_ptr)
81447b5b
PP
53
54 @property
55 def stream(self):
2ae9f48c
SM
56 stream_ptr = native_bt.event_borrow_stream(self._ptr)
57 assert stream_ptr is not None
3fb99a22 58 return bt2_stream._Stream._create_from_ptr_and_get_ref(stream_ptr)
81447b5b
PP
59
60 @property
2ae9f48c
SM
61 def common_context_field(self):
62 field_ptr = native_bt.event_borrow_common_context_field(self._ptr)
81447b5b
PP
63
64 if field_ptr is None:
65 return
66
3fb99a22 67 return bt2_field._create_field_from_ptr(
cfbd7cf3
FD
68 field_ptr, self._owner_ptr, self._owner_get_ref, self._owner_put_ref
69 )
81447b5b
PP
70
71 @property
2ae9f48c
SM
72 def specific_context_field(self):
73 field_ptr = native_bt.event_borrow_specific_context_field(self._ptr)
81447b5b
PP
74
75 if field_ptr is None:
76 return
77
3fb99a22 78 return bt2_field._create_field_from_ptr(
cfbd7cf3
FD
79 field_ptr, self._owner_ptr, self._owner_get_ref, self._owner_put_ref
80 )
81447b5b
PP
81
82 @property
83 def payload_field(self):
2ae9f48c 84 field_ptr = native_bt.event_borrow_payload_field(self._ptr)
81447b5b
PP
85
86 if field_ptr is None:
87 return
88
3fb99a22 89 return bt2_field._create_field_from_ptr(
cfbd7cf3
FD
90 field_ptr, self._owner_ptr, self._owner_get_ref, self._owner_put_ref
91 )
81447b5b
PP
92
93 def __getitem__(self, key):
94 utils._check_str(key)
95 payload_field = self.payload_field
96
97 if payload_field is not None and key in payload_field:
98 return payload_field[key]
99
2ae9f48c 100 specific_context_field = self.specific_context_field
81447b5b 101
2ae9f48c
SM
102 if specific_context_field is not None and key in specific_context_field:
103 return specific_context_field[key]
81447b5b 104
2ae9f48c 105 common_context_field = self.common_context_field
81447b5b 106
2ae9f48c
SM
107 if common_context_field is not None and key in common_context_field:
108 return common_context_field[key]
81447b5b 109
2ae9f48c 110 packet_context_field = self.packet.context_field
81447b5b 111
2ae9f48c
SM
112 if packet_context_field is not None and key in packet_context_field:
113 return packet_context_field[key]
81447b5b
PP
114
115 raise KeyError(key)
This page took 0.050928 seconds and 4 git commands to generate.