1 # The MIT License (MIT)
3 # Copyright (c) 2017 Philippe Proulx <pproulx@efficios.com>
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:
12 # The above copyright notice and this permission notice shall be included in
13 # all copies or substantial portions of the Software.
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
23 from bt2
import native_bt
24 from bt2
import component
as bt2_component
28 def _is_source_comp_cls(comp_cls
):
29 if isinstance(comp_cls
, bt2_component
._SourceComponentClassConst
):
33 return issubclass(comp_cls
, bt2_component
._UserSourceComponent
)
38 def _is_filter_comp_cls(comp_cls
):
39 if isinstance(comp_cls
, bt2_component
._FilterComponentClassConst
):
43 return issubclass(comp_cls
, bt2_component
._UserFilterComponent
)
48 def _is_sink_comp_cls(comp_cls
):
49 if isinstance(comp_cls
, bt2_component
._SinkComponentClassConst
):
53 return issubclass(comp_cls
, bt2_component
._UserSinkComponent
)
58 class ComponentDescriptor
:
59 def __init__(self
, component_class
, params
=None, obj
=None):
61 not _is_source_comp_cls(component_class
)
62 and not _is_filter_comp_cls(component_class
)
63 and not _is_sink_comp_cls(component_class
)
66 "'{}' is not a component class".format(
67 component_class
.__class
__.__name
__
71 base_cc_ptr
= component_class
._bt
_component
_class
_ptr
()
73 if obj
is not None and not native_bt
.bt2_is_python_component_class(base_cc_ptr
):
74 raise ValueError('cannot pass a Python object to a non-Python component')
76 self
._comp
_cls
= component_class
77 self
._params
= bt2
.create_value(params
)
81 def component_class(self
):