cpp-common/bt2c/fmt.hpp: use `wise_enum::string_type` in `EnableIfIsWiseEnum` definition
[babeltrace.git] / src / bindings / python / bt2 / bt2 / stream.py
CommitLineData
0235b0db 1# SPDX-License-Identifier: MIT
81447b5b
PP
2#
3# Copyright (c) 2016-2017 Philippe Proulx <pproulx@efficios.com>
81447b5b 4
5995b304 5from bt2 import error as bt2_error
e5914347 6from bt2 import utils as bt2_utils
5995b304 7from bt2 import value as bt2_value
3fb99a22
PP
8from bt2 import object as bt2_object
9from bt2 import packet as bt2_packet
5995b304 10from bt2 import native_bt
3fb99a22 11from bt2 import stream_class as bt2_stream_class
81447b5b
PP
12
13
79935628
SM
14def _bt2_trace():
15 from bt2 import trace as bt2_trace
16
17 return bt2_trace
18
19
f0a42b33 20class _StreamConst(bt2_object._SharedObject):
9dee90bd
SM
21 @staticmethod
22 def _get_ref(ptr):
23 native_bt.stream_get_ref(ptr)
24
25 @staticmethod
26 def _put_ref(ptr):
27 native_bt.stream_put_ref(ptr)
28
f0a42b33
FD
29 _borrow_class_ptr = staticmethod(native_bt.stream_borrow_class_const)
30 _borrow_user_attributes_ptr = staticmethod(
31 native_bt.stream_borrow_user_attributes_const
32 )
33 _create_value_from_ptr_and_get_ref = staticmethod(
34 bt2_value._create_from_const_ptr_and_get_ref
35 )
36 _borrow_trace_ptr = staticmethod(native_bt.stream_borrow_trace_const)
37 _stream_class_pycls = bt2_stream_class._StreamClassConst
79935628 38 _trace_pycls = property(lambda _: _bt2_trace()._TraceConst)
81447b5b 39
81447b5b 40 @property
e8ac1aae 41 def cls(self):
f0a42b33 42 stream_class_ptr = self._borrow_class_ptr(self._ptr)
af4bbfc7 43 assert stream_class_ptr is not None
f0a42b33 44 return self._stream_class_pycls._create_from_ptr_and_get_ref(stream_class_ptr)
81447b5b
PP
45
46 @property
47 def name(self):
50842bdc 48 return native_bt.stream_get_name(self._ptr)
81447b5b 49
5783664e
PP
50 @property
51 def user_attributes(self):
f0a42b33 52 ptr = self._borrow_user_attributes_ptr(self._ptr)
5783664e 53 assert ptr is not None
f0a42b33 54 return self._create_value_from_ptr_and_get_ref(ptr)
5783664e 55
811644b8
PP
56 @property
57 def id(self):
50842bdc 58 id = native_bt.stream_get_id(self._ptr)
811644b8
PP
59 return id if id >= 0 else None
60
f0a42b33
FD
61 @property
62 def trace(self):
63 trace_ptr = self._borrow_trace_ptr(self._ptr)
64 assert trace_ptr is not None
65 return self._trace_pycls._create_from_ptr_and_get_ref(trace_ptr)
66
67
68class _Stream(_StreamConst):
69 _borrow_class_ptr = staticmethod(native_bt.stream_borrow_class)
70 _borrow_user_attributes_ptr = staticmethod(native_bt.stream_borrow_user_attributes)
71 _create_value_from_ptr_and_get_ref = staticmethod(
72 bt2_value._create_from_ptr_and_get_ref
73 )
74 _borrow_trace_ptr = staticmethod(native_bt.stream_borrow_trace)
75 _stream_class_pycls = bt2_stream_class._StreamClass
79935628 76 _trace_pycls = property(lambda _: _bt2_trace()._Trace)
f0a42b33 77
81447b5b 78 def create_packet(self):
26fc5aed 79 if not self.cls.supports_packets:
ce4923b0 80 raise ValueError(
f5567ea8 81 "cannot create packet: stream class does not support packets"
cfbd7cf3 82 )
26fc5aed 83
50842bdc 84 packet_ptr = native_bt.packet_create(self._ptr)
81447b5b
PP
85
86 if packet_ptr is None:
c345b078 87 raise bt2_error._MemoryError("cannot create packet object")
81447b5b 88
3fb99a22 89 return bt2_packet._Packet._create_from_ptr(packet_ptr)
e071d36f 90
f0a42b33
FD
91 def _user_attributes(self, user_attributes):
92 value = bt2_value.create_value(user_attributes)
e5914347 93 bt2_utils._check_type(value, bt2_value.MapValue)
f0a42b33
FD
94 native_bt.stream_set_user_attributes(self._ptr, value._ptr)
95
96 _user_attributes = property(
97 fget=_StreamConst.user_attributes.fget, fset=_user_attributes
98 )
99
100 def _name(self, name):
e5914347 101 bt2_utils._check_str(name)
f0a42b33
FD
102 native_bt.stream_set_name(self._ptr, name)
103
104 _name = property(fget=_StreamConst.name.fget, fset=_name)
This page took 0.099747 seconds and 4 git commands to generate.