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 __init__(self, component_class, object_name, params=None, method_obj=None): if not isinstance(component_class, _bt2_component()._ComponentClassConst): err = False try: if not issubclass(component_class, _bt2_component()._UserComponent): err = True except TypeError: err = True if err: o = component_class raise TypeError( "'{}' is not a component class object".format(o)) utils._check_str(object_name) if params is None: params_ptr = native_bt.value_null else: params = bt2.create_value(params) params_ptr = params._ptr cc_ptr = component_class._bt_component_class_ptr() assert cc_ptr is not None if method_obj is not None and not native_bt.bt2_is_python_component_class( cc_ptr): raise ValueError( 'cannot pass a Python object to a non-Python component class') ptr = native_bt.bt2_query_executor_create(cc_ptr, object_name, params_ptr, method_obj) if ptr is None: raise bt2._MemoryError('cannot create query executor object') super().__init__(ptr) # Keep a reference of `method_obj` as the native query executor # does not have any. This ensures that, when this object's # query() method is called, the Python object still exists. self._method_obj = method_obj
def __init__(self, component_class, params=None, obj=None): if (not _is_source_comp_cls(component_class) and not _is_filter_comp_cls(component_class) and not _is_sink_comp_cls(component_class)): raise TypeError("'{}' is not a component class".format( component_class.__class__.__name__)) 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') self._comp_cls = component_class self._params = bt2.create_value(params) self._obj = obj