1 # SPDX-License-Identifier: MIT
3 # Copyright (c) 2016-2017 Philippe Proulx <pproulx@efficios.com>
5 from bt2
import native_bt
, utils
6 from bt2
import object as bt2_object
7 from bt2
import packet
as bt2_packet
8 from bt2
import stream_class
as bt2_stream_class
9 from bt2
import value
as bt2_value
14 from bt2
import trace
as bt2_trace
19 class _StreamConst(bt2_object
._SharedObject
):
20 _get_ref
= staticmethod(native_bt
.stream_get_ref
)
21 _put_ref
= staticmethod(native_bt
.stream_put_ref
)
22 _borrow_class_ptr
= staticmethod(native_bt
.stream_borrow_class_const
)
23 _borrow_user_attributes_ptr
= staticmethod(
24 native_bt
.stream_borrow_user_attributes_const
26 _create_value_from_ptr_and_get_ref
= staticmethod(
27 bt2_value
._create
_from
_const
_ptr
_and
_get
_ref
29 _borrow_trace_ptr
= staticmethod(native_bt
.stream_borrow_trace_const
)
30 _stream_class_pycls
= bt2_stream_class
._StreamClassConst
31 _trace_pycls
= property(lambda _
: _bt2_trace()._TraceConst
)
35 stream_class_ptr
= self
._borrow
_class
_ptr
(self
._ptr
)
36 assert stream_class_ptr
is not None
37 return self
._stream
_class
_pycls
._create
_from
_ptr
_and
_get
_ref
(stream_class_ptr
)
41 return native_bt
.stream_get_name(self
._ptr
)
44 def user_attributes(self
):
45 ptr
= self
._borrow
_user
_attributes
_ptr
(self
._ptr
)
46 assert ptr
is not None
47 return self
._create
_value
_from
_ptr
_and
_get
_ref
(ptr
)
51 id = native_bt
.stream_get_id(self
._ptr
)
52 return id if id >= 0 else None
56 trace_ptr
= self
._borrow
_trace
_ptr
(self
._ptr
)
57 assert trace_ptr
is not None
58 return self
._trace
_pycls
._create
_from
_ptr
_and
_get
_ref
(trace_ptr
)
61 class _Stream(_StreamConst
):
62 _borrow_class_ptr
= staticmethod(native_bt
.stream_borrow_class
)
63 _borrow_user_attributes_ptr
= staticmethod(native_bt
.stream_borrow_user_attributes
)
64 _create_value_from_ptr_and_get_ref
= staticmethod(
65 bt2_value
._create
_from
_ptr
_and
_get
_ref
67 _borrow_trace_ptr
= staticmethod(native_bt
.stream_borrow_trace
)
68 _stream_class_pycls
= bt2_stream_class
._StreamClass
69 _trace_pycls
= property(lambda _
: _bt2_trace()._Trace
)
71 def create_packet(self
):
72 if not self
.cls
.supports_packets
:
74 'cannot create packet: stream class does not support packets'
77 packet_ptr
= native_bt
.packet_create(self
._ptr
)
79 if packet_ptr
is None:
80 raise bt2
._MemoryError('cannot create packet object')
82 return bt2_packet
._Packet
._create
_from
_ptr
(packet_ptr
)
84 def _user_attributes(self
, user_attributes
):
85 value
= bt2_value
.create_value(user_attributes
)
86 utils
._check
_type
(value
, bt2_value
.MapValue
)
87 native_bt
.stream_set_user_attributes(self
._ptr
, value
._ptr
)
89 _user_attributes
= property(
90 fget
=_StreamConst
.user_attributes
.fget
, fset
=_user_attributes
93 def _name(self
, name
):
94 utils
._check
_str
(name
)
95 native_bt
.stream_set_name(self
._ptr
, name
)
97 _name
= property(fget
=_StreamConst
.name
.fget
, fset
=_name
)