2 * The MIT License (MIT)
4 * Copyright (c) 2017 Philippe Proulx <pproulx@efficios.com>
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 #include "logging/comp-logging.h"
26 #include "compat/glib.h"
29 * This hash table associates a BT component class object address to a
30 * user-defined Python class (PyObject *). The keys and values are NOT
31 * owned by this hash table. The Python class objects are owned by the
32 * Python module, which should not be unloaded until it is not possible
33 * to create a user Python component anyway.
35 * This hash table is written to when a user-defined Python component
36 * class is created by one of the bt_bt2_component_class_*_create()
39 * This function is read from when a user calls bt_component_create()
40 * with a component class pointer created by one of the functions above.
41 * In this case, the original Python class needs to be found to
42 * instantiate it and associate the created Python component object with
43 * a BT component object instance.
46 static GHashTable
*bt_cc_ptr_to_py_cls
;
49 void bt_bt2_unregister_cc_ptr_to_py_cls(const bt_component_class
*comp_cls
)
53 if (!bt_cc_ptr_to_py_cls
) {
57 existed
= g_hash_table_remove(bt_cc_ptr_to_py_cls
, comp_cls
);
62 void register_cc_ptr_to_py_cls(struct bt_component_class
*bt_cc
,
65 if (!bt_cc_ptr_to_py_cls
) {
67 * Lazy-initializing this GHashTable because GLib
68 * might not be initialized yet and it needs to be
69 * before we call g_hash_table_new()
71 BT_LOGD_STR("Creating native component class to Python component class hash table.");
72 bt_cc_ptr_to_py_cls
= g_hash_table_new(g_direct_hash
, g_direct_equal
);
73 BT_ASSERT(bt_cc_ptr_to_py_cls
);
76 g_hash_table_insert(bt_cc_ptr_to_py_cls
, (gpointer
) bt_cc
,
81 PyObject
*lookup_cc_ptr_to_py_cls(const bt_component_class
*bt_cc
)
83 if (!bt_cc_ptr_to_py_cls
) {
84 BT_LOGW("Cannot look up Python component class because hash table is NULL: "
85 "comp-cls-addr=%p", bt_cc
);
89 return (PyObject
*) g_hash_table_lookup(bt_cc_ptr_to_py_cls
,
90 (gconstpointer
) bt_cc
);
93 /* Library destructor */
95 __attribute__((destructor
))
97 void native_comp_class_dtor(void) {
98 /* Destroy component class association hash table */
99 if (bt_cc_ptr_to_py_cls
) {
100 BT_LOGD_STR("Destroying native component class to Python component class hash table.");
101 g_hash_table_destroy(bt_cc_ptr_to_py_cls
);
102 bt_cc_ptr_to_py_cls
= NULL
;
107 int py_exc_to_status_clear(
108 bt_self_component_class
*self_component_class
,
109 bt_self_component
*self_component
,
110 bt_self_message_iterator
*self_message_iterator
,
111 const char *module_name
, int active_log_level
)
114 PyObject
*exc
= PyErr_Occurred();
117 status
= __BT_FUNC_STATUS_OK
;
121 if (PyErr_GivenExceptionMatches(exc
,
122 py_mod_bt2_exc_try_again_type
)) {
123 status
= __BT_FUNC_STATUS_AGAIN
;
124 } else if (PyErr_GivenExceptionMatches(exc
,
125 py_mod_bt2_exc_stop_type
)) {
126 status
= __BT_FUNC_STATUS_END
;
127 } else if (PyErr_GivenExceptionMatches(exc
,
128 py_mod_bt2_exc_unknown_object_type
)) {
129 status
= __BT_FUNC_STATUS_UNKNOWN_OBJECT
;
132 * Unknown exception: convert to general error.
134 * Because we only want to fetch the log level when
135 * we actually get an exception, and not systematically
136 * when we call py_exc_to_status() (as py_exc_to_status()
137 * can return `__BT_FUNC_STATUS_OK`), we get it here
138 * depending on the actor's type.
140 if (self_component
) {
141 active_log_level
= get_self_component_log_level(
143 } else if (self_message_iterator
) {
144 active_log_level
= get_self_message_iterator_log_level(
145 self_message_iterator
);
148 BT_ASSERT(active_log_level
!= -1);
149 log_exception_and_maybe_append_cause(BT_LOG_WARNING
,
150 active_log_level
, true,
151 self_component_class
, self_component
,
152 self_message_iterator
, module_name
);
154 if (PyErr_GivenExceptionMatches(exc
,
155 py_mod_bt2_exc_memory_error
)) {
156 status
= __BT_FUNC_STATUS_MEMORY_ERROR
;
158 status
= __BT_FUNC_STATUS_ERROR
;
168 int py_exc_to_status_component_class_clear(
169 bt_self_component_class
*self_component_class
,
170 int active_log_level
)
172 return py_exc_to_status_clear(self_component_class
, NULL
, NULL
, NULL
,
177 int py_exc_to_status_component_clear(bt_self_component
*self_component
)
179 return py_exc_to_status_clear(NULL
, self_component
, NULL
, NULL
, -1);
183 int py_exc_to_status_message_iterator_clear(
184 bt_self_message_iterator
*self_message_iterator
)
186 return py_exc_to_status_clear(NULL
, NULL
, self_message_iterator
, NULL
, -1);
190 bool bt_bt2_is_python_component_class(const bt_component_class
*comp_cls
)
192 return bt_g_hash_table_contains(bt_cc_ptr_to_py_cls
, comp_cls
);
195 /* Component class proxy methods (delegate to the attached Python object) */
198 bt_component_class_initialize_method_status
component_class_init(
199 bt_self_component
*self_component
,
200 void *self_component_v
,
201 swig_type_info
*self_comp_cls_type_swig_type
,
202 const bt_value
*params
,
203 void *init_method_data
)
205 const bt_component
*component
= bt_self_component_as_component(self_component
);
206 const bt_component_class
*component_class
= bt_component_borrow_class_const(component
);
207 bt_component_class_initialize_method_status status
;
208 PyObject
*py_cls
= NULL
;
209 PyObject
*py_comp
= NULL
;
210 PyObject
*py_params_ptr
= NULL
;
211 PyObject
*py_comp_ptr
= NULL
;
212 bt_logging_level log_level
= get_self_component_log_level(
215 BT_ASSERT(self_component
);
216 BT_ASSERT(self_component_v
);
217 BT_ASSERT(self_comp_cls_type_swig_type
);
220 * Get the user-defined Python class which created this
221 * component's class in the first place (borrowed
224 py_cls
= lookup_cc_ptr_to_py_cls(component_class
);
226 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
227 "Cannot find Python class associated to native component class: "
228 "comp-cls-addr=%p", component_class
);
232 /* Parameters pointer -> SWIG pointer Python object */
233 py_params_ptr
= SWIG_NewPointerObj(SWIG_as_voidptr(params
),
234 SWIGTYPE_p_bt_value
, 0);
235 if (!py_params_ptr
) {
236 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
237 "Failed to create a SWIG pointer object.");
241 py_comp_ptr
= SWIG_NewPointerObj(SWIG_as_voidptr(self_component_v
),
242 self_comp_cls_type_swig_type
, 0);
244 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
245 "Failed to create a SWIG pointer object.");
250 * Do the equivalent of this:
252 * py_comp = py_cls._bt_init_from_native(py_comp_ptr,
253 * py_params_ptr, init_method_data ? init_method_data : Py_None)
255 * _UserComponentType._bt_init_from_native() calls the Python
256 * component object's __init__() function.
258 * We don't take any reference on `init_method_data` which, if
259 * not `NULL`, is assumed to be a `PyObject *`: the user's
260 * __init__() function will eventually take a reference if
261 * needed. If `init_method_data` is `NULL`, then we pass
262 * `Py_None` as the initialization's Python object.
264 py_comp
= PyObject_CallMethod(py_cls
,
265 "_bt_init_from_native", "(OOO)", py_comp_ptr
, py_params_ptr
,
266 init_method_data
? init_method_data
: Py_None
);
268 BT_COMP_LOG_CUR_LVL(BT_LOG_WARNING
, log_level
, self_component
,
269 "Failed to call Python class's _bt_init_from_native() method: "
270 "py-cls-addr=%p", py_cls
);
271 status
= py_exc_to_status_component_clear(self_component
);
276 * Our user Python component object is now fully created and
277 * initialized by the user. Since we just created it, this
278 * native component is its only (persistent) owner.
280 bt_self_component_set_data(self_component
, py_comp
);
283 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK
;
288 /* This error path is for non-Python errors only. */
289 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR
;
292 BT_ASSERT(!PyErr_Occurred());
294 Py_XDECREF(py_params_ptr
);
295 Py_XDECREF(py_comp_ptr
);
300 bt_component_class_get_supported_mip_versions_method_status
301 component_class_get_supported_mip_versions(
302 const bt_component_class
*component_class
,
303 bt_self_component_class
*self_component_class
,
304 const bt_value
*params
, void *init_method_data
,
305 bt_logging_level log_level
,
306 bt_integer_range_set_unsigned
*supported_versions
)
309 PyObject
*py_cls
= NULL
;
310 PyObject
*py_params_ptr
= NULL
;
311 PyObject
*py_range_set_addr
= NULL
;
312 bt_integer_range_set_unsigned
*ret_range_set
= NULL
;
313 bt_component_class_get_supported_mip_versions_method_status status
;
315 py_cls
= lookup_cc_ptr_to_py_cls(component_class
);
317 BT_LOG_WRITE_CUR_LVL(BT_LOG_ERROR
, log_level
, BT_LOG_TAG
,
318 "Cannot find Python class associated to native component class: "
319 "comp-cls-addr=%p", component_class
);
323 py_params_ptr
= SWIG_NewPointerObj(SWIG_as_voidptr(params
),
324 SWIGTYPE_p_bt_value
, 0);
325 if (!py_params_ptr
) {
326 BT_LOG_WRITE_CUR_LVL(BT_LOG_ERROR
, log_level
, BT_LOG_TAG
,
327 "Failed to create a SWIG pointer object.");
332 * We don't take any reference on `init_method_data` which, if
333 * not `NULL`, is assumed to be a `PyObject *`: the user's
334 * _user_get_supported_mip_versions() function will eventually
335 * take a reference if needed. If `init_method_data` is `NULL`,
336 * then we pass `Py_None` as the initialization's Python object.
338 py_range_set_addr
= PyObject_CallMethod(py_cls
,
339 "_bt_get_supported_mip_versions_from_native", "(OOi)",
340 py_params_ptr
, init_method_data
? init_method_data
: Py_None
,
342 if (!py_range_set_addr
) {
343 BT_LOG_WRITE_CUR_LVL(BT_LOG_WARNING
, log_level
, BT_LOG_TAG
,
344 "Failed to call Python class's _bt_get_supported_mip_versions_from_native() method: "
345 "py-cls-addr=%p", py_cls
);
346 status
= py_exc_to_status_component_class_clear(self_component_class
,
352 * The returned object, on success, is an integer object
353 * (PyLong) containing the address of a BT unsigned integer
354 * range set object (new reference).
356 ret_range_set
= PyLong_AsVoidPtr(py_range_set_addr
);
357 BT_ASSERT(!PyErr_Occurred());
358 BT_ASSERT(ret_range_set
);
360 /* Copy returned ranges to input range set */
361 for (i
= 0; i
< bt_integer_range_set_get_range_count(
362 bt_integer_range_set_unsigned_as_range_set_const(ret_range_set
));
364 const bt_integer_range_unsigned
*range
=
365 bt_integer_range_set_unsigned_borrow_range_by_index_const(
367 bt_integer_range_set_add_range_status add_range_status
;
369 add_range_status
= bt_integer_range_set_unsigned_add_range(
371 bt_integer_range_unsigned_get_lower(range
),
372 bt_integer_range_unsigned_get_upper(range
));
373 if (add_range_status
) {
374 BT_LOG_WRITE_CUR_LVL(BT_LOG_ERROR
, log_level
, BT_LOG_TAG
,
375 "Failed to add range to supported MIP versions range set.");
380 status
= BT_COMPONENT_CLASS_GET_SUPPORTED_MIP_VERSIONS_METHOD_STATUS_OK
;
385 /* This error path is for non-Python errors only. */
386 status
= BT_COMPONENT_CLASS_GET_SUPPORTED_MIP_VERSIONS_METHOD_STATUS_ERROR
;
389 BT_ASSERT(!PyErr_Occurred());
390 Py_XDECREF(py_params_ptr
);
391 Py_XDECREF(py_range_set_addr
);
392 bt_integer_range_set_unsigned_put_ref(ret_range_set
);
397 bt_component_class_get_supported_mip_versions_method_status
398 component_class_source_get_supported_mip_versions(
399 bt_self_component_class_source
*self_component_class_source
,
400 const bt_value
*params
, void *init_method_data
,
401 bt_logging_level log_level
,
402 bt_integer_range_set_unsigned
*supported_versions
)
404 const bt_component_class_source
*component_class_source
= bt_self_component_class_source_as_component_class_source(self_component_class_source
);
405 const bt_component_class
*component_class
= bt_component_class_source_as_component_class_const(component_class_source
);
406 bt_self_component_class
*self_component_class
= bt_self_component_class_source_as_self_component_class(self_component_class_source
);
408 return component_class_get_supported_mip_versions(
409 component_class
, self_component_class
,
410 params
, init_method_data
, log_level
, supported_versions
);
414 bt_component_class_get_supported_mip_versions_method_status
415 component_class_filter_get_supported_mip_versions(
416 bt_self_component_class_filter
*self_component_class_filter
,
417 const bt_value
*params
, void *init_method_data
,
418 bt_logging_level log_level
,
419 bt_integer_range_set_unsigned
*supported_versions
)
421 const bt_component_class_filter
*component_class_filter
= bt_self_component_class_filter_as_component_class_filter(self_component_class_filter
);
422 const bt_component_class
*component_class
= bt_component_class_filter_as_component_class_const(component_class_filter
);
423 bt_self_component_class
*self_component_class
= bt_self_component_class_filter_as_self_component_class(self_component_class_filter
);
425 return component_class_get_supported_mip_versions(
426 component_class
, self_component_class
,
427 params
, init_method_data
, log_level
, supported_versions
);
431 bt_component_class_get_supported_mip_versions_method_status
432 component_class_sink_get_supported_mip_versions(
433 bt_self_component_class_sink
*self_component_class_sink
,
434 const bt_value
*params
, void *init_method_data
,
435 bt_logging_level log_level
,
436 bt_integer_range_set_unsigned
*supported_versions
)
438 const bt_component_class_sink
*component_class_sink
= bt_self_component_class_sink_as_component_class_sink(self_component_class_sink
);
439 const bt_component_class
*component_class
= bt_component_class_sink_as_component_class_const(component_class_sink
);
440 bt_self_component_class
*self_component_class
= bt_self_component_class_sink_as_self_component_class(self_component_class_sink
);
442 return component_class_get_supported_mip_versions(
443 component_class
, self_component_class
,
444 params
, init_method_data
, log_level
, supported_versions
);
448 * Method of bt_component_class_source to initialize a bt_self_component_source
453 bt_component_class_initialize_method_status
component_class_source_init(
454 bt_self_component_source
*self_component_source
,
455 bt_self_component_source_configuration
*config
,
456 const bt_value
*params
, void *init_method_data
)
458 bt_self_component
*self_component
= bt_self_component_source_as_self_component(self_component_source
);
459 return component_class_init(
461 self_component_source
,
462 SWIGTYPE_p_bt_self_component_source
,
463 params
, init_method_data
);
467 bt_component_class_initialize_method_status
component_class_filter_init(
468 bt_self_component_filter
*self_component_filter
,
469 bt_self_component_filter_configuration
*config
,
470 const bt_value
*params
, void *init_method_data
)
472 bt_self_component
*self_component
= bt_self_component_filter_as_self_component(self_component_filter
);
473 return component_class_init(
475 self_component_filter
,
476 SWIGTYPE_p_bt_self_component_filter
,
477 params
, init_method_data
);
481 bt_component_class_initialize_method_status
component_class_sink_init(
482 bt_self_component_sink
*self_component_sink
,
483 bt_self_component_sink_configuration
*config
,
484 const bt_value
*params
, void *init_method_data
)
486 bt_self_component
*self_component
= bt_self_component_sink_as_self_component(self_component_sink
);
487 return component_class_init(
490 SWIGTYPE_p_bt_self_component_sink
,
491 params
, init_method_data
);
495 void component_class_finalize(bt_self_component
*self_component
)
497 PyObject
*py_comp
= bt_self_component_get_data(self_component
);
498 PyObject
*py_method_result
;
502 /* Call user's _user_finalize() method */
503 py_method_result
= PyObject_CallMethod(py_comp
, "_user_finalize", NULL
);
504 if (!py_method_result
) {
505 bt_logging_level log_level
= get_self_component_log_level(
508 BT_COMP_LOG_CUR_LVL(BT_LOG_WARNING
, log_level
, self_component
,
509 "User component's _user_finalize() method raised an exception: ignoring:");
510 logw_exception(log_level
);
513 * Ignore any exception raised by the _user_finalize() method
514 * because it won't change anything at this point: the component
515 * is being destroyed anyway.
521 BT_ASSERT(py_method_result
== Py_None
);
524 Py_XDECREF(py_method_result
);
529 void component_class_source_finalize(bt_self_component_source
*self_component_source
)
531 bt_self_component
*self_component
= bt_self_component_source_as_self_component(self_component_source
);
532 component_class_finalize(self_component
);
536 void component_class_filter_finalize(bt_self_component_filter
*self_component_filter
)
538 bt_self_component
*self_component
= bt_self_component_filter_as_self_component(self_component_filter
);
539 component_class_finalize(self_component
);
543 void component_class_sink_finalize(bt_self_component_sink
*self_component_sink
)
545 bt_self_component
*self_component
= bt_self_component_sink_as_self_component(self_component_sink
);
546 component_class_finalize(self_component
);
550 bt_component_class_message_iterator_can_seek_beginning_method_status
551 component_class_can_seek_beginning(
552 bt_self_message_iterator
*self_message_iterator
, bt_bool
*can_seek
)
555 PyObject
*py_result
= NULL
;
556 bt_component_class_message_iterator_can_seek_beginning_method_status status
;
557 py_iter
= bt_self_message_iterator_get_data(self_message_iterator
);
561 py_result
= PyObject_CallMethod(py_iter
,
562 "_bt_can_seek_beginning_from_native", NULL
);
564 status
= py_exc_to_status_message_iterator_clear(self_message_iterator
);
568 BT_ASSERT(PyBool_Check(py_result
));
569 *can_seek
= PyObject_IsTrue(py_result
);
571 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_CAN_SEEK_BEGINNING_METHOD_STATUS_OK
;
574 Py_XDECREF(py_result
);
580 bt_component_class_message_iterator_seek_beginning_method_status
581 component_class_seek_beginning(bt_self_message_iterator
*self_message_iterator
)
585 bt_component_class_message_iterator_seek_beginning_method_status status
;
587 py_iter
= bt_self_message_iterator_get_data(self_message_iterator
);
590 py_result
= PyObject_CallMethod(py_iter
,
591 "_bt_seek_beginning_from_native",
594 status
= py_exc_to_status_message_iterator_clear(self_message_iterator
);
598 BT_ASSERT(py_result
== Py_None
);
600 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_SEEK_BEGINNING_METHOD_STATUS_OK
;
603 Py_XDECREF(py_result
);
609 bt_component_class_message_iterator_can_seek_ns_from_origin_method_status
610 component_class_can_seek_ns_from_origin(
611 bt_self_message_iterator
*self_message_iterator
,
612 int64_t ns_from_origin
, bt_bool
*can_seek
)
615 PyObject
*py_result
= NULL
;
616 bt_component_class_message_iterator_can_seek_ns_from_origin_method_status status
;
618 py_iter
= bt_self_message_iterator_get_data(self_message_iterator
);
621 py_result
= PyObject_CallMethod(py_iter
,
622 "_bt_can_seek_ns_from_origin_from_native", "L", ns_from_origin
);
624 status
= py_exc_to_status_message_iterator_clear(self_message_iterator
);
628 BT_ASSERT(PyBool_Check(py_result
));
629 *can_seek
= PyObject_IsTrue(py_result
);
631 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_CAN_SEEK_NS_FROM_ORIGIN_METHOD_STATUS_OK
;
634 Py_XDECREF(py_result
);
640 bt_component_class_message_iterator_seek_ns_from_origin_method_status
641 component_class_seek_ns_from_origin(
642 bt_self_message_iterator
*self_message_iterator
,
643 int64_t ns_from_origin
)
647 bt_component_class_message_iterator_seek_ns_from_origin_method_status status
;
649 py_iter
= bt_self_message_iterator_get_data(self_message_iterator
);
652 py_result
= PyObject_CallMethod(py_iter
,
653 "_bt_seek_ns_from_origin_from_native", "L", ns_from_origin
);
655 status
= py_exc_to_status_message_iterator_clear(self_message_iterator
);
660 BT_ASSERT(py_result
== Py_None
);
662 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_SEEK_NS_FROM_ORIGIN_METHOD_STATUS_OK
;
665 Py_XDECREF(py_result
);
671 bt_component_class_port_connected_method_status
component_class_port_connected(
672 bt_self_component
*self_component
,
673 void *self_component_port
,
674 swig_type_info
*self_component_port_swig_type
,
675 bt_port_type self_component_port_type
,
676 const void *other_port
,
677 swig_type_info
*other_port_swig_type
)
679 bt_component_class_port_connected_method_status status
;
680 PyObject
*py_comp
= NULL
;
681 PyObject
*py_self_port_ptr
= NULL
;
682 PyObject
*py_other_port_ptr
= NULL
;
683 PyObject
*py_method_result
= NULL
;
684 bt_logging_level log_level
= get_self_component_log_level(
687 py_comp
= bt_self_component_get_data(self_component
);
689 py_self_port_ptr
= SWIG_NewPointerObj(SWIG_as_voidptr(self_component_port
),
690 self_component_port_swig_type
, 0);
691 if (!py_self_port_ptr
) {
692 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
693 "Failed to create a SWIG pointer object.");
694 status
= __BT_FUNC_STATUS_MEMORY_ERROR
;
698 py_other_port_ptr
= SWIG_NewPointerObj(SWIG_as_voidptr(other_port
),
699 other_port_swig_type
, 0);
700 if (!py_other_port_ptr
) {
701 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
702 "Failed to create a SWIG pointer object.");
703 status
= __BT_FUNC_STATUS_MEMORY_ERROR
;
707 py_method_result
= PyObject_CallMethod(py_comp
,
708 "_bt_port_connected_from_native", "(OiO)", py_self_port_ptr
,
709 self_component_port_type
, py_other_port_ptr
);
710 if (!py_method_result
) {
711 status
= py_exc_to_status_component_clear(self_component
);
715 BT_ASSERT(py_method_result
== Py_None
);
717 status
= BT_COMPONENT_CLASS_PORT_CONNECTED_METHOD_STATUS_OK
;
720 Py_XDECREF(py_self_port_ptr
);
721 Py_XDECREF(py_other_port_ptr
);
722 Py_XDECREF(py_method_result
);
728 bt_component_class_port_connected_method_status
729 component_class_source_output_port_connected(
730 bt_self_component_source
*self_component_source
,
731 bt_self_component_port_output
*self_component_port_output
,
732 const bt_port_input
*other_port_input
)
734 bt_self_component
*self_component
= bt_self_component_source_as_self_component(self_component_source
);
736 return component_class_port_connected(
738 self_component_port_output
,
739 SWIGTYPE_p_bt_self_component_port_output
,
742 SWIGTYPE_p_bt_port_input
);
746 bt_component_class_port_connected_method_status
747 component_class_filter_input_port_connected(
748 bt_self_component_filter
*self_component_filter
,
749 bt_self_component_port_input
*self_component_port_input
,
750 const bt_port_output
*other_port_output
)
752 bt_self_component
*self_component
= bt_self_component_filter_as_self_component(self_component_filter
);
754 return component_class_port_connected(
756 self_component_port_input
,
757 SWIGTYPE_p_bt_self_component_port_input
,
760 SWIGTYPE_p_bt_port_output
);
764 bt_component_class_port_connected_method_status
765 component_class_filter_output_port_connected(
766 bt_self_component_filter
*self_component_filter
,
767 bt_self_component_port_output
*self_component_port_output
,
768 const bt_port_input
*other_port_input
)
770 bt_self_component
*self_component
= bt_self_component_filter_as_self_component(self_component_filter
);
772 return component_class_port_connected(
774 self_component_port_output
,
775 SWIGTYPE_p_bt_self_component_port_output
,
778 SWIGTYPE_p_bt_port_input
);
782 bt_component_class_port_connected_method_status
783 component_class_sink_input_port_connected(
784 bt_self_component_sink
*self_component_sink
,
785 bt_self_component_port_input
*self_component_port_input
,
786 const bt_port_output
*other_port_output
)
788 bt_self_component
*self_component
= bt_self_component_sink_as_self_component(self_component_sink
);
790 return component_class_port_connected(
792 self_component_port_input
,
793 SWIGTYPE_p_bt_self_component_port_input
,
796 SWIGTYPE_p_bt_port_output
);
800 bt_component_class_sink_graph_is_configured_method_status
801 component_class_sink_graph_is_configured(
802 bt_self_component_sink
*self_component_sink
)
804 PyObject
*py_comp
= NULL
;
805 PyObject
*py_method_result
= NULL
;
806 bt_component_class_sink_graph_is_configured_method_status status
;
807 bt_self_component
*self_component
= bt_self_component_sink_as_self_component(self_component_sink
);
809 py_comp
= bt_self_component_get_data(self_component
);
811 py_method_result
= PyObject_CallMethod(py_comp
,
812 "_bt_graph_is_configured_from_native", NULL
);
813 if (!py_method_result
) {
814 status
= py_exc_to_status_component_clear(self_component
);
818 BT_ASSERT(py_method_result
== Py_None
);
820 status
= BT_COMPONENT_CLASS_SINK_GRAPH_IS_CONFIGURED_METHOD_STATUS_OK
;;
823 Py_XDECREF(py_method_result
);
828 bt_component_class_query_method_status
component_class_query(
829 const bt_component_class
*component_class
,
830 bt_self_component_class
*self_component_class
,
831 bt_private_query_executor
*priv_query_executor
,
832 const char *object
, const bt_value
*params
, void *method_data
,
833 const bt_value
**result
)
835 PyObject
*py_cls
= NULL
;
836 PyObject
*py_params_ptr
= NULL
;
837 PyObject
*py_priv_query_exec_ptr
= NULL
;
838 PyObject
*py_query_func
= NULL
;
839 PyObject
*py_object
= NULL
;
840 PyObject
*py_results_addr
= NULL
;
841 bt_component_class_query_method_status status
= __BT_FUNC_STATUS_OK
;
842 const bt_query_executor
*query_exec
=
843 bt_private_query_executor_as_query_executor_const(
844 priv_query_executor
);
845 bt_logging_level log_level
=
846 bt_query_executor_get_logging_level(query_exec
);
849 * If there's any `method_data`, assume this component class is
850 * getting queried from Python, so that `method_data` is a
851 * Python object to pass to the user's _user_query() method.
853 BT_ASSERT(!method_data
||
854 bt_bt2_is_python_component_class(component_class
));
856 py_cls
= lookup_cc_ptr_to_py_cls(component_class
);
858 BT_LOG_WRITE_CUR_LVL(BT_LOG_ERROR
, log_level
, BT_LOG_TAG
,
859 "Cannot find Python class associated to native component class: "
860 "comp-cls-addr=%p", component_class
);
864 py_params_ptr
= SWIG_NewPointerObj(SWIG_as_voidptr(params
),
865 SWIGTYPE_p_bt_value
, 0);
866 if (!py_params_ptr
) {
867 BT_LOG_WRITE_CUR_LVL(BT_LOG_ERROR
, log_level
, BT_LOG_TAG
,
868 "Failed to create a SWIG pointer object.");
872 py_priv_query_exec_ptr
= SWIG_NewPointerObj(
873 SWIG_as_voidptr(priv_query_executor
),
874 SWIGTYPE_p_bt_private_query_executor
, 0);
875 if (!py_priv_query_exec_ptr
) {
876 BT_LOG_WRITE_CUR_LVL(BT_LOG_ERROR
, log_level
, BT_LOG_TAG
,
877 "Failed to create a SWIG pointer object.");
881 py_object
= SWIG_FromCharPtr(object
);
883 BT_LOG_WRITE_CUR_LVL(BT_LOG_ERROR
, log_level
, BT_LOG_TAG
,
884 "Failed to create a Python string.");
889 * We don't take any reference on `method_data` which, if not
890 * `NULL`, is assumed to be a `PyObject *`: the user's
891 * _user_query() function will eventually take a reference if
892 * needed. If `method_data` is `NULL`, then we pass `Py_None` as
893 * the initialization's Python object.
895 py_results_addr
= PyObject_CallMethod(py_cls
,
896 "_bt_query_from_native", "(OOOO)", py_priv_query_exec_ptr
,
897 py_object
, py_params_ptr
,
898 method_data
? method_data
: Py_None
);
899 if (!py_results_addr
) {
900 status
= py_exc_to_status_component_class_clear(self_component_class
,
903 static const char *fmt
=
904 "Failed to call Python class's _bt_query_from_native() method: py-cls-addr=%p";
905 BT_LOG_WRITE_CUR_LVL(BT_LOG_WARNING
, log_level
, BT_LOG_TAG
,
907 BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_COMPONENT_CLASS(
908 self_component_class
, fmt
, py_cls
);
914 * The returned object, on success, is an integer object
915 * (PyLong) containing the address of a BT value object (new
918 *result
= PyLong_AsVoidPtr(py_results_addr
);
919 BT_ASSERT(!PyErr_Occurred());
925 status
= __BT_FUNC_STATUS_ERROR
;
928 Py_XDECREF(py_params_ptr
);
929 Py_XDECREF(py_priv_query_exec_ptr
);
930 Py_XDECREF(py_query_func
);
931 Py_XDECREF(py_object
);
932 Py_XDECREF(py_results_addr
);
937 bt_component_class_query_method_status
component_class_source_query(
938 bt_self_component_class_source
*self_component_class_source
,
939 bt_private_query_executor
*priv_query_executor
,
940 const char *object
, const bt_value
*params
, void *method_data
,
941 const bt_value
**result
)
943 const bt_component_class_source
*component_class_source
= bt_self_component_class_source_as_component_class_source(self_component_class_source
);
944 const bt_component_class
*component_class
= bt_component_class_source_as_component_class_const(component_class_source
);
945 bt_self_component_class
*self_component_class
= bt_self_component_class_source_as_self_component_class(self_component_class_source
);
947 return component_class_query(component_class
, self_component_class
,
948 priv_query_executor
, object
, params
, method_data
, result
);
952 bt_component_class_query_method_status
component_class_filter_query(
953 bt_self_component_class_filter
*self_component_class_filter
,
954 bt_private_query_executor
*priv_query_executor
,
955 const char *object
, const bt_value
*params
, void *method_data
,
956 const bt_value
**result
)
958 const bt_component_class_filter
*component_class_filter
= bt_self_component_class_filter_as_component_class_filter(self_component_class_filter
);
959 const bt_component_class
*component_class
= bt_component_class_filter_as_component_class_const(component_class_filter
);
960 bt_self_component_class
*self_component_class
= bt_self_component_class_filter_as_self_component_class(self_component_class_filter
);
962 return component_class_query(component_class
, self_component_class
,
963 priv_query_executor
, object
, params
, method_data
, result
);
967 bt_component_class_query_method_status
component_class_sink_query(
968 bt_self_component_class_sink
*self_component_class_sink
,
969 bt_private_query_executor
*priv_query_executor
,
970 const char *object
, const bt_value
*params
, void *method_data
,
971 const bt_value
**result
)
973 const bt_component_class_sink
*component_class_sink
= bt_self_component_class_sink_as_component_class_sink(self_component_class_sink
);
974 const bt_component_class
*component_class
= bt_component_class_sink_as_component_class_const(component_class_sink
);
975 bt_self_component_class
*self_component_class
= bt_self_component_class_sink_as_self_component_class(self_component_class_sink
);
977 return component_class_query(component_class
, self_component_class
,
978 priv_query_executor
, object
, params
, method_data
, result
);
982 bt_component_class_message_iterator_initialize_method_status
983 component_class_message_iterator_init(
984 bt_self_message_iterator
*self_message_iterator
,
985 bt_self_message_iterator_configuration
*config
,
986 bt_self_component
*self_component
,
987 bt_self_component_port_output
*self_component_port_output
)
989 bt_component_class_message_iterator_initialize_method_status status
= __BT_FUNC_STATUS_OK
;
990 PyObject
*py_comp_cls
= NULL
;
991 PyObject
*py_iter_cls
= NULL
;
992 PyObject
*py_iter_ptr
= NULL
;
993 PyObject
*py_config_ptr
= NULL
;
994 PyObject
*py_component_port_output_ptr
= NULL
;
995 PyObject
*py_init_method_result
= NULL
;
996 PyObject
*py_iter
= NULL
;
998 bt_logging_level log_level
= get_self_component_log_level(
1001 py_comp
= bt_self_component_get_data(self_component
);
1003 /* Find user's Python message iterator class */
1004 py_comp_cls
= PyObject_GetAttrString(py_comp
, "__class__");
1006 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
1007 "Cannot get Python object's `__class__` attribute.");
1011 py_iter_cls
= PyObject_GetAttrString(py_comp_cls
, "_iter_cls");
1013 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
1014 "Cannot get Python class's `_iter_cls` attribute.");
1018 py_iter_ptr
= SWIG_NewPointerObj(SWIG_as_voidptr(self_message_iterator
),
1019 SWIGTYPE_p_bt_self_message_iterator
, 0);
1021 const char *err
= "Failed to create a SWIG pointer object.";
1023 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
1025 BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_MESSAGE_ITERATOR(
1026 self_message_iterator
, err
);
1031 * Create object with borrowed native message iterator
1034 * py_iter = py_iter_cls.__new__(py_iter_cls, py_iter_ptr)
1036 py_iter
= PyObject_CallMethod(py_iter_cls
, "__new__",
1037 "(OO)", py_iter_cls
, py_iter_ptr
);
1039 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
1040 "Failed to call Python class's __new__() method: "
1041 "py-cls-addr=%p", py_iter_cls
);
1046 * Initialize object:
1048 * py_iter.__init__(config, self_output_port)
1050 * through the _init_from_native helper static method.
1052 * At this point, py_iter._ptr is set, so this initialization
1053 * function has access to self._component (which gives it the
1054 * user Python component object from which the iterator was
1057 py_config_ptr
= SWIG_NewPointerObj(SWIG_as_voidptr(config
),
1058 SWIGTYPE_p_bt_self_message_iterator_configuration
, 0);
1059 if (!py_config_ptr
) {
1060 const char *err
= "Failed to create a SWIG pointer object";
1062 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
1064 BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_MESSAGE_ITERATOR(
1065 self_message_iterator
, err
);
1069 py_component_port_output_ptr
= SWIG_NewPointerObj(
1070 SWIG_as_voidptr(self_component_port_output
),
1071 SWIGTYPE_p_bt_self_component_port_output
, 0);
1072 if (!py_component_port_output_ptr
) {
1073 const char *err
= "Failed to create a SWIG pointer object.";
1075 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
1077 BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_MESSAGE_ITERATOR(
1078 self_message_iterator
, err
);
1082 py_init_method_result
= PyObject_CallMethod(py_iter
,
1083 "_bt_init_from_native", "OO", py_config_ptr
,
1084 py_component_port_output_ptr
);
1085 if (!py_init_method_result
) {
1086 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
1087 "User's __init__() method failed:");
1092 * Since the Python code can never instantiate a user-defined
1093 * message iterator class, the native message iterator
1094 * object does NOT belong to a user Python message iterator
1095 * object (borrowed reference). However this Python object is
1096 * owned by this native message iterator object.
1098 * In the Python world, the lifetime of the native message
1099 * iterator is managed by a _GenericMessageIterator
1102 * _GenericMessageIterator instance:
1103 * owns a native bt_message_iterator object (iter)
1104 * owns a _UserMessageIterator instance (py_iter)
1105 * self._ptr is a borrowed reference to the
1106 * native bt_private_connection_private_message_iterator
1109 bt_self_message_iterator_set_data(self_message_iterator
, py_iter
);
1114 /* Handling of errors that cause a Python exception to be set. */
1115 status
= py_exc_to_status_message_iterator_clear(self_message_iterator
);
1119 /* Handling of errors that don't cause a Python exception to be set. */
1120 status
= __BT_FUNC_STATUS_ERROR
;
1123 BT_ASSERT(!PyErr_Occurred());
1125 Py_XDECREF(py_comp_cls
);
1126 Py_XDECREF(py_iter_cls
);
1127 Py_XDECREF(py_iter_ptr
);
1128 Py_XDECREF(py_component_port_output_ptr
);
1129 Py_XDECREF(py_init_method_result
);
1130 Py_XDECREF(py_iter
);
1135 bt_component_class_message_iterator_initialize_method_status
1136 component_class_source_message_iterator_init(
1137 bt_self_message_iterator
*self_message_iterator
,
1138 bt_self_message_iterator_configuration
*config
,
1139 bt_self_component_source
*self_component_source
,
1140 bt_self_component_port_output
*self_component_port_output
)
1142 bt_self_component
*self_component
=
1143 bt_self_component_source_as_self_component(self_component_source
);
1145 return component_class_message_iterator_init(self_message_iterator
,
1146 config
, self_component
, self_component_port_output
);
1150 bt_component_class_message_iterator_initialize_method_status
1151 component_class_filter_message_iterator_init(
1152 bt_self_message_iterator
*self_message_iterator
,
1153 bt_self_message_iterator_configuration
*config
,
1154 bt_self_component_filter
*self_component_filter
,
1155 bt_self_component_port_output
*self_component_port_output
)
1157 bt_self_component
*self_component
=
1158 bt_self_component_filter_as_self_component(self_component_filter
);
1160 return component_class_message_iterator_init(self_message_iterator
,
1161 config
, self_component
, self_component_port_output
);
1165 void component_class_message_iterator_finalize(
1166 bt_self_message_iterator
*message_iterator
)
1168 PyObject
*py_message_iter
= bt_self_message_iterator_get_data(
1170 PyObject
*py_method_result
= NULL
;
1172 BT_ASSERT(py_message_iter
);
1174 /* Call user's _user_finalize() method */
1175 py_method_result
= PyObject_CallMethod(py_message_iter
,
1176 "_user_finalize", NULL
);
1177 if (!py_method_result
) {
1178 bt_self_component
*self_comp
=
1179 bt_self_message_iterator_borrow_component(
1181 bt_logging_level log_level
= get_self_component_log_level(
1184 BT_COMP_LOG_CUR_LVL(BT_LOG_WARNING
, log_level
, self_comp
,
1185 "User's _user_finalize() method raised an exception: ignoring:");
1186 logw_exception(get_self_message_iterator_log_level(
1190 * Ignore any exception raised by the _user_finalize() method
1191 * because it won't change anything at this point: the component
1192 * is being destroyed anyway.
1197 Py_XDECREF(py_method_result
);
1198 Py_DECREF(py_message_iter
);
1201 /* Valid for both sources and filters. */
1204 bt_component_class_message_iterator_next_method_status
1205 component_class_message_iterator_next(
1206 bt_self_message_iterator
*message_iterator
,
1207 bt_message_array_const msgs
, uint64_t capacity
,
1210 bt_component_class_message_iterator_next_method_status status
;
1211 PyObject
*py_message_iter
= bt_self_message_iterator_get_data(message_iterator
);
1212 PyObject
*py_method_result
= NULL
;
1214 BT_ASSERT(py_message_iter
);
1216 py_method_result
= PyObject_CallMethod(py_message_iter
,
1217 "_bt_next_from_native", NULL
);
1218 if (!py_method_result
) {
1219 status
= py_exc_to_status_message_iterator_clear(message_iterator
);
1224 * The returned object, on success, is an integer object
1225 * (PyLong) containing the address of a native message
1226 * object (which is now ours).
1228 msgs
[0] = PyLong_AsVoidPtr(py_method_result
);
1231 /* Overflow errors should never happen. */
1232 BT_ASSERT(!PyErr_Occurred());
1234 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK
;
1237 Py_XDECREF(py_method_result
);
1242 bt_component_class_sink_consume_method_status
1243 component_class_sink_consume(bt_self_component_sink
*self_component_sink
)
1245 bt_self_component
*self_component
= bt_self_component_sink_as_self_component(self_component_sink
);
1246 PyObject
*py_comp
= bt_self_component_get_data(self_component
);
1247 PyObject
*py_method_result
= NULL
;
1248 bt_component_class_sink_consume_method_status status
;
1252 py_method_result
= PyObject_CallMethod(py_comp
,
1253 "_user_consume", NULL
);
1254 if (!py_method_result
) {
1255 status
= py_exc_to_status_component_clear(self_component
);
1259 status
= BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_OK
;
1262 Py_XDECREF(py_method_result
);
1267 int component_class_set_help_and_desc(
1268 bt_component_class
*component_class
,
1269 const char *description
, const char *help
)
1274 ret
= bt_component_class_set_description(component_class
, description
);
1276 BT_LOGE("Cannot set component class's description: "
1277 "comp-cls-addr=%p", component_class
);
1283 ret
= bt_component_class_set_help(component_class
, help
);
1285 BT_LOGE("Cannot set component class's help text: "
1286 "comp-cls-addr=%p", component_class
);
1298 bt_component_class_source
*bt_bt2_component_class_source_create(
1299 PyObject
*py_cls
, const char *name
, const char *description
,
1302 bt_component_class_source
*component_class_source
;
1303 bt_component_class
*component_class
;
1307 component_class_source
= bt_component_class_source_create(name
,
1308 component_class_message_iterator_next
);
1309 if (!component_class_source
) {
1310 BT_LOGE_STR("Cannot create source component class.");
1314 component_class
= bt_component_class_source_as_component_class(component_class_source
);
1316 if (component_class_set_help_and_desc(component_class
, description
, help
)) {
1320 ret
= bt_component_class_source_set_initialize_method(component_class_source
, component_class_source_init
);
1321 BT_ASSERT(ret
== 0);
1322 ret
= bt_component_class_source_set_finalize_method(component_class_source
, component_class_source_finalize
);
1323 BT_ASSERT(ret
== 0);
1324 ret
= bt_component_class_source_set_message_iterator_seek_beginning_methods(component_class_source
,
1325 component_class_seek_beginning
, component_class_can_seek_beginning
);
1326 ret
= bt_component_class_source_set_message_iterator_seek_ns_from_origin_methods(
1327 component_class_source
, component_class_seek_ns_from_origin
,
1328 component_class_can_seek_ns_from_origin
);
1329 BT_ASSERT(ret
== 0);
1330 ret
= bt_component_class_source_set_output_port_connected_method(component_class_source
,
1331 component_class_source_output_port_connected
);
1332 BT_ASSERT(ret
== 0);
1333 ret
= bt_component_class_source_set_query_method(component_class_source
, component_class_source_query
);
1334 BT_ASSERT(ret
== 0);
1335 ret
= bt_component_class_source_set_get_supported_mip_versions_method(component_class_source
, component_class_source_get_supported_mip_versions
);
1336 BT_ASSERT(ret
== 0);
1337 ret
= bt_component_class_source_set_message_iterator_initialize_method(
1338 component_class_source
, component_class_source_message_iterator_init
);
1339 BT_ASSERT(ret
== 0);
1340 ret
= bt_component_class_source_set_message_iterator_finalize_method(
1341 component_class_source
, component_class_message_iterator_finalize
);
1342 BT_ASSERT(ret
== 0);
1343 register_cc_ptr_to_py_cls(component_class
, py_cls
);
1346 return component_class_source
;
1350 bt_component_class_filter
*bt_bt2_component_class_filter_create(
1351 PyObject
*py_cls
, const char *name
, const char *description
,
1354 bt_component_class
*component_class
;
1355 bt_component_class_filter
*component_class_filter
;
1359 component_class_filter
= bt_component_class_filter_create(name
,
1360 component_class_message_iterator_next
);
1361 if (!component_class_filter
) {
1362 BT_LOGE_STR("Cannot create filter component class.");
1366 component_class
= bt_component_class_filter_as_component_class(component_class_filter
);
1368 if (component_class_set_help_and_desc(component_class
, description
, help
)) {
1372 ret
= bt_component_class_filter_set_initialize_method(component_class_filter
, component_class_filter_init
);
1373 BT_ASSERT(ret
== 0);
1374 ret
= bt_component_class_filter_set_finalize_method (component_class_filter
, component_class_filter_finalize
);
1375 BT_ASSERT(ret
== 0);
1376 ret
= bt_component_class_filter_set_message_iterator_seek_beginning_methods(component_class_filter
,
1377 component_class_seek_beginning
, component_class_can_seek_beginning
);
1378 BT_ASSERT(ret
== 0);
1379 ret
= bt_component_class_filter_set_message_iterator_seek_ns_from_origin_methods(
1380 component_class_filter
, component_class_seek_ns_from_origin
,
1381 component_class_can_seek_ns_from_origin
);
1382 ret
= bt_component_class_filter_set_input_port_connected_method(component_class_filter
,
1383 component_class_filter_input_port_connected
);
1384 BT_ASSERT(ret
== 0);
1385 ret
= bt_component_class_filter_set_output_port_connected_method(component_class_filter
,
1386 component_class_filter_output_port_connected
);
1387 BT_ASSERT(ret
== 0);
1388 ret
= bt_component_class_filter_set_query_method(component_class_filter
, component_class_filter_query
);
1389 BT_ASSERT(ret
== 0);
1390 ret
= bt_component_class_filter_set_get_supported_mip_versions_method(component_class_filter
, component_class_filter_get_supported_mip_versions
);
1391 BT_ASSERT(ret
== 0);
1392 ret
= bt_component_class_filter_set_message_iterator_initialize_method(
1393 component_class_filter
, component_class_filter_message_iterator_init
);
1394 BT_ASSERT(ret
== 0);
1395 ret
= bt_component_class_filter_set_message_iterator_finalize_method(
1396 component_class_filter
, component_class_message_iterator_finalize
);
1397 BT_ASSERT(ret
== 0);
1398 register_cc_ptr_to_py_cls(component_class
, py_cls
);
1401 return component_class_filter
;
1405 bt_component_class_sink
*bt_bt2_component_class_sink_create(
1406 PyObject
*py_cls
, const char *name
, const char *description
,
1409 bt_component_class_sink
*component_class_sink
;
1410 bt_component_class
*component_class
;
1414 component_class_sink
= bt_component_class_sink_create(name
, component_class_sink_consume
);
1416 if (!component_class_sink
) {
1417 BT_LOGE_STR("Cannot create sink component class.");
1421 component_class
= bt_component_class_sink_as_component_class(component_class_sink
);
1423 if (component_class_set_help_and_desc(component_class
, description
, help
)) {
1427 ret
= bt_component_class_sink_set_initialize_method(component_class_sink
, component_class_sink_init
);
1428 BT_ASSERT(ret
== 0);
1429 ret
= bt_component_class_sink_set_finalize_method(component_class_sink
, component_class_sink_finalize
);
1430 BT_ASSERT(ret
== 0);
1431 ret
= bt_component_class_sink_set_input_port_connected_method(component_class_sink
,
1432 component_class_sink_input_port_connected
);
1433 BT_ASSERT(ret
== 0);
1434 ret
= bt_component_class_sink_set_graph_is_configured_method(component_class_sink
,
1435 component_class_sink_graph_is_configured
);
1436 BT_ASSERT(ret
== 0);
1437 ret
= bt_component_class_sink_set_query_method(component_class_sink
, component_class_sink_query
);
1438 BT_ASSERT(ret
== 0);
1439 ret
= bt_component_class_sink_set_get_supported_mip_versions_method(component_class_sink
, component_class_sink_get_supported_mip_versions
);
1440 BT_ASSERT(ret
== 0);
1441 register_cc_ptr_to_py_cls(component_class
, py_cls
);
1444 return component_class_sink
;