bt2: update bindings to make test_component_class pass
[babeltrace.git] / bindings / python / bt2 / bt2 / component.py
1 # The MIT License (MIT)
2 #
3 # Copyright (c) 2017 Philippe Proulx <pproulx@efficios.com>
4 #
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:
11 #
12 # The above copyright notice and this permission notice shall be included in
13 # all copies or substantial portions of the Software.
14 #
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
21 # THE SOFTWARE.
22
23 from bt2 import native_bt, object, utils
24 import bt2.message_iterator
25 import collections.abc
26 import bt2.value
27 import traceback
28 import bt2.port
29 import sys
30 import bt2
31 import os
32
33
34 _env_var = os.environ.get('BABELTRACE_PYTHON_BT2_NO_TRACEBACK')
35 _NO_PRINT_TRACEBACK = _env_var == '1'
36
37
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
41 # class.
42 #
43 # Subclasses must implement some methods that this base class uses:
44 #
45 # - _as_component_class_ptr: static method, convert the passed component class
46 # pointer to a 'bt_component_class *'.
47
48 class _GenericComponentClass(object._SharedObject):
49 @property
50 def name(self):
51 ptr = self._as_component_class_ptr(self._ptr)
52 name = native_bt.component_class_get_name(ptr)
53 assert name is not None
54 return name
55
56 @property
57 def description(self):
58 ptr = self._as_component_class_ptr(self._ptr)
59 return native_bt.component_class_get_description(ptr)
60
61 @property
62 def help(self):
63 ptr = self._as_component_class_ptr(self._ptr)
64 return native_bt.component_class_get_help(ptr)
65
66 def _component_class_ptr(self):
67 return self._as_component_class_ptr(self._ptr)
68
69 def __eq__(self, other):
70 if not isinstance(other, _GenericComponentClass):
71 try:
72 if not issubclass(other, _UserComponent):
73 return False
74 except TypeError:
75 return False
76
77 return self.addr == other.addr
78
79
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
84
85
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
90
91
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
96
97
98 def _handle_component_status(status, gen_error_msg):
99 if status == native_bt.COMPONENT_STATUS_END:
100 raise bt2.Stop
101 elif status == native_bt.COMPONENT_STATUS_AGAIN:
102 raise bt2.TryAgain
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
109 elif status < 0:
110 raise bt2.Error(gen_error_msg)
111
112
113 class _PortIterator(collections.abc.Iterator):
114 def __init__(self, comp_ports):
115 self._comp_ports = comp_ports
116 self._at = 0
117
118 def __next__(self):
119 if self._at == len(self._comp_ports):
120 raise StopIteration
121
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)
125 assert(port_ptr)
126
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)
131 else:
132 name = native_bt.port_get_name(port_ptr)
133
134 assert(name is not None)
135 native_bt.put(port_ptr)
136 self._at += 1
137 return name
138
139
140 class _ComponentPorts(collections.abc.Mapping):
141 def __init__(self, is_private, component,
142 get_port_by_name_fn, get_port_at_index_fn,
143 get_port_count_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
149
150 def __getitem__(self, key):
151 utils._check_str(key)
152 port_ptr = self._get_port_by_name_fn(self._component._ptr, key)
153
154 if port_ptr is None:
155 raise KeyError(key)
156
157 if self._is_private:
158 return bt2.port._create_private_from_ptr(port_ptr)
159 else:
160 return bt2.port._create_from_ptr(port_ptr)
161
162 def __len__(self):
163 if self._is_private:
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)
167 else:
168 count = self._get_port_count_fn(self._component._ptr)
169
170 assert(count >= 0)
171 return count
172
173 def __iter__(self):
174 return _PortIterator(self)
175
176
177 # This class holds the methods which are common to both generic
178 # component objects and Python user component objects.
179 #
180 # Subclasses must provide these methods or property:
181 #
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_*
186 # constants.
187
188 class _Component:
189 @property
190 def name(self):
191 name = native_bt.component_get_name(self._ptr)
192 assert(name is not None)
193 return name
194
195 @property
196 def graph(self):
197 ptr = native_bt.component_get_graph(self._ptr)
198 assert(ptr)
199 return bt2.Graph._create_from_ptr(ptr)
200
201 @property
202 def component_class(self):
203 cc_ptr = self._borrow_component_class_ptr(self._ptr)
204 assert cc_ptr is not None
205 return _create_component_class_from_ptr_and_get_ref(cc_ptr, self._comp_cls_type)
206
207 def __eq__(self, other):
208 if not hasattr(other, 'addr'):
209 return False
210
211 return self.addr == other.addr
212
213
214 class _SourceComponent(_Component):
215 _borrow_component_class_ptr = native_bt.component_source_borrow_class_const
216 _comp_cls_type = native_bt.COMPONENT_CLASS_TYPE_SOURCE
217 _as_component_class_ptr = native_bt.component_class_source_as_component_class
218
219
220 class _FilterComponent(_Component):
221 _borrow_component_class_ptr = native_bt.component_filter_borrow_class_const
222 _comp_cls_type = native_bt.COMPONENT_CLASS_TYPE_FILTER
223 _as_component_class_ptr = native_bt.component_class_filter_as_component_class
224
225
226 class _SinkComponent(_Component):
227 _borrow_component_class_ptr = native_bt.component_sink_borrow_class_const
228 _comp_cls_type = native_bt.COMPONENT_CLASS_TYPE_SINK
229 _as_component_class_ptr = native_bt.component_class_sink_as_component_class
230
231
232 # This is analogous to _GenericSourceComponentClass, but for source
233 # component objects.
234 class _GenericSourceComponent(object._SharedObject, _SourceComponent):
235 @property
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)
241
242
243 # This is analogous to _GenericFilterComponentClass, but for filter
244 # component objects.
245 class _GenericFilterComponent(object._SharedObject, _FilterComponent):
246 @property
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)
252
253 @property
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)
259
260
261 # This is analogous to _GenericSinkComponentClass, but for sink
262 # component objects.
263 class _GenericSinkComponent(object._SharedObject, _SinkComponent):
264 _get_ref = native_bt.component_sink_get_ref
265 _put_ref = native_bt.component_sink_put_ref
266
267 @property
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)
273
274
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,
279 }
280
281
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,
286 }
287
288
289 # Create a component Python object of type _GenericSourceComponent,
290 # _GenericFilterComponent or _GenericSinkComponent, depending on
291 # comp_cls_type.
292 #
293 # Steals the reference to ptr from the caller.
294
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)
297
298 # Create a component class Python object of type
299 # _GenericSourceComponentClass, _GenericFilterComponentClass or
300 # _GenericSinkComponentClass, depending on comp_cls_type.
301 #
302 # Acquires a new reference to ptr.
303
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)
306
307
308 def _trim_docstring(docstring):
309 lines = docstring.expandtabs().splitlines()
310 indent = sys.maxsize
311
312 for line in lines[1:]:
313 stripped = line.lstrip()
314
315 if stripped:
316 indent = min(indent, len(line) - len(stripped))
317
318 trimmed = [lines[0].strip()]
319
320 if indent < sys.maxsize:
321 for line in lines[1:]:
322 trimmed.append(line[indent:].rstrip())
323
324 while trimmed and not trimmed[-1]:
325 trimmed.pop()
326
327 while trimmed and not trimmed[0]:
328 trimmed.pop(0)
329
330 return '\n'.join(trimmed)
331
332
333 # Metaclass for component classes defined by Python code.
334 #
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.
339 #
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.
346 #
347 # The component class name which is used is either:
348 #
349 # * The `name` parameter of the class:
350 #
351 # class MySink(bt2.SinkComponent, name='my-custom-sink'):
352 # ...
353 #
354 # * If the `name` class parameter is not used: the name of the class
355 # itself (`MySink` in the example above).
356 #
357 # The component class description which is used is the user-defined
358 # class's docstring:
359 #
360 # class MySink(bt2.SinkComponent):
361 # 'Description goes here'
362 # ...
363 #
364 # A user-defined Python component class can have an __init__() method
365 # which must at least accept the `params` and `name` arguments:
366 #
367 # def __init__(self, params, name, something_else):
368 # ...
369 #
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
372 # finalized.
373 #
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:
377 #
378 # class MyMessageIterator(bt2._UserMessageIterator):
379 # ...
380 #
381 # class MySource(bt2._UserSourceComponent,
382 # message_iterator_class=MyMessageIterator):
383 # ...
384 #
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.
393 #
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)
402
403 def __init__(cls, class_name, bases, namespace, **kwargs):
404 super().__init__(class_name, bases, namespace)
405
406 # skip our own bases; they are never directly instantiated by the user
407 own_bases = (
408 '_UserComponent',
409 '_UserFilterSinkComponent',
410 '_UserSourceComponent',
411 '_UserFilterComponent',
412 '_UserSinkComponent',
413 )
414
415 if class_name in own_bases:
416 return
417
418 comp_cls_name = kwargs.get('name', class_name)
419 utils._check_str(comp_cls_name)
420 comp_cls_descr = None
421 comp_cls_help = None
422
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()
427
428 if len(lines) >= 1:
429 comp_cls_descr = lines[0]
430
431 if len(lines) >= 3:
432 comp_cls_help = '\n'.join(lines[2:])
433
434 iter_cls = kwargs.get('message_iterator_class')
435
436 if _UserSourceComponent in bases:
437 _UserComponentType._set_iterator_class(cls, iter_cls)
438 cc_ptr = native_bt.py3_component_class_source_create(cls,
439 comp_cls_name,
440 comp_cls_descr,
441 comp_cls_help)
442 elif _UserFilterComponent in bases:
443 _UserComponentType._set_iterator_class(cls, iter_cls)
444 cc_ptr = native_bt.py3_component_class_filter_create(cls,
445 comp_cls_name,
446 comp_cls_descr,
447 comp_cls_help)
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))
451
452 cc_ptr = native_bt.py3_component_class_sink_create(cls,
453 comp_cls_name,
454 comp_cls_descr,
455 comp_cls_help)
456 else:
457 raise bt2.IncompleteUserClass("cannot find a known component class base in the bases of '{}'".format(class_name))
458
459 if cc_ptr is None:
460 raise bt2.CreationError("cannot create component class '{}'".format(class_name))
461
462 cls._cc_ptr = cc_ptr
463
464 def _init_from_native(cls, comp_ptr, params_ptr):
465 # create instance, not user-initialized yet
466 self = cls.__new__(cls)
467
468 # pointer to native self component object (weak/borrowed)
469 self._ptr = comp_ptr
470
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)
474 else:
475 params = None
476
477 self.__init__(params)
478 return self
479
480 def __call__(cls, *args, **kwargs):
481 raise bt2.Error('cannot directly instantiate a user component from a Python module')
482
483 @staticmethod
484 def _set_iterator_class(cls, iter_cls):
485 if iter_cls is None:
486 raise bt2.IncompleteUserClass("cannot create component class '{}': missing message iterator class".format(cls.__name__))
487
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__))
490
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__))
493
494 cls._iter_cls = iter_cls
495
496 @property
497 def name(cls):
498 ptr = cls._as_component_class_ptr(cls._cc_ptr)
499 return native_bt.component_class_get_name(ptr)
500
501 @property
502 def description(cls):
503 ptr = cls._as_component_class_ptr(cls._cc_ptr)
504 return native_bt.component_class_get_description(ptr)
505
506 @property
507 def help(cls):
508 ptr = cls._as_component_class_ptr(cls._cc_ptr)
509 return native_bt.component_class_get_help(ptr)
510
511 @property
512 def addr(cls):
513 return int(cls._cc_ptr)
514
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)
520 else:
521 params = None
522
523 query_exec = bt2.QueryExecutor._create_from_ptr_and_get_ref(
524 query_exec_ptr)
525
526 # this can raise, but the native side checks the exception
527 results = cls._query(query_exec, obj, params)
528
529 # this can raise, but the native side checks the exception
530 results = bt2.create_value(results)
531
532 if results is None:
533 results_addr = int(native_bt.value_null)
534 else:
535 # return new reference
536 results_addr = int(results._release())
537
538 return results_addr
539
540 def _query(cls, query_executor, obj, params):
541 raise NotImplementedError
542
543 def _component_class_ptr(self):
544 return self._as_component_class_ptr(self._cc_ptr)
545
546 def __del__(cls):
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)
550
551
552 class _UserComponent(metaclass=_UserComponentType):
553 @property
554 def name(self):
555 pub_ptr = native_bt.component_from_private(self._ptr)
556 name = native_bt.component_get_name(pub_ptr)
557 native_bt.put(pub_ptr)
558 assert(name is not None)
559 return name
560
561 @property
562 def graph(self):
563 pub_ptr = native_bt.component_from_private(self._ptr)
564 ptr = native_bt.component_get_graph(pub_ptr)
565 native_bt.put(pub_ptr)
566 assert(ptr)
567 return bt2.Graph._create_from_ptr(ptr)
568
569 @property
570 def component_class(self):
571 pub_ptr = native_bt.component_from_private(self._ptr)
572 cc_ptr = native_bt.component_get_class(pub_ptr)
573 native_bt.put(pub_ptr)
574 assert(cc_ptr)
575 return _create_generic_component_class_from_ptr(cc_ptr)
576
577 @property
578 def addr(self):
579 return int(self._ptr)
580
581 def __init__(self, params=None):
582 pass
583
584 def _finalize(self):
585 pass
586
587 def _accept_port_connection(self, port, other_port):
588 return True
589
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)
596
597 if type(res) is not bool:
598 raise TypeError("'{}' is not a 'bool' object")
599
600 return res
601
602 def _port_connected(self, port, other_port):
603 pass
604
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)
610
611 try:
612 self._port_connected(port, other_port)
613 except:
614 if not _NO_PRINT_TRACEBACK:
615 traceback.print_exc()
616
617 def _port_disconnected(self, port):
618 pass
619
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)
623
624 try:
625 self._port_disconnected(port)
626 except:
627 if not _NO_PRINT_TRACEBACK:
628 traceback.print_exc()
629
630
631 class _UserSourceComponent(_UserComponent, _SourceComponent):
632 @property
633 def _output_ports(self):
634 return _ComponentPorts(True, self,
635 native_bt.private_component_source_get_output_private_port_by_name,
636 native_bt.private_component_source_get_output_private_port_by_index,
637 native_bt.component_source_get_output_port_count)
638
639 def _add_output_port(self, name):
640 utils._check_str(name)
641 fn = native_bt.private_component_source_add_output_private_port
642 comp_status, priv_port_ptr = fn(self._ptr, name, None)
643 _handle_component_status(comp_status,
644 'cannot add output port to source component object')
645 assert(priv_port_ptr)
646 return bt2.port._create_private_from_ptr(priv_port_ptr)
647
648
649 class _UserFilterComponent(_UserComponent, _FilterComponent):
650 @property
651 def _output_ports(self):
652 return _ComponentPorts(True, self,
653 native_bt.private_component_filter_get_output_private_port_by_name,
654 native_bt.private_component_filter_get_output_private_port_by_index,
655 native_bt.component_filter_get_output_port_count)
656
657 @property
658 def _input_ports(self):
659 return _ComponentPorts(True, self,
660 native_bt.private_component_filter_get_input_private_port_by_name,
661 native_bt.private_component_filter_get_input_private_port_by_index,
662 native_bt.component_filter_get_input_port_count)
663
664 def _add_output_port(self, name):
665 utils._check_str(name)
666 fn = native_bt.private_component_filter_add_output_private_port
667 comp_status, priv_port_ptr = fn(self._ptr, name, None)
668 _handle_component_status(comp_status,
669 'cannot add output port to filter component object')
670 assert(priv_port_ptr)
671 return bt2.port._create_private_from_ptr(priv_port_ptr)
672
673 def _add_input_port(self, name):
674 utils._check_str(name)
675 fn = native_bt.private_component_filter_add_input_private_port
676 comp_status, priv_port_ptr = fn(self._ptr, name, None)
677 _handle_component_status(comp_status,
678 'cannot add input port to filter component object')
679 assert(priv_port_ptr)
680 return bt2.port._create_private_from_ptr(priv_port_ptr)
681
682
683 class _UserSinkComponent(_UserComponent, _SinkComponent):
684 @property
685 def _input_ports(self):
686 return _ComponentPorts(True, self,
687 native_bt.private_component_sink_get_input_private_port_by_name,
688 native_bt.private_component_sink_get_input_private_port_by_index,
689 native_bt.component_sink_get_input_port_count)
690
691 def _add_input_port(self, name):
692 utils._check_str(name)
693 fn = native_bt.private_component_sink_add_input_private_port
694 comp_status, priv_port_ptr = fn(self._ptr, name, None)
695 _handle_component_status(comp_status,
696 'cannot add input port to sink component object')
697 assert(priv_port_ptr)
698 return bt2.port._create_private_from_ptr(priv_port_ptr)
This page took 0.044068 seconds and 4 git commands to generate.