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
, object, utils
24 import bt2
.message_iterator
25 import collections
.abc
34 _env_var
= os
.environ
.get('BABELTRACE_PYTHON_BT2_NO_TRACEBACK')
35 _NO_PRINT_TRACEBACK
= _env_var
== '1'
38 # This class wraps a component class pointer. This component class could
39 # have been created by Python code, but since we only have the pointer,
40 # we can only wrap it in a generic way and lose the original Python
43 # Subclasses must implement some methods that this base class uses:
45 # - _as_component_class_ptr: static method, convert the passed component class
46 # pointer to a 'bt_component_class *'.
48 class _GenericComponentClass(object._SharedObject
):
51 ptr
= self
._as
_component
_class
_ptr
(self
._ptr
)
52 name
= native_bt
.component_class_get_name(ptr
)
53 assert name
is not None
57 def description(self
):
58 ptr
= self
._as
_component
_class
_ptr
(self
._ptr
)
59 return native_bt
.component_class_get_description(ptr
)
63 ptr
= self
._as
_component
_class
_ptr
(self
._ptr
)
64 return native_bt
.component_class_get_help(ptr
)
66 def _component_class_ptr(self
):
67 return self
._as
_component
_class
_ptr
(self
._ptr
)
69 def __eq__(self
, other
):
70 if not isinstance(other
, _GenericComponentClass
):
72 if not issubclass(other
, _UserComponent
):
77 return self
.addr
== other
.addr
80 class _GenericSourceComponentClass(_GenericComponentClass
):
81 _get_ref
= native_bt
.component_class_source_get_ref
82 _put_ref
= native_bt
.component_class_source_put_ref
83 _as_component_class_ptr
= native_bt
.component_class_source_as_component_class
86 class _GenericFilterComponentClass(_GenericComponentClass
):
87 _get_ref
= native_bt
.component_class_filter_get_ref
88 _put_ref
= native_bt
.component_class_filter_put_ref
89 _as_component_class_ptr
= native_bt
.component_class_filter_as_component_class
92 class _GenericSinkComponentClass(_GenericComponentClass
):
93 _get_ref
= native_bt
.component_class_sink_get_ref
94 _put_ref
= native_bt
.component_class_sink_put_ref
95 _as_component_class_ptr
= native_bt
.component_class_sink_as_component_class
98 def _handle_component_status(status
, gen_error_msg
):
99 if status
== native_bt
.COMPONENT_STATUS_END
:
101 elif status
== native_bt
.COMPONENT_STATUS_AGAIN
:
103 elif status
== native_bt
.COMPONENT_STATUS_UNSUPPORTED
:
104 raise bt2
.UnsupportedFeature
105 elif status
== native_bt
.COMPONENT_STATUS_REFUSE_PORT_CONNECTION
:
106 raise bt2
.PortConnectionRefused
107 elif status
== native_bt
.COMPONENT_STATUS_GRAPH_IS_CANCELED
:
108 raise bt2
.GraphCanceled
110 raise bt2
.Error(gen_error_msg
)
113 class _PortIterator(collections
.abc
.Iterator
):
114 def __init__(self
, comp_ports
):
115 self
._comp
_ports
= comp_ports
119 if self
._at
== len(self
._comp
_ports
):
122 comp_ports
= self
._comp
_ports
123 comp_ptr
= comp_ports
._component
._ptr
124 port_ptr
= comp_ports
._get
_port
_at
_index
_fn
(comp_ptr
, self
._at
)
127 if comp_ports
._is
_private
:
128 port_pub_ptr
= native_bt
.port_from_private(port_ptr
)
129 name
= native_bt
.port_get_name(port_pub_ptr
)
130 native_bt
.put(port_pub_ptr
)
132 name
= native_bt
.port_get_name(port_ptr
)
134 assert(name
is not None)
135 native_bt
.put(port_ptr
)
140 class _ComponentPorts(collections
.abc
.Mapping
):
141 def __init__(self
, is_private
, component
,
142 get_port_by_name_fn
, get_port_at_index_fn
,
144 self
._is
_private
= is_private
145 self
._component
= component
146 self
._get
_port
_by
_name
_fn
= get_port_by_name_fn
147 self
._get
_port
_at
_index
_fn
= get_port_at_index_fn
148 self
._get
_port
_count
_fn
= get_port_count_fn
150 def __getitem__(self
, key
):
151 utils
._check
_str
(key
)
152 port_ptr
= self
._get
_port
_by
_name
_fn
(self
._component
._ptr
, key
)
158 return bt2
.port
._create
_private
_from
_ptr
(port_ptr
)
160 return bt2
.port
._create
_from
_ptr
(port_ptr
)
164 pub_ptr
= native_bt
.component_from_private(self
._component
._ptr
)
165 count
= self
._get
_port
_count
_fn
(pub_ptr
)
166 native_bt
.put(pub_ptr
)
168 count
= self
._get
_port
_count
_fn
(self
._component
._ptr
)
174 return _PortIterator(self
)
177 # This class holds the methods which are common to both generic
178 # component objects and Python user component objects.
180 # Subclasses must provide these methods or property:
182 # - _borrow_component_class_ptr: static method, must return a pointer to the
183 # specialized component class (e.g. 'bt_component_class_sink *') of the
184 # passed specialized component pointer (e.g. 'bt_component_sink *').
185 # - _comp_cls_type: property, one of the native_bt.COMPONENT_CLASS_TYPE_*
187 # - _as_component_ptr: static method, must return the passed specialized
188 # component pointer (e.g. 'bt_component_sink *') as a 'bt_component *'.
193 ptr
= self
._as
_component
_ptr
(self
._ptr
)
194 name
= native_bt
.component_get_name(ptr
)
195 assert name
is not None
199 def component_class(self
):
200 cc_ptr
= self
._borrow
_component
_class
_ptr
(self
._ptr
)
201 assert cc_ptr
is not None
202 return _create_component_class_from_ptr_and_get_ref(cc_ptr
, self
._comp
_cls
_type
)
204 def __eq__(self
, other
):
205 if not hasattr(other
, 'addr'):
208 return self
.addr
== other
.addr
211 class _SourceComponent(_Component
):
212 _borrow_component_class_ptr
= native_bt
.component_source_borrow_class_const
213 _comp_cls_type
= native_bt
.COMPONENT_CLASS_TYPE_SOURCE
214 _as_component_class_ptr
= native_bt
.component_class_source_as_component_class
215 _as_component_ptr
= native_bt
.component_source_as_component_const
218 class _FilterComponent(_Component
):
219 _borrow_component_class_ptr
= native_bt
.component_filter_borrow_class_const
220 _comp_cls_type
= native_bt
.COMPONENT_CLASS_TYPE_FILTER
221 _as_component_class_ptr
= native_bt
.component_class_filter_as_component_class
222 _as_component_ptr
= native_bt
.component_filter_as_component_const
225 class _SinkComponent(_Component
):
226 _borrow_component_class_ptr
= native_bt
.component_sink_borrow_class_const
227 _comp_cls_type
= native_bt
.COMPONENT_CLASS_TYPE_SINK
228 _as_component_class_ptr
= native_bt
.component_class_sink_as_component_class
229 _as_component_ptr
= native_bt
.component_sink_as_component_const
232 # This is analogous to _GenericSourceComponentClass, but for source
234 class _GenericSourceComponent(object._SharedObject
, _SourceComponent
):
236 def output_ports(self
):
237 return _ComponentPorts(False, self
,
238 native_bt
.component_source_get_output_port_by_name
,
239 native_bt
.component_source_get_output_port_by_index
,
240 native_bt
.component_source_get_output_port_count
)
243 # This is analogous to _GenericFilterComponentClass, but for filter
245 class _GenericFilterComponent(object._SharedObject
, _FilterComponent
):
247 def output_ports(self
):
248 return _ComponentPorts(False, self
,
249 native_bt
.component_filter_get_output_port_by_name
,
250 native_bt
.component_filter_get_output_port_by_index
,
251 native_bt
.component_filter_get_output_port_count
)
254 def input_ports(self
):
255 return _ComponentPorts(False, self
,
256 native_bt
.component_filter_get_input_port_by_name
,
257 native_bt
.component_filter_get_input_port_by_index
,
258 native_bt
.component_filter_get_input_port_count
)
261 # This is analogous to _GenericSinkComponentClass, but for sink
263 class _GenericSinkComponent(object._SharedObject
, _SinkComponent
):
264 _get_ref
= native_bt
.component_sink_get_ref
265 _put_ref
= native_bt
.component_sink_put_ref
268 def input_ports(self
):
269 return _ComponentPorts(False, self
,
270 native_bt
.component_sink_get_input_port_by_name
,
271 native_bt
.component_sink_get_input_port_by_index
,
272 native_bt
.component_sink_get_input_port_count
)
275 _COMP_CLS_TYPE_TO_GENERIC_COMP_PYCLS
= {
276 native_bt
.COMPONENT_CLASS_TYPE_SOURCE
: _GenericSourceComponent
,
277 native_bt
.COMPONENT_CLASS_TYPE_FILTER
: _GenericFilterComponent
,
278 native_bt
.COMPONENT_CLASS_TYPE_SINK
: _GenericSinkComponent
,
282 _COMP_CLS_TYPE_TO_GENERIC_COMP_CLS_PYCLS
= {
283 native_bt
.COMPONENT_CLASS_TYPE_SOURCE
: _GenericSourceComponentClass
,
284 native_bt
.COMPONENT_CLASS_TYPE_FILTER
: _GenericFilterComponentClass
,
285 native_bt
.COMPONENT_CLASS_TYPE_SINK
: _GenericSinkComponentClass
,
289 # Create a component Python object of type _GenericSourceComponent,
290 # _GenericFilterComponent or _GenericSinkComponent, depending on
293 # Steals the reference to ptr from the caller.
295 def _create_component_from_ptr(ptr
, comp_cls_type
):
296 return _COMP_CLS_TYPE_TO_GENERIC_COMP_PYCLS
[comp_cls_type
]._create
_from
_ptr
(ptr
)
298 # Create a component class Python object of type
299 # _GenericSourceComponentClass, _GenericFilterComponentClass or
300 # _GenericSinkComponentClass, depending on comp_cls_type.
302 # Acquires a new reference to ptr.
304 def _create_component_class_from_ptr_and_get_ref(ptr
, comp_cls_type
):
305 return _COMP_CLS_TYPE_TO_GENERIC_COMP_CLS_PYCLS
[comp_cls_type
]._create
_from
_ptr
_and
_get
_ref
(ptr
)
308 def _trim_docstring(docstring
):
309 lines
= docstring
.expandtabs().splitlines()
312 for line
in lines
[1:]:
313 stripped
= line
.lstrip()
316 indent
= min(indent
, len(line
) - len(stripped
))
318 trimmed
= [lines
[0].strip()]
320 if indent
< sys
.maxsize
:
321 for line
in lines
[1:]:
322 trimmed
.append(line
[indent
:].rstrip())
324 while trimmed
and not trimmed
[-1]:
327 while trimmed
and not trimmed
[0]:
330 return '\n'.join(trimmed
)
333 # Metaclass for component classes defined by Python code.
335 # The Python user can create a standard Python class which inherits one
336 # of the three base classes (_UserSourceComponent, _UserFilterComponent,
337 # or _UserSinkComponent). Those base classes set this class
338 # (_UserComponentType) as their metaclass.
340 # Once the body of a user-defined component class is executed, this
341 # metaclass is used to create and initialize the class. The metaclass
342 # creates a native BT component class of the corresponding type and
343 # associates it with this user-defined class. The metaclass also defines
344 # class methods like the `name` and `description` properties to match
345 # the _GenericComponentClass interface.
347 # The component class name which is used is either:
349 # * The `name` parameter of the class:
351 # class MySink(bt2.SinkComponent, name='my-custom-sink'):
354 # * If the `name` class parameter is not used: the name of the class
355 # itself (`MySink` in the example above).
357 # The component class description which is used is the user-defined
360 # class MySink(bt2.SinkComponent):
361 # 'Description goes here'
364 # A user-defined Python component class can have an __init__() method
365 # which must at least accept the `params` and `name` arguments:
367 # def __init__(self, params, name, something_else):
370 # The user-defined component class can also have a _finalize() method
371 # (do NOT use __del__()) to be notified when the component object is
374 # User-defined source and filter component classes must use the
375 # `message_iterator_class` class parameter to specify the
376 # message iterator class to use for this component class:
378 # class MyMessageIterator(bt2._UserMessageIterator):
381 # class MySource(bt2._UserSourceComponent,
382 # message_iterator_class=MyMessageIterator):
385 # This message iterator class must inherit
386 # bt2._UserMessageIterator, and it must define the _get() and
387 # _next() methods. The message iterator class can also define an
388 # __init__() method: this method has access to the original Python
389 # component object which was used to create it as the `component`
390 # property. The message iterator class can also define a
391 # _finalize() method (again, do NOT use __del__()): this is called when
392 # the message iterator is (really) destroyed.
394 # When the user-defined class is destroyed, this metaclass's __del__()
395 # method is called: the native BT component class pointer is put (not
396 # needed anymore, at least not by any Python code since all references
397 # are dropped for __del__() to be called).
398 class _UserComponentType(type):
399 # __new__() is used to catch custom class parameters
400 def __new__(meta_cls
, class_name
, bases
, attrs
, **kwargs
):
401 return super().__new
__(meta_cls
, class_name
, bases
, attrs
)
403 def __init__(cls
, class_name
, bases
, namespace
, **kwargs
):
404 super().__init
__(class_name
, bases
, namespace
)
406 # skip our own bases; they are never directly instantiated by the user
409 '_UserFilterSinkComponent',
410 '_UserSourceComponent',
411 '_UserFilterComponent',
412 '_UserSinkComponent',
415 if class_name
in own_bases
:
418 comp_cls_name
= kwargs
.get('name', class_name
)
419 utils
._check
_str
(comp_cls_name
)
420 comp_cls_descr
= None
423 if hasattr(cls
, '__doc__') and cls
.__doc
__ is not None:
424 utils
._check
_str
(cls
.__doc
__)
425 docstring
= _trim_docstring(cls
.__doc
__)
426 lines
= docstring
.splitlines()
429 comp_cls_descr
= lines
[0]
432 comp_cls_help
= '\n'.join(lines
[2:])
434 iter_cls
= kwargs
.get('message_iterator_class')
436 if _UserSourceComponent
in bases
:
437 _UserComponentType
._set
_iterator
_class
(cls
, iter_cls
)
438 cc_ptr
= native_bt
.py3_component_class_source_create(cls
,
442 elif _UserFilterComponent
in bases
:
443 _UserComponentType
._set
_iterator
_class
(cls
, iter_cls
)
444 cc_ptr
= native_bt
.py3_component_class_filter_create(cls
,
448 elif _UserSinkComponent
in bases
:
449 if not hasattr(cls
, '_consume'):
450 raise bt2
.IncompleteUserClass("cannot create component class '{}': missing a _consume() method".format(class_name
))
452 cc_ptr
= native_bt
.py3_component_class_sink_create(cls
,
457 raise bt2
.IncompleteUserClass("cannot find a known component class base in the bases of '{}'".format(class_name
))
460 raise bt2
.CreationError("cannot create component class '{}'".format(class_name
))
464 def _init_from_native(cls
, comp_ptr
, params_ptr
):
465 # create instance, not user-initialized yet
466 self
= cls
.__new
__(cls
)
468 # pointer to native self component object (weak/borrowed)
471 # call user's __init__() method
472 if params_ptr
is not None:
473 params
= bt2
.value
._create
_from
_ptr
_and
_get
_ref
(params_ptr
)
477 self
.__init
__(params
)
480 def __call__(cls
, *args
, **kwargs
):
481 raise bt2
.Error('cannot directly instantiate a user component from a Python module')
484 def _set_iterator_class(cls
, iter_cls
):
486 raise bt2
.IncompleteUserClass("cannot create component class '{}': missing message iterator class".format(cls
.__name
__))
488 if not issubclass(iter_cls
, bt2
.message_iterator
._UserMessageIterator
):
489 raise bt2
.IncompleteUserClass("cannot create component class '{}': message iterator class does not inherit bt2._UserMessageIterator".format(cls
.__name
__))
491 if not hasattr(iter_cls
, '__next__'):
492 raise bt2
.IncompleteUserClass("cannot create component class '{}': message iterator class is missing a __next__() method".format(cls
.__name
__))
494 cls
._iter
_cls
= iter_cls
498 ptr
= cls
._as
_component
_class
_ptr
(cls
._cc
_ptr
)
499 return native_bt
.component_class_get_name(ptr
)
502 def description(cls
):
503 ptr
= cls
._as
_component
_class
_ptr
(cls
._cc
_ptr
)
504 return native_bt
.component_class_get_description(ptr
)
508 ptr
= cls
._as
_component
_class
_ptr
(cls
._cc
_ptr
)
509 return native_bt
.component_class_get_help(ptr
)
513 return int(cls
._cc
_ptr
)
515 def _query_from_native(cls
, query_exec_ptr
, obj
, params_ptr
):
516 # this can raise, in which case the native call to
517 # bt_component_class_query() returns NULL
518 if params_ptr
is not None:
519 params
= bt2
.value
._create
_from
_ptr
_and
_get
_ref
(params_ptr
)
523 query_exec
= bt2
.QueryExecutor
._create
_from
_ptr
_and
_get
_ref
(
526 # this can raise, but the native side checks the exception
527 results
= cls
._query
(query_exec
, obj
, params
)
529 # this can raise, but the native side checks the exception
530 results
= bt2
.create_value(results
)
533 results_addr
= int(native_bt
.value_null
)
535 # return new reference
536 results_addr
= int(results
._release
())
540 def _query(cls
, query_executor
, obj
, params
):
541 raise NotImplementedError
543 def _component_class_ptr(self
):
544 return self
._as
_component
_class
_ptr
(self
._cc
_ptr
)
547 if hasattr(cls
, '_cc_ptr'):
548 cc_ptr
= cls
._as
_component
_class
_ptr
(cls
._cc
_ptr
)
549 native_bt
.component_class_put_ref(cc_ptr
)
551 # Subclasses must provide these methods or property:
553 # - _as_not_self_specific_component_ptr: static method, must return the passed
554 # specialized self component pointer (e.g. 'bt_self_component_sink *') as a
555 # specialized non-self pointer (e.g. 'bt_component_sink *').
556 # - _borrow_component_class_ptr: static method, must return a pointer to the
557 # specialized component class (e.g. 'bt_component_class_sink *') of the
558 # passed specialized component pointer (e.g. 'bt_component_sink *').
559 # - _comp_cls_type: property, one of the native_bt.COMPONENT_CLASS_TYPE_*
562 class _UserComponent(metaclass
=_UserComponentType
):
565 ptr
= self
._as
_not
_self
_specific
_component
_ptr
(self
._ptr
)
566 ptr
= self
._as
_component
_ptr
(ptr
)
567 name
= native_bt
.component_get_name(ptr
)
568 assert name
is not None
572 def component_class(self
):
573 comp_ptr
= self
._as
_not
_self
_specific
_component
_ptr
(self
._ptr
)
574 cc_ptr
= self
._borrow
_component
_class
_ptr
(comp_ptr
)
575 return _create_component_class_from_ptr_and_get_ref(cc_ptr
, self
._comp
_cls
_type
)
579 return int(self
._ptr
)
581 def __init__(self
, params
=None):
587 def _accept_port_connection(self
, port
, other_port
):
590 def _accept_port_connection_from_native(self
, port_ptr
, other_port_ptr
):
591 native_bt
.get(port_ptr
)
592 native_bt
.get(other_port_ptr
)
593 port
= bt2
.port
._create
_private
_from
_ptr
(port_ptr
)
594 other_port
= bt2
.port
._create
_from
_ptr
(other_port_ptr
)
595 res
= self
._accept
_port
_connection
(port
, other_port_ptr
)
597 if type(res
) is not bool:
598 raise TypeError("'{}' is not a 'bool' object")
602 def _port_connected(self
, port
, other_port
):
605 def _port_connected_from_native(self
, port_ptr
, other_port_ptr
):
606 native_bt
.get(port_ptr
)
607 native_bt
.get(other_port_ptr
)
608 port
= bt2
.port
._create
_private
_from
_ptr
(port_ptr
)
609 other_port
= bt2
.port
._create
_from
_ptr
(other_port_ptr
)
612 self
._port
_connected
(port
, other_port
)
614 if not _NO_PRINT_TRACEBACK
:
615 traceback
.print_exc()
617 def _port_disconnected(self
, port
):
620 def _port_disconnected_from_native(self
, port_ptr
):
621 native_bt
.get(port_ptr
)
622 port
= bt2
.port
._create
_private
_from
_ptr
(port_ptr
)
625 self
._port
_disconnected
(port
)
627 if not _NO_PRINT_TRACEBACK
:
628 traceback
.print_exc()
631 class _UserSourceComponent(_UserComponent
, _SourceComponent
):
632 _as_not_self_specific_component_ptr
= native_bt
.self_component_source_as_component_source
635 def _output_ports(self
):
636 return _ComponentPorts(True, self
,
637 native_bt
.private_component_source_get_output_private_port_by_name
,
638 native_bt
.private_component_source_get_output_private_port_by_index
,
639 native_bt
.component_source_get_output_port_count
)
641 def _add_output_port(self
, name
):
642 utils
._check
_str
(name
)
643 fn
= native_bt
.private_component_source_add_output_private_port
644 comp_status
, priv_port_ptr
= fn(self
._ptr
, name
, None)
645 _handle_component_status(comp_status
,
646 'cannot add output port to source component object')
647 assert(priv_port_ptr
)
648 return bt2
.port
._create
_private
_from
_ptr
(priv_port_ptr
)
651 class _UserFilterComponent(_UserComponent
, _FilterComponent
):
652 _as_not_self_specific_component_ptr
= native_bt
.self_component_filter_as_component_filter
655 def _output_ports(self
):
656 return _ComponentPorts(True, self
,
657 native_bt
.private_component_filter_get_output_private_port_by_name
,
658 native_bt
.private_component_filter_get_output_private_port_by_index
,
659 native_bt
.component_filter_get_output_port_count
)
662 def _input_ports(self
):
663 return _ComponentPorts(True, self
,
664 native_bt
.private_component_filter_get_input_private_port_by_name
,
665 native_bt
.private_component_filter_get_input_private_port_by_index
,
666 native_bt
.component_filter_get_input_port_count
)
668 def _add_output_port(self
, name
):
669 utils
._check
_str
(name
)
670 fn
= native_bt
.private_component_filter_add_output_private_port
671 comp_status
, priv_port_ptr
= fn(self
._ptr
, name
, None)
672 _handle_component_status(comp_status
,
673 'cannot add output port to filter component object')
674 assert(priv_port_ptr
)
675 return bt2
.port
._create
_private
_from
_ptr
(priv_port_ptr
)
677 def _add_input_port(self
, name
):
678 utils
._check
_str
(name
)
679 fn
= native_bt
.private_component_filter_add_input_private_port
680 comp_status
, priv_port_ptr
= fn(self
._ptr
, name
, None)
681 _handle_component_status(comp_status
,
682 'cannot add input port to filter component object')
683 assert(priv_port_ptr
)
684 return bt2
.port
._create
_private
_from
_ptr
(priv_port_ptr
)
687 class _UserSinkComponent(_UserComponent
, _SinkComponent
):
688 _as_not_self_specific_component_ptr
= native_bt
.self_component_sink_as_component_sink
691 def _input_ports(self
):
692 return _ComponentPorts(True, self
,
693 native_bt
.private_component_sink_get_input_private_port_by_name
,
694 native_bt
.private_component_sink_get_input_private_port_by_index
,
695 native_bt
.component_sink_get_input_port_count
)
697 def _add_input_port(self
, name
):
698 utils
._check
_str
(name
)
699 fn
= native_bt
.private_component_sink_add_input_private_port
700 comp_status
, priv_port_ptr
= fn(self
._ptr
, name
, None)
701 _handle_component_status(comp_status
,
702 'cannot add input port to sink component object')
703 assert(priv_port_ptr
)
704 return bt2
.port
._create
_private
_from
_ptr
(priv_port_ptr
)