1 # The MIT License (MIT)
3 # Copyright (c) 2017 Philippe Proulx <pproulx@efficios.com>
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:
12 # The above copyright notice and this permission notice shall be included in
13 # all copies or substantial portions of the Software.
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
23 from bt2
import native_bt
, object, utils
24 import bt2
.field_class
25 import bt2
.event_class
26 import collections
.abc
31 class _StreamClass(object._SharedObject
, collections
.abc
.Mapping
):
32 _get_ref
= staticmethod(native_bt
.stream_class_get_ref
)
33 _put_ref
= staticmethod(native_bt
.stream_class_put_ref
)
35 def __getitem__(self
, key
):
36 utils
._check
_int
64(key
)
37 ec_ptr
= native_bt
.stream_class_borrow_event_class_by_id(self
._ptr
, key
)
42 return bt2
.event_class
._EventClass
._create
_from
_ptr
_and
_get
_ref
(ec_ptr
)
45 count
= native_bt
.stream_class_get_event_class_count(self
._ptr
)
50 for idx
in range(len(self
)):
51 ec_ptr
= native_bt
.stream_class_borrow_event_class_by_index_const(
54 assert ec_ptr
is not None
56 id = native_bt
.event_class_get_id(ec_ptr
)
61 def create_event_class(
67 specific_context_field_class
=None,
68 payload_field_class
=None,
70 if self
.assigns_automatic_event_class_id
:
73 'id provided, but stream class assigns automatic event class ids'
76 ec_ptr
= native_bt
.event_class_create(self
._ptr
)
80 'id not provided, but stream class does not assign automatic event class ids'
83 utils
._check
_uint
64(id)
84 ec_ptr
= native_bt
.event_class_create_with_id(self
._ptr
, id)
86 event_class
= bt2
.event_class
._EventClass
._create
_from
_ptr
(ec_ptr
)
89 event_class
._name
= name
91 if log_level
is not None:
92 event_class
._log
_level
= log_level
94 if emf_uri
is not None:
95 event_class
._emf
_uri
= emf_uri
97 if specific_context_field_class
is not None:
98 event_class
._specific
_context
_field
_class
= specific_context_field_class
100 if payload_field_class
is not None:
101 event_class
._payload
_field
_class
= payload_field_class
106 def trace_class(self
):
107 tc_ptr
= native_bt
.stream_class_borrow_trace_class_const(self
._ptr
)
109 if tc_ptr
is not None:
110 return bt2
._TraceClass
._create
_from
_ptr
_and
_get
_ref
(tc_ptr
)
114 return native_bt
.stream_class_get_name(self
._ptr
)
116 def _name(self
, name
):
117 utils
._check
_str
(name
)
118 status
= native_bt
.stream_class_set_name(self
._ptr
, name
)
119 utils
._handle
_func
_status
(status
, "cannot set stream class object's name")
121 _name
= property(fset
=_name
)
124 def assigns_automatic_event_class_id(self
):
125 return native_bt
.stream_class_assigns_automatic_event_class_id(self
._ptr
)
127 def _assigns_automatic_event_class_id(self
, auto_id
):
128 utils
._check
_bool
(auto_id
)
129 return native_bt
.stream_class_set_assigns_automatic_event_class_id(
133 _assigns_automatic_event_class_id
= property(fset
=_assigns_automatic_event_class_id
)
136 def assigns_automatic_stream_id(self
):
137 return native_bt
.stream_class_assigns_automatic_stream_id(self
._ptr
)
139 def _assigns_automatic_stream_id(self
, auto_id
):
140 utils
._check
_bool
(auto_id
)
141 return native_bt
.stream_class_set_assigns_automatic_stream_id(
145 _assigns_automatic_stream_id
= property(fset
=_assigns_automatic_stream_id
)
148 def supports_packets(self
):
149 return native_bt
.stream_class_supports_packets(self
._ptr
)
152 def packets_have_beginning_default_clock_snapshot(self
):
153 return native_bt
.stream_class_packets_have_beginning_default_clock_snapshot(
158 def packets_have_end_default_clock_snapshot(self
):
159 return native_bt
.stream_class_packets_have_end_default_clock_snapshot(self
._ptr
)
161 def _set_supports_packets(self
, supports
, with_begin_cs
=False, with_end_cs
=False):
162 utils
._check
_bool
(supports
)
163 utils
._check
_bool
(with_begin_cs
)
164 utils
._check
_bool
(with_end_cs
)
166 if not supports
and (with_begin_cs
or with_end_cs
):
168 'cannot not support packets, but have default clock snapshots'
171 if not supports
and self
.packet_context_field_class
is not None:
172 raise ValueError('stream class already has a packet context field class')
174 native_bt
.stream_class_set_supports_packets(
175 self
._ptr
, supports
, with_begin_cs
, with_end_cs
179 def supports_discarded_events(self
):
180 return native_bt
.stream_class_supports_discarded_events(self
._ptr
)
182 def _set_supports_discarded_events(self
, supports
, with_cs
=False):
183 utils
._check
_bool
(supports
)
184 utils
._check
_bool
(with_cs
)
186 if not supports
and with_cs
:
188 'cannot not support discarded events, but have default clock snapshots'
191 native_bt
.stream_class_set_supports_discarded_events(
192 self
._ptr
, supports
, with_cs
196 def discarded_events_have_default_clock_snapshots(self
):
197 return native_bt
.stream_class_discarded_events_have_default_clock_snapshots(
202 def supports_discarded_packets(self
):
203 return native_bt
.stream_class_supports_discarded_packets(self
._ptr
)
205 def _set_supports_discarded_packets(self
, supports
, with_cs
):
206 utils
._check
_bool
(supports
)
207 utils
._check
_bool
(with_cs
)
209 if supports
and not self
.supports_packets
:
211 'cannot support discarded packets, but not support packets'
214 if not supports
and with_cs
:
216 'cannot not support discarded packets, but have default clock snapshots'
219 native_bt
.stream_class_set_supports_discarded_packets(
220 self
._ptr
, supports
, with_cs
224 def discarded_packets_have_default_clock_snapshots(self
):
225 return native_bt
.stream_class_discarded_packets_have_default_clock_snapshots(
231 id = native_bt
.stream_class_get_id(self
._ptr
)
240 utils
._check
_int
64(id)
241 status
= native_bt
.stream_class_set_id(self
._ptr
, id)
242 utils
._handle
_func
_status
(status
, "cannot set stream class object's ID")
245 def packet_context_field_class(self
):
246 fc_ptr
= native_bt
.stream_class_borrow_packet_context_field_class_const(
253 return bt2
.field_class
._create
_field
_class
_from
_ptr
_and
_get
_ref
(fc_ptr
)
255 def _packet_context_field_class(self
, packet_context_field_class
):
256 if packet_context_field_class
is not None:
258 packet_context_field_class
, bt2
.field_class
._StructureFieldClass
261 if not self
.supports_packets
:
262 raise ValueError('stream class does not support packets')
264 status
= native_bt
.stream_class_set_packet_context_field_class(
265 self
._ptr
, packet_context_field_class
._ptr
267 utils
._handle
_func
_status
(
268 status
, "cannot set stream class' packet context field class"
271 _packet_context_field_class
= property(fset
=_packet_context_field_class
)
274 def event_common_context_field_class(self
):
275 fc_ptr
= native_bt
.stream_class_borrow_event_common_context_field_class_const(
282 return bt2
.field_class
._create
_field
_class
_from
_ptr
_and
_get
_ref
(fc_ptr
)
284 def _event_common_context_field_class(self
, event_common_context_field_class
):
285 if event_common_context_field_class
is not None:
287 event_common_context_field_class
, bt2
.field_class
._StructureFieldClass
290 set_context_fn
= native_bt
.stream_class_set_event_common_context_field_class
291 status
= set_context_fn(self
._ptr
, event_common_context_field_class
._ptr
)
292 utils
._handle
_func
_status
(
293 status
, "cannot set stream class' event context field type"
296 _event_common_context_field_class
= property(fset
=_event_common_context_field_class
)
299 def default_clock_class(self
):
300 cc_ptr
= native_bt
.stream_class_borrow_default_clock_class(self
._ptr
)
304 return bt2
.clock_class
._ClockClass
._create
_from
_ptr
_and
_get
_ref
(cc_ptr
)
306 def _default_clock_class(self
, clock_class
):
307 utils
._check
_type
(clock_class
, bt2
.clock_class
._ClockClass
)
308 native_bt
.stream_class_set_default_clock_class(self
._ptr
, clock_class
._ptr
)
310 _default_clock_class
= property(fset
=_default_clock_class
)