bt2: Adapt test_field.py and make it pass
[babeltrace.git] / 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
24import bt2.clock_class
25import bt2.packet
26import bt2.stream
c4239792 27import bt2.field
4b552f8b 28import bt2.clock_snapshot
81447b5b
PP
29import bt2
30
31
78288f58 32class _Event(object._UniqueObject):
81447b5b
PP
33 @property
34 def event_class(self):
2ae9f48c
SM
35 event_class_ptr = native_bt.event_borrow_class(self._ptr)
36 assert event_class_ptr is not None
37 return bt2.EventClass._create_from_ptr_and_get_ref(event_class_ptr)
81447b5b
PP
38
39 @property
40 def name(self):
2ae9f48c 41 return self.event_class.name
81447b5b
PP
42
43 @property
44 def id(self):
2ae9f48c 45 return self.event_class.id
81447b5b
PP
46
47 @property
48 def packet(self):
2ae9f48c
SM
49 packet_ptr = native_bt.event_borrow_packet(self._ptr)
50 assert packet_ptr is not None
51 return bt2.packet._Packet._create_from_ptr_and_get_ref(packet_ptr)
81447b5b
PP
52
53 @property
54 def stream(self):
2ae9f48c
SM
55 stream_ptr = native_bt.event_borrow_stream(self._ptr)
56 assert stream_ptr is not None
57 return bt2._Stream._create_from_ptr_and_get_ref(stream_ptr)
81447b5b
PP
58
59 @property
2ae9f48c
SM
60 def common_context_field(self):
61 field_ptr = native_bt.event_borrow_common_context_field(self._ptr)
81447b5b
PP
62
63 if field_ptr is None:
64 return
65
2ae9f48c
SM
66 return bt2.field._create_field_from_ptr(field_ptr, self._owner_ptr,
67 self._owner_get_ref,
68 self._owner_put_ref)
81447b5b
PP
69
70 @property
2ae9f48c
SM
71 def specific_context_field(self):
72 field_ptr = native_bt.event_borrow_specific_context_field(self._ptr)
81447b5b
PP
73
74 if field_ptr is None:
75 return
76
2ae9f48c
SM
77 return bt2.field._create_field_from_ptr(field_ptr, self._owner_ptr,
78 self._owner_get_ref,
79 self._owner_put_ref)
81447b5b
PP
80
81 @property
82 def payload_field(self):
2ae9f48c 83 field_ptr = native_bt.event_borrow_payload_field(self._ptr)
81447b5b
PP
84
85 if field_ptr is None:
86 return
87
2ae9f48c
SM
88 return bt2.field._create_field_from_ptr(field_ptr, self._owner_ptr,
89 self._owner_get_ref,
90 self._owner_put_ref)
81447b5b
PP
91
92 def __getitem__(self, key):
93 utils._check_str(key)
94 payload_field = self.payload_field
95
96 if payload_field is not None and key in payload_field:
97 return payload_field[key]
98
2ae9f48c 99 specific_context_field = self.specific_context_field
81447b5b 100
2ae9f48c
SM
101 if specific_context_field is not None and key in specific_context_field:
102 return specific_context_field[key]
81447b5b 103
2ae9f48c 104 common_context_field = self.common_context_field
81447b5b 105
2ae9f48c
SM
106 if common_context_field is not None and key in common_context_field:
107 return common_context_field[key]
81447b5b 108
2ae9f48c 109 packet_context_field = self.packet.context_field
81447b5b 110
2ae9f48c
SM
111 if packet_context_field is not None and key in packet_context_field:
112 return packet_context_field[key]
81447b5b
PP
113
114 raise KeyError(key)
This page took 0.057362 seconds and 4 git commands to generate.