2 * The MIT License (MIT)
4 * Copyright (c) 2017 Philippe Proulx <pproulx@efficios.com>
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 #include "logging/comp-logging.h"
26 #include "compat/glib.h"
29 * This hash table associates a BT component class object address to a
30 * user-defined Python class (PyObject *). The keys and values are NOT
31 * owned by this hash table. The Python class objects are owned by the
32 * Python module, which should not be unloaded until it is not possible
33 * to create a user Python component anyway.
35 * This hash table is written to when a user-defined Python component
36 * class is created by one of the bt_bt2_component_class_*_create()
39 * This function is read from when a user calls bt_component_create()
40 * with a component class pointer created by one of the functions above.
41 * In this case, the original Python class needs to be found to
42 * instantiate it and associate the created Python component object with
43 * a BT component object instance.
46 static GHashTable
*bt_cc_ptr_to_py_cls
;
49 void bt_bt2_unregister_cc_ptr_to_py_cls(const bt_component_class
*comp_cls
)
53 if (!bt_cc_ptr_to_py_cls
) {
57 existed
= g_hash_table_remove(bt_cc_ptr_to_py_cls
, comp_cls
);
62 void register_cc_ptr_to_py_cls(struct bt_component_class
*bt_cc
,
65 if (!bt_cc_ptr_to_py_cls
) {
67 * Lazy-initializing this GHashTable because GLib
68 * might not be initialized yet and it needs to be
69 * before we call g_hash_table_new()
71 BT_LOGD_STR("Creating native component class to Python component class hash table.");
72 bt_cc_ptr_to_py_cls
= g_hash_table_new(g_direct_hash
, g_direct_equal
);
73 BT_ASSERT(bt_cc_ptr_to_py_cls
);
76 g_hash_table_insert(bt_cc_ptr_to_py_cls
, (gpointer
) bt_cc
,
81 PyObject
*lookup_cc_ptr_to_py_cls(const bt_component_class
*bt_cc
)
83 if (!bt_cc_ptr_to_py_cls
) {
84 BT_LOGW("Cannot look up Python component class because hash table is NULL: "
85 "comp-cls-addr=%p", bt_cc
);
89 return (PyObject
*) g_hash_table_lookup(bt_cc_ptr_to_py_cls
,
90 (gconstpointer
) bt_cc
);
93 /* Library destructor */
95 __attribute__((destructor
))
97 void native_comp_class_dtor(void) {
98 /* Destroy component class association hash table */
99 if (bt_cc_ptr_to_py_cls
) {
100 BT_LOGD_STR("Destroying native component class to Python component class hash table.");
101 g_hash_table_destroy(bt_cc_ptr_to_py_cls
);
102 bt_cc_ptr_to_py_cls
= NULL
;
107 int py_exc_to_status_clear(
108 bt_self_component_class
*self_component_class
,
109 bt_self_component
*self_component
,
110 bt_self_message_iterator
*self_message_iterator
,
111 const char *module_name
, int active_log_level
)
114 PyObject
*exc
= PyErr_Occurred();
117 status
= __BT_FUNC_STATUS_OK
;
121 if (PyErr_GivenExceptionMatches(exc
,
122 py_mod_bt2_exc_try_again_type
)) {
123 status
= __BT_FUNC_STATUS_AGAIN
;
124 } else if (PyErr_GivenExceptionMatches(exc
,
125 py_mod_bt2_exc_stop_type
)) {
126 status
= __BT_FUNC_STATUS_END
;
127 } else if (PyErr_GivenExceptionMatches(exc
,
128 py_mod_bt2_exc_unknown_object_type
)) {
129 status
= __BT_FUNC_STATUS_UNKNOWN_OBJECT
;
132 * Unknown exception: convert to general error.
134 * Because we only want to fetch the log level when
135 * we actually get an exception, and not systematically
136 * when we call py_exc_to_status() (as py_exc_to_status()
137 * can return `__BT_FUNC_STATUS_OK`), we get it here
138 * depending on the actor's type.
140 if (self_component
) {
141 active_log_level
= get_self_component_log_level(
143 } else if (self_message_iterator
) {
144 active_log_level
= get_self_message_iterator_log_level(
145 self_message_iterator
);
148 BT_ASSERT(active_log_level
!= -1);
149 log_exception_and_maybe_append_cause(BT_LOG_WARNING
,
150 active_log_level
, true,
151 self_component_class
, self_component
,
152 self_message_iterator
, module_name
);
154 if (PyErr_GivenExceptionMatches(exc
,
155 py_mod_bt2_exc_memory_error
)) {
156 status
= __BT_FUNC_STATUS_MEMORY_ERROR
;
158 status
= __BT_FUNC_STATUS_ERROR
;
168 int py_exc_to_status_component_class_clear(
169 bt_self_component_class
*self_component_class
,
170 int active_log_level
)
172 return py_exc_to_status_clear(self_component_class
, NULL
, NULL
, NULL
,
177 int py_exc_to_status_component_clear(bt_self_component
*self_component
)
179 return py_exc_to_status_clear(NULL
, self_component
, NULL
, NULL
, -1);
183 int py_exc_to_status_message_iterator_clear(
184 bt_self_message_iterator
*self_message_iterator
)
186 return py_exc_to_status_clear(NULL
, NULL
, self_message_iterator
, NULL
, -1);
190 bool bt_bt2_is_python_component_class(const bt_component_class
*comp_cls
)
192 return bt_g_hash_table_contains(bt_cc_ptr_to_py_cls
, comp_cls
);
195 /* Component class proxy methods (delegate to the attached Python object) */
198 bt_component_class_initialize_method_status
component_class_init(
199 bt_self_component
*self_component
,
200 void *self_component_v
,
201 swig_type_info
*self_comp_cls_type_swig_type
,
202 const bt_value
*params
,
203 void *init_method_data
)
205 const bt_component
*component
= bt_self_component_as_component(self_component
);
206 const bt_component_class
*component_class
= bt_component_borrow_class_const(component
);
207 bt_component_class_initialize_method_status status
;
208 PyObject
*py_cls
= NULL
;
209 PyObject
*py_comp
= NULL
;
210 PyObject
*py_params_ptr
= NULL
;
211 PyObject
*py_comp_ptr
= NULL
;
212 bt_logging_level log_level
= get_self_component_log_level(
215 BT_ASSERT(self_component
);
216 BT_ASSERT(self_component_v
);
217 BT_ASSERT(self_comp_cls_type_swig_type
);
220 * Get the user-defined Python class which created this
221 * component's class in the first place (borrowed
224 py_cls
= lookup_cc_ptr_to_py_cls(component_class
);
226 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
227 "Cannot find Python class associated to native component class: "
228 "comp-cls-addr=%p", component_class
);
232 /* Parameters pointer -> SWIG pointer Python object */
233 py_params_ptr
= SWIG_NewPointerObj(SWIG_as_voidptr(params
),
234 SWIGTYPE_p_bt_value
, 0);
235 if (!py_params_ptr
) {
236 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
237 "Failed to create a SWIG pointer object.");
241 py_comp_ptr
= SWIG_NewPointerObj(SWIG_as_voidptr(self_component_v
),
242 self_comp_cls_type_swig_type
, 0);
244 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
245 "Failed to create a SWIG pointer object.");
250 * Do the equivalent of this:
252 * py_comp = py_cls._bt_init_from_native(py_comp_ptr,
253 * py_params_ptr, init_method_data ? init_method_data : Py_None)
255 * _UserComponentType._bt_init_from_native() calls the Python
256 * component object's __init__() function.
258 * We don't take any reference on `init_method_data` which, if
259 * not `NULL`, is assumed to be a `PyObject *`: the user's
260 * __init__() function will eventually take a reference if
261 * needed. If `init_method_data` is `NULL`, then we pass
262 * `Py_None` as the initialization's Python object.
264 py_comp
= PyObject_CallMethod(py_cls
,
265 "_bt_init_from_native", "(OOO)", py_comp_ptr
, py_params_ptr
,
266 init_method_data
? init_method_data
: Py_None
);
268 BT_COMP_LOG_CUR_LVL(BT_LOG_WARNING
, log_level
, self_component
,
269 "Failed to call Python class's _bt_init_from_native() method: "
270 "py-cls-addr=%p", py_cls
);
271 status
= py_exc_to_status_component_clear(self_component
);
276 * Our user Python component object is now fully created and
277 * initialized by the user. Since we just created it, this
278 * native component is its only (persistent) owner.
280 bt_self_component_set_data(self_component
, py_comp
);
283 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK
;
288 /* This error path is for non-Python errors only. */
289 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR
;
292 BT_ASSERT(!PyErr_Occurred());
294 Py_XDECREF(py_params_ptr
);
295 Py_XDECREF(py_comp_ptr
);
300 bt_component_class_get_supported_mip_versions_method_status
301 component_class_get_supported_mip_versions(
302 const bt_component_class
*component_class
,
303 bt_self_component_class
*self_component_class
,
304 const bt_value
*params
, void *init_method_data
,
305 bt_logging_level log_level
,
306 bt_integer_range_set_unsigned
*supported_versions
)
309 PyObject
*py_cls
= NULL
;
310 PyObject
*py_params_ptr
= NULL
;
311 PyObject
*py_range_set_addr
= NULL
;
312 bt_integer_range_set_unsigned
*ret_range_set
= NULL
;
313 bt_component_class_get_supported_mip_versions_method_status status
;
315 py_cls
= lookup_cc_ptr_to_py_cls(component_class
);
317 BT_LOG_WRITE_CUR_LVL(BT_LOG_ERROR
, log_level
, BT_LOG_TAG
,
318 "Cannot find Python class associated to native component class: "
319 "comp-cls-addr=%p", component_class
);
323 py_params_ptr
= SWIG_NewPointerObj(SWIG_as_voidptr(params
),
324 SWIGTYPE_p_bt_value
, 0);
325 if (!py_params_ptr
) {
326 BT_LOG_WRITE_CUR_LVL(BT_LOG_ERROR
, log_level
, BT_LOG_TAG
,
327 "Failed to create a SWIG pointer object.");
332 * We don't take any reference on `init_method_data` which, if
333 * not `NULL`, is assumed to be a `PyObject *`: the user's
334 * _user_get_supported_mip_versions() function will eventually
335 * take a reference if needed. If `init_method_data` is `NULL`,
336 * then we pass `Py_None` as the initialization's Python object.
338 py_range_set_addr
= PyObject_CallMethod(py_cls
,
339 "_bt_get_supported_mip_versions_from_native", "(OOi)",
340 py_params_ptr
, init_method_data
? init_method_data
: Py_None
,
342 if (!py_range_set_addr
) {
343 BT_LOG_WRITE_CUR_LVL(BT_LOG_WARNING
, log_level
, BT_LOG_TAG
,
344 "Failed to call Python class's _bt_get_supported_mip_versions_from_native() method: "
345 "py-cls-addr=%p", py_cls
);
346 status
= py_exc_to_status_component_class_clear(self_component_class
,
352 * The returned object, on success, is an integer object
353 * (PyLong) containing the address of a BT unsigned integer
354 * range set object (new reference).
356 ret_range_set
= PyLong_AsVoidPtr(py_range_set_addr
);
357 BT_ASSERT(!PyErr_Occurred());
358 BT_ASSERT(ret_range_set
);
360 /* Copy returned ranges to input range set */
361 for (i
= 0; i
< bt_integer_range_set_get_range_count(
362 bt_integer_range_set_unsigned_as_range_set_const(ret_range_set
));
364 const bt_integer_range_unsigned
*range
=
365 bt_integer_range_set_unsigned_borrow_range_by_index_const(
367 bt_integer_range_set_add_range_status add_range_status
;
369 add_range_status
= bt_integer_range_set_unsigned_add_range(
371 bt_integer_range_unsigned_get_lower(range
),
372 bt_integer_range_unsigned_get_upper(range
));
373 if (add_range_status
) {
374 BT_LOG_WRITE_CUR_LVL(BT_LOG_ERROR
, log_level
, BT_LOG_TAG
,
375 "Failed to add range to supported MIP versions range set.");
380 status
= BT_COMPONENT_CLASS_GET_SUPPORTED_MIP_VERSIONS_METHOD_STATUS_OK
;
385 /* This error path is for non-Python errors only. */
386 status
= BT_COMPONENT_CLASS_GET_SUPPORTED_MIP_VERSIONS_METHOD_STATUS_ERROR
;
389 BT_ASSERT(!PyErr_Occurred());
390 Py_XDECREF(py_params_ptr
);
391 Py_XDECREF(py_range_set_addr
);
392 bt_integer_range_set_unsigned_put_ref(ret_range_set
);
397 bt_component_class_get_supported_mip_versions_method_status
398 component_class_source_get_supported_mip_versions(
399 bt_self_component_class_source
*self_component_class_source
,
400 const bt_value
*params
, void *init_method_data
,
401 bt_logging_level log_level
,
402 bt_integer_range_set_unsigned
*supported_versions
)
404 const bt_component_class_source
*component_class_source
= bt_self_component_class_source_as_component_class_source(self_component_class_source
);
405 const bt_component_class
*component_class
= bt_component_class_source_as_component_class_const(component_class_source
);
406 bt_self_component_class
*self_component_class
= bt_self_component_class_source_as_self_component_class(self_component_class_source
);
408 return component_class_get_supported_mip_versions(
409 component_class
, self_component_class
,
410 params
, init_method_data
, log_level
, supported_versions
);
414 bt_component_class_get_supported_mip_versions_method_status
415 component_class_filter_get_supported_mip_versions(
416 bt_self_component_class_filter
*self_component_class_filter
,
417 const bt_value
*params
, void *init_method_data
,
418 bt_logging_level log_level
,
419 bt_integer_range_set_unsigned
*supported_versions
)
421 const bt_component_class_filter
*component_class_filter
= bt_self_component_class_filter_as_component_class_filter(self_component_class_filter
);
422 const bt_component_class
*component_class
= bt_component_class_filter_as_component_class_const(component_class_filter
);
423 bt_self_component_class
*self_component_class
= bt_self_component_class_filter_as_self_component_class(self_component_class_filter
);
425 return component_class_get_supported_mip_versions(
426 component_class
, self_component_class
,
427 params
, init_method_data
, log_level
, supported_versions
);
431 bt_component_class_get_supported_mip_versions_method_status
432 component_class_sink_get_supported_mip_versions(
433 bt_self_component_class_sink
*self_component_class_sink
,
434 const bt_value
*params
, void *init_method_data
,
435 bt_logging_level log_level
,
436 bt_integer_range_set_unsigned
*supported_versions
)
438 const bt_component_class_sink
*component_class_sink
= bt_self_component_class_sink_as_component_class_sink(self_component_class_sink
);
439 const bt_component_class
*component_class
= bt_component_class_sink_as_component_class_const(component_class_sink
);
440 bt_self_component_class
*self_component_class
= bt_self_component_class_sink_as_self_component_class(self_component_class_sink
);
442 return component_class_get_supported_mip_versions(
443 component_class
, self_component_class
,
444 params
, init_method_data
, log_level
, supported_versions
);
448 * Method of bt_component_class_source to initialize a bt_self_component_source
453 bt_component_class_initialize_method_status
component_class_source_init(
454 bt_self_component_source
*self_component_source
,
455 bt_self_component_source_configuration
*config
,
456 const bt_value
*params
, void *init_method_data
)
458 bt_self_component
*self_component
= bt_self_component_source_as_self_component(self_component_source
);
459 return component_class_init(
461 self_component_source
,
462 SWIGTYPE_p_bt_self_component_source
,
463 params
, init_method_data
);
467 bt_component_class_initialize_method_status
component_class_filter_init(
468 bt_self_component_filter
*self_component_filter
,
469 bt_self_component_filter_configuration
*config
,
470 const bt_value
*params
, void *init_method_data
)
472 bt_self_component
*self_component
= bt_self_component_filter_as_self_component(self_component_filter
);
473 return component_class_init(
475 self_component_filter
,
476 SWIGTYPE_p_bt_self_component_filter
,
477 params
, init_method_data
);
481 bt_component_class_initialize_method_status
component_class_sink_init(
482 bt_self_component_sink
*self_component_sink
,
483 bt_self_component_sink_configuration
*config
,
484 const bt_value
*params
, void *init_method_data
)
486 bt_self_component
*self_component
= bt_self_component_sink_as_self_component(self_component_sink
);
487 return component_class_init(
490 SWIGTYPE_p_bt_self_component_sink
,
491 params
, init_method_data
);
495 void component_class_finalize(bt_self_component
*self_component
)
497 PyObject
*py_comp
= bt_self_component_get_data(self_component
);
498 PyObject
*py_method_result
;
502 /* Call user's _user_finalize() method */
503 py_method_result
= PyObject_CallMethod(py_comp
, "_user_finalize", NULL
);
504 if (!py_method_result
) {
505 bt_logging_level log_level
= get_self_component_log_level(
509 * Ignore any exception raised by the _user_finalize() method
510 * because it won't change anything at this point: the component
511 * is being destroyed anyway.
513 BT_COMP_LOG_CUR_LVL(BT_LOG_WARNING
, log_level
, self_component
,
514 "User component's _user_finalize() method raised an exception: ignoring:");
515 logw_exception_clear(log_level
);
520 BT_ASSERT(py_method_result
== Py_None
);
523 Py_XDECREF(py_method_result
);
528 void component_class_source_finalize(bt_self_component_source
*self_component_source
)
530 bt_self_component
*self_component
= bt_self_component_source_as_self_component(self_component_source
);
531 component_class_finalize(self_component
);
535 void component_class_filter_finalize(bt_self_component_filter
*self_component_filter
)
537 bt_self_component
*self_component
= bt_self_component_filter_as_self_component(self_component_filter
);
538 component_class_finalize(self_component
);
542 void component_class_sink_finalize(bt_self_component_sink
*self_component_sink
)
544 bt_self_component
*self_component
= bt_self_component_sink_as_self_component(self_component_sink
);
545 component_class_finalize(self_component
);
549 bt_component_class_message_iterator_can_seek_beginning_method_status
550 component_class_can_seek_beginning(
551 bt_self_message_iterator
*self_message_iterator
, bt_bool
*can_seek
)
554 PyObject
*py_result
= NULL
;
555 bt_component_class_message_iterator_can_seek_beginning_method_status status
;
556 py_iter
= bt_self_message_iterator_get_data(self_message_iterator
);
560 py_result
= PyObject_CallMethod(py_iter
,
561 "_bt_can_seek_beginning_from_native", NULL
);
563 status
= py_exc_to_status_message_iterator_clear(self_message_iterator
);
567 BT_ASSERT(PyBool_Check(py_result
));
568 *can_seek
= PyObject_IsTrue(py_result
);
570 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_CAN_SEEK_BEGINNING_METHOD_STATUS_OK
;
573 Py_XDECREF(py_result
);
579 bt_component_class_message_iterator_seek_beginning_method_status
580 component_class_seek_beginning(bt_self_message_iterator
*self_message_iterator
)
584 bt_component_class_message_iterator_seek_beginning_method_status status
;
586 py_iter
= bt_self_message_iterator_get_data(self_message_iterator
);
589 py_result
= PyObject_CallMethod(py_iter
,
590 "_bt_seek_beginning_from_native",
593 status
= py_exc_to_status_message_iterator_clear(self_message_iterator
);
597 BT_ASSERT(py_result
== Py_None
);
599 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_SEEK_BEGINNING_METHOD_STATUS_OK
;
602 Py_XDECREF(py_result
);
608 bt_component_class_message_iterator_can_seek_ns_from_origin_method_status
609 component_class_can_seek_ns_from_origin(
610 bt_self_message_iterator
*self_message_iterator
,
611 int64_t ns_from_origin
, bt_bool
*can_seek
)
614 PyObject
*py_result
= NULL
;
615 bt_component_class_message_iterator_can_seek_ns_from_origin_method_status status
;
617 py_iter
= bt_self_message_iterator_get_data(self_message_iterator
);
620 py_result
= PyObject_CallMethod(py_iter
,
621 "_bt_can_seek_ns_from_origin_from_native", "L", ns_from_origin
);
623 status
= py_exc_to_status_message_iterator_clear(self_message_iterator
);
627 BT_ASSERT(PyBool_Check(py_result
));
628 *can_seek
= PyObject_IsTrue(py_result
);
630 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_CAN_SEEK_NS_FROM_ORIGIN_METHOD_STATUS_OK
;
633 Py_XDECREF(py_result
);
639 bt_component_class_message_iterator_seek_ns_from_origin_method_status
640 component_class_seek_ns_from_origin(
641 bt_self_message_iterator
*self_message_iterator
,
642 int64_t ns_from_origin
)
646 bt_component_class_message_iterator_seek_ns_from_origin_method_status status
;
648 py_iter
= bt_self_message_iterator_get_data(self_message_iterator
);
651 py_result
= PyObject_CallMethod(py_iter
,
652 "_bt_seek_ns_from_origin_from_native", "L", ns_from_origin
);
654 status
= py_exc_to_status_message_iterator_clear(self_message_iterator
);
659 BT_ASSERT(py_result
== Py_None
);
661 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_SEEK_NS_FROM_ORIGIN_METHOD_STATUS_OK
;
664 Py_XDECREF(py_result
);
670 bt_component_class_port_connected_method_status
component_class_port_connected(
671 bt_self_component
*self_component
,
672 void *self_component_port
,
673 swig_type_info
*self_component_port_swig_type
,
674 bt_port_type self_component_port_type
,
675 const void *other_port
,
676 swig_type_info
*other_port_swig_type
)
678 bt_component_class_port_connected_method_status status
;
679 PyObject
*py_comp
= NULL
;
680 PyObject
*py_self_port_ptr
= NULL
;
681 PyObject
*py_other_port_ptr
= NULL
;
682 PyObject
*py_method_result
= NULL
;
683 bt_logging_level log_level
= get_self_component_log_level(
686 py_comp
= bt_self_component_get_data(self_component
);
688 py_self_port_ptr
= SWIG_NewPointerObj(SWIG_as_voidptr(self_component_port
),
689 self_component_port_swig_type
, 0);
690 if (!py_self_port_ptr
) {
691 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
692 "Failed to create a SWIG pointer object.");
693 status
= __BT_FUNC_STATUS_MEMORY_ERROR
;
697 py_other_port_ptr
= SWIG_NewPointerObj(SWIG_as_voidptr(other_port
),
698 other_port_swig_type
, 0);
699 if (!py_other_port_ptr
) {
700 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
701 "Failed to create a SWIG pointer object.");
702 status
= __BT_FUNC_STATUS_MEMORY_ERROR
;
706 py_method_result
= PyObject_CallMethod(py_comp
,
707 "_bt_port_connected_from_native", "(OiO)", py_self_port_ptr
,
708 self_component_port_type
, py_other_port_ptr
);
709 if (!py_method_result
) {
710 status
= py_exc_to_status_component_clear(self_component
);
714 BT_ASSERT(py_method_result
== Py_None
);
716 status
= BT_COMPONENT_CLASS_PORT_CONNECTED_METHOD_STATUS_OK
;
719 Py_XDECREF(py_self_port_ptr
);
720 Py_XDECREF(py_other_port_ptr
);
721 Py_XDECREF(py_method_result
);
727 bt_component_class_port_connected_method_status
728 component_class_source_output_port_connected(
729 bt_self_component_source
*self_component_source
,
730 bt_self_component_port_output
*self_component_port_output
,
731 const bt_port_input
*other_port_input
)
733 bt_self_component
*self_component
= bt_self_component_source_as_self_component(self_component_source
);
735 return component_class_port_connected(
737 self_component_port_output
,
738 SWIGTYPE_p_bt_self_component_port_output
,
741 SWIGTYPE_p_bt_port_input
);
745 bt_component_class_port_connected_method_status
746 component_class_filter_input_port_connected(
747 bt_self_component_filter
*self_component_filter
,
748 bt_self_component_port_input
*self_component_port_input
,
749 const bt_port_output
*other_port_output
)
751 bt_self_component
*self_component
= bt_self_component_filter_as_self_component(self_component_filter
);
753 return component_class_port_connected(
755 self_component_port_input
,
756 SWIGTYPE_p_bt_self_component_port_input
,
759 SWIGTYPE_p_bt_port_output
);
763 bt_component_class_port_connected_method_status
764 component_class_filter_output_port_connected(
765 bt_self_component_filter
*self_component_filter
,
766 bt_self_component_port_output
*self_component_port_output
,
767 const bt_port_input
*other_port_input
)
769 bt_self_component
*self_component
= bt_self_component_filter_as_self_component(self_component_filter
);
771 return component_class_port_connected(
773 self_component_port_output
,
774 SWIGTYPE_p_bt_self_component_port_output
,
777 SWIGTYPE_p_bt_port_input
);
781 bt_component_class_port_connected_method_status
782 component_class_sink_input_port_connected(
783 bt_self_component_sink
*self_component_sink
,
784 bt_self_component_port_input
*self_component_port_input
,
785 const bt_port_output
*other_port_output
)
787 bt_self_component
*self_component
= bt_self_component_sink_as_self_component(self_component_sink
);
789 return component_class_port_connected(
791 self_component_port_input
,
792 SWIGTYPE_p_bt_self_component_port_input
,
795 SWIGTYPE_p_bt_port_output
);
799 bt_component_class_sink_graph_is_configured_method_status
800 component_class_sink_graph_is_configured(
801 bt_self_component_sink
*self_component_sink
)
803 PyObject
*py_comp
= NULL
;
804 PyObject
*py_method_result
= NULL
;
805 bt_component_class_sink_graph_is_configured_method_status status
;
806 bt_self_component
*self_component
= bt_self_component_sink_as_self_component(self_component_sink
);
808 py_comp
= bt_self_component_get_data(self_component
);
810 py_method_result
= PyObject_CallMethod(py_comp
,
811 "_bt_graph_is_configured_from_native", NULL
);
812 if (!py_method_result
) {
813 status
= py_exc_to_status_component_clear(self_component
);
817 BT_ASSERT(py_method_result
== Py_None
);
819 status
= BT_COMPONENT_CLASS_SINK_GRAPH_IS_CONFIGURED_METHOD_STATUS_OK
;;
822 Py_XDECREF(py_method_result
);
827 bt_component_class_query_method_status
component_class_query(
828 const bt_component_class
*component_class
,
829 bt_self_component_class
*self_component_class
,
830 bt_private_query_executor
*priv_query_executor
,
831 const char *object
, const bt_value
*params
, void *method_data
,
832 const bt_value
**result
)
834 PyObject
*py_cls
= NULL
;
835 PyObject
*py_params_ptr
= NULL
;
836 PyObject
*py_priv_query_exec_ptr
= NULL
;
837 PyObject
*py_query_func
= NULL
;
838 PyObject
*py_object
= NULL
;
839 PyObject
*py_results_addr
= NULL
;
840 bt_component_class_query_method_status status
= __BT_FUNC_STATUS_OK
;
841 const bt_query_executor
*query_exec
=
842 bt_private_query_executor_as_query_executor_const(
843 priv_query_executor
);
844 bt_logging_level log_level
=
845 bt_query_executor_get_logging_level(query_exec
);
848 * If there's any `method_data`, assume this component class is
849 * getting queried from Python, so that `method_data` is a
850 * Python object to pass to the user's _user_query() method.
852 BT_ASSERT(!method_data
||
853 bt_bt2_is_python_component_class(component_class
));
855 py_cls
= lookup_cc_ptr_to_py_cls(component_class
);
857 BT_LOG_WRITE_CUR_LVL(BT_LOG_ERROR
, log_level
, BT_LOG_TAG
,
858 "Cannot find Python class associated to native component class: "
859 "comp-cls-addr=%p", component_class
);
863 py_params_ptr
= SWIG_NewPointerObj(SWIG_as_voidptr(params
),
864 SWIGTYPE_p_bt_value
, 0);
865 if (!py_params_ptr
) {
866 BT_LOG_WRITE_CUR_LVL(BT_LOG_ERROR
, log_level
, BT_LOG_TAG
,
867 "Failed to create a SWIG pointer object.");
871 py_priv_query_exec_ptr
= SWIG_NewPointerObj(
872 SWIG_as_voidptr(priv_query_executor
),
873 SWIGTYPE_p_bt_private_query_executor
, 0);
874 if (!py_priv_query_exec_ptr
) {
875 BT_LOG_WRITE_CUR_LVL(BT_LOG_ERROR
, log_level
, BT_LOG_TAG
,
876 "Failed to create a SWIG pointer object.");
880 py_object
= SWIG_FromCharPtr(object
);
882 BT_LOG_WRITE_CUR_LVL(BT_LOG_ERROR
, log_level
, BT_LOG_TAG
,
883 "Failed to create a Python string.");
888 * We don't take any reference on `method_data` which, if not
889 * `NULL`, is assumed to be a `PyObject *`: the user's
890 * _user_query() function will eventually take a reference if
891 * needed. If `method_data` is `NULL`, then we pass `Py_None` as
892 * the initialization's Python object.
894 py_results_addr
= PyObject_CallMethod(py_cls
,
895 "_bt_query_from_native", "(OOOO)", py_priv_query_exec_ptr
,
896 py_object
, py_params_ptr
,
897 method_data
? method_data
: Py_None
);
898 if (!py_results_addr
) {
899 status
= py_exc_to_status_component_class_clear(self_component_class
,
902 static const char *fmt
=
903 "Failed to call Python class's _bt_query_from_native() method: py-cls-addr=%p";
904 BT_LOG_WRITE_CUR_LVL(BT_LOG_WARNING
, log_level
, BT_LOG_TAG
,
906 BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_COMPONENT_CLASS(
907 self_component_class
, fmt
, py_cls
);
913 * The returned object, on success, is an integer object
914 * (PyLong) containing the address of a BT value object (new
917 *result
= PyLong_AsVoidPtr(py_results_addr
);
918 BT_ASSERT(!PyErr_Occurred());
924 status
= __BT_FUNC_STATUS_ERROR
;
927 Py_XDECREF(py_params_ptr
);
928 Py_XDECREF(py_priv_query_exec_ptr
);
929 Py_XDECREF(py_query_func
);
930 Py_XDECREF(py_object
);
931 Py_XDECREF(py_results_addr
);
936 bt_component_class_query_method_status
component_class_source_query(
937 bt_self_component_class_source
*self_component_class_source
,
938 bt_private_query_executor
*priv_query_executor
,
939 const char *object
, const bt_value
*params
, void *method_data
,
940 const bt_value
**result
)
942 const bt_component_class_source
*component_class_source
= bt_self_component_class_source_as_component_class_source(self_component_class_source
);
943 const bt_component_class
*component_class
= bt_component_class_source_as_component_class_const(component_class_source
);
944 bt_self_component_class
*self_component_class
= bt_self_component_class_source_as_self_component_class(self_component_class_source
);
946 return component_class_query(component_class
, self_component_class
,
947 priv_query_executor
, object
, params
, method_data
, result
);
951 bt_component_class_query_method_status
component_class_filter_query(
952 bt_self_component_class_filter
*self_component_class_filter
,
953 bt_private_query_executor
*priv_query_executor
,
954 const char *object
, const bt_value
*params
, void *method_data
,
955 const bt_value
**result
)
957 const bt_component_class_filter
*component_class_filter
= bt_self_component_class_filter_as_component_class_filter(self_component_class_filter
);
958 const bt_component_class
*component_class
= bt_component_class_filter_as_component_class_const(component_class_filter
);
959 bt_self_component_class
*self_component_class
= bt_self_component_class_filter_as_self_component_class(self_component_class_filter
);
961 return component_class_query(component_class
, self_component_class
,
962 priv_query_executor
, object
, params
, method_data
, result
);
966 bt_component_class_query_method_status
component_class_sink_query(
967 bt_self_component_class_sink
*self_component_class_sink
,
968 bt_private_query_executor
*priv_query_executor
,
969 const char *object
, const bt_value
*params
, void *method_data
,
970 const bt_value
**result
)
972 const bt_component_class_sink
*component_class_sink
= bt_self_component_class_sink_as_component_class_sink(self_component_class_sink
);
973 const bt_component_class
*component_class
= bt_component_class_sink_as_component_class_const(component_class_sink
);
974 bt_self_component_class
*self_component_class
= bt_self_component_class_sink_as_self_component_class(self_component_class_sink
);
976 return component_class_query(component_class
, self_component_class
,
977 priv_query_executor
, object
, params
, method_data
, result
);
981 bt_component_class_message_iterator_initialize_method_status
982 component_class_message_iterator_init(
983 bt_self_message_iterator
*self_message_iterator
,
984 bt_self_message_iterator_configuration
*config
,
985 bt_self_component
*self_component
,
986 bt_self_component_port_output
*self_component_port_output
)
988 bt_component_class_message_iterator_initialize_method_status status
= __BT_FUNC_STATUS_OK
;
989 PyObject
*py_comp_cls
= NULL
;
990 PyObject
*py_iter_cls
= NULL
;
991 PyObject
*py_iter_ptr
= NULL
;
992 PyObject
*py_config_ptr
= NULL
;
993 PyObject
*py_component_port_output_ptr
= NULL
;
994 PyObject
*py_init_method_result
= NULL
;
995 PyObject
*py_iter
= NULL
;
997 bt_logging_level log_level
= get_self_component_log_level(
1000 py_comp
= bt_self_component_get_data(self_component
);
1002 /* Find user's Python message iterator class */
1003 py_comp_cls
= PyObject_GetAttrString(py_comp
, "__class__");
1005 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
1006 "Cannot get Python object's `__class__` attribute.");
1010 py_iter_cls
= PyObject_GetAttrString(py_comp_cls
, "_iter_cls");
1012 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
1013 "Cannot get Python class's `_iter_cls` attribute.");
1017 py_iter_ptr
= SWIG_NewPointerObj(SWIG_as_voidptr(self_message_iterator
),
1018 SWIGTYPE_p_bt_self_message_iterator
, 0);
1020 const char *err
= "Failed to create a SWIG pointer object.";
1022 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
1024 BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_MESSAGE_ITERATOR(
1025 self_message_iterator
, err
);
1030 * Create object with borrowed native message iterator
1033 * py_iter = py_iter_cls.__new__(py_iter_cls, py_iter_ptr)
1035 py_iter
= PyObject_CallMethod(py_iter_cls
, "__new__",
1036 "(OO)", py_iter_cls
, py_iter_ptr
);
1038 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
1039 "Failed to call Python class's __new__() method: "
1040 "py-cls-addr=%p", py_iter_cls
);
1045 * Initialize object:
1047 * py_iter.__init__(config, self_output_port)
1049 * through the _init_from_native helper static method.
1051 * At this point, py_iter._ptr is set, so this initialization
1052 * function has access to self._component (which gives it the
1053 * user Python component object from which the iterator was
1056 py_config_ptr
= SWIG_NewPointerObj(SWIG_as_voidptr(config
),
1057 SWIGTYPE_p_bt_self_message_iterator_configuration
, 0);
1058 if (!py_config_ptr
) {
1059 const char *err
= "Failed to create a SWIG pointer object";
1061 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
1063 BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_MESSAGE_ITERATOR(
1064 self_message_iterator
, err
);
1068 py_component_port_output_ptr
= SWIG_NewPointerObj(
1069 SWIG_as_voidptr(self_component_port_output
),
1070 SWIGTYPE_p_bt_self_component_port_output
, 0);
1071 if (!py_component_port_output_ptr
) {
1072 const char *err
= "Failed to create a SWIG pointer object.";
1074 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
1076 BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_MESSAGE_ITERATOR(
1077 self_message_iterator
, err
);
1081 py_init_method_result
= PyObject_CallMethod(py_iter
,
1082 "_bt_init_from_native", "OO", py_config_ptr
,
1083 py_component_port_output_ptr
);
1084 if (!py_init_method_result
) {
1085 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
1086 "User's __init__() method failed:");
1091 * Since the Python code can never instantiate a user-defined
1092 * message iterator class, the native message iterator
1093 * object does NOT belong to a user Python message iterator
1094 * object (borrowed reference). However this Python object is
1095 * owned by this native message iterator object.
1097 * In the Python world, the lifetime of the native message
1098 * iterator is managed by a _GenericMessageIterator
1101 * _GenericMessageIterator instance:
1102 * owns a native bt_message_iterator object (iter)
1103 * owns a _UserMessageIterator instance (py_iter)
1104 * self._ptr is a borrowed reference to the
1105 * native bt_private_connection_private_message_iterator
1108 bt_self_message_iterator_set_data(self_message_iterator
, py_iter
);
1113 /* Handling of errors that cause a Python exception to be set. */
1114 status
= py_exc_to_status_message_iterator_clear(self_message_iterator
);
1118 /* Handling of errors that don't cause a Python exception to be set. */
1119 status
= __BT_FUNC_STATUS_ERROR
;
1122 BT_ASSERT(!PyErr_Occurred());
1124 Py_XDECREF(py_comp_cls
);
1125 Py_XDECREF(py_iter_cls
);
1126 Py_XDECREF(py_iter_ptr
);
1127 Py_XDECREF(py_component_port_output_ptr
);
1128 Py_XDECREF(py_init_method_result
);
1129 Py_XDECREF(py_iter
);
1134 bt_component_class_message_iterator_initialize_method_status
1135 component_class_source_message_iterator_init(
1136 bt_self_message_iterator
*self_message_iterator
,
1137 bt_self_message_iterator_configuration
*config
,
1138 bt_self_component_source
*self_component_source
,
1139 bt_self_component_port_output
*self_component_port_output
)
1141 bt_self_component
*self_component
=
1142 bt_self_component_source_as_self_component(self_component_source
);
1144 return component_class_message_iterator_init(self_message_iterator
,
1145 config
, self_component
, self_component_port_output
);
1149 bt_component_class_message_iterator_initialize_method_status
1150 component_class_filter_message_iterator_init(
1151 bt_self_message_iterator
*self_message_iterator
,
1152 bt_self_message_iterator_configuration
*config
,
1153 bt_self_component_filter
*self_component_filter
,
1154 bt_self_component_port_output
*self_component_port_output
)
1156 bt_self_component
*self_component
=
1157 bt_self_component_filter_as_self_component(self_component_filter
);
1159 return component_class_message_iterator_init(self_message_iterator
,
1160 config
, self_component
, self_component_port_output
);
1164 void component_class_message_iterator_finalize(
1165 bt_self_message_iterator
*message_iterator
)
1167 PyObject
*py_message_iter
= bt_self_message_iterator_get_data(
1169 PyObject
*py_method_result
= NULL
;
1171 BT_ASSERT(py_message_iter
);
1173 /* Call user's _user_finalize() method */
1174 py_method_result
= PyObject_CallMethod(py_message_iter
,
1175 "_user_finalize", NULL
);
1176 if (!py_method_result
) {
1177 bt_self_component
*self_comp
=
1178 bt_self_message_iterator_borrow_component(
1180 bt_logging_level log_level
= get_self_component_log_level(
1184 * Ignore any exception raised by the _user_finalize() method
1185 * because it won't change anything at this point: the component
1186 * is being destroyed anyway.
1188 BT_COMP_LOG_CUR_LVL(BT_LOG_WARNING
, log_level
, self_comp
,
1189 "User's _user_finalize() method raised an exception: ignoring:");
1190 logw_exception_clear(get_self_message_iterator_log_level(
1194 Py_XDECREF(py_method_result
);
1195 Py_DECREF(py_message_iter
);
1198 /* Valid for both sources and filters. */
1201 bt_component_class_message_iterator_next_method_status
1202 component_class_message_iterator_next(
1203 bt_self_message_iterator
*message_iterator
,
1204 bt_message_array_const msgs
, uint64_t capacity
,
1207 bt_component_class_message_iterator_next_method_status status
;
1208 PyObject
*py_message_iter
= bt_self_message_iterator_get_data(message_iterator
);
1209 PyObject
*py_method_result
= NULL
;
1211 BT_ASSERT_DBG(py_message_iter
);
1212 py_method_result
= PyObject_CallMethod(py_message_iter
,
1213 "_bt_next_from_native", NULL
);
1214 if (!py_method_result
) {
1215 status
= py_exc_to_status_message_iterator_clear(message_iterator
);
1220 * The returned object, on success, is an integer object
1221 * (PyLong) containing the address of a native message
1222 * object (which is now ours).
1224 msgs
[0] = PyLong_AsVoidPtr(py_method_result
);
1227 /* Overflow errors should never happen. */
1228 BT_ASSERT_DBG(!PyErr_Occurred());
1230 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK
;
1233 Py_XDECREF(py_method_result
);
1238 bt_component_class_sink_consume_method_status
1239 component_class_sink_consume(bt_self_component_sink
*self_component_sink
)
1241 bt_self_component
*self_component
= bt_self_component_sink_as_self_component(self_component_sink
);
1242 PyObject
*py_comp
= bt_self_component_get_data(self_component
);
1243 PyObject
*py_method_result
= NULL
;
1244 bt_component_class_sink_consume_method_status status
;
1246 BT_ASSERT_DBG(py_comp
);
1248 py_method_result
= PyObject_CallMethod(py_comp
,
1249 "_user_consume", NULL
);
1250 if (!py_method_result
) {
1251 status
= py_exc_to_status_component_clear(self_component
);
1255 status
= BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_OK
;
1258 Py_XDECREF(py_method_result
);
1263 int component_class_set_help_and_desc(
1264 bt_component_class
*component_class
,
1265 const char *description
, const char *help
)
1270 ret
= bt_component_class_set_description(component_class
, description
);
1272 BT_LOGE("Cannot set component class's description: "
1273 "comp-cls-addr=%p", component_class
);
1279 ret
= bt_component_class_set_help(component_class
, help
);
1281 BT_LOGE("Cannot set component class's help text: "
1282 "comp-cls-addr=%p", component_class
);
1294 bt_component_class_source
*bt_bt2_component_class_source_create(
1295 PyObject
*py_cls
, const char *name
, const char *description
,
1298 bt_component_class_source
*component_class_source
;
1299 bt_component_class
*component_class
;
1303 component_class_source
= bt_component_class_source_create(name
,
1304 component_class_message_iterator_next
);
1305 if (!component_class_source
) {
1306 BT_LOGE_STR("Cannot create source component class.");
1310 component_class
= bt_component_class_source_as_component_class(component_class_source
);
1312 if (component_class_set_help_and_desc(component_class
, description
, help
)) {
1316 ret
= bt_component_class_source_set_initialize_method(component_class_source
, component_class_source_init
);
1317 BT_ASSERT(ret
== 0);
1318 ret
= bt_component_class_source_set_finalize_method(component_class_source
, component_class_source_finalize
);
1319 BT_ASSERT(ret
== 0);
1320 ret
= bt_component_class_source_set_message_iterator_seek_beginning_methods(component_class_source
,
1321 component_class_seek_beginning
, component_class_can_seek_beginning
);
1322 ret
= bt_component_class_source_set_message_iterator_seek_ns_from_origin_methods(
1323 component_class_source
, component_class_seek_ns_from_origin
,
1324 component_class_can_seek_ns_from_origin
);
1325 BT_ASSERT(ret
== 0);
1326 ret
= bt_component_class_source_set_output_port_connected_method(component_class_source
,
1327 component_class_source_output_port_connected
);
1328 BT_ASSERT(ret
== 0);
1329 ret
= bt_component_class_source_set_query_method(component_class_source
, component_class_source_query
);
1330 BT_ASSERT(ret
== 0);
1331 ret
= bt_component_class_source_set_get_supported_mip_versions_method(component_class_source
, component_class_source_get_supported_mip_versions
);
1332 BT_ASSERT(ret
== 0);
1333 ret
= bt_component_class_source_set_message_iterator_initialize_method(
1334 component_class_source
, component_class_source_message_iterator_init
);
1335 BT_ASSERT(ret
== 0);
1336 ret
= bt_component_class_source_set_message_iterator_finalize_method(
1337 component_class_source
, component_class_message_iterator_finalize
);
1338 BT_ASSERT(ret
== 0);
1339 register_cc_ptr_to_py_cls(component_class
, py_cls
);
1342 return component_class_source
;
1346 bt_component_class_filter
*bt_bt2_component_class_filter_create(
1347 PyObject
*py_cls
, const char *name
, const char *description
,
1350 bt_component_class
*component_class
;
1351 bt_component_class_filter
*component_class_filter
;
1355 component_class_filter
= bt_component_class_filter_create(name
,
1356 component_class_message_iterator_next
);
1357 if (!component_class_filter
) {
1358 BT_LOGE_STR("Cannot create filter component class.");
1362 component_class
= bt_component_class_filter_as_component_class(component_class_filter
);
1364 if (component_class_set_help_and_desc(component_class
, description
, help
)) {
1368 ret
= bt_component_class_filter_set_initialize_method(component_class_filter
, component_class_filter_init
);
1369 BT_ASSERT(ret
== 0);
1370 ret
= bt_component_class_filter_set_finalize_method (component_class_filter
, component_class_filter_finalize
);
1371 BT_ASSERT(ret
== 0);
1372 ret
= bt_component_class_filter_set_message_iterator_seek_beginning_methods(component_class_filter
,
1373 component_class_seek_beginning
, component_class_can_seek_beginning
);
1374 BT_ASSERT(ret
== 0);
1375 ret
= bt_component_class_filter_set_message_iterator_seek_ns_from_origin_methods(
1376 component_class_filter
, component_class_seek_ns_from_origin
,
1377 component_class_can_seek_ns_from_origin
);
1378 ret
= bt_component_class_filter_set_input_port_connected_method(component_class_filter
,
1379 component_class_filter_input_port_connected
);
1380 BT_ASSERT(ret
== 0);
1381 ret
= bt_component_class_filter_set_output_port_connected_method(component_class_filter
,
1382 component_class_filter_output_port_connected
);
1383 BT_ASSERT(ret
== 0);
1384 ret
= bt_component_class_filter_set_query_method(component_class_filter
, component_class_filter_query
);
1385 BT_ASSERT(ret
== 0);
1386 ret
= bt_component_class_filter_set_get_supported_mip_versions_method(component_class_filter
, component_class_filter_get_supported_mip_versions
);
1387 BT_ASSERT(ret
== 0);
1388 ret
= bt_component_class_filter_set_message_iterator_initialize_method(
1389 component_class_filter
, component_class_filter_message_iterator_init
);
1390 BT_ASSERT(ret
== 0);
1391 ret
= bt_component_class_filter_set_message_iterator_finalize_method(
1392 component_class_filter
, component_class_message_iterator_finalize
);
1393 BT_ASSERT(ret
== 0);
1394 register_cc_ptr_to_py_cls(component_class
, py_cls
);
1397 return component_class_filter
;
1401 bt_component_class_sink
*bt_bt2_component_class_sink_create(
1402 PyObject
*py_cls
, const char *name
, const char *description
,
1405 bt_component_class_sink
*component_class_sink
;
1406 bt_component_class
*component_class
;
1410 component_class_sink
= bt_component_class_sink_create(name
, component_class_sink_consume
);
1412 if (!component_class_sink
) {
1413 BT_LOGE_STR("Cannot create sink component class.");
1417 component_class
= bt_component_class_sink_as_component_class(component_class_sink
);
1419 if (component_class_set_help_and_desc(component_class
, description
, help
)) {
1423 ret
= bt_component_class_sink_set_initialize_method(component_class_sink
, component_class_sink_init
);
1424 BT_ASSERT(ret
== 0);
1425 ret
= bt_component_class_sink_set_finalize_method(component_class_sink
, component_class_sink_finalize
);
1426 BT_ASSERT(ret
== 0);
1427 ret
= bt_component_class_sink_set_input_port_connected_method(component_class_sink
,
1428 component_class_sink_input_port_connected
);
1429 BT_ASSERT(ret
== 0);
1430 ret
= bt_component_class_sink_set_graph_is_configured_method(component_class_sink
,
1431 component_class_sink_graph_is_configured
);
1432 BT_ASSERT(ret
== 0);
1433 ret
= bt_component_class_sink_set_query_method(component_class_sink
, component_class_sink_query
);
1434 BT_ASSERT(ret
== 0);
1435 ret
= bt_component_class_sink_set_get_supported_mip_versions_method(component_class_sink
, component_class_sink_get_supported_mip_versions
);
1436 BT_ASSERT(ret
== 0);
1437 register_cc_ptr_to_py_cls(component_class
, py_cls
);
1440 return component_class_sink
;