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
)
113 int status
= __BT_FUNC_STATUS_OK
;
114 PyObject
*exc
= PyErr_Occurred();
120 if (PyErr_GivenExceptionMatches(exc
,
121 py_mod_bt2_exc_try_again_type
)) {
122 status
= __BT_FUNC_STATUS_AGAIN
;
123 } else if (PyErr_GivenExceptionMatches(exc
,
124 py_mod_bt2_exc_stop_type
)) {
125 status
= __BT_FUNC_STATUS_END
;
126 } else if (PyErr_GivenExceptionMatches(exc
,
127 py_mod_bt2_exc_unknown_object_type
)) {
128 status
= __BT_FUNC_STATUS_UNKNOWN_OBJECT
;
131 * Unknown exception: convert to general error.
133 * Because we only want to fetch the log level when
134 * we actually get an exception, and not systematically
135 * when we call py_exc_to_status() (as py_exc_to_status()
136 * can return `__BT_FUNC_STATUS_OK`), we get it here
137 * depending on the actor's type.
139 if (self_component
) {
140 active_log_level
= get_self_component_log_level(
142 } else if (self_message_iterator
) {
143 active_log_level
= get_self_message_iterator_log_level(
144 self_message_iterator
);
147 BT_ASSERT(active_log_level
!= -1);
148 log_exception_and_maybe_append_cause(BT_LOG_WARNING
,
149 active_log_level
, true,
150 self_component_class
, self_component
,
151 self_message_iterator
, module_name
);
153 if (PyErr_GivenExceptionMatches(exc
,
154 py_mod_bt2_exc_memory_error
)) {
155 status
= __BT_FUNC_STATUS_MEMORY_ERROR
;
157 status
= __BT_FUNC_STATUS_ERROR
;
167 int py_exc_to_status_component_class_clear(
168 bt_self_component_class
*self_component_class
,
169 int active_log_level
)
171 return py_exc_to_status_clear(self_component_class
, NULL
, NULL
, NULL
,
176 int py_exc_to_status_component_clear(bt_self_component
*self_component
)
178 return py_exc_to_status_clear(NULL
, self_component
, NULL
, NULL
, -1);
182 int py_exc_to_status_message_iterator_clear(
183 bt_self_message_iterator
*self_message_iterator
)
185 return py_exc_to_status_clear(NULL
, NULL
, self_message_iterator
, NULL
, -1);
189 bool bt_bt2_is_python_component_class(const bt_component_class
*comp_cls
)
191 return bt_g_hash_table_contains(bt_cc_ptr_to_py_cls
, comp_cls
);
194 /* Component class proxy methods (delegate to the attached Python object) */
197 bt_component_class_initialize_method_status
component_class_init(
198 bt_self_component
*self_component
,
199 void *self_component_v
,
200 swig_type_info
*self_comp_cls_type_swig_type
,
201 const bt_value
*params
,
202 void *init_method_data
)
204 const bt_component
*component
= bt_self_component_as_component(self_component
);
205 const bt_component_class
*component_class
= bt_component_borrow_class_const(component
);
206 bt_component_class_initialize_method_status status
= __BT_FUNC_STATUS_OK
;
207 PyObject
*py_cls
= NULL
;
208 PyObject
*py_comp
= NULL
;
209 PyObject
*py_params_ptr
= NULL
;
210 PyObject
*py_comp_ptr
= NULL
;
211 bt_logging_level log_level
= get_self_component_log_level(
214 BT_ASSERT(self_component
);
215 BT_ASSERT(self_component_v
);
216 BT_ASSERT(self_comp_cls_type_swig_type
);
219 * Get the user-defined Python class which created this
220 * component's class in the first place (borrowed
223 py_cls
= lookup_cc_ptr_to_py_cls(component_class
);
225 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
226 "Cannot find Python class associated to native component class: "
227 "comp-cls-addr=%p", component_class
);
231 /* Parameters pointer -> SWIG pointer Python object */
232 py_params_ptr
= SWIG_NewPointerObj(SWIG_as_voidptr(params
),
233 SWIGTYPE_p_bt_value
, 0);
234 if (!py_params_ptr
) {
235 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
236 "Failed to create a SWIG pointer object.");
240 py_comp_ptr
= SWIG_NewPointerObj(SWIG_as_voidptr(self_component_v
),
241 self_comp_cls_type_swig_type
, 0);
243 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
244 "Failed to create a SWIG pointer object.");
249 * Do the equivalent of this:
251 * py_comp = py_cls._bt_init_from_native(py_comp_ptr,
252 * py_params_ptr, init_method_data ? init_method_data : Py_None)
254 * _UserComponentType._bt_init_from_native() calls the Python
255 * component object's __init__() function.
257 * We don't take any reference on `init_method_data` which, if
258 * not `NULL`, is assumed to be a `PyObject *`: the user's
259 * __init__() function will eventually take a reference if
260 * needed. If `init_method_data` is `NULL`, then we pass
261 * `Py_None` as the initialization's Python object.
263 py_comp
= PyObject_CallMethod(py_cls
,
264 "_bt_init_from_native", "(OOO)", py_comp_ptr
, py_params_ptr
,
265 init_method_data
? init_method_data
: Py_None
);
267 BT_COMP_LOG_CUR_LVL(BT_LOG_WARNING
, log_level
, self_component
,
268 "Failed to call Python class's _bt_init_from_native() method: "
269 "py-cls-addr=%p", py_cls
);
270 status
= py_exc_to_status_component_clear(self_component
);
275 * Our user Python component object is now fully created and
276 * initialized by the user. Since we just created it, this
277 * native component is its only (persistent) owner.
279 bt_self_component_set_data(self_component
, py_comp
);
284 status
= __BT_FUNC_STATUS_ERROR
;
287 * Clear any exception: we're returning a bad status anyway. If
288 * this call originated from Python (creation from a plugin's
289 * component class, for example), then the user gets an
290 * appropriate creation error.
296 Py_XDECREF(py_params_ptr
);
297 Py_XDECREF(py_comp_ptr
);
302 bt_component_class_get_supported_mip_versions_method_status
303 component_class_get_supported_mip_versions(
304 const bt_component_class
*component_class
,
305 bt_self_component_class
*self_component_class
,
306 const bt_value
*params
, void *init_method_data
,
307 bt_logging_level log_level
,
308 bt_integer_range_set_unsigned
*supported_versions
)
311 PyObject
*py_cls
= NULL
;
312 PyObject
*py_params_ptr
= NULL
;
313 PyObject
*py_range_set_addr
= NULL
;
314 bt_integer_range_set_unsigned
*ret_range_set
= NULL
;
315 bt_component_class_get_supported_mip_versions_method_status status
=
318 py_cls
= lookup_cc_ptr_to_py_cls(component_class
);
320 BT_LOG_WRITE_CUR_LVL(BT_LOG_ERROR
, log_level
, BT_LOG_TAG
,
321 "Cannot find Python class associated to native component class: "
322 "comp-cls-addr=%p", component_class
);
326 py_params_ptr
= SWIG_NewPointerObj(SWIG_as_voidptr(params
),
327 SWIGTYPE_p_bt_value
, 0);
328 if (!py_params_ptr
) {
329 BT_LOG_WRITE_CUR_LVL(BT_LOG_ERROR
, log_level
, BT_LOG_TAG
,
330 "Failed to create a SWIG pointer object.");
335 * We don't take any reference on `init_method_data` which, if
336 * not `NULL`, is assumed to be a `PyObject *`: the user's
337 * _user_get_supported_mip_versions() function will eventually
338 * take a reference if needed. If `init_method_data` is `NULL`,
339 * then we pass `Py_None` as the initialization's Python object.
341 py_range_set_addr
= PyObject_CallMethod(py_cls
,
342 "_bt_get_supported_mip_versions_from_native", "(OOi)",
343 py_params_ptr
, init_method_data
? init_method_data
: Py_None
,
345 if (!py_range_set_addr
) {
346 BT_LOG_WRITE_CUR_LVL(BT_LOG_WARNING
, log_level
, BT_LOG_TAG
,
347 "Failed to call Python class's _bt_get_supported_mip_versions_from_native() method: "
348 "py-cls-addr=%p", py_cls
);
349 status
= py_exc_to_status_component_class_clear(self_component_class
,
355 * The returned object, on success, is an integer object
356 * (PyLong) containing the address of a BT unsigned integer
357 * range set object (new reference).
359 ret_range_set
= PyLong_AsVoidPtr(py_range_set_addr
);
360 BT_ASSERT(!PyErr_Occurred());
361 BT_ASSERT(ret_range_set
);
363 /* Copy returned ranges to input range set */
364 for (i
= 0; i
< bt_integer_range_set_get_range_count(
365 bt_integer_range_set_unsigned_as_range_set_const(ret_range_set
));
367 const bt_integer_range_unsigned
*range
=
368 bt_integer_range_set_unsigned_borrow_range_by_index_const(
370 bt_integer_range_set_add_range_status add_range_status
;
372 add_range_status
= bt_integer_range_set_unsigned_add_range(
374 bt_integer_range_unsigned_get_lower(range
),
375 bt_integer_range_unsigned_get_upper(range
));
376 if (add_range_status
) {
377 BT_LOG_WRITE_CUR_LVL(BT_LOG_ERROR
, log_level
, BT_LOG_TAG
,
378 "Failed to add range to supported MIP versions range set.");
387 status
= __BT_FUNC_STATUS_ERROR
;
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
);
500 /* Call user's _user_finalize() method */
501 PyObject
*py_method_result
= PyObject_CallMethod(py_comp
,
502 "_user_finalize", NULL
);
504 if (PyErr_Occurred()) {
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
);
514 * Ignore any exception raised by the _user_finalize() method
515 * because it won't change anything at this point: the component
516 * is being destroyed anyway.
519 Py_XDECREF(py_method_result
);
524 void component_class_source_finalize(bt_self_component_source
*self_component_source
)
526 bt_self_component
*self_component
= bt_self_component_source_as_self_component(self_component_source
);
527 component_class_finalize(self_component
);
531 void component_class_filter_finalize(bt_self_component_filter
*self_component_filter
)
533 bt_self_component
*self_component
= bt_self_component_filter_as_self_component(self_component_filter
);
534 component_class_finalize(self_component
);
538 void component_class_sink_finalize(bt_self_component_sink
*self_component_sink
)
540 bt_self_component
*self_component
= bt_self_component_sink_as_self_component(self_component_sink
);
541 component_class_finalize(self_component
);
545 bt_component_class_message_iterator_can_seek_beginning_method_status
546 component_class_can_seek_beginning(
547 bt_self_message_iterator
*self_message_iterator
, bt_bool
*can_seek
)
550 PyObject
*py_result
= NULL
;
551 bt_component_class_message_iterator_can_seek_beginning_method_status status
;
552 py_iter
= bt_self_message_iterator_get_data(self_message_iterator
);
555 py_result
= PyObject_CallMethod(py_iter
,
556 "_bt_can_seek_beginning_from_native", NULL
);
558 BT_ASSERT(!py_result
|| PyBool_Check(py_result
));
561 *can_seek
= PyObject_IsTrue(py_result
);
562 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_CAN_SEEK_BEGINNING_METHOD_STATUS_OK
;
564 status
= py_exc_to_status_message_iterator_clear(self_message_iterator
);
565 BT_ASSERT(status
!= __BT_FUNC_STATUS_OK
);
568 Py_XDECREF(py_result
);
574 bt_component_class_message_iterator_seek_beginning_method_status
575 component_class_seek_beginning(bt_self_message_iterator
*self_message_iterator
)
579 bt_component_class_message_iterator_seek_beginning_method_status status
;
581 py_iter
= bt_self_message_iterator_get_data(self_message_iterator
);
583 py_result
= PyObject_CallMethod(py_iter
, "_bt_seek_beginning_from_native",
585 BT_ASSERT(!py_result
|| py_result
== Py_None
);
586 status
= py_exc_to_status_message_iterator_clear(self_message_iterator
);
587 Py_XDECREF(py_result
);
592 bt_component_class_message_iterator_can_seek_ns_from_origin_method_status
593 component_class_can_seek_ns_from_origin(
594 bt_self_message_iterator
*self_message_iterator
,
595 int64_t ns_from_origin
, bt_bool
*can_seek
)
598 PyObject
*py_result
= NULL
;
599 bt_component_class_message_iterator_can_seek_ns_from_origin_method_status status
;
600 py_iter
= bt_self_message_iterator_get_data(self_message_iterator
);
603 py_result
= PyObject_CallMethod(py_iter
,
604 "_bt_can_seek_ns_from_origin_from_native", "L", ns_from_origin
);
606 BT_ASSERT(!py_result
|| PyBool_Check(py_result
));
609 *can_seek
= PyObject_IsTrue(py_result
);
610 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_CAN_SEEK_NS_FROM_ORIGIN_METHOD_STATUS_OK
;
612 status
= py_exc_to_status_message_iterator_clear(self_message_iterator
);
613 BT_ASSERT(status
!= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_CAN_SEEK_NS_FROM_ORIGIN_METHOD_STATUS_OK
);
616 Py_XDECREF(py_result
);
622 bt_component_class_message_iterator_seek_ns_from_origin_method_status
623 component_class_seek_ns_from_origin(
624 bt_self_message_iterator
*self_message_iterator
,
625 int64_t ns_from_origin
)
629 bt_component_class_message_iterator_seek_ns_from_origin_method_status status
;
631 py_iter
= bt_self_message_iterator_get_data(self_message_iterator
);
633 py_result
= PyObject_CallMethod(py_iter
,
634 "_bt_seek_ns_from_origin_from_native", "L", ns_from_origin
);
635 BT_ASSERT(!py_result
|| py_result
== Py_None
);
636 status
= py_exc_to_status_message_iterator_clear(self_message_iterator
);
637 Py_XDECREF(py_result
);
642 bt_component_class_port_connected_method_status
component_class_port_connected(
643 bt_self_component
*self_component
,
644 void *self_component_port
,
645 swig_type_info
*self_component_port_swig_type
,
646 bt_port_type self_component_port_type
,
647 const void *other_port
,
648 swig_type_info
*other_port_swig_type
)
650 bt_component_class_port_connected_method_status status
;
651 PyObject
*py_comp
= NULL
;
652 PyObject
*py_self_port_ptr
= NULL
;
653 PyObject
*py_other_port_ptr
= NULL
;
654 PyObject
*py_method_result
= NULL
;
655 bt_logging_level log_level
= get_self_component_log_level(
658 py_comp
= bt_self_component_get_data(self_component
);
660 py_self_port_ptr
= SWIG_NewPointerObj(SWIG_as_voidptr(self_component_port
),
661 self_component_port_swig_type
, 0);
662 if (!py_self_port_ptr
) {
663 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
664 "Failed to create a SWIG pointer object.");
665 status
= __BT_FUNC_STATUS_MEMORY_ERROR
;
669 py_other_port_ptr
= SWIG_NewPointerObj(SWIG_as_voidptr(other_port
),
670 other_port_swig_type
, 0);
671 if (!py_other_port_ptr
) {
672 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
673 "Failed to create a SWIG pointer object.");
674 status
= __BT_FUNC_STATUS_MEMORY_ERROR
;
677 py_method_result
= PyObject_CallMethod(py_comp
,
678 "_bt_port_connected_from_native", "(OiO)", py_self_port_ptr
,
679 self_component_port_type
, py_other_port_ptr
);
680 BT_ASSERT(!py_method_result
|| py_method_result
== Py_None
);
681 status
= py_exc_to_status_component_clear(self_component
);
684 Py_XDECREF(py_self_port_ptr
);
685 Py_XDECREF(py_other_port_ptr
);
686 Py_XDECREF(py_method_result
);
691 bt_component_class_port_connected_method_status
692 component_class_source_output_port_connected(
693 bt_self_component_source
*self_component_source
,
694 bt_self_component_port_output
*self_component_port_output
,
695 const bt_port_input
*other_port_input
)
697 bt_self_component
*self_component
= bt_self_component_source_as_self_component(self_component_source
);
699 return component_class_port_connected(
701 self_component_port_output
,
702 SWIGTYPE_p_bt_self_component_port_output
,
705 SWIGTYPE_p_bt_port_input
);
709 bt_component_class_port_connected_method_status
710 component_class_filter_input_port_connected(
711 bt_self_component_filter
*self_component_filter
,
712 bt_self_component_port_input
*self_component_port_input
,
713 const bt_port_output
*other_port_output
)
715 bt_self_component
*self_component
= bt_self_component_filter_as_self_component(self_component_filter
);
717 return component_class_port_connected(
719 self_component_port_input
,
720 SWIGTYPE_p_bt_self_component_port_input
,
723 SWIGTYPE_p_bt_port_output
);
727 bt_component_class_port_connected_method_status
728 component_class_filter_output_port_connected(
729 bt_self_component_filter
*self_component_filter
,
730 bt_self_component_port_output
*self_component_port_output
,
731 const bt_port_input
*other_port_input
)
733 bt_self_component
*self_component
= bt_self_component_filter_as_self_component(self_component_filter
);
735 return component_class_port_connected(
737 self_component_port_output
,
738 SWIGTYPE_p_bt_self_component_port_output
,
741 SWIGTYPE_p_bt_port_input
);
745 bt_component_class_port_connected_method_status
746 component_class_sink_input_port_connected(
747 bt_self_component_sink
*self_component_sink
,
748 bt_self_component_port_input
*self_component_port_input
,
749 const bt_port_output
*other_port_output
)
751 bt_self_component
*self_component
= bt_self_component_sink_as_self_component(self_component_sink
);
753 return component_class_port_connected(
755 self_component_port_input
,
756 SWIGTYPE_p_bt_self_component_port_input
,
759 SWIGTYPE_p_bt_port_output
);
763 bt_component_class_sink_graph_is_configured_method_status
764 component_class_sink_graph_is_configured(
765 bt_self_component_sink
*self_component_sink
)
767 PyObject
*py_comp
= NULL
;
768 PyObject
*py_method_result
= NULL
;
769 bt_component_class_sink_graph_is_configured_method_status status
= __BT_FUNC_STATUS_OK
;
770 bt_self_component
*self_component
= bt_self_component_sink_as_self_component(self_component_sink
);
772 py_comp
= bt_self_component_get_data(self_component
);
773 py_method_result
= PyObject_CallMethod(py_comp
,
774 "_bt_graph_is_configured_from_native", NULL
);
775 BT_ASSERT(!py_method_result
|| py_method_result
== Py_None
);
776 status
= py_exc_to_status_component_clear(self_component
);
777 Py_XDECREF(py_method_result
);
782 bt_component_class_query_method_status
component_class_query(
783 const bt_component_class
*component_class
,
784 bt_self_component_class
*self_component_class
,
785 bt_private_query_executor
*priv_query_executor
,
786 const char *object
, const bt_value
*params
, void *method_data
,
787 const bt_value
**result
)
789 PyObject
*py_cls
= NULL
;
790 PyObject
*py_params_ptr
= NULL
;
791 PyObject
*py_priv_query_exec_ptr
= NULL
;
792 PyObject
*py_query_func
= NULL
;
793 PyObject
*py_object
= NULL
;
794 PyObject
*py_results_addr
= NULL
;
795 bt_component_class_query_method_status status
= __BT_FUNC_STATUS_OK
;
796 const bt_query_executor
*query_exec
=
797 bt_private_query_executor_as_query_executor_const(
798 priv_query_executor
);
799 bt_logging_level log_level
=
800 bt_query_executor_get_logging_level(query_exec
);
803 * If there's any `method_data`, assume this component class is
804 * getting queried from Python, so that `method_data` is a
805 * Python object to pass to the user's _user_query() method.
807 BT_ASSERT(!method_data
||
808 bt_bt2_is_python_component_class(component_class
));
810 py_cls
= lookup_cc_ptr_to_py_cls(component_class
);
812 BT_LOG_WRITE_CUR_LVL(BT_LOG_ERROR
, log_level
, BT_LOG_TAG
,
813 "Cannot find Python class associated to native component class: "
814 "comp-cls-addr=%p", component_class
);
818 py_params_ptr
= SWIG_NewPointerObj(SWIG_as_voidptr(params
),
819 SWIGTYPE_p_bt_value
, 0);
820 if (!py_params_ptr
) {
821 BT_LOG_WRITE_CUR_LVL(BT_LOG_ERROR
, log_level
, BT_LOG_TAG
,
822 "Failed to create a SWIG pointer object.");
826 py_priv_query_exec_ptr
= SWIG_NewPointerObj(
827 SWIG_as_voidptr(priv_query_executor
),
828 SWIGTYPE_p_bt_private_query_executor
, 0);
829 if (!py_priv_query_exec_ptr
) {
830 BT_LOG_WRITE_CUR_LVL(BT_LOG_ERROR
, log_level
, BT_LOG_TAG
,
831 "Failed to create a SWIG pointer object.");
835 py_object
= SWIG_FromCharPtr(object
);
837 BT_LOG_WRITE_CUR_LVL(BT_LOG_ERROR
, log_level
, BT_LOG_TAG
,
838 "Failed to create a Python string.");
843 * We don't take any reference on `method_data` which, if not
844 * `NULL`, is assumed to be a `PyObject *`: the user's
845 * _user_query() function will eventually take a reference if
846 * needed. If `method_data` is `NULL`, then we pass `Py_None` as
847 * the initialization's Python object.
849 py_results_addr
= PyObject_CallMethod(py_cls
,
850 "_bt_query_from_native", "(OOOO)", py_priv_query_exec_ptr
,
851 py_object
, py_params_ptr
,
852 method_data
? method_data
: Py_None
);
853 if (!py_results_addr
) {
854 status
= py_exc_to_status_component_class_clear(self_component_class
,
857 static const char *fmt
=
858 "Failed to call Python class's _bt_query_from_native() method: py-cls-addr=%p";
859 BT_LOG_WRITE_CUR_LVL(BT_LOG_WARNING
, log_level
, BT_LOG_TAG
,
861 BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_COMPONENT_CLASS(
862 self_component_class
, fmt
, py_cls
);
868 * The returned object, on success, is an integer object
869 * (PyLong) containing the address of a BT value object (new
872 *result
= PyLong_AsVoidPtr(py_results_addr
);
873 BT_ASSERT(!PyErr_Occurred());
879 status
= __BT_FUNC_STATUS_ERROR
;
882 Py_XDECREF(py_params_ptr
);
883 Py_XDECREF(py_priv_query_exec_ptr
);
884 Py_XDECREF(py_query_func
);
885 Py_XDECREF(py_object
);
886 Py_XDECREF(py_results_addr
);
891 bt_component_class_query_method_status
component_class_source_query(
892 bt_self_component_class_source
*self_component_class_source
,
893 bt_private_query_executor
*priv_query_executor
,
894 const char *object
, const bt_value
*params
, void *method_data
,
895 const bt_value
**result
)
897 const bt_component_class_source
*component_class_source
= bt_self_component_class_source_as_component_class_source(self_component_class_source
);
898 const bt_component_class
*component_class
= bt_component_class_source_as_component_class_const(component_class_source
);
899 bt_self_component_class
*self_component_class
= bt_self_component_class_source_as_self_component_class(self_component_class_source
);
901 return component_class_query(component_class
, self_component_class
,
902 priv_query_executor
, object
, params
, method_data
, result
);
906 bt_component_class_query_method_status
component_class_filter_query(
907 bt_self_component_class_filter
*self_component_class_filter
,
908 bt_private_query_executor
*priv_query_executor
,
909 const char *object
, const bt_value
*params
, void *method_data
,
910 const bt_value
**result
)
912 const bt_component_class_filter
*component_class_filter
= bt_self_component_class_filter_as_component_class_filter(self_component_class_filter
);
913 const bt_component_class
*component_class
= bt_component_class_filter_as_component_class_const(component_class_filter
);
914 bt_self_component_class
*self_component_class
= bt_self_component_class_filter_as_self_component_class(self_component_class_filter
);
916 return component_class_query(component_class
, self_component_class
,
917 priv_query_executor
, object
, params
, method_data
, result
);
921 bt_component_class_query_method_status
component_class_sink_query(
922 bt_self_component_class_sink
*self_component_class_sink
,
923 bt_private_query_executor
*priv_query_executor
,
924 const char *object
, const bt_value
*params
, void *method_data
,
925 const bt_value
**result
)
927 const bt_component_class_sink
*component_class_sink
= bt_self_component_class_sink_as_component_class_sink(self_component_class_sink
);
928 const bt_component_class
*component_class
= bt_component_class_sink_as_component_class_const(component_class_sink
);
929 bt_self_component_class
*self_component_class
= bt_self_component_class_sink_as_self_component_class(self_component_class_sink
);
931 return component_class_query(component_class
, self_component_class
,
932 priv_query_executor
, object
, params
, method_data
, result
);
936 bt_component_class_message_iterator_initialize_method_status
937 component_class_message_iterator_init(
938 bt_self_message_iterator
*self_message_iterator
,
939 bt_self_message_iterator_configuration
*config
,
940 bt_self_component
*self_component
,
941 bt_self_component_port_output
*self_component_port_output
)
943 bt_component_class_message_iterator_initialize_method_status status
= __BT_FUNC_STATUS_OK
;
944 PyObject
*py_comp_cls
= NULL
;
945 PyObject
*py_iter_cls
= NULL
;
946 PyObject
*py_iter_ptr
= NULL
;
947 PyObject
*py_config_ptr
= NULL
;
948 PyObject
*py_component_port_output_ptr
= NULL
;
949 PyObject
*py_init_method_result
= NULL
;
950 PyObject
*py_iter
= NULL
;
952 bt_logging_level log_level
= get_self_component_log_level(
955 py_comp
= bt_self_component_get_data(self_component
);
957 /* Find user's Python message iterator class */
958 py_comp_cls
= PyObject_GetAttrString(py_comp
, "__class__");
960 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
961 "Cannot get Python object's `__class__` attribute.");
965 py_iter_cls
= PyObject_GetAttrString(py_comp_cls
, "_iter_cls");
967 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
968 "Cannot get Python class's `_iter_cls` attribute.");
972 py_iter_ptr
= SWIG_NewPointerObj(SWIG_as_voidptr(self_message_iterator
),
973 SWIGTYPE_p_bt_self_message_iterator
, 0);
975 const char *err
= "Failed to create a SWIG pointer object.";
977 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
979 BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_MESSAGE_ITERATOR(
980 self_message_iterator
, err
);
985 * Create object with borrowed native message iterator
988 * py_iter = py_iter_cls.__new__(py_iter_cls, py_iter_ptr)
990 py_iter
= PyObject_CallMethod(py_iter_cls
, "__new__",
991 "(OO)", py_iter_cls
, py_iter_ptr
);
993 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
994 "Failed to call Python class's __new__() method: "
995 "py-cls-addr=%p", py_iter_cls
);
1000 * Initialize object:
1002 * py_iter.__init__(config, self_output_port)
1004 * through the _init_from_native helper static method.
1006 * At this point, py_iter._ptr is set, so this initialization
1007 * function has access to self._component (which gives it the
1008 * user Python component object from which the iterator was
1011 py_config_ptr
= SWIG_NewPointerObj(SWIG_as_voidptr(config
),
1012 SWIGTYPE_p_bt_self_message_iterator_configuration
, 0);
1013 if (!py_config_ptr
) {
1014 const char *err
= "Failed to create a SWIG pointer object";
1016 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
1018 BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_MESSAGE_ITERATOR(
1019 self_message_iterator
, err
);
1023 py_component_port_output_ptr
= SWIG_NewPointerObj(
1024 SWIG_as_voidptr(self_component_port_output
),
1025 SWIGTYPE_p_bt_self_component_port_output
, 0);
1026 if (!py_component_port_output_ptr
) {
1027 const char *err
= "Failed to create a SWIG pointer object.";
1029 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
1031 BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_MESSAGE_ITERATOR(
1032 self_message_iterator
, err
);
1036 py_init_method_result
= PyObject_CallMethod(py_iter
,
1037 "_bt_init_from_native", "OO", py_config_ptr
,
1038 py_component_port_output_ptr
);
1039 if (!py_init_method_result
) {
1040 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
1041 "User's __init__() method failed:");
1046 * Since the Python code can never instantiate a user-defined
1047 * message iterator class, the native message iterator
1048 * object does NOT belong to a user Python message iterator
1049 * object (borrowed reference). However this Python object is
1050 * owned by this native message iterator object.
1052 * In the Python world, the lifetime of the native message
1053 * iterator is managed by a _GenericMessageIterator
1056 * _GenericMessageIterator instance:
1057 * owns a native bt_message_iterator object (iter)
1058 * owns a _UserMessageIterator instance (py_iter)
1059 * self._ptr is a borrowed reference to the
1060 * native bt_private_connection_private_message_iterator
1063 bt_self_message_iterator_set_data(self_message_iterator
, py_iter
);
1068 /* Handling of errors that cause a Python exception to be set. */
1069 status
= py_exc_to_status_message_iterator_clear(self_message_iterator
);
1070 BT_ASSERT(status
!= __BT_FUNC_STATUS_OK
);
1074 /* Handling of errors that don't cause a Python exception to be set. */
1075 status
= __BT_FUNC_STATUS_ERROR
;
1078 BT_ASSERT(!PyErr_Occurred());
1080 Py_XDECREF(py_comp_cls
);
1081 Py_XDECREF(py_iter_cls
);
1082 Py_XDECREF(py_iter_ptr
);
1083 Py_XDECREF(py_component_port_output_ptr
);
1084 Py_XDECREF(py_init_method_result
);
1085 Py_XDECREF(py_iter
);
1090 bt_component_class_message_iterator_initialize_method_status
1091 component_class_source_message_iterator_init(
1092 bt_self_message_iterator
*self_message_iterator
,
1093 bt_self_message_iterator_configuration
*config
,
1094 bt_self_component_source
*self_component_source
,
1095 bt_self_component_port_output
*self_component_port_output
)
1097 bt_self_component
*self_component
=
1098 bt_self_component_source_as_self_component(self_component_source
);
1100 return component_class_message_iterator_init(self_message_iterator
,
1101 config
, self_component
, self_component_port_output
);
1105 bt_component_class_message_iterator_initialize_method_status
1106 component_class_filter_message_iterator_init(
1107 bt_self_message_iterator
*self_message_iterator
,
1108 bt_self_message_iterator_configuration
*config
,
1109 bt_self_component_filter
*self_component_filter
,
1110 bt_self_component_port_output
*self_component_port_output
)
1112 bt_self_component
*self_component
=
1113 bt_self_component_filter_as_self_component(self_component_filter
);
1115 return component_class_message_iterator_init(self_message_iterator
,
1116 config
, self_component
, self_component_port_output
);
1120 void component_class_message_iterator_finalize(
1121 bt_self_message_iterator
*message_iterator
)
1123 PyObject
*py_message_iter
= bt_self_message_iterator_get_data(
1125 PyObject
*py_method_result
= NULL
;
1127 BT_ASSERT(py_message_iter
);
1129 /* Call user's _user_finalize() method */
1130 py_method_result
= PyObject_CallMethod(py_message_iter
,
1131 "_user_finalize", NULL
);
1133 if (PyErr_Occurred()) {
1134 bt_self_component
*self_comp
=
1135 bt_self_message_iterator_borrow_component(
1137 bt_logging_level log_level
= get_self_component_log_level(
1140 BT_COMP_LOG_CUR_LVL(BT_LOG_WARNING
, log_level
, self_comp
,
1141 "User's _user_finalize() method raised an exception: ignoring:");
1142 logw_exception(get_self_message_iterator_log_level(
1147 * Ignore any exception raised by the _user_finalize() method
1148 * because it won't change anything at this point: the component
1149 * is being destroyed anyway.
1152 Py_XDECREF(py_method_result
);
1153 Py_DECREF(py_message_iter
);
1156 /* Valid for both sources and filters. */
1159 bt_component_class_message_iterator_next_method_status
1160 component_class_message_iterator_next(
1161 bt_self_message_iterator
*message_iterator
,
1162 bt_message_array_const msgs
, uint64_t capacity
,
1165 bt_component_class_message_iterator_next_method_status status
= __BT_FUNC_STATUS_OK
;
1166 PyObject
*py_message_iter
= bt_self_message_iterator_get_data(message_iterator
);
1167 PyObject
*py_method_result
= NULL
;
1169 BT_ASSERT(py_message_iter
);
1170 py_method_result
= PyObject_CallMethod(py_message_iter
,
1171 "_bt_next_from_native", NULL
);
1172 if (!py_method_result
) {
1173 status
= py_exc_to_status_message_iterator_clear(message_iterator
);
1174 BT_ASSERT(status
!= __BT_FUNC_STATUS_OK
);
1179 * The returned object, on success, is an integer object
1180 * (PyLong) containing the address of a native message
1181 * object (which is now ours).
1183 msgs
[0] = PyLong_AsVoidPtr(py_method_result
);
1186 /* Clear potential overflow error; should never happen */
1187 BT_ASSERT(!PyErr_Occurred());
1191 Py_XDECREF(py_method_result
);
1196 bt_component_class_sink_consume_method_status
1197 component_class_sink_consume(bt_self_component_sink
*self_component_sink
)
1199 bt_self_component
*self_component
= bt_self_component_sink_as_self_component(self_component_sink
);
1200 PyObject
*py_comp
= bt_self_component_get_data(self_component
);
1201 PyObject
*py_method_result
= NULL
;
1202 bt_component_class_sink_consume_method_status status
;
1205 py_method_result
= PyObject_CallMethod(py_comp
,
1206 "_user_consume", NULL
);
1207 status
= py_exc_to_status_component_clear(self_component
);
1208 BT_ASSERT(py_method_result
|| status
!= __BT_FUNC_STATUS_OK
);
1209 Py_XDECREF(py_method_result
);
1214 int component_class_set_help_and_desc(
1215 bt_component_class
*component_class
,
1216 const char *description
, const char *help
)
1221 ret
= bt_component_class_set_description(component_class
, description
);
1223 BT_LOGE("Cannot set component class's description: "
1224 "comp-cls-addr=%p", component_class
);
1230 ret
= bt_component_class_set_help(component_class
, help
);
1232 BT_LOGE("Cannot set component class's help text: "
1233 "comp-cls-addr=%p", component_class
);
1245 bt_component_class_source
*bt_bt2_component_class_source_create(
1246 PyObject
*py_cls
, const char *name
, const char *description
,
1249 bt_component_class_source
*component_class_source
;
1250 bt_component_class
*component_class
;
1254 component_class_source
= bt_component_class_source_create(name
,
1255 component_class_message_iterator_next
);
1256 if (!component_class_source
) {
1257 BT_LOGE_STR("Cannot create source component class.");
1261 component_class
= bt_component_class_source_as_component_class(component_class_source
);
1263 if (component_class_set_help_and_desc(component_class
, description
, help
)) {
1267 ret
= bt_component_class_source_set_initialize_method(component_class_source
, component_class_source_init
);
1268 BT_ASSERT(ret
== 0);
1269 ret
= bt_component_class_source_set_finalize_method(component_class_source
, component_class_source_finalize
);
1270 BT_ASSERT(ret
== 0);
1271 ret
= bt_component_class_source_set_message_iterator_seek_beginning_methods(component_class_source
,
1272 component_class_seek_beginning
, component_class_can_seek_beginning
);
1273 ret
= bt_component_class_source_set_message_iterator_seek_ns_from_origin_methods(
1274 component_class_source
, component_class_seek_ns_from_origin
,
1275 component_class_can_seek_ns_from_origin
);
1276 BT_ASSERT(ret
== 0);
1277 ret
= bt_component_class_source_set_output_port_connected_method(component_class_source
,
1278 component_class_source_output_port_connected
);
1279 BT_ASSERT(ret
== 0);
1280 ret
= bt_component_class_source_set_query_method(component_class_source
, component_class_source_query
);
1281 BT_ASSERT(ret
== 0);
1282 ret
= bt_component_class_source_set_get_supported_mip_versions_method(component_class_source
, component_class_source_get_supported_mip_versions
);
1283 BT_ASSERT(ret
== 0);
1284 ret
= bt_component_class_source_set_message_iterator_initialize_method(
1285 component_class_source
, component_class_source_message_iterator_init
);
1286 BT_ASSERT(ret
== 0);
1287 ret
= bt_component_class_source_set_message_iterator_finalize_method(
1288 component_class_source
, component_class_message_iterator_finalize
);
1289 BT_ASSERT(ret
== 0);
1290 register_cc_ptr_to_py_cls(component_class
, py_cls
);
1293 return component_class_source
;
1297 bt_component_class_filter
*bt_bt2_component_class_filter_create(
1298 PyObject
*py_cls
, const char *name
, const char *description
,
1301 bt_component_class
*component_class
;
1302 bt_component_class_filter
*component_class_filter
;
1306 component_class_filter
= bt_component_class_filter_create(name
,
1307 component_class_message_iterator_next
);
1308 if (!component_class_filter
) {
1309 BT_LOGE_STR("Cannot create filter component class.");
1313 component_class
= bt_component_class_filter_as_component_class(component_class_filter
);
1315 if (component_class_set_help_and_desc(component_class
, description
, help
)) {
1319 ret
= bt_component_class_filter_set_initialize_method(component_class_filter
, component_class_filter_init
);
1320 BT_ASSERT(ret
== 0);
1321 ret
= bt_component_class_filter_set_finalize_method (component_class_filter
, component_class_filter_finalize
);
1322 BT_ASSERT(ret
== 0);
1323 ret
= bt_component_class_filter_set_message_iterator_seek_beginning_methods(component_class_filter
,
1324 component_class_seek_beginning
, component_class_can_seek_beginning
);
1325 BT_ASSERT(ret
== 0);
1326 ret
= bt_component_class_filter_set_message_iterator_seek_ns_from_origin_methods(
1327 component_class_filter
, component_class_seek_ns_from_origin
,
1328 component_class_can_seek_ns_from_origin
);
1329 ret
= bt_component_class_filter_set_input_port_connected_method(component_class_filter
,
1330 component_class_filter_input_port_connected
);
1331 BT_ASSERT(ret
== 0);
1332 ret
= bt_component_class_filter_set_output_port_connected_method(component_class_filter
,
1333 component_class_filter_output_port_connected
);
1334 BT_ASSERT(ret
== 0);
1335 ret
= bt_component_class_filter_set_query_method(component_class_filter
, component_class_filter_query
);
1336 BT_ASSERT(ret
== 0);
1337 ret
= bt_component_class_filter_set_get_supported_mip_versions_method(component_class_filter
, component_class_filter_get_supported_mip_versions
);
1338 BT_ASSERT(ret
== 0);
1339 ret
= bt_component_class_filter_set_message_iterator_initialize_method(
1340 component_class_filter
, component_class_filter_message_iterator_init
);
1341 BT_ASSERT(ret
== 0);
1342 ret
= bt_component_class_filter_set_message_iterator_finalize_method(
1343 component_class_filter
, component_class_message_iterator_finalize
);
1344 BT_ASSERT(ret
== 0);
1345 register_cc_ptr_to_py_cls(component_class
, py_cls
);
1348 return component_class_filter
;
1352 bt_component_class_sink
*bt_bt2_component_class_sink_create(
1353 PyObject
*py_cls
, const char *name
, const char *description
,
1356 bt_component_class_sink
*component_class_sink
;
1357 bt_component_class
*component_class
;
1361 component_class_sink
= bt_component_class_sink_create(name
, component_class_sink_consume
);
1363 if (!component_class_sink
) {
1364 BT_LOGE_STR("Cannot create sink component class.");
1368 component_class
= bt_component_class_sink_as_component_class(component_class_sink
);
1370 if (component_class_set_help_and_desc(component_class
, description
, help
)) {
1374 ret
= bt_component_class_sink_set_initialize_method(component_class_sink
, component_class_sink_init
);
1375 BT_ASSERT(ret
== 0);
1376 ret
= bt_component_class_sink_set_finalize_method(component_class_sink
, component_class_sink_finalize
);
1377 BT_ASSERT(ret
== 0);
1378 ret
= bt_component_class_sink_set_input_port_connected_method(component_class_sink
,
1379 component_class_sink_input_port_connected
);
1380 BT_ASSERT(ret
== 0);
1381 ret
= bt_component_class_sink_set_graph_is_configured_method(component_class_sink
,
1382 component_class_sink_graph_is_configured
);
1383 BT_ASSERT(ret
== 0);
1384 ret
= bt_component_class_sink_set_query_method(component_class_sink
, component_class_sink_query
);
1385 BT_ASSERT(ret
== 0);
1386 ret
= bt_component_class_sink_set_get_supported_mip_versions_method(component_class_sink
, component_class_sink_get_supported_mip_versions
);
1387 BT_ASSERT(ret
== 0);
1388 register_cc_ptr_to_py_cls(component_class
, py_cls
);
1391 return component_class_sink
;