def cycles_to_ns_from_origin(self, cycles): utils._check_uint64(cycles) status, ns = native_bt.clock_class_cycles_to_ns_from_origin( self._ptr, cycles) error_msg = "cannot convert clock value to nanoseconds from origin for given clock class" utils._handle_func_status(status, error_msg) return ns
def append_option(self, name, field_class, ranges, user_attributes=None): utils._check_str(name) utils._check_type(field_class, _FieldClass) utils._check_type(ranges, self._variant_option_pycls._range_set_pycls) if name in self: raise ValueError("duplicate option name '{}'".format(name)) if len(ranges) == 0: raise ValueError('range set is empty') user_attributes_value = None if user_attributes is not None: # check now that user attributes are valid user_attributes_value = bt2.create_value(user_attributes) # TODO: check overlaps (precondition of self._append_option()) status = self._append_option(self._ptr, name, field_class._ptr, ranges._ptr) utils._handle_func_status( status, 'cannot append option to variant field class object' ) if user_attributes is not None: self[name]._user_attributes = user_attributes_value
def _specific_context_field_class(self, context_field_class): status = native_bt.event_class_set_specific_context_field_class( self._ptr, context_field_class._ptr ) utils._handle_func_status( status, "cannot set event class object's context field class" )
def find_plugin( name, find_in_std_env_var=True, find_in_user_dir=True, find_in_sys_dir=True, find_in_static=True, fail_on_load_error=False, ): utils._check_str(name) utils._check_bool(fail_on_load_error) status, ptr = native_bt.bt2_plugin_find( name, int(find_in_std_env_var), int(find_in_user_dir), int(find_in_sys_dir), int(find_in_static), int(fail_on_load_error), ) if status == native_bt.__BT_FUNC_STATUS_NOT_FOUND: return utils._handle_func_status(status, 'failed to find plugin') assert ptr is not None return _Plugin._create_from_ptr(ptr)
def _event_common_context_field_class(self, event_common_context_field_class): set_context_fn = native_bt.stream_class_set_event_common_context_field_class status = set_context_fn(self._ptr, event_common_context_field_class._ptr) utils._handle_func_status( status, "cannot set stream class' event context field type")
def _payload_field_class(self, payload_field_class): status = native_bt.event_class_set_payload_field_class( self._ptr, payload_field_class._ptr ) utils._handle_func_status( status, "cannot set event class object's payload field class" )
def __iadd__(self, value): value = self._value_to_str(value) status = native_bt.field_string_append(self._ptr, value) utils._handle_func_status( status, "cannot append to string field object's value" ) return self
def labels(self): status, labels = self._get_mapping_labels(self._ptr) utils._handle_func_status(status, "cannot get label for enumeration field") assert labels is not None return labels
def add_component( self, component_class, name, params=None, obj=None, logging_level=bt2_logging.LoggingLevel.NONE, ): if isinstance(component_class, bt2_component._SourceComponentClassConst): cc_ptr = component_class._ptr add_fn = native_bt.bt2_graph_add_source_component cc_type = native_bt.COMPONENT_CLASS_TYPE_SOURCE elif isinstance(component_class, bt2_component._FilterComponentClassConst): cc_ptr = component_class._ptr add_fn = native_bt.bt2_graph_add_filter_component cc_type = native_bt.COMPONENT_CLASS_TYPE_FILTER elif isinstance(component_class, bt2_component._SinkComponentClassConst): cc_ptr = component_class._ptr add_fn = native_bt.bt2_graph_add_sink_component cc_type = native_bt.COMPONENT_CLASS_TYPE_SINK elif issubclass(component_class, bt2_component._UserSourceComponent): cc_ptr = component_class._bt_cc_ptr add_fn = native_bt.bt2_graph_add_source_component cc_type = native_bt.COMPONENT_CLASS_TYPE_SOURCE elif issubclass(component_class, bt2_component._UserSinkComponent): cc_ptr = component_class._bt_cc_ptr add_fn = native_bt.bt2_graph_add_sink_component cc_type = native_bt.COMPONENT_CLASS_TYPE_SINK elif issubclass(component_class, bt2_component._UserFilterComponent): cc_ptr = component_class._bt_cc_ptr add_fn = native_bt.bt2_graph_add_filter_component cc_type = native_bt.COMPONENT_CLASS_TYPE_FILTER else: raise TypeError( "'{}' is not a component class".format( component_class.__class__.__name__ ) ) utils._check_str(name) utils._check_log_level(logging_level) base_cc_ptr = component_class._bt_component_class_ptr() if obj is not None and not native_bt.bt2_is_python_component_class(base_cc_ptr): raise ValueError('cannot pass a Python object to a non-Python component') if params is not None and not isinstance(params, (dict, bt2.MapValue)): raise TypeError("'params' parameter is not a 'dict' or a 'bt2.MapValue'.") params = bt2.create_value(params) params_ptr = params._ptr if params is not None else None status, comp_ptr = add_fn( self._ptr, cc_ptr, name, params_ptr, obj, logging_level ) utils._handle_func_status(status, 'cannot add component to graph') assert comp_ptr return bt2_component._create_component_from_const_ptr(comp_ptr, cc_type)
def mappings_for_value(self, value): self._check_int_type(value) status, labels = self._get_mapping_labels_for_value(self._ptr, value) utils._handle_func_status( status, 'cannot get mapping labels for value {}'.format(value) ) return [self[label] for label in labels]
def seek_beginning(self): # Forget about buffered messages, they won't be valid after seeking. self._current_msgs.clear() self._at = 0 status = native_bt.message_iterator_seek_beginning(self._ptr) utils._handle_func_status(status, 'cannot seek message iterator beginning')
def can_seek_beginning(self): (status, res) = native_bt.message_iterator_can_seek_beginning(self._ptr) utils._handle_func_status( status, 'cannot check whether or not message iterator can seek its beginning', ) return res != 0
def _payload_field_class(self, payload_field_class): if payload_field_class is not None: utils._check_type(payload_field_class, bt2_field_class._StructureFieldClass) status = native_bt.event_class_set_payload_field_class( self._ptr, payload_field_class._ptr) utils._handle_func_status( status, "cannot set event class object's payload field class")
def _specific_context_field_class(self, context_field_class): if context_field_class is not None: utils._check_type(context_field_class, bt2_field_class._StructureFieldClass) status = native_bt.event_class_set_specific_context_field_class( self._ptr, context_field_class._ptr) utils._handle_func_status( status, "cannot set event class object's context field class")
def add(self, rg): if type(rg) is not self._range_type: # assume it's a simple pair (will raise if it's not) rg = self._range_type(rg[0], rg[1]) status = self._add_range(self._ptr, rg.lower, rg.upper) utils._handle_func_status(status, 'cannot add range to range set object')
def _add_input_port(self, name, user_data=None): utils._check_str(name) fn = native_bt.self_component_sink_add_input_port comp_status, self_port_ptr = fn(self._bt_ptr, name, user_data) utils._handle_func_status( comp_status, 'cannot add input port to sink component object') assert self_port_ptr return bt2_port._UserComponentInputPort._create_from_ptr(self_port_ptr)
def can_seek_ns_from_origin(self, ns_from_origin): utils._check_int64(ns_from_origin) (status, res) = native_bt.message_iterator_can_seek_ns_from_origin( self._ptr, ns_from_origin) utils._handle_func_status( status, 'cannot check whether or not message iterator can seek given ns from origin', ) return res != 0
def _add_output_port(self, name, user_data=None): utils._check_str(name) fn = native_bt.self_component_filter_add_output_port comp_status, self_port_ptr = fn(self._bt_ptr, name, user_data) utils._handle_func_status( comp_status, 'cannot add output port to filter component object') assert self_port_ptr return bt2_port._UserComponentOutputPort._create_from_ptr_and_get_ref( self_port_ptr)
def connect_ports(self, upstream_port, downstream_port): utils._check_type(upstream_port, bt2_port._OutputPortConst) utils._check_type(downstream_port, bt2_port._InputPortConst) status, conn_ptr = native_bt.graph_connect_ports( self._ptr, upstream_port._ptr, downstream_port._ptr ) utils._handle_func_status(status, 'cannot connect component ports within graph') assert conn_ptr return bt2_connection._ConnectionConst._create_from_ptr(conn_ptr)
def __setitem__(self, key, value): if isinstance(value, str): set_env_entry_fn = native_bt.trace_set_environment_entry_string elif isinstance(value, int): set_env_entry_fn = native_bt.trace_set_environment_entry_integer else: raise TypeError('expected str or int, got {}'.format(type(value))) status = set_env_entry_fn(self._trace._ptr, key, value) utils._handle_func_status(status, "cannot set trace object's environment entry")
def append(self, value): value = create_value(value) if value is None: ptr = native_bt.value_null else: ptr = value._ptr status = native_bt.value_array_append_element(self._ptr, ptr) utils._handle_func_status(status)
def add_mapping(self, label, ranges): utils._check_str(label) utils._check_type(ranges, self._range_set_type) if label in self: raise ValueError("duplicate mapping label '{}'".format(label)) status = self._add_mapping(self._ptr, label, ranges._ptr) utils._handle_func_status( status, 'cannot add mapping to enumeration field class object')
def run(self): status = native_bt.graph_run(self._ptr) try: utils._handle_func_status(status, 'graph object stopped running') except bt2.Stop: # done return except Exception: raise
def append_member(self, name, field_class): utils._check_str(name) utils._check_type(field_class, _FieldClass) if name in self: raise ValueError("duplicate member name '{}'".format(name)) status = native_bt.field_class_structure_append_member( self._ptr, name, field_class._ptr) utils._handle_func_status( status, 'cannot append member to structure field class object')
def seek_ns_from_origin(self, ns_from_origin): utils._check_int64(ns_from_origin) # Forget about buffered messages, they won't be valid after seeking. self._current_msgs.clear() self._at = 0 status = native_bt.message_iterator_seek_ns_from_origin( self._ptr, ns_from_origin) utils._handle_func_status( status, 'message iterator cannot seek given ns from origin')
def append_option(self, name, field_class): utils._check_str(name) utils._check_type(field_class, _FieldClass) if name in self: raise ValueError("duplicate option name '{}'".format(name)) status = native_bt.field_class_variant_without_selector_append_option( self._ptr, name, field_class._ptr) utils._handle_func_status( status, 'cannot append option to variant field class object')
def __setitem__(self, index, value): self._check_index(index) value = create_value(value) if value is None: ptr = native_bt.value_null else: ptr = value._ptr status = native_bt.value_array_set_element_by_index(self._ptr, index, ptr) utils._handle_func_status(status)
def __setitem__(self, key, value): self._check_key_type(key) value = create_value(value) if value is None: ptr = native_bt.value_null else: ptr = value._ptr status = native_bt.value_map_insert_entry(self._ptr, key, ptr) utils._handle_func_status(status)
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) set_context_fn = native_bt.stream_class_set_event_common_context_field_class status = set_context_fn(self._ptr, event_common_context_field_class._ptr) utils._handle_func_status( status, "cannot set stream class' event context field type")
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) if not self.supports_packets: raise ValueError('stream class does not support packets') status = native_bt.stream_class_set_packet_context_field_class( self._ptr, packet_context_field_class._ptr) utils._handle_func_status( status, "cannot set stream class' packet context field class")