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(self
._ptr
, idx
)
52 assert ec_ptr
is not None
54 id = native_bt
.event_class_get_id(ec_ptr
)
59 def create_event_class(self
, id=None, name
=None, log_level
=None, emf_uri
=None,
60 specific_context_field_class
=None,
61 payload_field_class
=None):
62 if self
.assigns_automatic_event_class_id
:
64 raise ValueError('id provided, but stream class assigns automatic event class ids')
66 ec_ptr
= native_bt
.event_class_create(self
._ptr
)
69 raise ValueError('id not provided, but stream class does not assign automatic event class ids')
71 utils
._check
_uint
64(id)
72 ec_ptr
= native_bt
.event_class_create_with_id(self
._ptr
, id)
74 event_class
= bt2
.event_class
._EventClass
._create
_from
_ptr
(ec_ptr
)
77 event_class
._name
= name
79 if log_level
is not None:
80 event_class
._log
_level
= log_level
82 if emf_uri
is not None:
83 event_class
._emf
_uri
= emf_uri
85 if specific_context_field_class
is not None:
86 event_class
._specific
_context
_field
_class
= specific_context_field_class
88 if payload_field_class
is not None:
89 event_class
._payload
_field
_class
= payload_field_class
94 def trace_class(self
):
95 tc_ptr
= native_bt
.stream_class_borrow_trace_class_const(self
._ptr
)
97 if tc_ptr
is not None:
98 return bt2
._TraceClass
._create
_from
_ptr
_and
_get
_ref
(tc_ptr
)
102 return native_bt
.stream_class_get_name(self
._ptr
)
104 def _name(self
, name
):
105 utils
._check
_str
(name
)
106 ret
= native_bt
.stream_class_set_name(self
._ptr
, name
)
107 utils
._handle
_ret
(ret
, "cannot set stream class object's name")
109 _name
= property(fset
=_name
)
112 def assigns_automatic_event_class_id(self
):
113 return native_bt
.stream_class_assigns_automatic_event_class_id(self
._ptr
)
115 def _assigns_automatic_event_class_id(self
, auto_id
):
116 utils
._check
_bool
(auto_id
)
117 return native_bt
.stream_class_set_assigns_automatic_event_class_id(self
._ptr
, auto_id
)
119 _assigns_automatic_event_class_id
= property(fset
=_assigns_automatic_event_class_id
)
122 def assigns_automatic_stream_id(self
):
123 return native_bt
.stream_class_assigns_automatic_stream_id(self
._ptr
)
125 def _assigns_automatic_stream_id(self
, auto_id
):
126 utils
._check
_bool
(auto_id
)
127 return native_bt
.stream_class_set_assigns_automatic_stream_id(self
._ptr
, auto_id
)
129 _assigns_automatic_stream_id
= property(fset
=_assigns_automatic_stream_id
)
132 def packets_have_beginning_default_clock_snapshot(self
):
133 return native_bt
.stream_class_packets_have_beginning_default_clock_snapshot(self
._ptr
)
135 def _packets_have_beginning_default_clock_snapshot(self
, value
):
136 utils
._check
_bool
(value
)
137 native_bt
.stream_class_set_packets_have_beginning_default_clock_snapshot(self
._ptr
, value
)
139 _packets_have_beginning_default_clock_snapshot
= property(fset
=_packets_have_beginning_default_clock_snapshot
)
142 def packets_have_end_default_clock_snapshot(self
):
143 return native_bt
.stream_class_packets_have_end_default_clock_snapshot(self
._ptr
)
145 def _packets_have_end_default_clock_snapshot(self
, value
):
146 utils
._check
_bool
(value
)
147 native_bt
.stream_class_set_packets_have_end_default_clock_snapshot(self
._ptr
, value
)
149 _packets_have_end_default_clock_snapshot
= property(fset
=_packets_have_end_default_clock_snapshot
)
152 def supports_discarded_events(self
):
153 return native_bt
.stream_class_supports_discarded_events(self
._ptr
)
155 def _set_supports_discarded_events(self
, supports
, with_cs
=False):
156 utils
._check
_bool
(supports
)
157 utils
._check
_bool
(with_cs
)
159 if not supports
and with_cs
:
160 raise ValueError('cannot not support discarded events, but have default clock snapshots')
162 native_bt
.stream_class_set_supports_discarded_events(self
._ptr
, supports
, with_cs
)
165 def discarded_events_have_default_clock_snapshots(self
):
166 return native_bt
.stream_class_discarded_events_have_default_clock_snapshots(self
._ptr
)
169 def supports_discarded_packets(self
):
170 return native_bt
.stream_class_supports_discarded_packets(self
._ptr
)
172 def _set_supports_discarded_packets(self
, supports
, with_cs
):
173 utils
._check
_bool
(supports
)
174 utils
._check
_bool
(with_cs
)
176 if not supports
and with_cs
:
177 raise ValueError('cannot not support discarded packets, but have default clock snapshots')
179 native_bt
.stream_class_set_supports_discarded_packets(self
._ptr
, supports
, with_cs
)
182 def discarded_packets_have_default_clock_snapshots(self
):
183 return native_bt
.stream_class_discarded_packets_have_default_clock_snapshots(self
._ptr
)
187 id = native_bt
.stream_class_get_id(self
._ptr
)
196 utils
._check
_int
64(id)
197 ret
= native_bt
.stream_class_set_id(self
._ptr
, id)
198 utils
._handle
_ret
(ret
, "cannot set stream class object's ID")
201 def packet_context_field_class(self
):
202 fc_ptr
= native_bt
.stream_class_borrow_packet_context_field_class_const(self
._ptr
)
207 return bt2
.field_class
._create
_field
_class
_from
_ptr
_and
_get
_ref
(fc_ptr
)
209 def _packet_context_field_class(self
, packet_context_field_class
):
210 if packet_context_field_class
is not None:
211 utils
._check
_type
(packet_context_field_class
,
212 bt2
.field_class
._StructureFieldClass
)
213 ret
= native_bt
.stream_class_set_packet_context_field_class(self
._ptr
,
214 packet_context_field_class
._ptr
)
215 utils
._handle
_ret
(ret
, "cannot set stream class' packet context field class")
217 _packet_context_field_class
= property(fset
=_packet_context_field_class
)
220 def event_common_context_field_class(self
):
221 fc_ptr
= native_bt
.stream_class_borrow_event_common_context_field_class_const(self
._ptr
)
226 return bt2
.field_class
._create
_field
_class
_from
_ptr
_and
_get
_ref
(fc_ptr
)
228 def _event_common_context_field_class(self
, event_common_context_field_class
):
229 if event_common_context_field_class
is not None:
230 utils
._check
_type
(event_common_context_field_class
,
231 bt2
.field_class
._StructureFieldClass
)
233 set_context_fn
= native_bt
.stream_class_set_event_common_context_field_class
234 ret
= set_context_fn(self
._ptr
, event_common_context_field_class
._ptr
)
236 utils
._handle
_ret
(ret
, "cannot set stream class' event context field type")
238 _event_common_context_field_class
= property(fset
=_event_common_context_field_class
)
241 def default_clock_class(self
):
242 cc_ptr
= native_bt
.stream_class_borrow_default_clock_class(self
._ptr
)
246 return bt2
.clock_class
._ClockClass
._create
_from
_ptr
_and
_get
_ref
(cc_ptr
)
248 def _default_clock_class(self
, clock_class
):
249 utils
._check
_type
(clock_class
, bt2
.clock_class
._ClockClass
)
250 native_bt
.stream_class_set_default_clock_class(
251 self
._ptr
, clock_class
._ptr
)
253 _default_clock_class
= property(fset
=_default_clock_class
)