1 # SPDX-License-Identifier: MIT
3 # Copyright (c) 2017 Philippe Proulx <pproulx@efficios.com>
5 from bt2
import value
as bt2_value
6 from bt2
import component
as bt2_component
7 from bt2
import native_bt
10 def _is_source_comp_cls(comp_cls
):
11 if isinstance(comp_cls
, bt2_component
._SourceComponentClassConst
):
15 return issubclass(comp_cls
, bt2_component
._UserSourceComponent
)
20 def _is_filter_comp_cls(comp_cls
):
21 if isinstance(comp_cls
, bt2_component
._FilterComponentClassConst
):
25 return issubclass(comp_cls
, bt2_component
._UserFilterComponent
)
30 def _is_sink_comp_cls(comp_cls
):
31 if isinstance(comp_cls
, bt2_component
._SinkComponentClassConst
):
35 return issubclass(comp_cls
, bt2_component
._UserSinkComponent
)
40 class ComponentDescriptor
:
41 def __init__(self
, component_class
, params
=None, obj
=None):
43 not _is_source_comp_cls(component_class
)
44 and not _is_filter_comp_cls(component_class
)
45 and not _is_sink_comp_cls(component_class
)
48 "'{}' is not a component class".format(
49 component_class
.__class
__.__name
__
53 base_cc_ptr
= component_class
._bt
_component
_class
_ptr
()
55 if obj
is not None and not native_bt
.bt2_is_python_component_class(base_cc_ptr
):
56 raise ValueError("cannot pass a Python object to a non-Python component")
58 self
._comp
_cls
= component_class
59 self
._params
= bt2_value
.create_value(params
)
63 def component_class(self
):