cpp-common/bt2c/fmt.hpp: use `wise_enum::string_type` in `EnableIfIsWiseEnum` definition
[babeltrace.git] / src / bindings / python / bt2 / bt2 / packet.py
1 # SPDX-License-Identifier: MIT
2 #
3 # Copyright (c) 2016-2017 Philippe Proulx <pproulx@efficios.com>
4
5 from bt2 import field as bt2_field
6 from bt2 import object as bt2_object
7 from bt2 import native_bt
8
9
10 def _bt2_stream():
11 from bt2 import stream as bt2_stream
12
13 return bt2_stream
14
15
16 class _PacketConst(bt2_object._SharedObject):
17 @staticmethod
18 def _get_ref(ptr):
19 native_bt.packet_get_ref(ptr)
20
21 @staticmethod
22 def _put_ref(ptr):
23 native_bt.packet_put_ref(ptr)
24
25 _borrow_stream_ptr = staticmethod(native_bt.packet_borrow_stream_const)
26 _borrow_context_field_ptr = staticmethod(
27 native_bt.packet_borrow_context_field_const
28 )
29 _stream_pycls = property(lambda _: _bt2_stream()._StreamConst)
30 _create_field_from_ptr = staticmethod(bt2_field._create_field_from_const_ptr)
31
32 @property
33 def stream(self):
34 stream_ptr = self._borrow_stream_ptr(self._ptr)
35 assert stream_ptr is not None
36 return self._stream_pycls._create_from_ptr_and_get_ref(stream_ptr)
37
38 @property
39 def context_field(self):
40 field_ptr = self._borrow_context_field_ptr(self._ptr)
41
42 if field_ptr is None:
43 return
44
45 return self._create_field_from_ptr(
46 field_ptr, self._ptr, self._get_ref, self._put_ref
47 )
48
49
50 class _Packet(_PacketConst):
51 _borrow_stream_ptr = staticmethod(native_bt.packet_borrow_stream)
52 _borrow_context_field_ptr = staticmethod(native_bt.packet_borrow_context_field)
53 _stream_pycls = property(lambda _: _bt2_stream()._Stream)
54 _create_field_from_ptr = staticmethod(bt2_field._create_field_from_ptr)
This page took 0.029659 seconds and 4 git commands to generate.