1 # SPDX-License-Identifier: MIT
3 # Copyright (c) 2016-2017 Philippe Proulx <pproulx@efficios.com>
5 from bt2
import error
as bt2_error
6 from bt2
import utils
as bt2_utils
7 from bt2
import value
as bt2_value
8 from bt2
import object as bt2_object
9 from bt2
import packet
as bt2_packet
10 from bt2
import native_bt
11 from bt2
import stream_class
as bt2_stream_class
15 from bt2
import trace
as bt2_trace
20 class _StreamConst(bt2_object
._SharedObject
):
23 native_bt
.stream_get_ref(ptr
)
27 native_bt
.stream_put_ref(ptr
)
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
33 _create_value_from_ptr_and_get_ref
= staticmethod(
34 bt2_value
._create
_from
_const
_ptr
_and
_get
_ref
36 _borrow_trace_ptr
= staticmethod(native_bt
.stream_borrow_trace_const
)
37 _stream_class_pycls
= bt2_stream_class
._StreamClassConst
38 _trace_pycls
= property(lambda _
: _bt2_trace()._TraceConst
)
42 stream_class_ptr
= self
._borrow
_class
_ptr
(self
._ptr
)
43 assert stream_class_ptr
is not None
44 return self
._stream
_class
_pycls
._create
_from
_ptr
_and
_get
_ref
(stream_class_ptr
)
48 return native_bt
.stream_get_name(self
._ptr
)
51 def user_attributes(self
):
52 ptr
= self
._borrow
_user
_attributes
_ptr
(self
._ptr
)
53 assert ptr
is not None
54 return self
._create
_value
_from
_ptr
_and
_get
_ref
(ptr
)
58 id = native_bt
.stream_get_id(self
._ptr
)
59 return id if id >= 0 else None
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
)
68 class _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
74 _borrow_trace_ptr
= staticmethod(native_bt
.stream_borrow_trace
)
75 _stream_class_pycls
= bt2_stream_class
._StreamClass
76 _trace_pycls
= property(lambda _
: _bt2_trace()._Trace
)
78 def create_packet(self
):
79 if not self
.cls
.supports_packets
:
81 "cannot create packet: stream class does not support packets"
84 packet_ptr
= native_bt
.packet_create(self
._ptr
)
86 if packet_ptr
is None:
87 raise bt2_error
._MemoryError
("cannot create packet object")
89 return bt2_packet
._Packet
._create
_from
_ptr
(packet_ptr
)
91 def _user_attributes(self
, user_attributes
):
92 value
= bt2_value
.create_value(user_attributes
)
93 bt2_utils
._check
_type
(value
, bt2_value
.MapValue
)
94 native_bt
.stream_set_user_attributes(self
._ptr
, value
._ptr
)
96 _user_attributes
= property(
97 fget
=_StreamConst
.user_attributes
.fget
, fset
=_user_attributes
100 def _name(self
, name
):
101 bt2_utils
._check
_str
(name
)
102 native_bt
.stream_set_name(self
._ptr
, name
)
104 _name
= property(fget
=_StreamConst
.name
.fget
, fset
=_name
)