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 #define BT_FMT_SWIG_ALLOC_FAILED "Failed to create a SWIG pointer object."
48 static GHashTable
*bt_cc_ptr_to_py_cls
;
51 void bt_bt2_unregister_cc_ptr_to_py_cls(const bt_component_class
*comp_cls
)
55 if (!bt_cc_ptr_to_py_cls
) {
59 existed
= g_hash_table_remove(bt_cc_ptr_to_py_cls
, comp_cls
);
64 void register_cc_ptr_to_py_cls(struct bt_component_class
*bt_cc
,
67 if (!bt_cc_ptr_to_py_cls
) {
69 * Lazy-initializing this GHashTable because GLib
70 * might not be initialized yet and it needs to be
71 * before we call g_hash_table_new()
73 BT_LOGD_STR("Creating native component class to Python component class hash table.");
74 bt_cc_ptr_to_py_cls
= g_hash_table_new(g_direct_hash
, g_direct_equal
);
75 BT_ASSERT(bt_cc_ptr_to_py_cls
);
78 g_hash_table_insert(bt_cc_ptr_to_py_cls
, (gpointer
) bt_cc
,
83 PyObject
*lookup_cc_ptr_to_py_cls(const bt_component_class
*bt_cc
)
85 if (!bt_cc_ptr_to_py_cls
) {
86 BT_LOGW("Cannot look up Python component class because hash table is NULL: "
87 "comp-cls-addr=%p", bt_cc
);
91 return (PyObject
*) g_hash_table_lookup(bt_cc_ptr_to_py_cls
,
92 (gconstpointer
) bt_cc
);
95 /* Library destructor */
97 __attribute__((destructor
))
99 void native_comp_class_dtor(void) {
100 /* Destroy component class association hash table */
101 if (bt_cc_ptr_to_py_cls
) {
102 BT_LOGD_STR("Destroying native component class to Python component class hash table.");
103 g_hash_table_destroy(bt_cc_ptr_to_py_cls
);
104 bt_cc_ptr_to_py_cls
= NULL
;
109 int py_exc_to_status_clear(
110 bt_self_component_class
*self_component_class
,
111 bt_self_component
*self_component
,
112 bt_self_message_iterator
*self_message_iterator
,
113 const char *module_name
, int active_log_level
)
116 PyObject
*exc
= PyErr_Occurred();
119 status
= __BT_FUNC_STATUS_OK
;
123 if (PyErr_GivenExceptionMatches(exc
,
124 py_mod_bt2_exc_try_again_type
)) {
125 status
= __BT_FUNC_STATUS_AGAIN
;
126 } else if (PyErr_GivenExceptionMatches(exc
,
127 py_mod_bt2_exc_stop_type
)) {
128 status
= __BT_FUNC_STATUS_END
;
129 } else if (PyErr_GivenExceptionMatches(exc
,
130 py_mod_bt2_exc_unknown_object_type
)) {
131 status
= __BT_FUNC_STATUS_UNKNOWN_OBJECT
;
134 * Unknown exception: convert to general error.
136 * Because we only want to fetch the log level when
137 * we actually get an exception, and not systematically
138 * when we call py_exc_to_status() (as py_exc_to_status()
139 * can return `__BT_FUNC_STATUS_OK`), we get it here
140 * depending on the actor's type.
142 if (self_component
) {
143 active_log_level
= get_self_component_log_level(
145 } else if (self_message_iterator
) {
146 active_log_level
= get_self_message_iterator_log_level(
147 self_message_iterator
);
150 BT_ASSERT(active_log_level
!= -1);
151 log_exception_and_maybe_append_cause(BT_LOG_WARNING
,
152 active_log_level
, true,
153 self_component_class
, self_component
,
154 self_message_iterator
, module_name
);
156 if (PyErr_GivenExceptionMatches(exc
,
157 py_mod_bt2_exc_memory_error
)) {
158 status
= __BT_FUNC_STATUS_MEMORY_ERROR
;
160 status
= __BT_FUNC_STATUS_ERROR
;
170 int py_exc_to_status_component_class_clear(
171 bt_self_component_class
*self_component_class
,
172 int active_log_level
)
174 return py_exc_to_status_clear(self_component_class
, NULL
, NULL
, NULL
,
179 int py_exc_to_status_component_clear(bt_self_component
*self_component
)
181 return py_exc_to_status_clear(NULL
, self_component
, NULL
, NULL
, -1);
185 int py_exc_to_status_message_iterator_clear(
186 bt_self_message_iterator
*self_message_iterator
)
188 return py_exc_to_status_clear(NULL
, NULL
, self_message_iterator
, NULL
, -1);
192 bool bt_bt2_is_python_component_class(const bt_component_class
*comp_cls
)
194 return bt_g_hash_table_contains(bt_cc_ptr_to_py_cls
, comp_cls
);
197 /* Component class proxy methods (delegate to the attached Python object) */
200 bt_component_class_initialize_method_status
component_class_init(
201 bt_self_component
*self_component
,
202 void *self_component_v
,
203 swig_type_info
*self_comp_cls_type_swig_type
,
204 const bt_value
*params
,
205 void *init_method_data
)
207 const bt_component
*component
= bt_self_component_as_component(self_component
);
208 const bt_component_class
*component_class
= bt_component_borrow_class_const(component
);
209 bt_component_class_initialize_method_status status
;
210 PyObject
*py_cls
= NULL
;
211 PyObject
*py_comp
= NULL
;
212 PyObject
*py_params_ptr
= NULL
;
213 PyObject
*py_comp_ptr
= NULL
;
214 bt_logging_level log_level
= get_self_component_log_level(
217 BT_ASSERT(self_component
);
218 BT_ASSERT(self_component_v
);
219 BT_ASSERT(self_comp_cls_type_swig_type
);
222 * Get the user-defined Python class which created this
223 * component's class in the first place (borrowed
226 py_cls
= lookup_cc_ptr_to_py_cls(component_class
);
228 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
229 "Cannot find Python class associated to native component class: "
230 "comp-cls-addr=%p", component_class
);
234 /* Parameters pointer -> SWIG pointer Python object */
235 py_params_ptr
= SWIG_NewPointerObj(SWIG_as_voidptr(params
),
236 SWIGTYPE_p_bt_value
, 0);
237 if (!py_params_ptr
) {
238 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
239 BT_FMT_SWIG_ALLOC_FAILED
);
243 py_comp_ptr
= SWIG_NewPointerObj(SWIG_as_voidptr(self_component_v
),
244 self_comp_cls_type_swig_type
, 0);
246 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
247 BT_FMT_SWIG_ALLOC_FAILED
);
252 * Do the equivalent of this:
254 * py_comp = py_cls._bt_init_from_native(py_comp_ptr,
255 * py_params_ptr, init_method_data ? init_method_data : Py_None)
257 * _UserComponentType._bt_init_from_native() calls the Python
258 * component object's __init__() function.
260 * We don't take any reference on `init_method_data` which, if
261 * not `NULL`, is assumed to be a `PyObject *`: the user's
262 * __init__() function will eventually take a reference if
263 * needed. If `init_method_data` is `NULL`, then we pass
264 * `Py_None` as the initialization's Python object.
266 py_comp
= PyObject_CallMethod(py_cls
,
267 "_bt_init_from_native", "(OOO)", py_comp_ptr
, py_params_ptr
,
268 init_method_data
? init_method_data
: Py_None
);
270 BT_COMP_LOG_CUR_LVL(BT_LOG_WARNING
, log_level
, self_component
,
271 "Failed to call Python class's _bt_init_from_native() method: "
272 "py-cls-addr=%p", py_cls
);
273 status
= py_exc_to_status_component_clear(self_component
);
278 * Our user Python component object is now fully created and
279 * initialized by the user. Since we just created it, this
280 * native component is its only (persistent) owner.
282 bt_self_component_set_data(self_component
, py_comp
);
285 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK
;
290 /* This error path is for non-Python errors only. */
291 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR
;
294 BT_ASSERT(!PyErr_Occurred());
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
;
317 py_cls
= lookup_cc_ptr_to_py_cls(component_class
);
319 BT_LOG_WRITE_CUR_LVL(BT_LOG_ERROR
, log_level
, BT_LOG_TAG
,
320 "Cannot find Python class associated to native component class: "
321 "comp-cls-addr=%p", component_class
);
325 py_params_ptr
= SWIG_NewPointerObj(SWIG_as_voidptr(params
),
326 SWIGTYPE_p_bt_value
, 0);
327 if (!py_params_ptr
) {
328 BT_LOG_WRITE_CUR_LVL(BT_LOG_ERROR
, log_level
, BT_LOG_TAG
,
329 BT_FMT_SWIG_ALLOC_FAILED
);
334 * We don't take any reference on `init_method_data` which, if
335 * not `NULL`, is assumed to be a `PyObject *`: the user's
336 * _user_get_supported_mip_versions() function will eventually
337 * take a reference if needed. If `init_method_data` is `NULL`,
338 * then we pass `Py_None` as the initialization's Python object.
340 py_range_set_addr
= PyObject_CallMethod(py_cls
,
341 "_bt_get_supported_mip_versions_from_native", "(OOi)",
342 py_params_ptr
, init_method_data
? init_method_data
: Py_None
,
344 if (!py_range_set_addr
) {
345 BT_LOG_WRITE_CUR_LVL(BT_LOG_WARNING
, log_level
, BT_LOG_TAG
,
346 "Failed to call Python class's _bt_get_supported_mip_versions_from_native() method: "
347 "py-cls-addr=%p", py_cls
);
348 status
= py_exc_to_status_component_class_clear(self_component_class
,
354 * The returned object, on success, is an integer object
355 * (PyLong) containing the address of a BT unsigned integer
356 * range set object (new reference).
358 ret_range_set
= PyLong_AsVoidPtr(py_range_set_addr
);
359 BT_ASSERT(!PyErr_Occurred());
360 BT_ASSERT(ret_range_set
);
362 /* Copy returned ranges to input range set */
363 for (i
= 0; i
< bt_integer_range_set_get_range_count(
364 bt_integer_range_set_unsigned_as_range_set_const(ret_range_set
));
366 const bt_integer_range_unsigned
*range
=
367 bt_integer_range_set_unsigned_borrow_range_by_index_const(
369 bt_integer_range_set_add_range_status add_range_status
;
371 add_range_status
= bt_integer_range_set_unsigned_add_range(
373 bt_integer_range_unsigned_get_lower(range
),
374 bt_integer_range_unsigned_get_upper(range
));
375 if (add_range_status
) {
376 BT_LOG_WRITE_CUR_LVL(BT_LOG_ERROR
, log_level
, BT_LOG_TAG
,
377 "Failed to add range to supported MIP versions range set.");
382 status
= BT_COMPONENT_CLASS_GET_SUPPORTED_MIP_VERSIONS_METHOD_STATUS_OK
;
387 /* This error path is for non-Python errors only. */
388 status
= BT_COMPONENT_CLASS_GET_SUPPORTED_MIP_VERSIONS_METHOD_STATUS_ERROR
;
391 BT_ASSERT(!PyErr_Occurred());
392 Py_XDECREF(py_params_ptr
);
393 Py_XDECREF(py_range_set_addr
);
394 bt_integer_range_set_unsigned_put_ref(ret_range_set
);
399 bt_component_class_get_supported_mip_versions_method_status
400 component_class_source_get_supported_mip_versions(
401 bt_self_component_class_source
*self_component_class_source
,
402 const bt_value
*params
, void *init_method_data
,
403 bt_logging_level log_level
,
404 bt_integer_range_set_unsigned
*supported_versions
)
406 const bt_component_class_source
*component_class_source
= bt_self_component_class_source_as_component_class_source(self_component_class_source
);
407 const bt_component_class
*component_class
= bt_component_class_source_as_component_class_const(component_class_source
);
408 bt_self_component_class
*self_component_class
= bt_self_component_class_source_as_self_component_class(self_component_class_source
);
410 return component_class_get_supported_mip_versions(
411 component_class
, self_component_class
,
412 params
, init_method_data
, log_level
, supported_versions
);
416 bt_component_class_get_supported_mip_versions_method_status
417 component_class_filter_get_supported_mip_versions(
418 bt_self_component_class_filter
*self_component_class_filter
,
419 const bt_value
*params
, void *init_method_data
,
420 bt_logging_level log_level
,
421 bt_integer_range_set_unsigned
*supported_versions
)
423 const bt_component_class_filter
*component_class_filter
= bt_self_component_class_filter_as_component_class_filter(self_component_class_filter
);
424 const bt_component_class
*component_class
= bt_component_class_filter_as_component_class_const(component_class_filter
);
425 bt_self_component_class
*self_component_class
= bt_self_component_class_filter_as_self_component_class(self_component_class_filter
);
427 return component_class_get_supported_mip_versions(
428 component_class
, self_component_class
,
429 params
, init_method_data
, log_level
, supported_versions
);
433 bt_component_class_get_supported_mip_versions_method_status
434 component_class_sink_get_supported_mip_versions(
435 bt_self_component_class_sink
*self_component_class_sink
,
436 const bt_value
*params
, void *init_method_data
,
437 bt_logging_level log_level
,
438 bt_integer_range_set_unsigned
*supported_versions
)
440 const bt_component_class_sink
*component_class_sink
= bt_self_component_class_sink_as_component_class_sink(self_component_class_sink
);
441 const bt_component_class
*component_class
= bt_component_class_sink_as_component_class_const(component_class_sink
);
442 bt_self_component_class
*self_component_class
= bt_self_component_class_sink_as_self_component_class(self_component_class_sink
);
444 return component_class_get_supported_mip_versions(
445 component_class
, self_component_class
,
446 params
, init_method_data
, log_level
, supported_versions
);
450 * Method of bt_component_class_source to initialize a bt_self_component_source
455 bt_component_class_initialize_method_status
component_class_source_init(
456 bt_self_component_source
*self_component_source
,
457 bt_self_component_source_configuration
*config
,
458 const bt_value
*params
, void *init_method_data
)
460 bt_self_component
*self_component
= bt_self_component_source_as_self_component(self_component_source
);
461 return component_class_init(
463 self_component_source
,
464 SWIGTYPE_p_bt_self_component_source
,
465 params
, init_method_data
);
469 bt_component_class_initialize_method_status
component_class_filter_init(
470 bt_self_component_filter
*self_component_filter
,
471 bt_self_component_filter_configuration
*config
,
472 const bt_value
*params
, void *init_method_data
)
474 bt_self_component
*self_component
= bt_self_component_filter_as_self_component(self_component_filter
);
475 return component_class_init(
477 self_component_filter
,
478 SWIGTYPE_p_bt_self_component_filter
,
479 params
, init_method_data
);
483 bt_component_class_initialize_method_status
component_class_sink_init(
484 bt_self_component_sink
*self_component_sink
,
485 bt_self_component_sink_configuration
*config
,
486 const bt_value
*params
, void *init_method_data
)
488 bt_self_component
*self_component
= bt_self_component_sink_as_self_component(self_component_sink
);
489 return component_class_init(
492 SWIGTYPE_p_bt_self_component_sink
,
493 params
, init_method_data
);
497 void component_class_finalize(bt_self_component
*self_component
)
499 PyObject
*py_comp
= bt_self_component_get_data(self_component
);
500 PyObject
*py_method_result
;
504 /* Call user's _user_finalize() method */
505 py_method_result
= PyObject_CallMethod(py_comp
, "_user_finalize", NULL
);
506 if (!py_method_result
) {
507 bt_logging_level log_level
= get_self_component_log_level(
511 * Ignore any exception raised by the _user_finalize() method
512 * because it won't change anything at this point: the component
513 * is being destroyed anyway.
515 BT_COMP_LOG_CUR_LVL(BT_LOG_WARNING
, log_level
, self_component
,
516 "User component's _user_finalize() method raised an exception: ignoring:");
517 logw_exception_clear(log_level
);
522 BT_ASSERT(py_method_result
== Py_None
);
525 Py_XDECREF(py_method_result
);
529 /* Decref the Python object in the user data associated to `port`. */
532 void delete_port_user_data(bt_self_component_port
*port
)
534 Py_DECREF(bt_self_component_port_get_data(port
));
538 void delete_port_input_user_data(bt_self_component_port_input
*port_input
)
540 bt_self_component_port
*port
=
541 bt_self_component_port_input_as_self_component_port(port_input
);
543 delete_port_user_data(port
);
547 void delete_port_output_user_data(bt_self_component_port_output
*port_output
)
549 bt_self_component_port
*port
=
550 bt_self_component_port_output_as_self_component_port(port_output
);
552 delete_port_user_data(port
);
556 void component_class_source_finalize(bt_self_component_source
*self_component_source
)
559 bt_self_component
*self_component
;
560 const bt_component_source
*component_source
;
562 self_component
= bt_self_component_source_as_self_component(
563 self_component_source
);
564 component_source
= bt_self_component_source_as_component_source(
565 self_component_source
);
567 component_class_finalize(self_component
);
570 * Free the user data Python object attached to the port. The
571 * corresponding incref was done by the `void *` typemap in
574 for (i
= 0; i
< bt_component_source_get_output_port_count(component_source
); i
++) {
575 bt_self_component_port_output
*port_output
;
577 port_output
= bt_self_component_source_borrow_output_port_by_index(
578 self_component_source
, i
);
580 delete_port_output_user_data(port_output
);
585 void component_class_filter_finalize(bt_self_component_filter
*self_component_filter
)
588 bt_self_component
*self_component
;
589 const bt_component_filter
*component_filter
;
591 self_component
= bt_self_component_filter_as_self_component(
592 self_component_filter
);
593 component_filter
= bt_self_component_filter_as_component_filter(
594 self_component_filter
);
596 component_class_finalize(self_component
);
599 * Free the user data Python object attached to the port. The
600 * corresponding incref was done by the `void *` typemap in
603 for (i
= 0; i
< bt_component_filter_get_input_port_count(component_filter
); i
++) {
604 bt_self_component_port_input
*port_input
;
606 port_input
= bt_self_component_filter_borrow_input_port_by_index(
607 self_component_filter
, i
);
609 delete_port_input_user_data(port_input
);
612 for (i
= 0; i
< bt_component_filter_get_output_port_count(component_filter
); i
++) {
613 bt_self_component_port_output
*port_output
;
615 port_output
= bt_self_component_filter_borrow_output_port_by_index(
616 self_component_filter
, i
);
618 delete_port_output_user_data(port_output
);
623 void component_class_sink_finalize(bt_self_component_sink
*self_component_sink
)
626 bt_self_component
*self_component
;
627 const bt_component_sink
*component_sink
;
629 self_component
= bt_self_component_sink_as_self_component(
630 self_component_sink
);
631 component_sink
= bt_self_component_sink_as_component_sink(
632 self_component_sink
);
634 component_class_finalize(self_component
);
637 * Free the user data Python object attached to the port. The
638 * corresponding incref was done by the `void *` typemap in
641 for (i
= 0; i
< bt_component_sink_get_input_port_count(component_sink
); i
++) {
642 bt_self_component_port_input
*port_input
;
644 port_input
= bt_self_component_sink_borrow_input_port_by_index(
645 self_component_sink
, i
);
647 delete_port_input_user_data(port_input
);
652 bt_message_iterator_class_can_seek_beginning_method_status
653 component_class_can_seek_beginning(
654 bt_self_message_iterator
*self_message_iterator
, bt_bool
*can_seek
)
657 PyObject
*py_result
= NULL
;
658 bt_message_iterator_class_can_seek_beginning_method_status status
;
659 py_iter
= bt_self_message_iterator_get_data(self_message_iterator
);
663 py_result
= PyObject_CallMethod(py_iter
,
664 "_bt_can_seek_beginning_from_native", NULL
);
666 status
= py_exc_to_status_message_iterator_clear(self_message_iterator
);
670 BT_ASSERT(PyBool_Check(py_result
));
671 *can_seek
= PyObject_IsTrue(py_result
);
673 status
= BT_MESSAGE_ITERATOR_CLASS_CAN_SEEK_BEGINNING_METHOD_STATUS_OK
;
676 Py_XDECREF(py_result
);
682 bt_message_iterator_class_seek_beginning_method_status
683 component_class_seek_beginning(bt_self_message_iterator
*self_message_iterator
)
687 bt_message_iterator_class_seek_beginning_method_status status
;
689 py_iter
= bt_self_message_iterator_get_data(self_message_iterator
);
692 py_result
= PyObject_CallMethod(py_iter
,
693 "_bt_seek_beginning_from_native",
696 status
= py_exc_to_status_message_iterator_clear(self_message_iterator
);
700 BT_ASSERT(py_result
== Py_None
);
702 status
= BT_MESSAGE_ITERATOR_CLASS_SEEK_BEGINNING_METHOD_STATUS_OK
;
705 Py_XDECREF(py_result
);
711 bt_message_iterator_class_can_seek_ns_from_origin_method_status
712 component_class_can_seek_ns_from_origin(
713 bt_self_message_iterator
*self_message_iterator
,
714 int64_t ns_from_origin
, bt_bool
*can_seek
)
717 PyObject
*py_result
= NULL
;
718 bt_message_iterator_class_can_seek_ns_from_origin_method_status status
;
720 py_iter
= bt_self_message_iterator_get_data(self_message_iterator
);
723 py_result
= PyObject_CallMethod(py_iter
,
724 "_bt_can_seek_ns_from_origin_from_native", "L", ns_from_origin
);
726 status
= py_exc_to_status_message_iterator_clear(self_message_iterator
);
730 BT_ASSERT(PyBool_Check(py_result
));
731 *can_seek
= PyObject_IsTrue(py_result
);
733 status
= BT_MESSAGE_ITERATOR_CLASS_CAN_SEEK_NS_FROM_ORIGIN_METHOD_STATUS_OK
;
736 Py_XDECREF(py_result
);
742 bt_message_iterator_class_seek_ns_from_origin_method_status
743 component_class_seek_ns_from_origin(
744 bt_self_message_iterator
*self_message_iterator
,
745 int64_t ns_from_origin
)
749 bt_message_iterator_class_seek_ns_from_origin_method_status status
;
751 py_iter
= bt_self_message_iterator_get_data(self_message_iterator
);
754 py_result
= PyObject_CallMethod(py_iter
,
755 "_bt_seek_ns_from_origin_from_native", "L", ns_from_origin
);
757 status
= py_exc_to_status_message_iterator_clear(self_message_iterator
);
762 BT_ASSERT(py_result
== Py_None
);
764 status
= BT_MESSAGE_ITERATOR_CLASS_SEEK_NS_FROM_ORIGIN_METHOD_STATUS_OK
;
767 Py_XDECREF(py_result
);
773 bt_component_class_port_connected_method_status
component_class_port_connected(
774 bt_self_component
*self_component
,
775 void *self_component_port
,
776 swig_type_info
*self_component_port_swig_type
,
777 bt_port_type self_component_port_type
,
778 const void *other_port
,
779 swig_type_info
*other_port_swig_type
)
781 bt_component_class_port_connected_method_status status
;
782 PyObject
*py_comp
= NULL
;
783 PyObject
*py_self_port_ptr
= NULL
;
784 PyObject
*py_other_port_ptr
= NULL
;
785 PyObject
*py_method_result
= NULL
;
786 bt_logging_level log_level
= get_self_component_log_level(
789 py_comp
= bt_self_component_get_data(self_component
);
791 py_self_port_ptr
= SWIG_NewPointerObj(SWIG_as_voidptr(self_component_port
),
792 self_component_port_swig_type
, 0);
793 if (!py_self_port_ptr
) {
794 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
795 BT_FMT_SWIG_ALLOC_FAILED
);
796 status
= __BT_FUNC_STATUS_MEMORY_ERROR
;
800 py_other_port_ptr
= SWIG_NewPointerObj(SWIG_as_voidptr(other_port
),
801 other_port_swig_type
, 0);
802 if (!py_other_port_ptr
) {
803 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
804 BT_FMT_SWIG_ALLOC_FAILED
);
805 status
= __BT_FUNC_STATUS_MEMORY_ERROR
;
809 py_method_result
= PyObject_CallMethod(py_comp
,
810 "_bt_port_connected_from_native", "(OiO)", py_self_port_ptr
,
811 self_component_port_type
, py_other_port_ptr
);
812 if (!py_method_result
) {
813 status
= py_exc_to_status_component_clear(self_component
);
817 BT_ASSERT(py_method_result
== Py_None
);
819 status
= BT_COMPONENT_CLASS_PORT_CONNECTED_METHOD_STATUS_OK
;
822 Py_XDECREF(py_self_port_ptr
);
823 Py_XDECREF(py_other_port_ptr
);
824 Py_XDECREF(py_method_result
);
830 bt_component_class_port_connected_method_status
831 component_class_source_output_port_connected(
832 bt_self_component_source
*self_component_source
,
833 bt_self_component_port_output
*self_component_port_output
,
834 const bt_port_input
*other_port_input
)
836 bt_self_component
*self_component
= bt_self_component_source_as_self_component(self_component_source
);
838 return component_class_port_connected(
840 self_component_port_output
,
841 SWIGTYPE_p_bt_self_component_port_output
,
844 SWIGTYPE_p_bt_port_input
);
848 bt_component_class_port_connected_method_status
849 component_class_filter_input_port_connected(
850 bt_self_component_filter
*self_component_filter
,
851 bt_self_component_port_input
*self_component_port_input
,
852 const bt_port_output
*other_port_output
)
854 bt_self_component
*self_component
= bt_self_component_filter_as_self_component(self_component_filter
);
856 return component_class_port_connected(
858 self_component_port_input
,
859 SWIGTYPE_p_bt_self_component_port_input
,
862 SWIGTYPE_p_bt_port_output
);
866 bt_component_class_port_connected_method_status
867 component_class_filter_output_port_connected(
868 bt_self_component_filter
*self_component_filter
,
869 bt_self_component_port_output
*self_component_port_output
,
870 const bt_port_input
*other_port_input
)
872 bt_self_component
*self_component
= bt_self_component_filter_as_self_component(self_component_filter
);
874 return component_class_port_connected(
876 self_component_port_output
,
877 SWIGTYPE_p_bt_self_component_port_output
,
880 SWIGTYPE_p_bt_port_input
);
884 bt_component_class_port_connected_method_status
885 component_class_sink_input_port_connected(
886 bt_self_component_sink
*self_component_sink
,
887 bt_self_component_port_input
*self_component_port_input
,
888 const bt_port_output
*other_port_output
)
890 bt_self_component
*self_component
= bt_self_component_sink_as_self_component(self_component_sink
);
892 return component_class_port_connected(
894 self_component_port_input
,
895 SWIGTYPE_p_bt_self_component_port_input
,
898 SWIGTYPE_p_bt_port_output
);
902 bt_component_class_sink_graph_is_configured_method_status
903 component_class_sink_graph_is_configured(
904 bt_self_component_sink
*self_component_sink
)
906 PyObject
*py_comp
= NULL
;
907 PyObject
*py_method_result
= NULL
;
908 bt_component_class_sink_graph_is_configured_method_status status
;
909 bt_self_component
*self_component
= bt_self_component_sink_as_self_component(self_component_sink
);
911 py_comp
= bt_self_component_get_data(self_component
);
913 py_method_result
= PyObject_CallMethod(py_comp
,
914 "_bt_graph_is_configured_from_native", NULL
);
915 if (!py_method_result
) {
916 status
= py_exc_to_status_component_clear(self_component
);
920 BT_ASSERT(py_method_result
== Py_None
);
922 status
= BT_COMPONENT_CLASS_SINK_GRAPH_IS_CONFIGURED_METHOD_STATUS_OK
;;
925 Py_XDECREF(py_method_result
);
930 bt_component_class_query_method_status
component_class_query(
931 const bt_component_class
*component_class
,
932 bt_self_component_class
*self_component_class
,
933 bt_private_query_executor
*priv_query_executor
,
934 const char *object
, const bt_value
*params
, void *method_data
,
935 const bt_value
**result
)
937 PyObject
*py_cls
= NULL
;
938 PyObject
*py_params_ptr
= NULL
;
939 PyObject
*py_priv_query_exec_ptr
= NULL
;
940 PyObject
*py_query_func
= NULL
;
941 PyObject
*py_object
= NULL
;
942 PyObject
*py_results_addr
= NULL
;
943 bt_component_class_query_method_status status
= __BT_FUNC_STATUS_OK
;
944 const bt_query_executor
*query_exec
=
945 bt_private_query_executor_as_query_executor_const(
946 priv_query_executor
);
947 bt_logging_level log_level
=
948 bt_query_executor_get_logging_level(query_exec
);
951 * If there's any `method_data`, assume this component class is
952 * getting queried from Python, so that `method_data` is a
953 * Python object to pass to the user's _user_query() method.
955 BT_ASSERT(!method_data
||
956 bt_bt2_is_python_component_class(component_class
));
958 py_cls
= lookup_cc_ptr_to_py_cls(component_class
);
960 BT_LOG_WRITE_CUR_LVL(BT_LOG_ERROR
, log_level
, BT_LOG_TAG
,
961 "Cannot find Python class associated to native component class: "
962 "comp-cls-addr=%p", component_class
);
966 py_params_ptr
= SWIG_NewPointerObj(SWIG_as_voidptr(params
),
967 SWIGTYPE_p_bt_value
, 0);
968 if (!py_params_ptr
) {
969 BT_LOG_WRITE_CUR_LVL(BT_LOG_ERROR
, log_level
, BT_LOG_TAG
,
970 BT_FMT_SWIG_ALLOC_FAILED
);
974 py_priv_query_exec_ptr
= SWIG_NewPointerObj(
975 SWIG_as_voidptr(priv_query_executor
),
976 SWIGTYPE_p_bt_private_query_executor
, 0);
977 if (!py_priv_query_exec_ptr
) {
978 BT_LOG_WRITE_CUR_LVL(BT_LOG_ERROR
, log_level
, BT_LOG_TAG
,
979 BT_FMT_SWIG_ALLOC_FAILED
);
983 py_object
= SWIG_FromCharPtr(object
);
985 BT_LOG_WRITE_CUR_LVL(BT_LOG_ERROR
, log_level
, BT_LOG_TAG
,
986 "Failed to create a Python string.");
991 * We don't take any reference on `method_data` which, if not
992 * `NULL`, is assumed to be a `PyObject *`: the user's
993 * _user_query() function will eventually take a reference if
994 * needed. If `method_data` is `NULL`, then we pass `Py_None` as
995 * the initialization's Python object.
997 py_results_addr
= PyObject_CallMethod(py_cls
,
998 "_bt_query_from_native", "(OOOO)", py_priv_query_exec_ptr
,
999 py_object
, py_params_ptr
,
1000 method_data
? method_data
: Py_None
);
1001 if (!py_results_addr
) {
1002 status
= py_exc_to_status_component_class_clear(self_component_class
,
1005 static const char *fmt
=
1006 "Failed to call Python class's _bt_query_from_native() method: py-cls-addr=%p";
1007 BT_LOG_WRITE_CUR_LVL(BT_LOG_WARNING
, log_level
, BT_LOG_TAG
,
1009 BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_COMPONENT_CLASS(
1010 self_component_class
, fmt
, py_cls
);
1016 * The returned object, on success, is an integer object
1017 * (PyLong) containing the address of a BT value object (new
1020 *result
= PyLong_AsVoidPtr(py_results_addr
);
1021 BT_ASSERT(!PyErr_Occurred());
1027 status
= __BT_FUNC_STATUS_ERROR
;
1030 Py_XDECREF(py_params_ptr
);
1031 Py_XDECREF(py_priv_query_exec_ptr
);
1032 Py_XDECREF(py_query_func
);
1033 Py_XDECREF(py_object
);
1034 Py_XDECREF(py_results_addr
);
1039 bt_component_class_query_method_status
component_class_source_query(
1040 bt_self_component_class_source
*self_component_class_source
,
1041 bt_private_query_executor
*priv_query_executor
,
1042 const char *object
, const bt_value
*params
, void *method_data
,
1043 const bt_value
**result
)
1045 const bt_component_class_source
*component_class_source
= bt_self_component_class_source_as_component_class_source(self_component_class_source
);
1046 const bt_component_class
*component_class
= bt_component_class_source_as_component_class_const(component_class_source
);
1047 bt_self_component_class
*self_component_class
= bt_self_component_class_source_as_self_component_class(self_component_class_source
);
1049 return component_class_query(component_class
, self_component_class
,
1050 priv_query_executor
, object
, params
, method_data
, result
);
1054 bt_component_class_query_method_status
component_class_filter_query(
1055 bt_self_component_class_filter
*self_component_class_filter
,
1056 bt_private_query_executor
*priv_query_executor
,
1057 const char *object
, const bt_value
*params
, void *method_data
,
1058 const bt_value
**result
)
1060 const bt_component_class_filter
*component_class_filter
= bt_self_component_class_filter_as_component_class_filter(self_component_class_filter
);
1061 const bt_component_class
*component_class
= bt_component_class_filter_as_component_class_const(component_class_filter
);
1062 bt_self_component_class
*self_component_class
= bt_self_component_class_filter_as_self_component_class(self_component_class_filter
);
1064 return component_class_query(component_class
, self_component_class
,
1065 priv_query_executor
, object
, params
, method_data
, result
);
1069 bt_component_class_query_method_status
component_class_sink_query(
1070 bt_self_component_class_sink
*self_component_class_sink
,
1071 bt_private_query_executor
*priv_query_executor
,
1072 const char *object
, const bt_value
*params
, void *method_data
,
1073 const bt_value
**result
)
1075 const bt_component_class_sink
*component_class_sink
= bt_self_component_class_sink_as_component_class_sink(self_component_class_sink
);
1076 const bt_component_class
*component_class
= bt_component_class_sink_as_component_class_const(component_class_sink
);
1077 bt_self_component_class
*self_component_class
= bt_self_component_class_sink_as_self_component_class(self_component_class_sink
);
1079 return component_class_query(component_class
, self_component_class
,
1080 priv_query_executor
, object
, params
, method_data
, result
);
1084 bt_message_iterator_class_initialize_method_status
1085 component_class_message_iterator_init(
1086 bt_self_message_iterator
*self_message_iterator
,
1087 bt_self_message_iterator_configuration
*config
,
1088 bt_self_component_port_output
*self_component_port_output
)
1090 bt_message_iterator_class_initialize_method_status status
= __BT_FUNC_STATUS_OK
;
1091 PyObject
*py_comp_cls
= NULL
;
1092 PyObject
*py_iter_cls
= NULL
;
1093 PyObject
*py_iter_ptr
= NULL
;
1094 PyObject
*py_config_ptr
= NULL
;
1095 PyObject
*py_component_port_output_ptr
= NULL
;
1096 PyObject
*py_init_method_result
= NULL
;
1097 PyObject
*py_iter
= NULL
;
1099 bt_self_component
*self_component
=
1100 bt_self_message_iterator_borrow_component(
1101 self_message_iterator
);
1102 bt_logging_level log_level
= get_self_component_log_level(
1105 py_comp
= bt_self_component_get_data(self_component
);
1107 /* Find user's Python message iterator class */
1108 py_comp_cls
= PyObject_GetAttrString(py_comp
, "__class__");
1110 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
1111 "Cannot get Python object's `__class__` attribute.");
1115 py_iter_cls
= PyObject_GetAttrString(py_comp_cls
, "_iter_cls");
1117 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
1118 "Cannot get Python class's `_iter_cls` attribute.");
1122 py_iter_ptr
= SWIG_NewPointerObj(SWIG_as_voidptr(self_message_iterator
),
1123 SWIGTYPE_p_bt_self_message_iterator
, 0);
1125 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
1126 BT_FMT_SWIG_ALLOC_FAILED
);
1127 BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_MESSAGE_ITERATOR(
1128 self_message_iterator
, BT_FMT_SWIG_ALLOC_FAILED
);
1133 * Create object with borrowed native message iterator
1136 * py_iter = py_iter_cls.__new__(py_iter_cls, py_iter_ptr)
1138 py_iter
= PyObject_CallMethod(py_iter_cls
, "__new__",
1139 "(OO)", py_iter_cls
, py_iter_ptr
);
1141 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
1142 "Failed to call Python class's __new__() method: "
1143 "py-cls-addr=%p", py_iter_cls
);
1148 * Initialize object:
1150 * py_iter.__init__(config, self_output_port)
1152 * through the _init_from_native helper static method.
1154 * At this point, py_iter._ptr is set, so this initialization
1155 * function has access to self._component (which gives it the
1156 * user Python component object from which the iterator was
1159 py_config_ptr
= SWIG_NewPointerObj(SWIG_as_voidptr(config
),
1160 SWIGTYPE_p_bt_self_message_iterator_configuration
, 0);
1161 if (!py_config_ptr
) {
1162 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
1163 BT_FMT_SWIG_ALLOC_FAILED
);
1164 BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_MESSAGE_ITERATOR(
1165 self_message_iterator
, BT_FMT_SWIG_ALLOC_FAILED
);
1169 py_component_port_output_ptr
= SWIG_NewPointerObj(
1170 SWIG_as_voidptr(self_component_port_output
),
1171 SWIGTYPE_p_bt_self_component_port_output
, 0);
1172 if (!py_component_port_output_ptr
) {
1173 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
1174 "%s", BT_FMT_SWIG_ALLOC_FAILED
);
1175 BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_MESSAGE_ITERATOR(
1176 self_message_iterator
, BT_FMT_SWIG_ALLOC_FAILED
);
1180 py_init_method_result
= PyObject_CallMethod(py_iter
,
1181 "_bt_init_from_native", "OO", py_config_ptr
,
1182 py_component_port_output_ptr
);
1183 if (!py_init_method_result
) {
1184 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
1185 "User's __init__() method failed:");
1190 * Since the Python code can never instantiate a user-defined
1191 * message iterator class, the native message iterator
1192 * object does NOT belong to a user Python message iterator
1193 * object (borrowed reference). However this Python object is
1194 * owned by this native message iterator object.
1196 * In the Python world, the lifetime of the native message
1197 * iterator is managed by a _GenericMessageIterator
1200 * _GenericMessageIterator instance:
1201 * owns a native bt_message_iterator object (iter)
1202 * owns a _UserMessageIterator instance (py_iter)
1203 * self._ptr is a borrowed reference to the
1204 * native bt_private_connection_private_message_iterator
1207 bt_self_message_iterator_set_data(self_message_iterator
, py_iter
);
1212 /* Handling of errors that cause a Python exception to be set. */
1213 status
= py_exc_to_status_message_iterator_clear(self_message_iterator
);
1217 /* Handling of errors that don't cause a Python exception to be set. */
1218 status
= __BT_FUNC_STATUS_ERROR
;
1221 BT_ASSERT(!PyErr_Occurred());
1223 Py_XDECREF(py_comp_cls
);
1224 Py_XDECREF(py_iter_cls
);
1225 Py_XDECREF(py_iter_ptr
);
1226 Py_XDECREF(py_component_port_output_ptr
);
1227 Py_XDECREF(py_init_method_result
);
1228 Py_XDECREF(py_iter
);
1233 void component_class_message_iterator_finalize(
1234 bt_self_message_iterator
*message_iterator
)
1236 PyObject
*py_message_iter
= bt_self_message_iterator_get_data(
1238 PyObject
*py_method_result
= NULL
;
1240 BT_ASSERT(py_message_iter
);
1242 /* Call user's _user_finalize() method */
1243 py_method_result
= PyObject_CallMethod(py_message_iter
,
1244 "_user_finalize", NULL
);
1245 if (!py_method_result
) {
1246 bt_self_component
*self_comp
=
1247 bt_self_message_iterator_borrow_component(
1249 bt_logging_level log_level
= get_self_component_log_level(
1253 * Ignore any exception raised by the _user_finalize() method
1254 * because it won't change anything at this point: the component
1255 * is being destroyed anyway.
1257 BT_COMP_LOG_CUR_LVL(BT_LOG_WARNING
, log_level
, self_comp
,
1258 "User's _user_finalize() method raised an exception: ignoring:");
1259 logw_exception_clear(get_self_message_iterator_log_level(
1263 Py_XDECREF(py_method_result
);
1264 Py_DECREF(py_message_iter
);
1267 /* Valid for both sources and filters. */
1270 bt_message_iterator_class_next_method_status
1271 component_class_message_iterator_next(
1272 bt_self_message_iterator
*message_iterator
,
1273 bt_message_array_const msgs
, uint64_t capacity
,
1276 bt_message_iterator_class_next_method_status status
;
1277 PyObject
*py_message_iter
= bt_self_message_iterator_get_data(message_iterator
);
1278 PyObject
*py_method_result
= NULL
;
1280 BT_ASSERT_DBG(py_message_iter
);
1281 py_method_result
= PyObject_CallMethod(py_message_iter
,
1282 "_bt_next_from_native", NULL
);
1283 if (!py_method_result
) {
1284 status
= py_exc_to_status_message_iterator_clear(message_iterator
);
1289 * The returned object, on success, is an integer object
1290 * (PyLong) containing the address of a native message
1291 * object (which is now ours).
1293 msgs
[0] = PyLong_AsVoidPtr(py_method_result
);
1296 /* Overflow errors should never happen. */
1297 BT_ASSERT_DBG(!PyErr_Occurred());
1299 status
= BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_OK
;
1302 Py_XDECREF(py_method_result
);
1307 bt_component_class_sink_consume_method_status
1308 component_class_sink_consume(bt_self_component_sink
*self_component_sink
)
1310 bt_self_component
*self_component
= bt_self_component_sink_as_self_component(self_component_sink
);
1311 PyObject
*py_comp
= bt_self_component_get_data(self_component
);
1312 PyObject
*py_method_result
= NULL
;
1313 bt_component_class_sink_consume_method_status status
;
1315 BT_ASSERT_DBG(py_comp
);
1317 py_method_result
= PyObject_CallMethod(py_comp
,
1318 "_user_consume", NULL
);
1319 if (!py_method_result
) {
1320 status
= py_exc_to_status_component_clear(self_component
);
1324 status
= BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_OK
;
1327 Py_XDECREF(py_method_result
);
1332 int component_class_set_help_and_desc(
1333 bt_component_class
*component_class
,
1334 const char *description
, const char *help
)
1339 ret
= bt_component_class_set_description(component_class
, description
);
1341 BT_LOGE("Cannot set component class's description: "
1342 "comp-cls-addr=%p", component_class
);
1348 ret
= bt_component_class_set_help(component_class
, help
);
1350 BT_LOGE("Cannot set component class's help text: "
1351 "comp-cls-addr=%p", component_class
);
1363 bt_message_iterator_class
*create_message_iterator_class(void)
1365 bt_message_iterator_class
*message_iterator_class
;
1366 bt_message_iterator_class_set_method_status ret
;
1368 message_iterator_class
= bt_message_iterator_class_create(
1369 component_class_message_iterator_next
);
1370 if (!message_iterator_class
) {
1371 BT_LOGE_STR("Cannot create message iterator class.");
1375 ret
= bt_message_iterator_class_set_seek_beginning_methods(
1376 message_iterator_class
, component_class_seek_beginning
,
1377 component_class_can_seek_beginning
);
1378 BT_ASSERT(ret
== 0);
1379 ret
= bt_message_iterator_class_set_seek_ns_from_origin_methods(
1380 message_iterator_class
, component_class_seek_ns_from_origin
,
1381 component_class_can_seek_ns_from_origin
);
1382 BT_ASSERT(ret
== 0);
1383 ret
= bt_message_iterator_class_set_initialize_method(
1384 message_iterator_class
, component_class_message_iterator_init
);
1385 BT_ASSERT(ret
== 0);
1386 ret
= bt_message_iterator_class_set_finalize_method(
1387 message_iterator_class
, component_class_message_iterator_finalize
);
1388 BT_ASSERT(ret
== 0);
1391 return message_iterator_class
;
1395 bt_component_class_source
*bt_bt2_component_class_source_create(
1396 PyObject
*py_cls
, const char *name
, const char *description
,
1399 bt_component_class_source
*component_class_source
= NULL
;
1400 bt_message_iterator_class
*message_iterator_class
;
1401 bt_component_class
*component_class
;
1406 message_iterator_class
= create_message_iterator_class();
1407 if (!message_iterator_class
) {
1411 component_class_source
= bt_component_class_source_create(name
,
1412 message_iterator_class
);
1413 if (!component_class_source
) {
1414 BT_LOGE_STR("Cannot create source component class.");
1418 component_class
= bt_component_class_source_as_component_class(component_class_source
);
1420 if (component_class_set_help_and_desc(component_class
, description
, help
)) {
1424 ret
= bt_component_class_source_set_initialize_method(component_class_source
, component_class_source_init
);
1425 BT_ASSERT(ret
== 0);
1426 ret
= bt_component_class_source_set_finalize_method(component_class_source
, component_class_source_finalize
);
1427 BT_ASSERT(ret
== 0);
1428 ret
= bt_component_class_source_set_output_port_connected_method(component_class_source
,
1429 component_class_source_output_port_connected
);
1430 BT_ASSERT(ret
== 0);
1431 ret
= bt_component_class_source_set_query_method(component_class_source
, component_class_source_query
);
1432 BT_ASSERT(ret
== 0);
1433 ret
= bt_component_class_source_set_get_supported_mip_versions_method(component_class_source
, component_class_source_get_supported_mip_versions
);
1434 BT_ASSERT(ret
== 0);
1435 register_cc_ptr_to_py_cls(component_class
, py_cls
);
1438 bt_message_iterator_class_put_ref(message_iterator_class
);
1439 return component_class_source
;
1443 bt_component_class_filter
*bt_bt2_component_class_filter_create(
1444 PyObject
*py_cls
, const char *name
, const char *description
,
1447 bt_component_class_filter
*component_class_filter
= NULL
;
1448 bt_message_iterator_class
*message_iterator_class
;
1449 bt_component_class
*component_class
;
1454 message_iterator_class
= create_message_iterator_class();
1455 if (!message_iterator_class
) {
1459 component_class_filter
= bt_component_class_filter_create(name
,
1460 message_iterator_class
);
1461 if (!component_class_filter
) {
1462 BT_LOGE_STR("Cannot create filter component class.");
1466 component_class
= bt_component_class_filter_as_component_class(component_class_filter
);
1468 if (component_class_set_help_and_desc(component_class
, description
, help
)) {
1472 ret
= bt_component_class_filter_set_initialize_method(component_class_filter
, component_class_filter_init
);
1473 BT_ASSERT(ret
== 0);
1474 ret
= bt_component_class_filter_set_finalize_method (component_class_filter
, component_class_filter_finalize
);
1475 BT_ASSERT(ret
== 0);
1476 ret
= bt_component_class_filter_set_input_port_connected_method(component_class_filter
,
1477 component_class_filter_input_port_connected
);
1478 BT_ASSERT(ret
== 0);
1479 ret
= bt_component_class_filter_set_output_port_connected_method(component_class_filter
,
1480 component_class_filter_output_port_connected
);
1481 BT_ASSERT(ret
== 0);
1482 ret
= bt_component_class_filter_set_query_method(component_class_filter
, component_class_filter_query
);
1483 BT_ASSERT(ret
== 0);
1484 ret
= bt_component_class_filter_set_get_supported_mip_versions_method(component_class_filter
, component_class_filter_get_supported_mip_versions
);
1485 BT_ASSERT(ret
== 0);
1486 register_cc_ptr_to_py_cls(component_class
, py_cls
);
1489 bt_message_iterator_class_put_ref(message_iterator_class
);
1490 return component_class_filter
;
1494 bt_component_class_sink
*bt_bt2_component_class_sink_create(
1495 PyObject
*py_cls
, const char *name
, const char *description
,
1498 bt_component_class_sink
*component_class_sink
;
1499 bt_component_class
*component_class
;
1503 component_class_sink
= bt_component_class_sink_create(name
, component_class_sink_consume
);
1505 if (!component_class_sink
) {
1506 BT_LOGE_STR("Cannot create sink component class.");
1510 component_class
= bt_component_class_sink_as_component_class(component_class_sink
);
1512 if (component_class_set_help_and_desc(component_class
, description
, help
)) {
1516 ret
= bt_component_class_sink_set_initialize_method(component_class_sink
, component_class_sink_init
);
1517 BT_ASSERT(ret
== 0);
1518 ret
= bt_component_class_sink_set_finalize_method(component_class_sink
, component_class_sink_finalize
);
1519 BT_ASSERT(ret
== 0);
1520 ret
= bt_component_class_sink_set_input_port_connected_method(component_class_sink
,
1521 component_class_sink_input_port_connected
);
1522 BT_ASSERT(ret
== 0);
1523 ret
= bt_component_class_sink_set_graph_is_configured_method(component_class_sink
,
1524 component_class_sink_graph_is_configured
);
1525 BT_ASSERT(ret
== 0);
1526 ret
= bt_component_class_sink_set_query_method(component_class_sink
, component_class_sink_query
);
1527 BT_ASSERT(ret
== 0);
1528 ret
= bt_component_class_sink_set_get_supported_mip_versions_method(component_class_sink
, component_class_sink_get_supported_mip_versions
);
1529 BT_ASSERT(ret
== 0);
1530 register_cc_ptr_to_py_cls(component_class
, py_cls
);
1533 return component_class_sink
;