2 * SPDX-License-Identifier: MIT
4 * Copyright (c) 2017 Philippe Proulx <pproulx@efficios.com>
7 #include "logging/comp-logging.h"
8 #include "compat/glib.h"
11 * This hash table associates a BT component class object address to a
12 * user-defined Python class (PyObject *). The keys and values are NOT
13 * owned by this hash table. The Python class objects are owned by the
14 * Python module, which should not be unloaded until it is not possible
15 * to create a user Python component anyway.
17 * This hash table is written to when a user-defined Python component
18 * class is created by one of the bt_bt2_component_class_*_create()
21 * This function is read from when a user calls bt_component_create()
22 * with a component class pointer created by one of the functions above.
23 * In this case, the original Python class needs to be found to
24 * instantiate it and associate the created Python component object with
25 * a BT component object instance.
28 #define BT_FMT_SWIG_ALLOC_FAILED "Failed to create a SWIG pointer object."
30 static GHashTable
*bt_cc_ptr_to_py_cls
;
33 void bt_bt2_unregister_cc_ptr_to_py_cls(const bt_component_class
*comp_cls
)
37 if (!bt_cc_ptr_to_py_cls
) {
41 existed
= g_hash_table_remove(bt_cc_ptr_to_py_cls
, comp_cls
);
46 void register_cc_ptr_to_py_cls(struct bt_component_class
*bt_cc
,
49 if (!bt_cc_ptr_to_py_cls
) {
51 * Lazy-initializing this GHashTable because GLib
52 * might not be initialized yet and it needs to be
53 * before we call g_hash_table_new()
55 BT_LOGD_STR("Creating native component class to Python component class hash table.");
56 bt_cc_ptr_to_py_cls
= g_hash_table_new(g_direct_hash
, g_direct_equal
);
57 BT_ASSERT(bt_cc_ptr_to_py_cls
);
60 g_hash_table_insert(bt_cc_ptr_to_py_cls
, (gpointer
) bt_cc
,
65 PyObject
*lookup_cc_ptr_to_py_cls(const bt_component_class
*bt_cc
)
67 if (!bt_cc_ptr_to_py_cls
) {
68 BT_LOGW("Cannot look up Python component class because hash table is NULL: "
69 "comp-cls-addr=%p", bt_cc
);
73 return (PyObject
*) g_hash_table_lookup(bt_cc_ptr_to_py_cls
,
74 (gconstpointer
) bt_cc
);
77 /* Library destructor */
79 __attribute__((destructor
))
81 void native_comp_class_dtor(void) {
82 /* Destroy component class association hash table */
83 if (bt_cc_ptr_to_py_cls
) {
84 BT_LOGD_STR("Destroying native component class to Python component class hash table.");
85 g_hash_table_destroy(bt_cc_ptr_to_py_cls
);
86 bt_cc_ptr_to_py_cls
= NULL
;
91 int py_exc_to_status_clear(
92 bt_self_component_class
*self_component_class
,
93 bt_self_component
*self_component
,
94 bt_self_message_iterator
*self_message_iterator
,
95 const char *module_name
, int active_log_level
)
98 PyObject
*exc
= PyErr_Occurred();
101 status
= __BT_FUNC_STATUS_OK
;
105 if (PyErr_GivenExceptionMatches(exc
,
106 py_mod_bt2_exc_try_again_type
)) {
107 status
= __BT_FUNC_STATUS_AGAIN
;
108 } else if (PyErr_GivenExceptionMatches(exc
,
109 py_mod_bt2_exc_stop_type
)) {
110 status
= __BT_FUNC_STATUS_END
;
111 } else if (PyErr_GivenExceptionMatches(exc
,
112 py_mod_bt2_exc_unknown_object_type
)) {
113 status
= __BT_FUNC_STATUS_UNKNOWN_OBJECT
;
116 * Unknown exception: convert to general error.
118 * Because we only want to fetch the log level when
119 * we actually get an exception, and not systematically
120 * when we call py_exc_to_status() (as py_exc_to_status()
121 * can return `__BT_FUNC_STATUS_OK`), we get it here
122 * depending on the actor's type.
124 if (self_component
) {
125 active_log_level
= get_self_component_log_level(
127 } else if (self_message_iterator
) {
128 active_log_level
= get_self_message_iterator_log_level(
129 self_message_iterator
);
132 BT_ASSERT(active_log_level
!= -1);
133 log_exception_and_maybe_append_cause(BT_LOG_WARNING
,
134 active_log_level
, true,
135 self_component_class
, self_component
,
136 self_message_iterator
, module_name
);
138 if (PyErr_GivenExceptionMatches(exc
,
139 py_mod_bt2_exc_memory_error
)) {
140 status
= __BT_FUNC_STATUS_MEMORY_ERROR
;
142 status
= __BT_FUNC_STATUS_ERROR
;
152 int py_exc_to_status_component_class_clear(
153 bt_self_component_class
*self_component_class
,
154 int active_log_level
)
156 return py_exc_to_status_clear(self_component_class
, NULL
, NULL
, NULL
,
161 int py_exc_to_status_component_clear(bt_self_component
*self_component
)
163 return py_exc_to_status_clear(NULL
, self_component
, NULL
, NULL
, -1);
167 int py_exc_to_status_message_iterator_clear(
168 bt_self_message_iterator
*self_message_iterator
)
170 return py_exc_to_status_clear(NULL
, NULL
, self_message_iterator
, NULL
, -1);
174 bool bt_bt2_is_python_component_class(const bt_component_class
*comp_cls
)
176 return bt_g_hash_table_contains(bt_cc_ptr_to_py_cls
, comp_cls
);
179 /* Component class proxy methods (delegate to the attached Python object) */
182 bt_component_class_initialize_method_status
component_class_init(
183 bt_self_component
*self_component
,
184 void *self_component_v
,
185 swig_type_info
*self_comp_cls_type_swig_type
,
186 const bt_value
*params
,
187 void *init_method_data
)
189 const bt_component
*component
= bt_self_component_as_component(self_component
);
190 const bt_component_class
*component_class
= bt_component_borrow_class_const(component
);
191 bt_component_class_initialize_method_status status
;
192 PyObject
*py_cls
= NULL
;
193 PyObject
*py_comp
= NULL
;
194 PyObject
*py_params_ptr
= NULL
;
195 PyObject
*py_comp_ptr
= NULL
;
196 bt_logging_level log_level
= get_self_component_log_level(
199 BT_ASSERT(self_component
);
200 BT_ASSERT(self_component_v
);
201 BT_ASSERT(self_comp_cls_type_swig_type
);
204 * Get the user-defined Python class which created this
205 * component's class in the first place (borrowed
208 py_cls
= lookup_cc_ptr_to_py_cls(component_class
);
210 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
211 "Cannot find Python class associated to native component class: "
212 "comp-cls-addr=%p", component_class
);
216 /* Parameters pointer -> SWIG pointer Python object */
217 py_params_ptr
= SWIG_NewPointerObj(SWIG_as_voidptr(params
),
218 SWIGTYPE_p_bt_value
, 0);
219 if (!py_params_ptr
) {
220 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
221 BT_FMT_SWIG_ALLOC_FAILED
);
225 py_comp_ptr
= SWIG_NewPointerObj(SWIG_as_voidptr(self_component_v
),
226 self_comp_cls_type_swig_type
, 0);
228 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
229 BT_FMT_SWIG_ALLOC_FAILED
);
234 * Do the equivalent of this:
236 * py_comp = py_cls._bt_init_from_native(py_comp_ptr,
237 * py_params_ptr, init_method_data ? init_method_data : Py_None)
239 * _UserComponentType._bt_init_from_native() calls the Python
240 * component object's __init__() function.
242 * We don't take any reference on `init_method_data` which, if
243 * not `NULL`, is assumed to be a `PyObject *`: the user's
244 * __init__() function will eventually take a reference if
245 * needed. If `init_method_data` is `NULL`, then we pass
246 * `Py_None` as the initialization's Python object.
248 py_comp
= PyObject_CallMethod(py_cls
,
249 "_bt_init_from_native", "(OOO)", py_comp_ptr
, py_params_ptr
,
250 init_method_data
? init_method_data
: Py_None
);
252 BT_COMP_LOG_CUR_LVL(BT_LOG_WARNING
, log_level
, self_component
,
253 "Failed to call Python class's _bt_init_from_native() method: "
254 "py-cls-addr=%p", py_cls
);
255 status
= py_exc_to_status_component_clear(self_component
);
260 * Our user Python component object is now fully created and
261 * initialized by the user. Since we just created it, this
262 * native component is its only (persistent) owner.
264 bt_self_component_set_data(self_component
, py_comp
);
267 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK
;
272 /* This error path is for non-Python errors only. */
273 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR
;
276 BT_ASSERT(!PyErr_Occurred());
278 Py_XDECREF(py_params_ptr
);
279 Py_XDECREF(py_comp_ptr
);
284 bt_component_class_get_supported_mip_versions_method_status
285 component_class_get_supported_mip_versions(
286 const bt_component_class
*component_class
,
287 bt_self_component_class
*self_component_class
,
288 const bt_value
*params
, void *init_method_data
,
289 bt_logging_level log_level
,
290 bt_integer_range_set_unsigned
*supported_versions
)
293 PyObject
*py_cls
= NULL
;
294 PyObject
*py_params_ptr
= NULL
;
295 PyObject
*py_range_set_addr
= NULL
;
296 bt_integer_range_set_unsigned
*ret_range_set
= NULL
;
297 bt_component_class_get_supported_mip_versions_method_status status
;
299 py_cls
= lookup_cc_ptr_to_py_cls(component_class
);
301 BT_LOG_WRITE_CUR_LVL(BT_LOG_ERROR
, log_level
, BT_LOG_TAG
,
302 "Cannot find Python class associated to native component class: "
303 "comp-cls-addr=%p", component_class
);
307 py_params_ptr
= SWIG_NewPointerObj(SWIG_as_voidptr(params
),
308 SWIGTYPE_p_bt_value
, 0);
309 if (!py_params_ptr
) {
310 BT_LOG_WRITE_CUR_LVL(BT_LOG_ERROR
, log_level
, BT_LOG_TAG
,
311 BT_FMT_SWIG_ALLOC_FAILED
);
316 * We don't take any reference on `init_method_data` which, if
317 * not `NULL`, is assumed to be a `PyObject *`: the user's
318 * _user_get_supported_mip_versions() function will eventually
319 * take a reference if needed. If `init_method_data` is `NULL`,
320 * then we pass `Py_None` as the initialization's Python object.
322 py_range_set_addr
= PyObject_CallMethod(py_cls
,
323 "_bt_get_supported_mip_versions_from_native", "(OOi)",
324 py_params_ptr
, init_method_data
? init_method_data
: Py_None
,
326 if (!py_range_set_addr
) {
327 BT_LOG_WRITE_CUR_LVL(BT_LOG_WARNING
, log_level
, BT_LOG_TAG
,
328 "Failed to call Python class's _bt_get_supported_mip_versions_from_native() method: "
329 "py-cls-addr=%p", py_cls
);
330 status
= py_exc_to_status_component_class_clear(self_component_class
,
336 * The returned object, on success, is an integer object
337 * (PyLong) containing the address of a BT unsigned integer
338 * range set object (new reference).
340 ret_range_set
= PyLong_AsVoidPtr(py_range_set_addr
);
341 BT_ASSERT(!PyErr_Occurred());
342 BT_ASSERT(ret_range_set
);
344 /* Copy returned ranges to input range set */
345 for (i
= 0; i
< bt_integer_range_set_get_range_count(
346 bt_integer_range_set_unsigned_as_range_set_const(ret_range_set
));
348 const bt_integer_range_unsigned
*range
=
349 bt_integer_range_set_unsigned_borrow_range_by_index_const(
351 bt_integer_range_set_add_range_status add_range_status
;
353 add_range_status
= bt_integer_range_set_unsigned_add_range(
355 bt_integer_range_unsigned_get_lower(range
),
356 bt_integer_range_unsigned_get_upper(range
));
357 if (add_range_status
) {
358 BT_LOG_WRITE_CUR_LVL(BT_LOG_ERROR
, log_level
, BT_LOG_TAG
,
359 "Failed to add range to supported MIP versions range set.");
364 status
= BT_COMPONENT_CLASS_GET_SUPPORTED_MIP_VERSIONS_METHOD_STATUS_OK
;
369 /* This error path is for non-Python errors only. */
370 status
= BT_COMPONENT_CLASS_GET_SUPPORTED_MIP_VERSIONS_METHOD_STATUS_ERROR
;
373 BT_ASSERT(!PyErr_Occurred());
374 Py_XDECREF(py_params_ptr
);
375 Py_XDECREF(py_range_set_addr
);
376 bt_integer_range_set_unsigned_put_ref(ret_range_set
);
381 bt_component_class_get_supported_mip_versions_method_status
382 component_class_source_get_supported_mip_versions(
383 bt_self_component_class_source
*self_component_class_source
,
384 const bt_value
*params
, void *init_method_data
,
385 bt_logging_level log_level
,
386 bt_integer_range_set_unsigned
*supported_versions
)
388 const bt_component_class_source
*component_class_source
= bt_self_component_class_source_as_component_class_source(self_component_class_source
);
389 const bt_component_class
*component_class
= bt_component_class_source_as_component_class_const(component_class_source
);
390 bt_self_component_class
*self_component_class
= bt_self_component_class_source_as_self_component_class(self_component_class_source
);
392 return component_class_get_supported_mip_versions(
393 component_class
, self_component_class
,
394 params
, init_method_data
, log_level
, supported_versions
);
398 bt_component_class_get_supported_mip_versions_method_status
399 component_class_filter_get_supported_mip_versions(
400 bt_self_component_class_filter
*self_component_class_filter
,
401 const bt_value
*params
, void *init_method_data
,
402 bt_logging_level log_level
,
403 bt_integer_range_set_unsigned
*supported_versions
)
405 const bt_component_class_filter
*component_class_filter
= bt_self_component_class_filter_as_component_class_filter(self_component_class_filter
);
406 const bt_component_class
*component_class
= bt_component_class_filter_as_component_class_const(component_class_filter
);
407 bt_self_component_class
*self_component_class
= bt_self_component_class_filter_as_self_component_class(self_component_class_filter
);
409 return component_class_get_supported_mip_versions(
410 component_class
, self_component_class
,
411 params
, init_method_data
, log_level
, supported_versions
);
415 bt_component_class_get_supported_mip_versions_method_status
416 component_class_sink_get_supported_mip_versions(
417 bt_self_component_class_sink
*self_component_class_sink
,
418 const bt_value
*params
, void *init_method_data
,
419 bt_logging_level log_level
,
420 bt_integer_range_set_unsigned
*supported_versions
)
422 const bt_component_class_sink
*component_class_sink
= bt_self_component_class_sink_as_component_class_sink(self_component_class_sink
);
423 const bt_component_class
*component_class
= bt_component_class_sink_as_component_class_const(component_class_sink
);
424 bt_self_component_class
*self_component_class
= bt_self_component_class_sink_as_self_component_class(self_component_class_sink
);
426 return component_class_get_supported_mip_versions(
427 component_class
, self_component_class
,
428 params
, init_method_data
, log_level
, supported_versions
);
432 * Method of bt_component_class_source to initialize a bt_self_component_source
437 bt_component_class_initialize_method_status
component_class_source_init(
438 bt_self_component_source
*self_component_source
,
439 bt_self_component_source_configuration
*config
,
440 const bt_value
*params
, void *init_method_data
)
442 bt_self_component
*self_component
= bt_self_component_source_as_self_component(self_component_source
);
443 return component_class_init(
445 self_component_source
,
446 SWIGTYPE_p_bt_self_component_source
,
447 params
, init_method_data
);
451 bt_component_class_initialize_method_status
component_class_filter_init(
452 bt_self_component_filter
*self_component_filter
,
453 bt_self_component_filter_configuration
*config
,
454 const bt_value
*params
, void *init_method_data
)
456 bt_self_component
*self_component
= bt_self_component_filter_as_self_component(self_component_filter
);
457 return component_class_init(
459 self_component_filter
,
460 SWIGTYPE_p_bt_self_component_filter
,
461 params
, init_method_data
);
465 bt_component_class_initialize_method_status
component_class_sink_init(
466 bt_self_component_sink
*self_component_sink
,
467 bt_self_component_sink_configuration
*config
,
468 const bt_value
*params
, void *init_method_data
)
470 bt_self_component
*self_component
= bt_self_component_sink_as_self_component(self_component_sink
);
471 return component_class_init(
474 SWIGTYPE_p_bt_self_component_sink
,
475 params
, init_method_data
);
479 void component_class_finalize(bt_self_component
*self_component
)
481 PyObject
*py_comp
= bt_self_component_get_data(self_component
);
482 PyObject
*py_method_result
;
486 /* Call user's _user_finalize() method */
487 py_method_result
= PyObject_CallMethod(py_comp
, "_user_finalize", NULL
);
488 if (!py_method_result
) {
489 bt_logging_level log_level
= get_self_component_log_level(
493 * Ignore any exception raised by the _user_finalize() method
494 * because it won't change anything at this point: the component
495 * is being destroyed anyway.
497 BT_COMP_LOG_CUR_LVL(BT_LOG_WARNING
, log_level
, self_component
,
498 "User component's _user_finalize() method raised an exception: ignoring:");
499 logw_exception_clear(log_level
);
504 BT_ASSERT(py_method_result
== Py_None
);
507 Py_XDECREF(py_method_result
);
511 /* Decref the Python object in the user data associated to `port`. */
514 void delete_port_user_data(bt_self_component_port
*port
)
516 Py_DECREF(bt_self_component_port_get_data(port
));
520 void delete_port_input_user_data(bt_self_component_port_input
*port_input
)
522 bt_self_component_port
*port
=
523 bt_self_component_port_input_as_self_component_port(port_input
);
525 delete_port_user_data(port
);
529 void delete_port_output_user_data(bt_self_component_port_output
*port_output
)
531 bt_self_component_port
*port
=
532 bt_self_component_port_output_as_self_component_port(port_output
);
534 delete_port_user_data(port
);
538 void component_class_source_finalize(bt_self_component_source
*self_component_source
)
541 bt_self_component
*self_component
;
542 const bt_component_source
*component_source
;
544 self_component
= bt_self_component_source_as_self_component(
545 self_component_source
);
546 component_source
= bt_self_component_source_as_component_source(
547 self_component_source
);
549 component_class_finalize(self_component
);
552 * Free the user data Python object attached to the port. The
553 * corresponding incref was done by the `void *` typemap in
556 for (i
= 0; i
< bt_component_source_get_output_port_count(component_source
); i
++) {
557 bt_self_component_port_output
*port_output
;
559 port_output
= bt_self_component_source_borrow_output_port_by_index(
560 self_component_source
, i
);
562 delete_port_output_user_data(port_output
);
567 void component_class_filter_finalize(bt_self_component_filter
*self_component_filter
)
570 bt_self_component
*self_component
;
571 const bt_component_filter
*component_filter
;
573 self_component
= bt_self_component_filter_as_self_component(
574 self_component_filter
);
575 component_filter
= bt_self_component_filter_as_component_filter(
576 self_component_filter
);
578 component_class_finalize(self_component
);
581 * Free the user data Python object attached to the port. The
582 * corresponding incref was done by the `void *` typemap in
585 for (i
= 0; i
< bt_component_filter_get_input_port_count(component_filter
); i
++) {
586 bt_self_component_port_input
*port_input
;
588 port_input
= bt_self_component_filter_borrow_input_port_by_index(
589 self_component_filter
, i
);
591 delete_port_input_user_data(port_input
);
594 for (i
= 0; i
< bt_component_filter_get_output_port_count(component_filter
); i
++) {
595 bt_self_component_port_output
*port_output
;
597 port_output
= bt_self_component_filter_borrow_output_port_by_index(
598 self_component_filter
, i
);
600 delete_port_output_user_data(port_output
);
605 void component_class_sink_finalize(bt_self_component_sink
*self_component_sink
)
608 bt_self_component
*self_component
;
609 const bt_component_sink
*component_sink
;
611 self_component
= bt_self_component_sink_as_self_component(
612 self_component_sink
);
613 component_sink
= bt_self_component_sink_as_component_sink(
614 self_component_sink
);
616 component_class_finalize(self_component
);
619 * Free the user data Python object attached to the port. The
620 * corresponding incref was done by the `void *` typemap in
623 for (i
= 0; i
< bt_component_sink_get_input_port_count(component_sink
); i
++) {
624 bt_self_component_port_input
*port_input
;
626 port_input
= bt_self_component_sink_borrow_input_port_by_index(
627 self_component_sink
, i
);
629 delete_port_input_user_data(port_input
);
634 bt_message_iterator_class_can_seek_beginning_method_status
635 component_class_can_seek_beginning(
636 bt_self_message_iterator
*self_message_iterator
, bt_bool
*can_seek
)
639 PyObject
*py_result
= NULL
;
640 bt_message_iterator_class_can_seek_beginning_method_status status
;
641 py_iter
= bt_self_message_iterator_get_data(self_message_iterator
);
645 py_result
= PyObject_CallMethod(py_iter
,
646 "_bt_can_seek_beginning_from_native", NULL
);
648 status
= py_exc_to_status_message_iterator_clear(self_message_iterator
);
652 BT_ASSERT(PyBool_Check(py_result
));
653 *can_seek
= PyObject_IsTrue(py_result
);
655 status
= BT_MESSAGE_ITERATOR_CLASS_CAN_SEEK_BEGINNING_METHOD_STATUS_OK
;
658 Py_XDECREF(py_result
);
664 bt_message_iterator_class_seek_beginning_method_status
665 component_class_seek_beginning(bt_self_message_iterator
*self_message_iterator
)
669 bt_message_iterator_class_seek_beginning_method_status status
;
671 py_iter
= bt_self_message_iterator_get_data(self_message_iterator
);
674 py_result
= PyObject_CallMethod(py_iter
,
675 "_bt_seek_beginning_from_native",
678 status
= py_exc_to_status_message_iterator_clear(self_message_iterator
);
682 BT_ASSERT(py_result
== Py_None
);
684 status
= BT_MESSAGE_ITERATOR_CLASS_SEEK_BEGINNING_METHOD_STATUS_OK
;
687 Py_XDECREF(py_result
);
693 bt_message_iterator_class_can_seek_ns_from_origin_method_status
694 component_class_can_seek_ns_from_origin(
695 bt_self_message_iterator
*self_message_iterator
,
696 int64_t ns_from_origin
, bt_bool
*can_seek
)
699 PyObject
*py_result
= NULL
;
700 bt_message_iterator_class_can_seek_ns_from_origin_method_status status
;
702 py_iter
= bt_self_message_iterator_get_data(self_message_iterator
);
705 py_result
= PyObject_CallMethod(py_iter
,
706 "_bt_can_seek_ns_from_origin_from_native", "L", ns_from_origin
);
708 status
= py_exc_to_status_message_iterator_clear(self_message_iterator
);
712 BT_ASSERT(PyBool_Check(py_result
));
713 *can_seek
= PyObject_IsTrue(py_result
);
715 status
= BT_MESSAGE_ITERATOR_CLASS_CAN_SEEK_NS_FROM_ORIGIN_METHOD_STATUS_OK
;
718 Py_XDECREF(py_result
);
724 bt_message_iterator_class_seek_ns_from_origin_method_status
725 component_class_seek_ns_from_origin(
726 bt_self_message_iterator
*self_message_iterator
,
727 int64_t ns_from_origin
)
731 bt_message_iterator_class_seek_ns_from_origin_method_status status
;
733 py_iter
= bt_self_message_iterator_get_data(self_message_iterator
);
736 py_result
= PyObject_CallMethod(py_iter
,
737 "_bt_seek_ns_from_origin_from_native", "L", ns_from_origin
);
739 status
= py_exc_to_status_message_iterator_clear(self_message_iterator
);
744 BT_ASSERT(py_result
== Py_None
);
746 status
= BT_MESSAGE_ITERATOR_CLASS_SEEK_NS_FROM_ORIGIN_METHOD_STATUS_OK
;
749 Py_XDECREF(py_result
);
755 bt_component_class_port_connected_method_status
component_class_port_connected(
756 bt_self_component
*self_component
,
757 void *self_component_port
,
758 swig_type_info
*self_component_port_swig_type
,
759 bt_port_type self_component_port_type
,
760 const void *other_port
,
761 swig_type_info
*other_port_swig_type
)
763 bt_component_class_port_connected_method_status status
;
764 PyObject
*py_comp
= NULL
;
765 PyObject
*py_self_port_ptr
= NULL
;
766 PyObject
*py_other_port_ptr
= NULL
;
767 PyObject
*py_method_result
= NULL
;
768 bt_logging_level log_level
= get_self_component_log_level(
771 py_comp
= bt_self_component_get_data(self_component
);
773 py_self_port_ptr
= SWIG_NewPointerObj(SWIG_as_voidptr(self_component_port
),
774 self_component_port_swig_type
, 0);
775 if (!py_self_port_ptr
) {
776 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
777 BT_FMT_SWIG_ALLOC_FAILED
);
778 status
= __BT_FUNC_STATUS_MEMORY_ERROR
;
782 py_other_port_ptr
= SWIG_NewPointerObj(SWIG_as_voidptr(other_port
),
783 other_port_swig_type
, 0);
784 if (!py_other_port_ptr
) {
785 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
786 BT_FMT_SWIG_ALLOC_FAILED
);
787 status
= __BT_FUNC_STATUS_MEMORY_ERROR
;
791 py_method_result
= PyObject_CallMethod(py_comp
,
792 "_bt_port_connected_from_native", "(OiO)", py_self_port_ptr
,
793 self_component_port_type
, py_other_port_ptr
);
794 if (!py_method_result
) {
795 status
= py_exc_to_status_component_clear(self_component
);
799 BT_ASSERT(py_method_result
== Py_None
);
801 status
= BT_COMPONENT_CLASS_PORT_CONNECTED_METHOD_STATUS_OK
;
804 Py_XDECREF(py_self_port_ptr
);
805 Py_XDECREF(py_other_port_ptr
);
806 Py_XDECREF(py_method_result
);
812 bt_component_class_port_connected_method_status
813 component_class_source_output_port_connected(
814 bt_self_component_source
*self_component_source
,
815 bt_self_component_port_output
*self_component_port_output
,
816 const bt_port_input
*other_port_input
)
818 bt_self_component
*self_component
= bt_self_component_source_as_self_component(self_component_source
);
820 return component_class_port_connected(
822 self_component_port_output
,
823 SWIGTYPE_p_bt_self_component_port_output
,
826 SWIGTYPE_p_bt_port_input
);
830 bt_component_class_port_connected_method_status
831 component_class_filter_input_port_connected(
832 bt_self_component_filter
*self_component_filter
,
833 bt_self_component_port_input
*self_component_port_input
,
834 const bt_port_output
*other_port_output
)
836 bt_self_component
*self_component
= bt_self_component_filter_as_self_component(self_component_filter
);
838 return component_class_port_connected(
840 self_component_port_input
,
841 SWIGTYPE_p_bt_self_component_port_input
,
844 SWIGTYPE_p_bt_port_output
);
848 bt_component_class_port_connected_method_status
849 component_class_filter_output_port_connected(
850 bt_self_component_filter
*self_component_filter
,
851 bt_self_component_port_output
*self_component_port_output
,
852 const bt_port_input
*other_port_input
)
854 bt_self_component
*self_component
= bt_self_component_filter_as_self_component(self_component_filter
);
856 return component_class_port_connected(
858 self_component_port_output
,
859 SWIGTYPE_p_bt_self_component_port_output
,
862 SWIGTYPE_p_bt_port_input
);
866 bt_component_class_port_connected_method_status
867 component_class_sink_input_port_connected(
868 bt_self_component_sink
*self_component_sink
,
869 bt_self_component_port_input
*self_component_port_input
,
870 const bt_port_output
*other_port_output
)
872 bt_self_component
*self_component
= bt_self_component_sink_as_self_component(self_component_sink
);
874 return component_class_port_connected(
876 self_component_port_input
,
877 SWIGTYPE_p_bt_self_component_port_input
,
880 SWIGTYPE_p_bt_port_output
);
884 bt_component_class_sink_graph_is_configured_method_status
885 component_class_sink_graph_is_configured(
886 bt_self_component_sink
*self_component_sink
)
888 PyObject
*py_comp
= NULL
;
889 PyObject
*py_method_result
= NULL
;
890 bt_component_class_sink_graph_is_configured_method_status status
;
891 bt_self_component
*self_component
= bt_self_component_sink_as_self_component(self_component_sink
);
893 py_comp
= bt_self_component_get_data(self_component
);
895 py_method_result
= PyObject_CallMethod(py_comp
,
896 "_bt_graph_is_configured_from_native", NULL
);
897 if (!py_method_result
) {
898 status
= py_exc_to_status_component_clear(self_component
);
902 BT_ASSERT(py_method_result
== Py_None
);
904 status
= BT_COMPONENT_CLASS_SINK_GRAPH_IS_CONFIGURED_METHOD_STATUS_OK
;;
907 Py_XDECREF(py_method_result
);
912 bt_component_class_query_method_status
component_class_query(
913 const bt_component_class
*component_class
,
914 bt_self_component_class
*self_component_class
,
915 bt_private_query_executor
*priv_query_executor
,
916 const char *object
, const bt_value
*params
, void *method_data
,
917 const bt_value
**result
)
919 PyObject
*py_cls
= NULL
;
920 PyObject
*py_params_ptr
= NULL
;
921 PyObject
*py_priv_query_exec_ptr
= NULL
;
922 PyObject
*py_query_func
= NULL
;
923 PyObject
*py_object
= NULL
;
924 PyObject
*py_results_addr
= NULL
;
925 bt_component_class_query_method_status status
= __BT_FUNC_STATUS_OK
;
926 const bt_query_executor
*query_exec
=
927 bt_private_query_executor_as_query_executor_const(
928 priv_query_executor
);
929 bt_logging_level log_level
=
930 bt_query_executor_get_logging_level(query_exec
);
933 * If there's any `method_data`, assume this component class is
934 * getting queried from Python, so that `method_data` is a
935 * Python object to pass to the user's _user_query() method.
937 BT_ASSERT(!method_data
||
938 bt_bt2_is_python_component_class(component_class
));
940 py_cls
= lookup_cc_ptr_to_py_cls(component_class
);
942 BT_LOG_WRITE_CUR_LVL(BT_LOG_ERROR
, log_level
, BT_LOG_TAG
,
943 "Cannot find Python class associated to native component class: "
944 "comp-cls-addr=%p", component_class
);
948 py_params_ptr
= SWIG_NewPointerObj(SWIG_as_voidptr(params
),
949 SWIGTYPE_p_bt_value
, 0);
950 if (!py_params_ptr
) {
951 BT_LOG_WRITE_CUR_LVL(BT_LOG_ERROR
, log_level
, BT_LOG_TAG
,
952 BT_FMT_SWIG_ALLOC_FAILED
);
956 py_priv_query_exec_ptr
= SWIG_NewPointerObj(
957 SWIG_as_voidptr(priv_query_executor
),
958 SWIGTYPE_p_bt_private_query_executor
, 0);
959 if (!py_priv_query_exec_ptr
) {
960 BT_LOG_WRITE_CUR_LVL(BT_LOG_ERROR
, log_level
, BT_LOG_TAG
,
961 BT_FMT_SWIG_ALLOC_FAILED
);
965 py_object
= SWIG_FromCharPtr(object
);
967 BT_LOG_WRITE_CUR_LVL(BT_LOG_ERROR
, log_level
, BT_LOG_TAG
,
968 "Failed to create a Python string.");
973 * We don't take any reference on `method_data` which, if not
974 * `NULL`, is assumed to be a `PyObject *`: the user's
975 * _user_query() function will eventually take a reference if
976 * needed. If `method_data` is `NULL`, then we pass `Py_None` as
977 * the initialization's Python object.
979 py_results_addr
= PyObject_CallMethod(py_cls
,
980 "_bt_query_from_native", "(OOOO)", py_priv_query_exec_ptr
,
981 py_object
, py_params_ptr
,
982 method_data
? method_data
: Py_None
);
983 if (!py_results_addr
) {
984 status
= py_exc_to_status_component_class_clear(self_component_class
,
987 #define BT_FMT "Failed to call Python class's _bt_query_from_native() method: py-cls-addr=%p"
988 BT_LOG_WRITE_CUR_LVL(BT_LOG_WARNING
, log_level
, BT_LOG_TAG
,
990 BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_COMPONENT_CLASS(
991 self_component_class
, BT_FMT
, py_cls
);
998 * The returned object, on success, is an integer object
999 * (PyLong) containing the address of a BT value object (new
1002 *result
= PyLong_AsVoidPtr(py_results_addr
);
1003 BT_ASSERT(!PyErr_Occurred());
1009 status
= __BT_FUNC_STATUS_ERROR
;
1012 Py_XDECREF(py_params_ptr
);
1013 Py_XDECREF(py_priv_query_exec_ptr
);
1014 Py_XDECREF(py_query_func
);
1015 Py_XDECREF(py_object
);
1016 Py_XDECREF(py_results_addr
);
1021 bt_component_class_query_method_status
component_class_source_query(
1022 bt_self_component_class_source
*self_component_class_source
,
1023 bt_private_query_executor
*priv_query_executor
,
1024 const char *object
, const bt_value
*params
, void *method_data
,
1025 const bt_value
**result
)
1027 const bt_component_class_source
*component_class_source
= bt_self_component_class_source_as_component_class_source(self_component_class_source
);
1028 const bt_component_class
*component_class
= bt_component_class_source_as_component_class_const(component_class_source
);
1029 bt_self_component_class
*self_component_class
= bt_self_component_class_source_as_self_component_class(self_component_class_source
);
1031 return component_class_query(component_class
, self_component_class
,
1032 priv_query_executor
, object
, params
, method_data
, result
);
1036 bt_component_class_query_method_status
component_class_filter_query(
1037 bt_self_component_class_filter
*self_component_class_filter
,
1038 bt_private_query_executor
*priv_query_executor
,
1039 const char *object
, const bt_value
*params
, void *method_data
,
1040 const bt_value
**result
)
1042 const bt_component_class_filter
*component_class_filter
= bt_self_component_class_filter_as_component_class_filter(self_component_class_filter
);
1043 const bt_component_class
*component_class
= bt_component_class_filter_as_component_class_const(component_class_filter
);
1044 bt_self_component_class
*self_component_class
= bt_self_component_class_filter_as_self_component_class(self_component_class_filter
);
1046 return component_class_query(component_class
, self_component_class
,
1047 priv_query_executor
, object
, params
, method_data
, result
);
1051 bt_component_class_query_method_status
component_class_sink_query(
1052 bt_self_component_class_sink
*self_component_class_sink
,
1053 bt_private_query_executor
*priv_query_executor
,
1054 const char *object
, const bt_value
*params
, void *method_data
,
1055 const bt_value
**result
)
1057 const bt_component_class_sink
*component_class_sink
= bt_self_component_class_sink_as_component_class_sink(self_component_class_sink
);
1058 const bt_component_class
*component_class
= bt_component_class_sink_as_component_class_const(component_class_sink
);
1059 bt_self_component_class
*self_component_class
= bt_self_component_class_sink_as_self_component_class(self_component_class_sink
);
1061 return component_class_query(component_class
, self_component_class
,
1062 priv_query_executor
, object
, params
, method_data
, result
);
1066 bt_message_iterator_class_initialize_method_status
1067 component_class_message_iterator_init(
1068 bt_self_message_iterator
*self_message_iterator
,
1069 bt_self_message_iterator_configuration
*config
,
1070 bt_self_component_port_output
*self_component_port_output
)
1072 bt_message_iterator_class_initialize_method_status status
= __BT_FUNC_STATUS_OK
;
1073 PyObject
*py_comp_cls
= NULL
;
1074 PyObject
*py_iter_cls
= NULL
;
1075 PyObject
*py_iter_ptr
= NULL
;
1076 PyObject
*py_config_ptr
= NULL
;
1077 PyObject
*py_component_port_output_ptr
= NULL
;
1078 PyObject
*py_init_method_result
= NULL
;
1079 PyObject
*py_iter
= NULL
;
1081 bt_self_component
*self_component
=
1082 bt_self_message_iterator_borrow_component(
1083 self_message_iterator
);
1084 bt_logging_level log_level
= get_self_component_log_level(
1087 py_comp
= bt_self_component_get_data(self_component
);
1089 /* Find user's Python message iterator class */
1090 py_comp_cls
= PyObject_GetAttrString(py_comp
, "__class__");
1092 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
1093 "Cannot get Python object's `__class__` attribute.");
1097 py_iter_cls
= PyObject_GetAttrString(py_comp_cls
, "_iter_cls");
1099 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
1100 "Cannot get Python class's `_iter_cls` attribute.");
1104 py_iter_ptr
= SWIG_NewPointerObj(SWIG_as_voidptr(self_message_iterator
),
1105 SWIGTYPE_p_bt_self_message_iterator
, 0);
1107 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
1108 BT_FMT_SWIG_ALLOC_FAILED
);
1109 BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_MESSAGE_ITERATOR(
1110 self_message_iterator
, BT_FMT_SWIG_ALLOC_FAILED
);
1115 * Create object with borrowed native message iterator
1118 * py_iter = py_iter_cls.__new__(py_iter_cls, py_iter_ptr)
1120 py_iter
= PyObject_CallMethod(py_iter_cls
, "__new__",
1121 "(OO)", py_iter_cls
, py_iter_ptr
);
1123 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
1124 "Failed to call Python class's __new__() method: "
1125 "py-cls-addr=%p", py_iter_cls
);
1130 * Initialize object:
1132 * py_iter.__init__(config, self_output_port)
1134 * through the _init_from_native helper static method.
1136 * At this point, py_iter._ptr is set, so this initialization
1137 * function has access to self._component (which gives it the
1138 * user Python component object from which the iterator was
1141 py_config_ptr
= SWIG_NewPointerObj(SWIG_as_voidptr(config
),
1142 SWIGTYPE_p_bt_self_message_iterator_configuration
, 0);
1143 if (!py_config_ptr
) {
1144 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
1145 BT_FMT_SWIG_ALLOC_FAILED
);
1146 BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_MESSAGE_ITERATOR(
1147 self_message_iterator
, BT_FMT_SWIG_ALLOC_FAILED
);
1151 py_component_port_output_ptr
= SWIG_NewPointerObj(
1152 SWIG_as_voidptr(self_component_port_output
),
1153 SWIGTYPE_p_bt_self_component_port_output
, 0);
1154 if (!py_component_port_output_ptr
) {
1155 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
1156 "%s", BT_FMT_SWIG_ALLOC_FAILED
);
1157 BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_MESSAGE_ITERATOR(
1158 self_message_iterator
, BT_FMT_SWIG_ALLOC_FAILED
);
1162 py_init_method_result
= PyObject_CallMethod(py_iter
,
1163 "_bt_init_from_native", "OO", py_config_ptr
,
1164 py_component_port_output_ptr
);
1165 if (!py_init_method_result
) {
1166 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
1167 "User's __init__() method failed:");
1172 * Since the Python code can never instantiate a user-defined
1173 * message iterator class, the native message iterator
1174 * object does NOT belong to a user Python message iterator
1175 * object (borrowed reference). However this Python object is
1176 * owned by this native message iterator object.
1178 * In the Python world, the lifetime of the native message
1179 * iterator is managed by a _GenericMessageIterator
1182 * _GenericMessageIterator instance:
1183 * owns a native bt_message_iterator object (iter)
1184 * owns a _UserMessageIterator instance (py_iter)
1185 * self._ptr is a borrowed reference to the
1186 * native bt_private_connection_private_message_iterator
1189 bt_self_message_iterator_set_data(self_message_iterator
, py_iter
);
1194 /* Handling of errors that cause a Python exception to be set. */
1195 status
= py_exc_to_status_message_iterator_clear(self_message_iterator
);
1199 /* Handling of errors that don't cause a Python exception to be set. */
1200 status
= __BT_FUNC_STATUS_ERROR
;
1203 BT_ASSERT(!PyErr_Occurred());
1205 Py_XDECREF(py_comp_cls
);
1206 Py_XDECREF(py_iter_cls
);
1207 Py_XDECREF(py_iter_ptr
);
1208 Py_XDECREF(py_component_port_output_ptr
);
1209 Py_XDECREF(py_init_method_result
);
1210 Py_XDECREF(py_iter
);
1215 void component_class_message_iterator_finalize(
1216 bt_self_message_iterator
*message_iterator
)
1218 PyObject
*py_message_iter
= bt_self_message_iterator_get_data(
1220 PyObject
*py_method_result
= NULL
;
1222 BT_ASSERT(py_message_iter
);
1224 /* Call user's _user_finalize() method */
1225 py_method_result
= PyObject_CallMethod(py_message_iter
,
1226 "_user_finalize", NULL
);
1227 if (!py_method_result
) {
1228 bt_self_component
*self_comp
=
1229 bt_self_message_iterator_borrow_component(
1231 bt_logging_level log_level
= get_self_component_log_level(
1235 * Ignore any exception raised by the _user_finalize() method
1236 * because it won't change anything at this point: the component
1237 * is being destroyed anyway.
1239 BT_COMP_LOG_CUR_LVL(BT_LOG_WARNING
, log_level
, self_comp
,
1240 "User's _user_finalize() method raised an exception: ignoring:");
1241 logw_exception_clear(get_self_message_iterator_log_level(
1245 Py_XDECREF(py_method_result
);
1246 Py_DECREF(py_message_iter
);
1249 /* Valid for both sources and filters. */
1252 bt_message_iterator_class_next_method_status
1253 component_class_message_iterator_next(
1254 bt_self_message_iterator
*message_iterator
,
1255 bt_message_array_const msgs
, uint64_t capacity
,
1258 bt_message_iterator_class_next_method_status status
;
1259 PyObject
*py_message_iter
= bt_self_message_iterator_get_data(message_iterator
);
1260 PyObject
*py_method_result
= NULL
;
1262 BT_ASSERT_DBG(py_message_iter
);
1263 py_method_result
= PyObject_CallMethod(py_message_iter
,
1264 "_bt_next_from_native", NULL
);
1265 if (!py_method_result
) {
1266 status
= py_exc_to_status_message_iterator_clear(message_iterator
);
1271 * The returned object, on success, is an integer object
1272 * (PyLong) containing the address of a native message
1273 * object (which is now ours).
1275 msgs
[0] = PyLong_AsVoidPtr(py_method_result
);
1278 /* Overflow errors should never happen. */
1279 BT_ASSERT_DBG(!PyErr_Occurred());
1281 status
= BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_OK
;
1284 Py_XDECREF(py_method_result
);
1289 bt_component_class_sink_consume_method_status
1290 component_class_sink_consume(bt_self_component_sink
*self_component_sink
)
1292 bt_self_component
*self_component
= bt_self_component_sink_as_self_component(self_component_sink
);
1293 PyObject
*py_comp
= bt_self_component_get_data(self_component
);
1294 PyObject
*py_method_result
= NULL
;
1295 bt_component_class_sink_consume_method_status status
;
1297 BT_ASSERT_DBG(py_comp
);
1299 py_method_result
= PyObject_CallMethod(py_comp
,
1300 "_user_consume", NULL
);
1301 if (!py_method_result
) {
1302 status
= py_exc_to_status_component_clear(self_component
);
1306 status
= BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_OK
;
1309 Py_XDECREF(py_method_result
);
1314 int component_class_set_help_and_desc(
1315 bt_component_class
*component_class
,
1316 const char *description
, const char *help
)
1321 ret
= bt_component_class_set_description(component_class
, description
);
1323 BT_LOGE("Cannot set component class's description: "
1324 "comp-cls-addr=%p", component_class
);
1330 ret
= bt_component_class_set_help(component_class
, help
);
1332 BT_LOGE("Cannot set component class's help text: "
1333 "comp-cls-addr=%p", component_class
);
1345 bt_message_iterator_class
*create_message_iterator_class(void)
1347 bt_message_iterator_class
*message_iterator_class
;
1348 bt_message_iterator_class_set_method_status ret
;
1350 message_iterator_class
= bt_message_iterator_class_create(
1351 component_class_message_iterator_next
);
1352 if (!message_iterator_class
) {
1353 BT_LOGE_STR("Cannot create message iterator class.");
1357 ret
= bt_message_iterator_class_set_seek_beginning_methods(
1358 message_iterator_class
, component_class_seek_beginning
,
1359 component_class_can_seek_beginning
);
1360 BT_ASSERT(ret
== 0);
1361 ret
= bt_message_iterator_class_set_seek_ns_from_origin_methods(
1362 message_iterator_class
, component_class_seek_ns_from_origin
,
1363 component_class_can_seek_ns_from_origin
);
1364 BT_ASSERT(ret
== 0);
1365 ret
= bt_message_iterator_class_set_initialize_method(
1366 message_iterator_class
, component_class_message_iterator_init
);
1367 BT_ASSERT(ret
== 0);
1368 ret
= bt_message_iterator_class_set_finalize_method(
1369 message_iterator_class
, component_class_message_iterator_finalize
);
1370 BT_ASSERT(ret
== 0);
1373 return message_iterator_class
;
1377 bt_component_class_source
*bt_bt2_component_class_source_create(
1378 PyObject
*py_cls
, const char *name
, const char *description
,
1381 bt_component_class_source
*component_class_source
= NULL
;
1382 bt_message_iterator_class
*message_iterator_class
;
1383 bt_component_class
*component_class
;
1388 message_iterator_class
= create_message_iterator_class();
1389 if (!message_iterator_class
) {
1393 component_class_source
= bt_component_class_source_create(name
,
1394 message_iterator_class
);
1395 if (!component_class_source
) {
1396 BT_LOGE_STR("Cannot create source component class.");
1400 component_class
= bt_component_class_source_as_component_class(component_class_source
);
1402 if (component_class_set_help_and_desc(component_class
, description
, help
)) {
1406 ret
= bt_component_class_source_set_initialize_method(component_class_source
, component_class_source_init
);
1407 BT_ASSERT(ret
== 0);
1408 ret
= bt_component_class_source_set_finalize_method(component_class_source
, component_class_source_finalize
);
1409 BT_ASSERT(ret
== 0);
1410 ret
= bt_component_class_source_set_output_port_connected_method(component_class_source
,
1411 component_class_source_output_port_connected
);
1412 BT_ASSERT(ret
== 0);
1413 ret
= bt_component_class_source_set_query_method(component_class_source
, component_class_source_query
);
1414 BT_ASSERT(ret
== 0);
1415 ret
= bt_component_class_source_set_get_supported_mip_versions_method(component_class_source
, component_class_source_get_supported_mip_versions
);
1416 BT_ASSERT(ret
== 0);
1417 register_cc_ptr_to_py_cls(component_class
, py_cls
);
1420 bt_message_iterator_class_put_ref(message_iterator_class
);
1421 return component_class_source
;
1425 bt_component_class_filter
*bt_bt2_component_class_filter_create(
1426 PyObject
*py_cls
, const char *name
, const char *description
,
1429 bt_component_class_filter
*component_class_filter
= NULL
;
1430 bt_message_iterator_class
*message_iterator_class
;
1431 bt_component_class
*component_class
;
1436 message_iterator_class
= create_message_iterator_class();
1437 if (!message_iterator_class
) {
1441 component_class_filter
= bt_component_class_filter_create(name
,
1442 message_iterator_class
);
1443 if (!component_class_filter
) {
1444 BT_LOGE_STR("Cannot create filter component class.");
1448 component_class
= bt_component_class_filter_as_component_class(component_class_filter
);
1450 if (component_class_set_help_and_desc(component_class
, description
, help
)) {
1454 ret
= bt_component_class_filter_set_initialize_method(component_class_filter
, component_class_filter_init
);
1455 BT_ASSERT(ret
== 0);
1456 ret
= bt_component_class_filter_set_finalize_method (component_class_filter
, component_class_filter_finalize
);
1457 BT_ASSERT(ret
== 0);
1458 ret
= bt_component_class_filter_set_input_port_connected_method(component_class_filter
,
1459 component_class_filter_input_port_connected
);
1460 BT_ASSERT(ret
== 0);
1461 ret
= bt_component_class_filter_set_output_port_connected_method(component_class_filter
,
1462 component_class_filter_output_port_connected
);
1463 BT_ASSERT(ret
== 0);
1464 ret
= bt_component_class_filter_set_query_method(component_class_filter
, component_class_filter_query
);
1465 BT_ASSERT(ret
== 0);
1466 ret
= bt_component_class_filter_set_get_supported_mip_versions_method(component_class_filter
, component_class_filter_get_supported_mip_versions
);
1467 BT_ASSERT(ret
== 0);
1468 register_cc_ptr_to_py_cls(component_class
, py_cls
);
1471 bt_message_iterator_class_put_ref(message_iterator_class
);
1472 return component_class_filter
;
1476 bt_component_class_sink
*bt_bt2_component_class_sink_create(
1477 PyObject
*py_cls
, const char *name
, const char *description
,
1480 bt_component_class_sink
*component_class_sink
;
1481 bt_component_class
*component_class
;
1485 component_class_sink
= bt_component_class_sink_create(name
, component_class_sink_consume
);
1487 if (!component_class_sink
) {
1488 BT_LOGE_STR("Cannot create sink component class.");
1492 component_class
= bt_component_class_sink_as_component_class(component_class_sink
);
1494 if (component_class_set_help_and_desc(component_class
, description
, help
)) {
1498 ret
= bt_component_class_sink_set_initialize_method(component_class_sink
, component_class_sink_init
);
1499 BT_ASSERT(ret
== 0);
1500 ret
= bt_component_class_sink_set_finalize_method(component_class_sink
, component_class_sink_finalize
);
1501 BT_ASSERT(ret
== 0);
1502 ret
= bt_component_class_sink_set_input_port_connected_method(component_class_sink
,
1503 component_class_sink_input_port_connected
);
1504 BT_ASSERT(ret
== 0);
1505 ret
= bt_component_class_sink_set_graph_is_configured_method(component_class_sink
,
1506 component_class_sink_graph_is_configured
);
1507 BT_ASSERT(ret
== 0);
1508 ret
= bt_component_class_sink_set_query_method(component_class_sink
, component_class_sink_query
);
1509 BT_ASSERT(ret
== 0);
1510 ret
= bt_component_class_sink_set_get_supported_mip_versions_method(component_class_sink
, component_class_sink_get_supported_mip_versions
);
1511 BT_ASSERT(ret
== 0);
1512 register_cc_ptr_to_py_cls(component_class
, py_cls
);
1515 return component_class_sink
;