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_PRINTF_CUR_LVL(BT_LOG_ERROR
,
302 (enum bt_log_level
) log_level
, BT_LOG_TAG
,
303 "Cannot find Python class associated to native component class: "
304 "comp-cls-addr=%p", component_class
);
308 py_params_ptr
= SWIG_NewPointerObj(SWIG_as_voidptr(params
),
309 SWIGTYPE_p_bt_value
, 0);
310 if (!py_params_ptr
) {
311 BT_LOG_WRITE_PRINTF_CUR_LVL(BT_LOG_ERROR
,
312 (enum bt_log_level
) log_level
, BT_LOG_TAG
,
313 BT_FMT_SWIG_ALLOC_FAILED
);
318 * We don't take any reference on `init_method_data` which, if
319 * not `NULL`, is assumed to be a `PyObject *`: the user's
320 * _user_get_supported_mip_versions() function will eventually
321 * take a reference if needed. If `init_method_data` is `NULL`,
322 * then we pass `Py_None` as the initialization's Python object.
324 py_range_set_addr
= PyObject_CallMethod(py_cls
,
325 "_bt_get_supported_mip_versions_from_native", "(OOi)",
326 py_params_ptr
, init_method_data
? init_method_data
: Py_None
,
328 if (!py_range_set_addr
) {
329 BT_LOG_WRITE_PRINTF_CUR_LVL(BT_LOG_WARNING
,
330 (enum bt_log_level
) log_level
, BT_LOG_TAG
,
331 "Failed to call Python class's _bt_get_supported_mip_versions_from_native() method: "
332 "py-cls-addr=%p", py_cls
);
333 status
= py_exc_to_status_component_class_clear(self_component_class
,
339 * The returned object, on success, is an integer object
340 * (PyLong) containing the address of a BT unsigned integer
341 * range set object (new reference).
343 ret_range_set
= PyLong_AsVoidPtr(py_range_set_addr
);
344 BT_ASSERT(!PyErr_Occurred());
345 BT_ASSERT(ret_range_set
);
347 /* Copy returned ranges to input range set */
348 for (i
= 0; i
< bt_integer_range_set_get_range_count(
349 bt_integer_range_set_unsigned_as_range_set_const(ret_range_set
));
351 const bt_integer_range_unsigned
*range
=
352 bt_integer_range_set_unsigned_borrow_range_by_index_const(
354 bt_integer_range_set_add_range_status add_range_status
;
356 add_range_status
= bt_integer_range_set_unsigned_add_range(
358 bt_integer_range_unsigned_get_lower(range
),
359 bt_integer_range_unsigned_get_upper(range
));
360 if (add_range_status
) {
361 BT_LOG_WRITE_PRINTF_CUR_LVL(BT_LOG_ERROR
,
362 (enum bt_log_level
) log_level
, BT_LOG_TAG
,
363 "Failed to add range to supported MIP versions range set.");
368 status
= BT_COMPONENT_CLASS_GET_SUPPORTED_MIP_VERSIONS_METHOD_STATUS_OK
;
373 /* This error path is for non-Python errors only. */
374 status
= BT_COMPONENT_CLASS_GET_SUPPORTED_MIP_VERSIONS_METHOD_STATUS_ERROR
;
377 BT_ASSERT(!PyErr_Occurred());
378 Py_XDECREF(py_params_ptr
);
379 Py_XDECREF(py_range_set_addr
);
380 bt_integer_range_set_unsigned_put_ref(ret_range_set
);
385 bt_component_class_get_supported_mip_versions_method_status
386 component_class_source_get_supported_mip_versions(
387 bt_self_component_class_source
*self_component_class_source
,
388 const bt_value
*params
, void *init_method_data
,
389 bt_logging_level log_level
,
390 bt_integer_range_set_unsigned
*supported_versions
)
392 const bt_component_class_source
*component_class_source
= bt_self_component_class_source_as_component_class_source(self_component_class_source
);
393 const bt_component_class
*component_class
= bt_component_class_source_as_component_class_const(component_class_source
);
394 bt_self_component_class
*self_component_class
= bt_self_component_class_source_as_self_component_class(self_component_class_source
);
396 return component_class_get_supported_mip_versions(
397 component_class
, self_component_class
,
398 params
, init_method_data
, log_level
, supported_versions
);
402 bt_component_class_get_supported_mip_versions_method_status
403 component_class_filter_get_supported_mip_versions(
404 bt_self_component_class_filter
*self_component_class_filter
,
405 const bt_value
*params
, void *init_method_data
,
406 bt_logging_level log_level
,
407 bt_integer_range_set_unsigned
*supported_versions
)
409 const bt_component_class_filter
*component_class_filter
= bt_self_component_class_filter_as_component_class_filter(self_component_class_filter
);
410 const bt_component_class
*component_class
= bt_component_class_filter_as_component_class_const(component_class_filter
);
411 bt_self_component_class
*self_component_class
= bt_self_component_class_filter_as_self_component_class(self_component_class_filter
);
413 return component_class_get_supported_mip_versions(
414 component_class
, self_component_class
,
415 params
, init_method_data
, log_level
, supported_versions
);
419 bt_component_class_get_supported_mip_versions_method_status
420 component_class_sink_get_supported_mip_versions(
421 bt_self_component_class_sink
*self_component_class_sink
,
422 const bt_value
*params
, void *init_method_data
,
423 bt_logging_level log_level
,
424 bt_integer_range_set_unsigned
*supported_versions
)
426 const bt_component_class_sink
*component_class_sink
= bt_self_component_class_sink_as_component_class_sink(self_component_class_sink
);
427 const bt_component_class
*component_class
= bt_component_class_sink_as_component_class_const(component_class_sink
);
428 bt_self_component_class
*self_component_class
= bt_self_component_class_sink_as_self_component_class(self_component_class_sink
);
430 return component_class_get_supported_mip_versions(
431 component_class
, self_component_class
,
432 params
, init_method_data
, log_level
, supported_versions
);
436 * Method of bt_component_class_source to initialize a bt_self_component_source
441 bt_component_class_initialize_method_status
component_class_source_init(
442 bt_self_component_source
*self_component_source
,
443 bt_self_component_source_configuration
*config
,
444 const bt_value
*params
, void *init_method_data
)
446 bt_self_component
*self_component
= bt_self_component_source_as_self_component(self_component_source
);
447 return component_class_init(
449 self_component_source
,
450 SWIGTYPE_p_bt_self_component_source
,
451 params
, init_method_data
);
455 bt_component_class_initialize_method_status
component_class_filter_init(
456 bt_self_component_filter
*self_component_filter
,
457 bt_self_component_filter_configuration
*config
,
458 const bt_value
*params
, void *init_method_data
)
460 bt_self_component
*self_component
= bt_self_component_filter_as_self_component(self_component_filter
);
461 return component_class_init(
463 self_component_filter
,
464 SWIGTYPE_p_bt_self_component_filter
,
465 params
, init_method_data
);
469 bt_component_class_initialize_method_status
component_class_sink_init(
470 bt_self_component_sink
*self_component_sink
,
471 bt_self_component_sink_configuration
*config
,
472 const bt_value
*params
, void *init_method_data
)
474 bt_self_component
*self_component
= bt_self_component_sink_as_self_component(self_component_sink
);
475 return component_class_init(
478 SWIGTYPE_p_bt_self_component_sink
,
479 params
, init_method_data
);
483 void component_class_finalize(bt_self_component
*self_component
)
485 PyObject
*py_comp
= bt_self_component_get_data(self_component
);
486 PyObject
*py_method_result
;
490 /* Call user's _user_finalize() method */
491 py_method_result
= PyObject_CallMethod(py_comp
, "_user_finalize", NULL
);
492 if (!py_method_result
) {
493 bt_logging_level log_level
= get_self_component_log_level(
497 * Ignore any exception raised by the _user_finalize() method
498 * because it won't change anything at this point: the component
499 * is being destroyed anyway.
501 BT_COMP_LOG_CUR_LVL(BT_LOG_WARNING
, log_level
, self_component
,
502 "User component's _user_finalize() method raised an exception: ignoring:");
503 logw_exception_clear(log_level
);
508 BT_ASSERT(py_method_result
== Py_None
);
511 Py_XDECREF(py_method_result
);
515 /* Decref the Python object in the user data associated to `port`. */
518 void delete_port_user_data(bt_self_component_port
*port
)
520 Py_DECREF(bt_self_component_port_get_data(port
));
524 void delete_port_input_user_data(bt_self_component_port_input
*port_input
)
526 bt_self_component_port
*port
=
527 bt_self_component_port_input_as_self_component_port(port_input
);
529 delete_port_user_data(port
);
533 void delete_port_output_user_data(bt_self_component_port_output
*port_output
)
535 bt_self_component_port
*port
=
536 bt_self_component_port_output_as_self_component_port(port_output
);
538 delete_port_user_data(port
);
542 void component_class_source_finalize(bt_self_component_source
*self_component_source
)
545 bt_self_component
*self_component
;
546 const bt_component_source
*component_source
;
548 self_component
= bt_self_component_source_as_self_component(
549 self_component_source
);
550 component_source
= bt_self_component_source_as_component_source(
551 self_component_source
);
553 component_class_finalize(self_component
);
556 * Free the user data Python object attached to the port. The
557 * corresponding incref was done by the `void *` typemap in
560 for (i
= 0; i
< bt_component_source_get_output_port_count(component_source
); i
++) {
561 bt_self_component_port_output
*port_output
;
563 port_output
= bt_self_component_source_borrow_output_port_by_index(
564 self_component_source
, i
);
566 delete_port_output_user_data(port_output
);
571 void component_class_filter_finalize(bt_self_component_filter
*self_component_filter
)
574 bt_self_component
*self_component
;
575 const bt_component_filter
*component_filter
;
577 self_component
= bt_self_component_filter_as_self_component(
578 self_component_filter
);
579 component_filter
= bt_self_component_filter_as_component_filter(
580 self_component_filter
);
582 component_class_finalize(self_component
);
585 * Free the user data Python object attached to the port. The
586 * corresponding incref was done by the `void *` typemap in
589 for (i
= 0; i
< bt_component_filter_get_input_port_count(component_filter
); i
++) {
590 bt_self_component_port_input
*port_input
;
592 port_input
= bt_self_component_filter_borrow_input_port_by_index(
593 self_component_filter
, i
);
595 delete_port_input_user_data(port_input
);
598 for (i
= 0; i
< bt_component_filter_get_output_port_count(component_filter
); i
++) {
599 bt_self_component_port_output
*port_output
;
601 port_output
= bt_self_component_filter_borrow_output_port_by_index(
602 self_component_filter
, i
);
604 delete_port_output_user_data(port_output
);
609 void component_class_sink_finalize(bt_self_component_sink
*self_component_sink
)
612 bt_self_component
*self_component
;
613 const bt_component_sink
*component_sink
;
615 self_component
= bt_self_component_sink_as_self_component(
616 self_component_sink
);
617 component_sink
= bt_self_component_sink_as_component_sink(
618 self_component_sink
);
620 component_class_finalize(self_component
);
623 * Free the user data Python object attached to the port. The
624 * corresponding incref was done by the `void *` typemap in
627 for (i
= 0; i
< bt_component_sink_get_input_port_count(component_sink
); i
++) {
628 bt_self_component_port_input
*port_input
;
630 port_input
= bt_self_component_sink_borrow_input_port_by_index(
631 self_component_sink
, i
);
633 delete_port_input_user_data(port_input
);
638 bt_message_iterator_class_can_seek_beginning_method_status
639 component_class_can_seek_beginning(
640 bt_self_message_iterator
*self_message_iterator
, bt_bool
*can_seek
)
643 PyObject
*py_result
= NULL
;
644 bt_message_iterator_class_can_seek_beginning_method_status status
;
645 py_iter
= bt_self_message_iterator_get_data(self_message_iterator
);
649 py_result
= PyObject_CallMethod(py_iter
,
650 "_bt_can_seek_beginning_from_native", NULL
);
652 status
= py_exc_to_status_message_iterator_clear(self_message_iterator
);
656 BT_ASSERT(PyBool_Check(py_result
));
657 *can_seek
= PyObject_IsTrue(py_result
);
659 status
= BT_MESSAGE_ITERATOR_CLASS_CAN_SEEK_BEGINNING_METHOD_STATUS_OK
;
662 Py_XDECREF(py_result
);
668 bt_message_iterator_class_seek_beginning_method_status
669 component_class_seek_beginning(bt_self_message_iterator
*self_message_iterator
)
673 bt_message_iterator_class_seek_beginning_method_status status
;
675 py_iter
= bt_self_message_iterator_get_data(self_message_iterator
);
678 py_result
= PyObject_CallMethod(py_iter
,
679 "_bt_seek_beginning_from_native",
682 status
= py_exc_to_status_message_iterator_clear(self_message_iterator
);
686 BT_ASSERT(py_result
== Py_None
);
688 status
= BT_MESSAGE_ITERATOR_CLASS_SEEK_BEGINNING_METHOD_STATUS_OK
;
691 Py_XDECREF(py_result
);
697 bt_message_iterator_class_can_seek_ns_from_origin_method_status
698 component_class_can_seek_ns_from_origin(
699 bt_self_message_iterator
*self_message_iterator
,
700 int64_t ns_from_origin
, bt_bool
*can_seek
)
703 PyObject
*py_result
= NULL
;
704 bt_message_iterator_class_can_seek_ns_from_origin_method_status status
;
706 py_iter
= bt_self_message_iterator_get_data(self_message_iterator
);
709 py_result
= PyObject_CallMethod(py_iter
,
710 "_bt_can_seek_ns_from_origin_from_native", "L", ns_from_origin
);
712 status
= py_exc_to_status_message_iterator_clear(self_message_iterator
);
716 BT_ASSERT(PyBool_Check(py_result
));
717 *can_seek
= PyObject_IsTrue(py_result
);
719 status
= BT_MESSAGE_ITERATOR_CLASS_CAN_SEEK_NS_FROM_ORIGIN_METHOD_STATUS_OK
;
722 Py_XDECREF(py_result
);
728 bt_message_iterator_class_seek_ns_from_origin_method_status
729 component_class_seek_ns_from_origin(
730 bt_self_message_iterator
*self_message_iterator
,
731 int64_t ns_from_origin
)
735 bt_message_iterator_class_seek_ns_from_origin_method_status status
;
737 py_iter
= bt_self_message_iterator_get_data(self_message_iterator
);
740 py_result
= PyObject_CallMethod(py_iter
,
741 "_bt_seek_ns_from_origin_from_native", "L", ns_from_origin
);
743 status
= py_exc_to_status_message_iterator_clear(self_message_iterator
);
748 BT_ASSERT(py_result
== Py_None
);
750 status
= BT_MESSAGE_ITERATOR_CLASS_SEEK_NS_FROM_ORIGIN_METHOD_STATUS_OK
;
753 Py_XDECREF(py_result
);
759 bt_component_class_port_connected_method_status
component_class_port_connected(
760 bt_self_component
*self_component
,
761 void *self_component_port
,
762 swig_type_info
*self_component_port_swig_type
,
763 bt_port_type self_component_port_type
,
764 const void *other_port
,
765 swig_type_info
*other_port_swig_type
)
767 bt_component_class_port_connected_method_status status
;
768 PyObject
*py_comp
= NULL
;
769 PyObject
*py_self_port_ptr
= NULL
;
770 PyObject
*py_other_port_ptr
= NULL
;
771 PyObject
*py_method_result
= NULL
;
772 bt_logging_level log_level
= get_self_component_log_level(
775 py_comp
= bt_self_component_get_data(self_component
);
777 py_self_port_ptr
= SWIG_NewPointerObj(SWIG_as_voidptr(self_component_port
),
778 self_component_port_swig_type
, 0);
779 if (!py_self_port_ptr
) {
780 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
781 BT_FMT_SWIG_ALLOC_FAILED
);
782 status
= __BT_FUNC_STATUS_MEMORY_ERROR
;
786 py_other_port_ptr
= SWIG_NewPointerObj(SWIG_as_voidptr(other_port
),
787 other_port_swig_type
, 0);
788 if (!py_other_port_ptr
) {
789 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
790 BT_FMT_SWIG_ALLOC_FAILED
);
791 status
= __BT_FUNC_STATUS_MEMORY_ERROR
;
795 py_method_result
= PyObject_CallMethod(py_comp
,
796 "_bt_port_connected_from_native", "(OiO)", py_self_port_ptr
,
797 self_component_port_type
, py_other_port_ptr
);
798 if (!py_method_result
) {
799 status
= py_exc_to_status_component_clear(self_component
);
803 BT_ASSERT(py_method_result
== Py_None
);
805 status
= BT_COMPONENT_CLASS_PORT_CONNECTED_METHOD_STATUS_OK
;
808 Py_XDECREF(py_self_port_ptr
);
809 Py_XDECREF(py_other_port_ptr
);
810 Py_XDECREF(py_method_result
);
816 bt_component_class_port_connected_method_status
817 component_class_source_output_port_connected(
818 bt_self_component_source
*self_component_source
,
819 bt_self_component_port_output
*self_component_port_output
,
820 const bt_port_input
*other_port_input
)
822 bt_self_component
*self_component
= bt_self_component_source_as_self_component(self_component_source
);
824 return component_class_port_connected(
826 self_component_port_output
,
827 SWIGTYPE_p_bt_self_component_port_output
,
830 SWIGTYPE_p_bt_port_input
);
834 bt_component_class_port_connected_method_status
835 component_class_filter_input_port_connected(
836 bt_self_component_filter
*self_component_filter
,
837 bt_self_component_port_input
*self_component_port_input
,
838 const bt_port_output
*other_port_output
)
840 bt_self_component
*self_component
= bt_self_component_filter_as_self_component(self_component_filter
);
842 return component_class_port_connected(
844 self_component_port_input
,
845 SWIGTYPE_p_bt_self_component_port_input
,
848 SWIGTYPE_p_bt_port_output
);
852 bt_component_class_port_connected_method_status
853 component_class_filter_output_port_connected(
854 bt_self_component_filter
*self_component_filter
,
855 bt_self_component_port_output
*self_component_port_output
,
856 const bt_port_input
*other_port_input
)
858 bt_self_component
*self_component
= bt_self_component_filter_as_self_component(self_component_filter
);
860 return component_class_port_connected(
862 self_component_port_output
,
863 SWIGTYPE_p_bt_self_component_port_output
,
866 SWIGTYPE_p_bt_port_input
);
870 bt_component_class_port_connected_method_status
871 component_class_sink_input_port_connected(
872 bt_self_component_sink
*self_component_sink
,
873 bt_self_component_port_input
*self_component_port_input
,
874 const bt_port_output
*other_port_output
)
876 bt_self_component
*self_component
= bt_self_component_sink_as_self_component(self_component_sink
);
878 return component_class_port_connected(
880 self_component_port_input
,
881 SWIGTYPE_p_bt_self_component_port_input
,
884 SWIGTYPE_p_bt_port_output
);
888 bt_component_class_sink_graph_is_configured_method_status
889 component_class_sink_graph_is_configured(
890 bt_self_component_sink
*self_component_sink
)
892 PyObject
*py_comp
= NULL
;
893 PyObject
*py_method_result
= NULL
;
894 bt_component_class_sink_graph_is_configured_method_status status
;
895 bt_self_component
*self_component
= bt_self_component_sink_as_self_component(self_component_sink
);
897 py_comp
= bt_self_component_get_data(self_component
);
899 py_method_result
= PyObject_CallMethod(py_comp
,
900 "_bt_graph_is_configured_from_native", NULL
);
901 if (!py_method_result
) {
902 status
= py_exc_to_status_component_clear(self_component
);
906 BT_ASSERT(py_method_result
== Py_None
);
908 status
= BT_COMPONENT_CLASS_SINK_GRAPH_IS_CONFIGURED_METHOD_STATUS_OK
;;
911 Py_XDECREF(py_method_result
);
916 bt_component_class_query_method_status
component_class_query(
917 const bt_component_class
*component_class
,
918 bt_self_component_class
*self_component_class
,
919 bt_private_query_executor
*priv_query_executor
,
920 const char *object
, const bt_value
*params
, void *method_data
,
921 const bt_value
**result
)
923 PyObject
*py_cls
= NULL
;
924 PyObject
*py_params_ptr
= NULL
;
925 PyObject
*py_priv_query_exec_ptr
= NULL
;
926 PyObject
*py_query_func
= NULL
;
927 PyObject
*py_object
= NULL
;
928 PyObject
*py_results_addr
= NULL
;
929 bt_component_class_query_method_status status
= __BT_FUNC_STATUS_OK
;
930 const bt_query_executor
*query_exec
=
931 bt_private_query_executor_as_query_executor_const(
932 priv_query_executor
);
933 bt_logging_level log_level
=
934 bt_query_executor_get_logging_level(query_exec
);
937 * If there's any `method_data`, assume this component class is
938 * getting queried from Python, so that `method_data` is a
939 * Python object to pass to the user's _user_query() method.
941 BT_ASSERT(!method_data
||
942 bt_bt2_is_python_component_class(component_class
));
944 py_cls
= lookup_cc_ptr_to_py_cls(component_class
);
946 BT_LOG_WRITE_PRINTF_CUR_LVL(BT_LOG_ERROR
,
947 (enum bt_log_level
) log_level
, BT_LOG_TAG
,
948 "Cannot find Python class associated to native component class: "
949 "comp-cls-addr=%p", component_class
);
953 py_params_ptr
= SWIG_NewPointerObj(SWIG_as_voidptr(params
),
954 SWIGTYPE_p_bt_value
, 0);
955 if (!py_params_ptr
) {
956 BT_LOG_WRITE_PRINTF_CUR_LVL(BT_LOG_ERROR
,
957 (enum bt_log_level
) log_level
, BT_LOG_TAG
,
958 BT_FMT_SWIG_ALLOC_FAILED
);
962 py_priv_query_exec_ptr
= SWIG_NewPointerObj(
963 SWIG_as_voidptr(priv_query_executor
),
964 SWIGTYPE_p_bt_private_query_executor
, 0);
965 if (!py_priv_query_exec_ptr
) {
966 BT_LOG_WRITE_PRINTF_CUR_LVL(BT_LOG_ERROR
,
967 (enum bt_log_level
) log_level
, BT_LOG_TAG
,
968 BT_FMT_SWIG_ALLOC_FAILED
);
972 py_object
= SWIG_FromCharPtr(object
);
974 BT_LOG_WRITE_PRINTF_CUR_LVL(BT_LOG_ERROR
,
975 (enum bt_log_level
) log_level
, BT_LOG_TAG
,
976 "Failed to create a Python string.");
981 * We don't take any reference on `method_data` which, if not
982 * `NULL`, is assumed to be a `PyObject *`: the user's
983 * _user_query() function will eventually take a reference if
984 * needed. If `method_data` is `NULL`, then we pass `Py_None` as
985 * the initialization's Python object.
987 py_results_addr
= PyObject_CallMethod(py_cls
,
988 "_bt_query_from_native", "(OOOO)", py_priv_query_exec_ptr
,
989 py_object
, py_params_ptr
,
990 method_data
? method_data
: Py_None
);
991 if (!py_results_addr
) {
992 status
= py_exc_to_status_component_class_clear(self_component_class
,
995 #define BT_FMT "Failed to call Python class's _bt_query_from_native() method: py-cls-addr=%p"
996 BT_LOG_WRITE_PRINTF_CUR_LVL(BT_LOG_WARNING
,
997 (enum bt_log_level
) log_level
,
998 BT_LOG_TAG
, BT_FMT
, py_cls
);
999 BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_COMPONENT_CLASS(
1000 self_component_class
, BT_FMT
, py_cls
);
1007 * The returned object, on success, is an integer object
1008 * (PyLong) containing the address of a BT value object (new
1011 *result
= PyLong_AsVoidPtr(py_results_addr
);
1012 BT_ASSERT(!PyErr_Occurred());
1018 status
= __BT_FUNC_STATUS_ERROR
;
1021 Py_XDECREF(py_params_ptr
);
1022 Py_XDECREF(py_priv_query_exec_ptr
);
1023 Py_XDECREF(py_query_func
);
1024 Py_XDECREF(py_object
);
1025 Py_XDECREF(py_results_addr
);
1030 bt_component_class_query_method_status
component_class_source_query(
1031 bt_self_component_class_source
*self_component_class_source
,
1032 bt_private_query_executor
*priv_query_executor
,
1033 const char *object
, const bt_value
*params
, void *method_data
,
1034 const bt_value
**result
)
1036 const bt_component_class_source
*component_class_source
= bt_self_component_class_source_as_component_class_source(self_component_class_source
);
1037 const bt_component_class
*component_class
= bt_component_class_source_as_component_class_const(component_class_source
);
1038 bt_self_component_class
*self_component_class
= bt_self_component_class_source_as_self_component_class(self_component_class_source
);
1040 return component_class_query(component_class
, self_component_class
,
1041 priv_query_executor
, object
, params
, method_data
, result
);
1045 bt_component_class_query_method_status
component_class_filter_query(
1046 bt_self_component_class_filter
*self_component_class_filter
,
1047 bt_private_query_executor
*priv_query_executor
,
1048 const char *object
, const bt_value
*params
, void *method_data
,
1049 const bt_value
**result
)
1051 const bt_component_class_filter
*component_class_filter
= bt_self_component_class_filter_as_component_class_filter(self_component_class_filter
);
1052 const bt_component_class
*component_class
= bt_component_class_filter_as_component_class_const(component_class_filter
);
1053 bt_self_component_class
*self_component_class
= bt_self_component_class_filter_as_self_component_class(self_component_class_filter
);
1055 return component_class_query(component_class
, self_component_class
,
1056 priv_query_executor
, object
, params
, method_data
, result
);
1060 bt_component_class_query_method_status
component_class_sink_query(
1061 bt_self_component_class_sink
*self_component_class_sink
,
1062 bt_private_query_executor
*priv_query_executor
,
1063 const char *object
, const bt_value
*params
, void *method_data
,
1064 const bt_value
**result
)
1066 const bt_component_class_sink
*component_class_sink
= bt_self_component_class_sink_as_component_class_sink(self_component_class_sink
);
1067 const bt_component_class
*component_class
= bt_component_class_sink_as_component_class_const(component_class_sink
);
1068 bt_self_component_class
*self_component_class
= bt_self_component_class_sink_as_self_component_class(self_component_class_sink
);
1070 return component_class_query(component_class
, self_component_class
,
1071 priv_query_executor
, object
, params
, method_data
, result
);
1075 bt_message_iterator_class_initialize_method_status
1076 component_class_message_iterator_init(
1077 bt_self_message_iterator
*self_message_iterator
,
1078 bt_self_message_iterator_configuration
*config
,
1079 bt_self_component_port_output
*self_component_port_output
)
1081 bt_message_iterator_class_initialize_method_status status
= __BT_FUNC_STATUS_OK
;
1082 PyObject
*py_comp_cls
= NULL
;
1083 PyObject
*py_iter_cls
= NULL
;
1084 PyObject
*py_iter_ptr
= NULL
;
1085 PyObject
*py_config_ptr
= NULL
;
1086 PyObject
*py_component_port_output_ptr
= NULL
;
1087 PyObject
*py_init_method_result
= NULL
;
1088 PyObject
*py_iter
= NULL
;
1090 bt_self_component
*self_component
=
1091 bt_self_message_iterator_borrow_component(
1092 self_message_iterator
);
1093 bt_logging_level log_level
= get_self_component_log_level(
1096 py_comp
= bt_self_component_get_data(self_component
);
1098 /* Find user's Python message iterator class */
1099 py_comp_cls
= PyObject_GetAttrString(py_comp
, "__class__");
1101 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
1102 "Cannot get Python object's `__class__` attribute.");
1106 py_iter_cls
= PyObject_GetAttrString(py_comp_cls
, "_iter_cls");
1108 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
1109 "Cannot get Python class's `_iter_cls` attribute.");
1113 py_iter_ptr
= SWIG_NewPointerObj(SWIG_as_voidptr(self_message_iterator
),
1114 SWIGTYPE_p_bt_self_message_iterator
, 0);
1116 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
1117 BT_FMT_SWIG_ALLOC_FAILED
);
1118 BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_MESSAGE_ITERATOR(
1119 self_message_iterator
, BT_FMT_SWIG_ALLOC_FAILED
);
1124 * Create object with borrowed native message iterator
1127 * py_iter = py_iter_cls.__new__(py_iter_cls, py_iter_ptr)
1129 py_iter
= PyObject_CallMethod(py_iter_cls
, "__new__",
1130 "(OO)", py_iter_cls
, py_iter_ptr
);
1132 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
1133 "Failed to call Python class's __new__() method: "
1134 "py-cls-addr=%p", py_iter_cls
);
1139 * Initialize object:
1141 * py_iter.__init__(config, self_output_port)
1143 * through the _init_from_native helper static method.
1145 * At this point, py_iter._ptr is set, so this initialization
1146 * function has access to self._component (which gives it the
1147 * user Python component object from which the iterator was
1150 py_config_ptr
= SWIG_NewPointerObj(SWIG_as_voidptr(config
),
1151 SWIGTYPE_p_bt_self_message_iterator_configuration
, 0);
1152 if (!py_config_ptr
) {
1153 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
1154 BT_FMT_SWIG_ALLOC_FAILED
);
1155 BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_MESSAGE_ITERATOR(
1156 self_message_iterator
, BT_FMT_SWIG_ALLOC_FAILED
);
1160 py_component_port_output_ptr
= SWIG_NewPointerObj(
1161 SWIG_as_voidptr(self_component_port_output
),
1162 SWIGTYPE_p_bt_self_component_port_output
, 0);
1163 if (!py_component_port_output_ptr
) {
1164 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
1165 "%s", BT_FMT_SWIG_ALLOC_FAILED
);
1166 BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_MESSAGE_ITERATOR(
1167 self_message_iterator
, BT_FMT_SWIG_ALLOC_FAILED
);
1171 py_init_method_result
= PyObject_CallMethod(py_iter
,
1172 "_bt_init_from_native", "OO", py_config_ptr
,
1173 py_component_port_output_ptr
);
1174 if (!py_init_method_result
) {
1175 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
1176 "User's __init__() method failed:");
1181 * Since the Python code can never instantiate a user-defined
1182 * message iterator class, the native message iterator
1183 * object does NOT belong to a user Python message iterator
1184 * object (borrowed reference). However this Python object is
1185 * owned by this native message iterator object.
1187 * In the Python world, the lifetime of the native message
1188 * iterator is managed by a _GenericMessageIterator
1191 * _GenericMessageIterator instance:
1192 * owns a native bt_message_iterator object (iter)
1193 * owns a _UserMessageIterator instance (py_iter)
1194 * self._ptr is a borrowed reference to the
1195 * native bt_private_connection_private_message_iterator
1198 bt_self_message_iterator_set_data(self_message_iterator
, py_iter
);
1203 /* Handling of errors that cause a Python exception to be set. */
1204 status
= py_exc_to_status_message_iterator_clear(self_message_iterator
);
1208 /* Handling of errors that don't cause a Python exception to be set. */
1209 status
= __BT_FUNC_STATUS_ERROR
;
1212 BT_ASSERT(!PyErr_Occurred());
1214 Py_XDECREF(py_comp_cls
);
1215 Py_XDECREF(py_iter_cls
);
1216 Py_XDECREF(py_iter_ptr
);
1217 Py_XDECREF(py_config_ptr
);
1218 Py_XDECREF(py_component_port_output_ptr
);
1219 Py_XDECREF(py_init_method_result
);
1220 Py_XDECREF(py_iter
);
1225 void component_class_message_iterator_finalize(
1226 bt_self_message_iterator
*message_iterator
)
1228 PyObject
*py_message_iter
= bt_self_message_iterator_get_data(
1230 PyObject
*py_method_result
= NULL
;
1232 BT_ASSERT(py_message_iter
);
1234 /* Call user's _user_finalize() method */
1235 py_method_result
= PyObject_CallMethod(py_message_iter
,
1236 "_user_finalize", NULL
);
1237 if (!py_method_result
) {
1238 bt_self_component
*self_comp
=
1239 bt_self_message_iterator_borrow_component(
1241 bt_logging_level log_level
= get_self_component_log_level(
1245 * Ignore any exception raised by the _user_finalize() method
1246 * because it won't change anything at this point: the component
1247 * is being destroyed anyway.
1249 BT_COMP_LOG_CUR_LVL(BT_LOG_WARNING
, log_level
, self_comp
,
1250 "User's _user_finalize() method raised an exception: ignoring:");
1251 logw_exception_clear(get_self_message_iterator_log_level(
1255 Py_XDECREF(py_method_result
);
1256 Py_DECREF(py_message_iter
);
1259 /* Valid for both sources and filters. */
1262 bt_message_iterator_class_next_method_status
1263 component_class_message_iterator_next(
1264 bt_self_message_iterator
*message_iterator
,
1265 bt_message_array_const msgs
, uint64_t capacity
,
1268 bt_message_iterator_class_next_method_status status
;
1269 PyObject
*py_message_iter
= bt_self_message_iterator_get_data(message_iterator
);
1270 PyObject
*py_method_result
= NULL
;
1272 BT_ASSERT_DBG(py_message_iter
);
1273 py_method_result
= PyObject_CallMethod(py_message_iter
,
1274 "_bt_next_from_native", NULL
);
1275 if (!py_method_result
) {
1276 status
= py_exc_to_status_message_iterator_clear(message_iterator
);
1281 * The returned object, on success, is an integer object
1282 * (PyLong) containing the address of a native message
1283 * object (which is now ours).
1285 msgs
[0] = PyLong_AsVoidPtr(py_method_result
);
1288 /* Overflow errors should never happen. */
1289 BT_ASSERT_DBG(!PyErr_Occurred());
1291 status
= BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_OK
;
1294 Py_XDECREF(py_method_result
);
1299 bt_component_class_sink_consume_method_status
1300 component_class_sink_consume(bt_self_component_sink
*self_component_sink
)
1302 bt_self_component
*self_component
= bt_self_component_sink_as_self_component(self_component_sink
);
1303 PyObject
*py_comp
= bt_self_component_get_data(self_component
);
1304 PyObject
*py_method_result
= NULL
;
1305 bt_component_class_sink_consume_method_status status
;
1307 BT_ASSERT_DBG(py_comp
);
1309 py_method_result
= PyObject_CallMethod(py_comp
,
1310 "_user_consume", NULL
);
1311 if (!py_method_result
) {
1312 status
= py_exc_to_status_component_clear(self_component
);
1316 status
= BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_OK
;
1319 Py_XDECREF(py_method_result
);
1324 int component_class_set_help_and_desc(
1325 bt_component_class
*component_class
,
1326 const char *description
, const char *help
)
1331 ret
= bt_component_class_set_description(component_class
, description
);
1333 BT_LOGE("Cannot set component class's description: "
1334 "comp-cls-addr=%p", component_class
);
1340 ret
= bt_component_class_set_help(component_class
, help
);
1342 BT_LOGE("Cannot set component class's help text: "
1343 "comp-cls-addr=%p", component_class
);
1355 bt_message_iterator_class
*create_message_iterator_class(void)
1357 bt_message_iterator_class
*message_iterator_class
;
1358 bt_message_iterator_class_set_method_status ret
;
1360 message_iterator_class
= bt_message_iterator_class_create(
1361 component_class_message_iterator_next
);
1362 if (!message_iterator_class
) {
1363 BT_LOGE_STR("Cannot create message iterator class.");
1367 ret
= bt_message_iterator_class_set_seek_beginning_methods(
1368 message_iterator_class
, component_class_seek_beginning
,
1369 component_class_can_seek_beginning
);
1370 BT_ASSERT(ret
== 0);
1371 ret
= bt_message_iterator_class_set_seek_ns_from_origin_methods(
1372 message_iterator_class
, component_class_seek_ns_from_origin
,
1373 component_class_can_seek_ns_from_origin
);
1374 BT_ASSERT(ret
== 0);
1375 ret
= bt_message_iterator_class_set_initialize_method(
1376 message_iterator_class
, component_class_message_iterator_init
);
1377 BT_ASSERT(ret
== 0);
1378 ret
= bt_message_iterator_class_set_finalize_method(
1379 message_iterator_class
, component_class_message_iterator_finalize
);
1380 BT_ASSERT(ret
== 0);
1383 return message_iterator_class
;
1387 bt_component_class_source
*bt_bt2_component_class_source_create(
1388 PyObject
*py_cls
, const char *name
, const char *description
,
1391 bt_component_class_source
*component_class_source
= NULL
;
1392 bt_message_iterator_class
*message_iterator_class
;
1393 bt_component_class
*component_class
;
1398 message_iterator_class
= create_message_iterator_class();
1399 if (!message_iterator_class
) {
1403 component_class_source
= bt_component_class_source_create(name
,
1404 message_iterator_class
);
1405 if (!component_class_source
) {
1406 BT_LOGE_STR("Cannot create source component class.");
1410 component_class
= bt_component_class_source_as_component_class(component_class_source
);
1412 if (component_class_set_help_and_desc(component_class
, description
, help
)) {
1416 ret
= bt_component_class_source_set_initialize_method(component_class_source
, component_class_source_init
);
1417 BT_ASSERT(ret
== 0);
1418 ret
= bt_component_class_source_set_finalize_method(component_class_source
, component_class_source_finalize
);
1419 BT_ASSERT(ret
== 0);
1420 ret
= bt_component_class_source_set_output_port_connected_method(component_class_source
,
1421 component_class_source_output_port_connected
);
1422 BT_ASSERT(ret
== 0);
1423 ret
= bt_component_class_source_set_query_method(component_class_source
, component_class_source_query
);
1424 BT_ASSERT(ret
== 0);
1425 ret
= bt_component_class_source_set_get_supported_mip_versions_method(component_class_source
, component_class_source_get_supported_mip_versions
);
1426 BT_ASSERT(ret
== 0);
1427 register_cc_ptr_to_py_cls(component_class
, py_cls
);
1430 bt_message_iterator_class_put_ref(message_iterator_class
);
1431 return component_class_source
;
1435 bt_component_class_filter
*bt_bt2_component_class_filter_create(
1436 PyObject
*py_cls
, const char *name
, const char *description
,
1439 bt_component_class_filter
*component_class_filter
= NULL
;
1440 bt_message_iterator_class
*message_iterator_class
;
1441 bt_component_class
*component_class
;
1446 message_iterator_class
= create_message_iterator_class();
1447 if (!message_iterator_class
) {
1451 component_class_filter
= bt_component_class_filter_create(name
,
1452 message_iterator_class
);
1453 if (!component_class_filter
) {
1454 BT_LOGE_STR("Cannot create filter component class.");
1458 component_class
= bt_component_class_filter_as_component_class(component_class_filter
);
1460 if (component_class_set_help_and_desc(component_class
, description
, help
)) {
1464 ret
= bt_component_class_filter_set_initialize_method(component_class_filter
, component_class_filter_init
);
1465 BT_ASSERT(ret
== 0);
1466 ret
= bt_component_class_filter_set_finalize_method (component_class_filter
, component_class_filter_finalize
);
1467 BT_ASSERT(ret
== 0);
1468 ret
= bt_component_class_filter_set_input_port_connected_method(component_class_filter
,
1469 component_class_filter_input_port_connected
);
1470 BT_ASSERT(ret
== 0);
1471 ret
= bt_component_class_filter_set_output_port_connected_method(component_class_filter
,
1472 component_class_filter_output_port_connected
);
1473 BT_ASSERT(ret
== 0);
1474 ret
= bt_component_class_filter_set_query_method(component_class_filter
, component_class_filter_query
);
1475 BT_ASSERT(ret
== 0);
1476 ret
= bt_component_class_filter_set_get_supported_mip_versions_method(component_class_filter
, component_class_filter_get_supported_mip_versions
);
1477 BT_ASSERT(ret
== 0);
1478 register_cc_ptr_to_py_cls(component_class
, py_cls
);
1481 bt_message_iterator_class_put_ref(message_iterator_class
);
1482 return component_class_filter
;
1486 bt_component_class_sink
*bt_bt2_component_class_sink_create(
1487 PyObject
*py_cls
, const char *name
, const char *description
,
1490 bt_component_class_sink
*component_class_sink
;
1491 bt_component_class
*component_class
;
1495 component_class_sink
= bt_component_class_sink_create(name
, component_class_sink_consume
);
1497 if (!component_class_sink
) {
1498 BT_LOGE_STR("Cannot create sink component class.");
1502 component_class
= bt_component_class_sink_as_component_class(component_class_sink
);
1504 if (component_class_set_help_and_desc(component_class
, description
, help
)) {
1508 ret
= bt_component_class_sink_set_initialize_method(component_class_sink
, component_class_sink_init
);
1509 BT_ASSERT(ret
== 0);
1510 ret
= bt_component_class_sink_set_finalize_method(component_class_sink
, component_class_sink_finalize
);
1511 BT_ASSERT(ret
== 0);
1512 ret
= bt_component_class_sink_set_input_port_connected_method(component_class_sink
,
1513 component_class_sink_input_port_connected
);
1514 BT_ASSERT(ret
== 0);
1515 ret
= bt_component_class_sink_set_graph_is_configured_method(component_class_sink
,
1516 component_class_sink_graph_is_configured
);
1517 BT_ASSERT(ret
== 0);
1518 ret
= bt_component_class_sink_set_query_method(component_class_sink
, component_class_sink_query
);
1519 BT_ASSERT(ret
== 0);
1520 ret
= bt_component_class_sink_set_get_supported_mip_versions_method(component_class_sink
, component_class_sink_get_supported_mip_versions
);
1521 BT_ASSERT(ret
== 0);
1522 register_cc_ptr_to_py_cls(component_class
, py_cls
);
1525 return component_class_sink
;