X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=bindings%2Fpython%2Fbt2%2Fbt2%2Fstream_class.py;h=20dd006c9880327098a8eec4d82ecd81c7d590c3;hb=afd452743c7fcc89246029f68055d6f251c857e6;hp=17c6de0f975bff9e6866683f9d2f637025ab46fa;hpb=1b8fb86234d51aff255b8e97435d4dbb3316eaec;p=babeltrace.git diff --git a/bindings/python/bt2/bt2/stream_class.py b/bindings/python/bt2/bt2/stream_class.py index 17c6de0f..20dd006c 100644 --- a/bindings/python/bt2/bt2/stream_class.py +++ b/bindings/python/bt2/bt2/stream_class.py @@ -21,106 +21,170 @@ # THE SOFTWARE. from bt2 import native_bt, object, utils -import bt2.field_types +import bt2.field_class import collections.abc import bt2.ctf_writer import bt2.stream -import copy import bt2 -class _EventClassIterator(collections.abc.Iterator): - def __init__(self, stream_class): - self._stream_class = stream_class - self._at = 0 +class StreamClass(object._SharedObject, collections.abc.Mapping): + _get_ref = staticmethod(native_bt.stream_class_get_ref) + _put_ref = staticmethod(native_bt.stream_class_put_ref) - def __next__(self): - if self._at == len(self._stream_class): - raise StopIteration + def __getitem__(self, key): + utils._check_int64(key) + ec_ptr = native_bt.stream_class_borrow_event_class_by_id(self._ptr, key) - ec_ptr = native_bt.ctf_stream_class_get_event_class_by_index(self._stream_class._ptr, - self._at) - assert(ec_ptr) - ev_id = native_bt.ctf_event_class_get_id(ec_ptr) - native_bt.put(ec_ptr) - utils._handle_ret(ev_id, "cannot get event class object's ID") - self._at += 1 - return ev_id + if ec_ptr is None: + raise KeyError(key) + return bt2.EventClass._create_from_ptr_and_get_ref(ec_ptr) -class StreamClass(object._Object, collections.abc.Mapping): - def __init__(self, name=None, id=None, packet_context_field_type=None, - event_header_field_type=None, event_context_field_type=None, - event_classes=None): - ptr = native_bt.ctf_stream_class_create_empty(None) + def __len__(self): + count = native_bt.stream_class_get_event_class_count(self._ptr) + assert count >= 0 + return count - if ptr is None: - raise bt2.CreationError('cannot create stream class object') + def __iter__(self): + for idx in range(len(self)): + ec_ptr = native_bt.stream_class_borrow_event_class_by_index_const(self._ptr, idx) + assert ec_ptr is not None - super().__init__(ptr) + id = native_bt.event_class_get_id(ec_ptr) + assert id >= 0 - if name is not None: - self.name = name + yield id - if id is not None: - self.id = id + def create_event_class(self, id=None, name=None, log_level=None, emf_uri=None, + specific_context_field_class=None, + payload_field_class=None): + if self.assigns_automatic_event_class_id: + if id is not None: + raise ValueError('id provided, but stream class assigns automatic event class ids') - if packet_context_field_type is not None: - self.packet_context_field_type = packet_context_field_type + ec_ptr = native_bt.event_class_create(self._ptr) + else: + if id is None: + raise ValueError('id not provided, but stream class does not assign automatic event class ids') - if event_header_field_type is not None: - self.event_header_field_type = event_header_field_type + utils._check_uint64(id) + ec_ptr = native_bt.event_class_create_with_id(self._ptr, id) - if event_context_field_type is not None: - self.event_context_field_type = event_context_field_type + event_class = bt2.event_class.EventClass._create_from_ptr(ec_ptr) - if event_classes is not None: - for event_class in event_classes: - self.add_event_class(event_class) + if name is not None: + event_class._name = name - def __getitem__(self, key): - utils._check_int64(key) - ec_ptr = native_bt.ctf_stream_class_get_event_class_by_id(self._ptr, - key) + if log_level is not None: + event_class._log_level = log_level - if ec_ptr is None: - raise KeyError(key) + if emf_uri is not None: + event_class._emf_uri = emf_uri - return bt2.EventClass._create_from_ptr(ec_ptr) + if specific_context_field_class is not None: + event_class._specific_context_field_class = specific_context_field_class - def __len__(self): - count = native_bt.ctf_stream_class_get_event_class_count(self._ptr) - assert(count >= 0) - return count - - def __iter__(self): - return _EventClassIterator(self) + if payload_field_class is not None: + event_class._payload_field_class = payload_field_class - def add_event_class(self, event_class): - utils._check_type(event_class, bt2.EventClass) - ret = native_bt.ctf_stream_class_add_event_class(self._ptr, event_class._ptr) - utils._handle_ret(ret, "cannot add event class object to stream class object's") + return event_class @property - def trace(self): - tc_ptr = native_bt.ctf_stream_class_get_trace(self._ptr) + def trace_class(self): + tc_ptr = native_bt.stream_class_borrow_trace_class_const(self._ptr) if tc_ptr is not None: - return bt2.Trace._create_from_ptr(tc_ptr) + return bt2.TraceClass._create_from_ptr_and_get_ref(tc_ptr) @property def name(self): - return native_bt.ctf_stream_class_get_name(self._ptr) + return native_bt.stream_class_get_name(self._ptr) - @name.setter - def name(self, name): + def _name(self, name): utils._check_str(name) - ret = native_bt.ctf_stream_class_set_name(self._ptr, name) + ret = native_bt.stream_class_set_name(self._ptr, name) utils._handle_ret(ret, "cannot set stream class object's name") + _name = property(fset=_name) + + @property + def assigns_automatic_event_class_id(self): + return native_bt.stream_class_assigns_automatic_event_class_id(self._ptr) + + def _assigns_automatic_event_class_id(self, auto_id): + utils._check_bool(auto_id) + return native_bt.stream_class_set_assigns_automatic_event_class_id(self._ptr, auto_id) + + _assigns_automatic_event_class_id = property(fset=_assigns_automatic_event_class_id) + + @property + def assigns_automatic_stream_id(self): + return native_bt.stream_class_assigns_automatic_stream_id(self._ptr) + + def _assigns_automatic_stream_id(self, auto_id): + utils._check_bool(auto_id) + return native_bt.stream_class_set_assigns_automatic_stream_id(self._ptr, auto_id) + + _assigns_automatic_stream_id = property(fset=_assigns_automatic_stream_id) + + @property + def packets_have_default_beginning_clock_snapshot(self): + return native_bt.stream_class_packets_have_default_beginning_clock_snapshot(self._ptr) + + def _packets_have_default_beginning_clock_snapshot(self, value): + utils._check_bool(value) + native_bt.stream_class_set_packets_have_default_beginning_clock_snapshot(self._ptr, value) + + _packets_have_default_beginning_clock_snapshot = property(fset=_packets_have_default_beginning_clock_snapshot) + + @property + def packets_have_default_end_clock_snapshot(self): + return native_bt.stream_class_packets_have_default_end_clock_snapshot(self._ptr) + + def _packets_have_default_end_clock_snapshot(self, value): + utils._check_bool(value) + native_bt.stream_class_set_packets_have_default_end_clock_snapshot(self._ptr, value) + + _packets_have_default_end_clock_snapshot = property(fset=_packets_have_default_end_clock_snapshot) + + @property + def supports_discarded_events(self): + return native_bt.stream_class_supports_discarded_events(self._ptr) + + def _set_supports_discarded_events(self, supports, with_cs=False): + utils._check_bool(supports) + utils._check_bool(with_cs) + + if not supports and with_cs: + raise ValueError('cannot not support discarded events, but have default clock snapshots') + + native_bt.stream_class_set_supports_discarded_events(self._ptr, supports, with_cs) + + @property + def discarded_events_have_default_clock_snapshots(self): + return native_bt.stream_class_discarded_events_have_default_clock_snapshots(self._ptr) + + @property + def supports_discarded_packets(self): + return native_bt.stream_class_supports_discarded_packets(self._ptr) + + def _set_supports_discarded_packets(self, supports, with_cs): + utils._check_bool(supports) + utils._check_bool(with_cs) + + if not supports and with_cs: + raise ValueError('cannot not support discarded packets, but have default clock snapshots') + + native_bt.stream_class_set_supports_discarded_packets(self._ptr, supports, with_cs) + + @property + def discarded_packets_have_default_clock_snapshots(self): + return native_bt.stream_class_discarded_packets_have_default_clock_snapshots(self._ptr) + @property def id(self): - id = native_bt.ctf_stream_class_get_id(self._ptr) + id = native_bt.stream_class_get_id(self._ptr) if id < 0: return @@ -130,12 +194,12 @@ class StreamClass(object._Object, collections.abc.Mapping): @id.setter def id(self, id): utils._check_int64(id) - ret = native_bt.ctf_stream_class_set_id(self._ptr, id) + ret = native_bt.stream_class_set_id(self._ptr, id) utils._handle_ret(ret, "cannot set stream class object's ID") @property def clock(self): - clock_ptr = native_bt.ctf_stream_class_get_clock(self._ptr) + clock_ptr = native_bt.stream_class_get_clock(self._ptr) if clock_ptr is None: return @@ -145,141 +209,60 @@ class StreamClass(object._Object, collections.abc.Mapping): @clock.setter def clock(self, clock): utils._check_type(clock, bt2.ctf_writer.CtfWriterClock) - ret = native_bt.ctf_stream_class_set_clock(self._ptr, clock._ptr) + ret = native_bt.stream_class_set_clock(self._ptr, clock._ptr) utils._handle_ret(ret, "cannot set stream class object's CTF writer clock object") @property - def packet_context_field_type(self): - ft_ptr = native_bt.ctf_stream_class_get_packet_context_type(self._ptr) + def packet_context_field_class(self): + fc_ptr = native_bt.stream_class_borrow_packet_context_field_class_const(self._ptr) - if ft_ptr is None: + if fc_ptr is None: return - return bt2.field_types._create_from_ptr(ft_ptr) - - @packet_context_field_type.setter - def packet_context_field_type(self, packet_context_field_type): - packet_context_field_type_ptr = None + return bt2.field_class._create_field_class_from_ptr_and_get_ref(fc_ptr) - if packet_context_field_type is not None: - utils._check_type(packet_context_field_type, bt2.field_types._FieldType) - packet_context_field_type_ptr = packet_context_field_type._ptr + def _packet_context_field_class(self, packet_context_field_class): + if packet_context_field_class is not None: + utils._check_type(packet_context_field_class, + bt2.field_class._StructureFieldClass) + ret = native_bt.stream_class_set_packet_context_field_class(self._ptr, + packet_context_field_class._ptr) + utils._handle_ret(ret, "cannot set stream class' packet context field class") - ret = native_bt.ctf_stream_class_set_packet_context_type(self._ptr, - packet_context_field_type_ptr) - utils._handle_ret(ret, "cannot set stream class object's packet context field type") + _packet_context_field_class = property(fset=_packet_context_field_class) @property - def event_header_field_type(self): - ft_ptr = native_bt.ctf_stream_class_get_event_header_type(self._ptr) + def event_common_context_field_class(self): + fc_ptr = native_bt.stream_class_borrow_event_common_context_field_class_const(self._ptr) - if ft_ptr is None: + if fc_ptr is None: return - return bt2.field_types._create_from_ptr(ft_ptr) + return bt2.field_class._create_field_class_from_ptr_and_get_ref(fc_ptr) - @event_header_field_type.setter - def event_header_field_type(self, event_header_field_type): - event_header_field_type_ptr = None + def _event_common_context_field_class(self, event_common_context_field_class): + if event_common_context_field_class is not None: + utils._check_type(event_common_context_field_class, + bt2.field_class._StructureFieldClass) - if event_header_field_type is not None: - utils._check_type(event_header_field_type, bt2.field_types._FieldType) - event_header_field_type_ptr = event_header_field_type._ptr + set_context_fn = native_bt.stream_class_set_event_common_context_field_class + ret = set_context_fn(self._ptr, event_common_context_field_class._ptr) - ret = native_bt.ctf_stream_class_set_event_header_type(self._ptr, - event_header_field_type_ptr) - utils._handle_ret(ret, "cannot set stream class object's event header field type") + utils._handle_ret(ret, "cannot set stream class' event context field type") - @property - def event_context_field_type(self): - ft_ptr = native_bt.ctf_stream_class_get_event_context_type(self._ptr) + _event_common_context_field_class = property(fset=_event_common_context_field_class) - if ft_ptr is None: + @property + def default_clock_class(self): + cc_ptr = native_bt.stream_class_borrow_default_clock_class(self._ptr) + if cc_ptr is None: return - return bt2.field_types._create_from_ptr(ft_ptr) - - @event_context_field_type.setter - def event_context_field_type(self, event_context_field_type): - event_context_field_type_ptr = None - - if event_context_field_type is not None: - utils._check_type(event_context_field_type, bt2.field_types._FieldType) - event_context_field_type_ptr = event_context_field_type._ptr + return bt2.clock_class._ClockClass._create_from_ptr_and_get_ref(cc_ptr) - ret = native_bt.ctf_stream_class_set_event_context_type(self._ptr, - event_context_field_type_ptr) - utils._handle_ret(ret, "cannot set stream class object's event context field type") + def _default_clock_class(self, clock_class): + utils._check_type(clock_class, bt2.clock_class._ClockClass) + native_bt.stream_class_set_default_clock_class( + self._ptr, clock_class._ptr) - def __call__(self, name=None, id=None): - if name is not None: - utils._check_str(name) - - if id is None: - stream_ptr = native_bt.ctf_stream_create(self._ptr, name) - else: - stream_ptr = native_bt.ctf_stream_create_with_id(self._ptr, name, id) - - if stream_ptr is None: - raise bt2.CreationError('cannot create stream object') - - return bt2.stream._create_from_ptr(stream_ptr) - - def __eq__(self, other): - if type(other) is not type(self): - return False - - if self.addr == other.addr: - return True - - self_event_classes = list(self.values()) - other_event_classes = list(other.values()) - self_props = ( - self_event_classes, - self.name, - self.id, - self.packet_context_field_type, - self.event_header_field_type, - self.event_context_field_type, - self.clock, - ) - other_props = ( - other_event_classes, - other.name, - other.id, - other.packet_context_field_type, - other.event_header_field_type, - other.event_context_field_type, - other.clock, - ) - - return self_props == other_props - - def _copy(self, ft_copy_func, ev_copy_func): - cpy = StreamClass() - - if self.id is not None: - cpy.id = self.id - - if self.name is not None: - cpy.name = self.name - - if self.clock is not None: - cpy.clock = self.clock - - cpy.packet_context_field_type = ft_copy_func(self.packet_context_field_type) - cpy.event_header_field_type = ft_copy_func(self.event_header_field_type) - cpy.event_context_field_type = ft_copy_func(self.event_context_field_type) - - for event_class in self.values(): - cpy.add_event_class(ev_copy_func(event_class)) - - return cpy - - def __copy__(self): - return self._copy(lambda ft: ft, copy.copy) - - def __deepcopy__(self, memo): - cpy = self._copy(copy.deepcopy, copy.deepcopy) - memo[id(self)] = cpy - return cpy + _default_clock_class = property(fset=_default_clock_class)