Remove everything related to the `bt2.ctf_writer` Python module
[babeltrace.git] / bindings / python / bt2 / bt2 / stream_class.py
CommitLineData
81447b5b
PP
1# The MIT License (MIT)
2#
811644b8 3# Copyright (c) 2017 Philippe Proulx <pproulx@efficios.com>
81447b5b
PP
4#
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:
11#
12# The above copyright notice and this permission notice shall be included in
13# all copies or substantial portions of the Software.
14#
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
21# THE SOFTWARE.
22
23from bt2 import native_bt, object, utils
b4f45851 24import bt2.field_class
81447b5b 25import collections.abc
81447b5b 26import bt2.stream
81447b5b
PP
27import bt2
28
29
78288f58 30class StreamClass(object._SharedObject, collections.abc.Mapping):
fbbe9302
SM
31 _get_ref = staticmethod(native_bt.stream_class_get_ref)
32 _put_ref = staticmethod(native_bt.stream_class_put_ref)
33
81447b5b 34 def __getitem__(self, key):
811644b8 35 utils._check_int64(key)
3cdfbaea 36 ec_ptr = native_bt.stream_class_borrow_event_class_by_id(self._ptr, key)
81447b5b
PP
37
38 if ec_ptr is None:
39 raise KeyError(key)
40
3cdfbaea 41 return bt2.EventClass._create_from_ptr_and_get_ref(ec_ptr)
81447b5b
PP
42
43 def __len__(self):
50842bdc 44 count = native_bt.stream_class_get_event_class_count(self._ptr)
3cdfbaea 45 assert count >= 0
81447b5b
PP
46 return count
47
48 def __iter__(self):
3cdfbaea
SM
49 for idx in range(len(self)):
50 ec_ptr = native_bt.stream_class_borrow_event_class_by_index_const(self._ptr, idx)
51 assert ec_ptr is not None
52
53 id = native_bt.event_class_get_id(ec_ptr)
54 assert id >= 0
55
56 yield id
81447b5b 57
af4bbfc7
SM
58 def create_event_class(self, id=None, name=None, log_level=None, emf_uri=None,
59 specific_context_field_class=None,
60 payload_field_class=None):
3cdfbaea
SM
61 if self.assigns_automatic_event_class_id:
62 if id is not None:
4430bc80 63 raise ValueError('id provided, but stream class assigns automatic event class ids')
3cdfbaea
SM
64
65 ec_ptr = native_bt.event_class_create(self._ptr)
66 else:
67 if id is None:
4430bc80 68 raise ValueError('id not provided, but stream class does not assign automatic event class ids')
3cdfbaea
SM
69
70 utils._check_uint64(id)
71 ec_ptr = native_bt.event_class_create_with_id(self._ptr, id)
72
af4bbfc7
SM
73 event_class = bt2.event_class.EventClass._create_from_ptr(ec_ptr)
74
75 if name is not None:
76 event_class._name = name
77
78 if log_level is not None:
79 event_class._log_level = log_level
80
81 if emf_uri is not None:
82 event_class._emf_uri = emf_uri
83
84 if specific_context_field_class is not None:
85 event_class._specific_context_field_class = specific_context_field_class
86
87 if payload_field_class is not None:
88 event_class._payload_field_class = payload_field_class
89
90 return event_class
81447b5b
PP
91
92 @property
3cdfbaea
SM
93 def trace_class(self):
94 tc_ptr = native_bt.stream_class_borrow_trace_class_const(self._ptr)
81447b5b
PP
95
96 if tc_ptr is not None:
3cdfbaea 97 return bt2.TraceClass._create_from_ptr_and_get_ref(tc_ptr)
81447b5b
PP
98
99 @property
100 def name(self):
50842bdc 101 return native_bt.stream_class_get_name(self._ptr)
81447b5b 102
3cdfbaea 103 def _name(self, name):
81447b5b 104 utils._check_str(name)
50842bdc 105 ret = native_bt.stream_class_set_name(self._ptr, name)
81447b5b
PP
106 utils._handle_ret(ret, "cannot set stream class object's name")
107
3cdfbaea
SM
108 _name = property(fset=_name)
109
110 @property
111 def assigns_automatic_event_class_id(self):
112 return native_bt.stream_class_assigns_automatic_event_class_id(self._ptr)
113
114 def _assigns_automatic_event_class_id(self, auto_id):
115 utils._check_bool(auto_id)
116 return native_bt.stream_class_set_assigns_automatic_event_class_id(self._ptr, auto_id)
117
118 _assigns_automatic_event_class_id = property(fset=_assigns_automatic_event_class_id)
119
8c2367b8
SM
120 @property
121 def assigns_automatic_stream_id(self):
122 return native_bt.stream_class_assigns_automatic_stream_id(self._ptr)
123
124 def _assigns_automatic_stream_id(self, auto_id):
125 utils._check_bool(auto_id)
126 return native_bt.stream_class_set_assigns_automatic_stream_id(self._ptr, auto_id)
127
128 _assigns_automatic_stream_id = property(fset=_assigns_automatic_stream_id)
129
3cdfbaea 130 @property
9b24b6aa
PP
131 def packets_have_beginning_default_clock_snapshot(self):
132 return native_bt.stream_class_packets_have_beginning_default_clock_snapshot(self._ptr)
3cdfbaea 133
9b24b6aa 134 def _packets_have_beginning_default_clock_snapshot(self, value):
3cdfbaea 135 utils._check_bool(value)
9b24b6aa 136 native_bt.stream_class_set_packets_have_beginning_default_clock_snapshot(self._ptr, value)
3cdfbaea 137
9b24b6aa 138 _packets_have_beginning_default_clock_snapshot = property(fset=_packets_have_beginning_default_clock_snapshot)
3cdfbaea
SM
139
140 @property
9b24b6aa
PP
141 def packets_have_end_default_clock_snapshot(self):
142 return native_bt.stream_class_packets_have_end_default_clock_snapshot(self._ptr)
3cdfbaea 143
9b24b6aa 144 def _packets_have_end_default_clock_snapshot(self, value):
3cdfbaea 145 utils._check_bool(value)
9b24b6aa 146 native_bt.stream_class_set_packets_have_end_default_clock_snapshot(self._ptr, value)
3cdfbaea 147
9b24b6aa 148 _packets_have_end_default_clock_snapshot = property(fset=_packets_have_end_default_clock_snapshot)
3cdfbaea 149
2e90378a
PP
150 @property
151 def supports_discarded_events(self):
152 return native_bt.stream_class_supports_discarded_events(self._ptr)
153
154 def _set_supports_discarded_events(self, supports, with_cs=False):
155 utils._check_bool(supports)
156 utils._check_bool(with_cs)
157
158 if not supports and with_cs:
159 raise ValueError('cannot not support discarded events, but have default clock snapshots')
160
161 native_bt.stream_class_set_supports_discarded_events(self._ptr, supports, with_cs)
162
163 @property
164 def discarded_events_have_default_clock_snapshots(self):
165 return native_bt.stream_class_discarded_events_have_default_clock_snapshots(self._ptr)
166
167 @property
168 def supports_discarded_packets(self):
169 return native_bt.stream_class_supports_discarded_packets(self._ptr)
170
171 def _set_supports_discarded_packets(self, supports, with_cs):
172 utils._check_bool(supports)
173 utils._check_bool(with_cs)
174
175 if not supports and with_cs:
176 raise ValueError('cannot not support discarded packets, but have default clock snapshots')
177
178 native_bt.stream_class_set_supports_discarded_packets(self._ptr, supports, with_cs)
179
180 @property
181 def discarded_packets_have_default_clock_snapshots(self):
182 return native_bt.stream_class_discarded_packets_have_default_clock_snapshots(self._ptr)
183
81447b5b
PP
184 @property
185 def id(self):
50842bdc 186 id = native_bt.stream_class_get_id(self._ptr)
81447b5b 187
811644b8
PP
188 if id < 0:
189 return
81447b5b
PP
190
191 return id
192
193 @id.setter
194 def id(self, id):
195 utils._check_int64(id)
50842bdc 196 ret = native_bt.stream_class_set_id(self._ptr, id)
81447b5b
PP
197 utils._handle_ret(ret, "cannot set stream class object's ID")
198
81447b5b 199 @property
b4f45851 200 def packet_context_field_class(self):
3cdfbaea 201 fc_ptr = native_bt.stream_class_borrow_packet_context_field_class_const(self._ptr)
81447b5b 202
b4f45851 203 if fc_ptr is None:
81447b5b
PP
204 return
205
3cdfbaea 206 return bt2.field_class._create_field_class_from_ptr_and_get_ref(fc_ptr)
81447b5b 207
3cdfbaea 208 def _packet_context_field_class(self, packet_context_field_class):
b4f45851 209 if packet_context_field_class is not None:
3cdfbaea
SM
210 utils._check_type(packet_context_field_class,
211 bt2.field_class._StructureFieldClass)
212 ret = native_bt.stream_class_set_packet_context_field_class(self._ptr,
213 packet_context_field_class._ptr)
214 utils._handle_ret(ret, "cannot set stream class' packet context field class")
81447b5b 215
3cdfbaea 216 _packet_context_field_class = property(fset=_packet_context_field_class)
81447b5b
PP
217
218 @property
3cdfbaea
SM
219 def event_common_context_field_class(self):
220 fc_ptr = native_bt.stream_class_borrow_event_common_context_field_class_const(self._ptr)
81447b5b 221
b4f45851 222 if fc_ptr is None:
81447b5b
PP
223 return
224
3cdfbaea 225 return bt2.field_class._create_field_class_from_ptr_and_get_ref(fc_ptr)
81447b5b 226
3cdfbaea
SM
227 def _event_common_context_field_class(self, event_common_context_field_class):
228 if event_common_context_field_class is not None:
229 utils._check_type(event_common_context_field_class,
230 bt2.field_class._StructureFieldClass)
81447b5b 231
3cdfbaea
SM
232 set_context_fn = native_bt.stream_class_set_event_common_context_field_class
233 ret = set_context_fn(self._ptr, event_common_context_field_class._ptr)
81447b5b 234
3cdfbaea 235 utils._handle_ret(ret, "cannot set stream class' event context field type")
81447b5b 236
3cdfbaea 237 _event_common_context_field_class = property(fset=_event_common_context_field_class)
81447b5b 238
3cdfbaea
SM
239 @property
240 def default_clock_class(self):
241 cc_ptr = native_bt.stream_class_borrow_default_clock_class(self._ptr)
242 if cc_ptr is None:
81447b5b
PP
243 return
244
be7bbff9 245 return bt2.clock_class._ClockClass._create_from_ptr_and_get_ref(cc_ptr)
81447b5b 246
3cdfbaea 247 def _default_clock_class(self, clock_class):
be7bbff9 248 utils._check_type(clock_class, bt2.clock_class._ClockClass)
3cdfbaea
SM
249 native_bt.stream_class_set_default_clock_class(
250 self._ptr, clock_class._ptr)
81447b5b 251
3cdfbaea 252 _default_clock_class = property(fset=_default_clock_class)
This page took 0.050556 seconds and 4 git commands to generate.