2 * The MIT License (MIT)
4 * Copyright (c) 2017 Philippe Proulx <pproulx@efficios.com>
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 #include "logging/comp-logging.h"
26 #include "compat/glib.h"
29 * This hash table associates a BT component class object address to a
30 * user-defined Python class (PyObject *). The keys and values are NOT
31 * owned by this hash table. The Python class objects are owned by the
32 * Python module, which should not be unloaded until it is not possible
33 * to create a user Python component anyway.
35 * This hash table is written to when a user-defined Python component
36 * class is created by one of the bt_bt2_component_class_*_create()
39 * This function is read from when a user calls bt_component_create()
40 * with a component class pointer created by one of the functions above.
41 * In this case, the original Python class needs to be found to
42 * instantiate it and associate the created Python component object with
43 * a BT component object instance.
46 static GHashTable
*bt_cc_ptr_to_py_cls
;
49 void bt_bt2_unregister_cc_ptr_to_py_cls(const bt_component_class
*comp_cls
)
53 if (!bt_cc_ptr_to_py_cls
) {
57 existed
= g_hash_table_remove(bt_cc_ptr_to_py_cls
, comp_cls
);
62 void register_cc_ptr_to_py_cls(struct bt_component_class
*bt_cc
,
65 if (!bt_cc_ptr_to_py_cls
) {
67 * Lazy-initializing this GHashTable because GLib
68 * might not be initialized yet and it needs to be
69 * before we call g_hash_table_new()
71 BT_LOGD_STR("Creating native component class to Python component class hash table.");
72 bt_cc_ptr_to_py_cls
= g_hash_table_new(g_direct_hash
, g_direct_equal
);
73 BT_ASSERT(bt_cc_ptr_to_py_cls
);
76 g_hash_table_insert(bt_cc_ptr_to_py_cls
, (gpointer
) bt_cc
,
81 PyObject
*lookup_cc_ptr_to_py_cls(const bt_component_class
*bt_cc
)
83 if (!bt_cc_ptr_to_py_cls
) {
84 BT_LOGW("Cannot look up Python component class because hash table is NULL: "
85 "comp-cls-addr=%p", bt_cc
);
89 return (PyObject
*) g_hash_table_lookup(bt_cc_ptr_to_py_cls
,
90 (gconstpointer
) bt_cc
);
93 /* Library destructor */
95 __attribute__((destructor
))
97 void native_comp_class_dtor(void) {
98 /* Destroy component class association hash table */
99 if (bt_cc_ptr_to_py_cls
) {
100 BT_LOGD_STR("Destroying native component class to Python component class hash table.");
101 g_hash_table_destroy(bt_cc_ptr_to_py_cls
);
102 bt_cc_ptr_to_py_cls
= NULL
;
107 int py_exc_to_status_clear(
108 bt_self_component_class
*self_component_class
,
109 bt_self_component
*self_component
,
110 bt_self_message_iterator
*self_message_iterator
,
111 const char *module_name
, int active_log_level
)
114 PyObject
*exc
= PyErr_Occurred();
117 status
= __BT_FUNC_STATUS_OK
;
121 if (PyErr_GivenExceptionMatches(exc
,
122 py_mod_bt2_exc_try_again_type
)) {
123 status
= __BT_FUNC_STATUS_AGAIN
;
124 } else if (PyErr_GivenExceptionMatches(exc
,
125 py_mod_bt2_exc_stop_type
)) {
126 status
= __BT_FUNC_STATUS_END
;
127 } else if (PyErr_GivenExceptionMatches(exc
,
128 py_mod_bt2_exc_unknown_object_type
)) {
129 status
= __BT_FUNC_STATUS_UNKNOWN_OBJECT
;
132 * Unknown exception: convert to general error.
134 * Because we only want to fetch the log level when
135 * we actually get an exception, and not systematically
136 * when we call py_exc_to_status() (as py_exc_to_status()
137 * can return `__BT_FUNC_STATUS_OK`), we get it here
138 * depending on the actor's type.
140 if (self_component
) {
141 active_log_level
= get_self_component_log_level(
143 } else if (self_message_iterator
) {
144 active_log_level
= get_self_message_iterator_log_level(
145 self_message_iterator
);
148 BT_ASSERT(active_log_level
!= -1);
149 log_exception_and_maybe_append_cause(BT_LOG_WARNING
,
150 active_log_level
, true,
151 self_component_class
, self_component
,
152 self_message_iterator
, module_name
);
154 if (PyErr_GivenExceptionMatches(exc
,
155 py_mod_bt2_exc_memory_error
)) {
156 status
= __BT_FUNC_STATUS_MEMORY_ERROR
;
158 status
= __BT_FUNC_STATUS_ERROR
;
168 int py_exc_to_status_component_class_clear(
169 bt_self_component_class
*self_component_class
,
170 int active_log_level
)
172 return py_exc_to_status_clear(self_component_class
, NULL
, NULL
, NULL
,
177 int py_exc_to_status_component_clear(bt_self_component
*self_component
)
179 return py_exc_to_status_clear(NULL
, self_component
, NULL
, NULL
, -1);
183 int py_exc_to_status_message_iterator_clear(
184 bt_self_message_iterator
*self_message_iterator
)
186 return py_exc_to_status_clear(NULL
, NULL
, self_message_iterator
, NULL
, -1);
190 bool bt_bt2_is_python_component_class(const bt_component_class
*comp_cls
)
192 return bt_g_hash_table_contains(bt_cc_ptr_to_py_cls
, comp_cls
);
195 /* Component class proxy methods (delegate to the attached Python object) */
198 bt_component_class_initialize_method_status
component_class_init(
199 bt_self_component
*self_component
,
200 void *self_component_v
,
201 swig_type_info
*self_comp_cls_type_swig_type
,
202 const bt_value
*params
,
203 void *init_method_data
)
205 const bt_component
*component
= bt_self_component_as_component(self_component
);
206 const bt_component_class
*component_class
= bt_component_borrow_class_const(component
);
207 bt_component_class_initialize_method_status status
;
208 PyObject
*py_cls
= NULL
;
209 PyObject
*py_comp
= NULL
;
210 PyObject
*py_params_ptr
= NULL
;
211 PyObject
*py_comp_ptr
= NULL
;
212 bt_logging_level log_level
= get_self_component_log_level(
215 BT_ASSERT(self_component
);
216 BT_ASSERT(self_component_v
);
217 BT_ASSERT(self_comp_cls_type_swig_type
);
220 * Get the user-defined Python class which created this
221 * component's class in the first place (borrowed
224 py_cls
= lookup_cc_ptr_to_py_cls(component_class
);
226 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
227 "Cannot find Python class associated to native component class: "
228 "comp-cls-addr=%p", component_class
);
232 /* Parameters pointer -> SWIG pointer Python object */
233 py_params_ptr
= SWIG_NewPointerObj(SWIG_as_voidptr(params
),
234 SWIGTYPE_p_bt_value
, 0);
235 if (!py_params_ptr
) {
236 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
237 "Failed to create a SWIG pointer object.");
241 py_comp_ptr
= SWIG_NewPointerObj(SWIG_as_voidptr(self_component_v
),
242 self_comp_cls_type_swig_type
, 0);
244 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
245 "Failed to create a SWIG pointer object.");
250 * Do the equivalent of this:
252 * py_comp = py_cls._bt_init_from_native(py_comp_ptr,
253 * py_params_ptr, init_method_data ? init_method_data : Py_None)
255 * _UserComponentType._bt_init_from_native() calls the Python
256 * component object's __init__() function.
258 * We don't take any reference on `init_method_data` which, if
259 * not `NULL`, is assumed to be a `PyObject *`: the user's
260 * __init__() function will eventually take a reference if
261 * needed. If `init_method_data` is `NULL`, then we pass
262 * `Py_None` as the initialization's Python object.
264 py_comp
= PyObject_CallMethod(py_cls
,
265 "_bt_init_from_native", "(OOO)", py_comp_ptr
, py_params_ptr
,
266 init_method_data
? init_method_data
: Py_None
);
268 BT_COMP_LOG_CUR_LVL(BT_LOG_WARNING
, log_level
, self_component
,
269 "Failed to call Python class's _bt_init_from_native() method: "
270 "py-cls-addr=%p", py_cls
);
271 status
= py_exc_to_status_component_clear(self_component
);
276 * Our user Python component object is now fully created and
277 * initialized by the user. Since we just created it, this
278 * native component is its only (persistent) owner.
280 bt_self_component_set_data(self_component
, py_comp
);
283 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK
;
288 /* This error path is for non-Python errors only. */
289 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR
;
292 BT_ASSERT(!PyErr_Occurred());
294 Py_XDECREF(py_params_ptr
);
295 Py_XDECREF(py_comp_ptr
);
300 bt_component_class_get_supported_mip_versions_method_status
301 component_class_get_supported_mip_versions(
302 const bt_component_class
*component_class
,
303 bt_self_component_class
*self_component_class
,
304 const bt_value
*params
, void *init_method_data
,
305 bt_logging_level log_level
,
306 bt_integer_range_set_unsigned
*supported_versions
)
309 PyObject
*py_cls
= NULL
;
310 PyObject
*py_params_ptr
= NULL
;
311 PyObject
*py_range_set_addr
= NULL
;
312 bt_integer_range_set_unsigned
*ret_range_set
= NULL
;
313 bt_component_class_get_supported_mip_versions_method_status status
;
315 py_cls
= lookup_cc_ptr_to_py_cls(component_class
);
317 BT_LOG_WRITE_CUR_LVL(BT_LOG_ERROR
, log_level
, BT_LOG_TAG
,
318 "Cannot find Python class associated to native component class: "
319 "comp-cls-addr=%p", component_class
);
323 py_params_ptr
= SWIG_NewPointerObj(SWIG_as_voidptr(params
),
324 SWIGTYPE_p_bt_value
, 0);
325 if (!py_params_ptr
) {
326 BT_LOG_WRITE_CUR_LVL(BT_LOG_ERROR
, log_level
, BT_LOG_TAG
,
327 "Failed to create a SWIG pointer object.");
332 * We don't take any reference on `init_method_data` which, if
333 * not `NULL`, is assumed to be a `PyObject *`: the user's
334 * _user_get_supported_mip_versions() function will eventually
335 * take a reference if needed. If `init_method_data` is `NULL`,
336 * then we pass `Py_None` as the initialization's Python object.
338 py_range_set_addr
= PyObject_CallMethod(py_cls
,
339 "_bt_get_supported_mip_versions_from_native", "(OOi)",
340 py_params_ptr
, init_method_data
? init_method_data
: Py_None
,
342 if (!py_range_set_addr
) {
343 BT_LOG_WRITE_CUR_LVL(BT_LOG_WARNING
, log_level
, BT_LOG_TAG
,
344 "Failed to call Python class's _bt_get_supported_mip_versions_from_native() method: "
345 "py-cls-addr=%p", py_cls
);
346 status
= py_exc_to_status_component_class_clear(self_component_class
,
352 * The returned object, on success, is an integer object
353 * (PyLong) containing the address of a BT unsigned integer
354 * range set object (new reference).
356 ret_range_set
= PyLong_AsVoidPtr(py_range_set_addr
);
357 BT_ASSERT(!PyErr_Occurred());
358 BT_ASSERT(ret_range_set
);
360 /* Copy returned ranges to input range set */
361 for (i
= 0; i
< bt_integer_range_set_get_range_count(
362 bt_integer_range_set_unsigned_as_range_set_const(ret_range_set
));
364 const bt_integer_range_unsigned
*range
=
365 bt_integer_range_set_unsigned_borrow_range_by_index_const(
367 bt_integer_range_set_add_range_status add_range_status
;
369 add_range_status
= bt_integer_range_set_unsigned_add_range(
371 bt_integer_range_unsigned_get_lower(range
),
372 bt_integer_range_unsigned_get_upper(range
));
373 if (add_range_status
) {
374 BT_LOG_WRITE_CUR_LVL(BT_LOG_ERROR
, log_level
, BT_LOG_TAG
,
375 "Failed to add range to supported MIP versions range set.");
380 status
= BT_COMPONENT_CLASS_GET_SUPPORTED_MIP_VERSIONS_METHOD_STATUS_OK
;
385 /* This error path is for non-Python errors only. */
386 status
= BT_COMPONENT_CLASS_GET_SUPPORTED_MIP_VERSIONS_METHOD_STATUS_ERROR
;
389 BT_ASSERT(!PyErr_Occurred());
390 Py_XDECREF(py_params_ptr
);
391 Py_XDECREF(py_range_set_addr
);
392 bt_integer_range_set_unsigned_put_ref(ret_range_set
);
397 bt_component_class_get_supported_mip_versions_method_status
398 component_class_source_get_supported_mip_versions(
399 bt_self_component_class_source
*self_component_class_source
,
400 const bt_value
*params
, void *init_method_data
,
401 bt_logging_level log_level
,
402 bt_integer_range_set_unsigned
*supported_versions
)
404 const bt_component_class_source
*component_class_source
= bt_self_component_class_source_as_component_class_source(self_component_class_source
);
405 const bt_component_class
*component_class
= bt_component_class_source_as_component_class_const(component_class_source
);
406 bt_self_component_class
*self_component_class
= bt_self_component_class_source_as_self_component_class(self_component_class_source
);
408 return component_class_get_supported_mip_versions(
409 component_class
, self_component_class
,
410 params
, init_method_data
, log_level
, supported_versions
);
414 bt_component_class_get_supported_mip_versions_method_status
415 component_class_filter_get_supported_mip_versions(
416 bt_self_component_class_filter
*self_component_class_filter
,
417 const bt_value
*params
, void *init_method_data
,
418 bt_logging_level log_level
,
419 bt_integer_range_set_unsigned
*supported_versions
)
421 const bt_component_class_filter
*component_class_filter
= bt_self_component_class_filter_as_component_class_filter(self_component_class_filter
);
422 const bt_component_class
*component_class
= bt_component_class_filter_as_component_class_const(component_class_filter
);
423 bt_self_component_class
*self_component_class
= bt_self_component_class_filter_as_self_component_class(self_component_class_filter
);
425 return component_class_get_supported_mip_versions(
426 component_class
, self_component_class
,
427 params
, init_method_data
, log_level
, supported_versions
);
431 bt_component_class_get_supported_mip_versions_method_status
432 component_class_sink_get_supported_mip_versions(
433 bt_self_component_class_sink
*self_component_class_sink
,
434 const bt_value
*params
, void *init_method_data
,
435 bt_logging_level log_level
,
436 bt_integer_range_set_unsigned
*supported_versions
)
438 const bt_component_class_sink
*component_class_sink
= bt_self_component_class_sink_as_component_class_sink(self_component_class_sink
);
439 const bt_component_class
*component_class
= bt_component_class_sink_as_component_class_const(component_class_sink
);
440 bt_self_component_class
*self_component_class
= bt_self_component_class_sink_as_self_component_class(self_component_class_sink
);
442 return component_class_get_supported_mip_versions(
443 component_class
, self_component_class
,
444 params
, init_method_data
, log_level
, supported_versions
);
448 * Method of bt_component_class_source to initialize a bt_self_component_source
453 bt_component_class_initialize_method_status
component_class_source_init(
454 bt_self_component_source
*self_component_source
,
455 bt_self_component_source_configuration
*config
,
456 const bt_value
*params
, void *init_method_data
)
458 bt_self_component
*self_component
= bt_self_component_source_as_self_component(self_component_source
);
459 return component_class_init(
461 self_component_source
,
462 SWIGTYPE_p_bt_self_component_source
,
463 params
, init_method_data
);
467 bt_component_class_initialize_method_status
component_class_filter_init(
468 bt_self_component_filter
*self_component_filter
,
469 bt_self_component_filter_configuration
*config
,
470 const bt_value
*params
, void *init_method_data
)
472 bt_self_component
*self_component
= bt_self_component_filter_as_self_component(self_component_filter
);
473 return component_class_init(
475 self_component_filter
,
476 SWIGTYPE_p_bt_self_component_filter
,
477 params
, init_method_data
);
481 bt_component_class_initialize_method_status
component_class_sink_init(
482 bt_self_component_sink
*self_component_sink
,
483 bt_self_component_sink_configuration
*config
,
484 const bt_value
*params
, void *init_method_data
)
486 bt_self_component
*self_component
= bt_self_component_sink_as_self_component(self_component_sink
);
487 return component_class_init(
490 SWIGTYPE_p_bt_self_component_sink
,
491 params
, init_method_data
);
495 void component_class_finalize(bt_self_component
*self_component
)
497 PyObject
*py_comp
= bt_self_component_get_data(self_component
);
498 PyObject
*py_method_result
;
502 /* Call user's _user_finalize() method */
503 py_method_result
= PyObject_CallMethod(py_comp
, "_user_finalize", NULL
);
504 if (!py_method_result
) {
505 bt_logging_level log_level
= get_self_component_log_level(
509 * Ignore any exception raised by the _user_finalize() method
510 * because it won't change anything at this point: the component
511 * is being destroyed anyway.
513 BT_COMP_LOG_CUR_LVL(BT_LOG_WARNING
, log_level
, self_component
,
514 "User component's _user_finalize() method raised an exception: ignoring:");
515 logw_exception_clear(log_level
);
520 BT_ASSERT(py_method_result
== Py_None
);
523 Py_XDECREF(py_method_result
);
527 /* Decref the Python object in the user data associated to `port`. */
530 void delete_port_user_data(bt_self_component_port
*port
)
532 Py_DECREF(bt_self_component_port_get_data(port
));
536 void delete_port_input_user_data(bt_self_component_port_input
*port_input
)
538 bt_self_component_port
*port
=
539 bt_self_component_port_input_as_self_component_port(port_input
);
541 delete_port_user_data(port
);
545 void delete_port_output_user_data(bt_self_component_port_output
*port_output
)
547 bt_self_component_port
*port
=
548 bt_self_component_port_output_as_self_component_port(port_output
);
550 delete_port_user_data(port
);
554 void component_class_source_finalize(bt_self_component_source
*self_component_source
)
557 bt_self_component
*self_component
;
558 const bt_component_source
*component_source
;
560 self_component
= bt_self_component_source_as_self_component(
561 self_component_source
);
562 component_source
= bt_self_component_source_as_component_source(
563 self_component_source
);
565 component_class_finalize(self_component
);
568 * Free the user data Python object attached to the port. The
569 * corresponding incref was done by the `void *` typemap in
572 for (i
= 0; i
< bt_component_source_get_output_port_count(component_source
); i
++) {
573 bt_self_component_port_output
*port_output
;
575 port_output
= bt_self_component_source_borrow_output_port_by_index(
576 self_component_source
, i
);
578 delete_port_output_user_data(port_output
);
583 void component_class_filter_finalize(bt_self_component_filter
*self_component_filter
)
586 bt_self_component
*self_component
;
587 const bt_component_filter
*component_filter
;
589 self_component
= bt_self_component_filter_as_self_component(
590 self_component_filter
);
591 component_filter
= bt_self_component_filter_as_component_filter(
592 self_component_filter
);
594 component_class_finalize(self_component
);
597 * Free the user data Python object attached to the port. The
598 * corresponding incref was done by the `void *` typemap in
601 for (i
= 0; i
< bt_component_filter_get_input_port_count(component_filter
); i
++) {
602 bt_self_component_port_input
*port_input
;
604 port_input
= bt_self_component_filter_borrow_input_port_by_index(
605 self_component_filter
, i
);
607 delete_port_input_user_data(port_input
);
610 for (i
= 0; i
< bt_component_filter_get_output_port_count(component_filter
); i
++) {
611 bt_self_component_port_output
*port_output
;
613 port_output
= bt_self_component_filter_borrow_output_port_by_index(
614 self_component_filter
, i
);
616 delete_port_output_user_data(port_output
);
621 void component_class_sink_finalize(bt_self_component_sink
*self_component_sink
)
624 bt_self_component
*self_component
;
625 const bt_component_sink
*component_sink
;
627 self_component
= bt_self_component_sink_as_self_component(
628 self_component_sink
);
629 component_sink
= bt_self_component_sink_as_component_sink(
630 self_component_sink
);
632 component_class_finalize(self_component
);
635 * Free the user data Python object attached to the port. The
636 * corresponding incref was done by the `void *` typemap in
639 for (i
= 0; i
< bt_component_sink_get_input_port_count(component_sink
); i
++) {
640 bt_self_component_port_input
*port_input
;
642 port_input
= bt_self_component_sink_borrow_input_port_by_index(
643 self_component_sink
, i
);
645 delete_port_input_user_data(port_input
);
650 bt_component_class_message_iterator_can_seek_beginning_method_status
651 component_class_can_seek_beginning(
652 bt_self_message_iterator
*self_message_iterator
, bt_bool
*can_seek
)
655 PyObject
*py_result
= NULL
;
656 bt_component_class_message_iterator_can_seek_beginning_method_status status
;
657 py_iter
= bt_self_message_iterator_get_data(self_message_iterator
);
661 py_result
= PyObject_CallMethod(py_iter
,
662 "_bt_can_seek_beginning_from_native", NULL
);
664 status
= py_exc_to_status_message_iterator_clear(self_message_iterator
);
668 BT_ASSERT(PyBool_Check(py_result
));
669 *can_seek
= PyObject_IsTrue(py_result
);
671 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_CAN_SEEK_BEGINNING_METHOD_STATUS_OK
;
674 Py_XDECREF(py_result
);
680 bt_component_class_message_iterator_seek_beginning_method_status
681 component_class_seek_beginning(bt_self_message_iterator
*self_message_iterator
)
685 bt_component_class_message_iterator_seek_beginning_method_status status
;
687 py_iter
= bt_self_message_iterator_get_data(self_message_iterator
);
690 py_result
= PyObject_CallMethod(py_iter
,
691 "_bt_seek_beginning_from_native",
694 status
= py_exc_to_status_message_iterator_clear(self_message_iterator
);
698 BT_ASSERT(py_result
== Py_None
);
700 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_SEEK_BEGINNING_METHOD_STATUS_OK
;
703 Py_XDECREF(py_result
);
709 bt_component_class_message_iterator_can_seek_ns_from_origin_method_status
710 component_class_can_seek_ns_from_origin(
711 bt_self_message_iterator
*self_message_iterator
,
712 int64_t ns_from_origin
, bt_bool
*can_seek
)
715 PyObject
*py_result
= NULL
;
716 bt_component_class_message_iterator_can_seek_ns_from_origin_method_status status
;
718 py_iter
= bt_self_message_iterator_get_data(self_message_iterator
);
721 py_result
= PyObject_CallMethod(py_iter
,
722 "_bt_can_seek_ns_from_origin_from_native", "L", ns_from_origin
);
724 status
= py_exc_to_status_message_iterator_clear(self_message_iterator
);
728 BT_ASSERT(PyBool_Check(py_result
));
729 *can_seek
= PyObject_IsTrue(py_result
);
731 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_CAN_SEEK_NS_FROM_ORIGIN_METHOD_STATUS_OK
;
734 Py_XDECREF(py_result
);
740 bt_component_class_message_iterator_seek_ns_from_origin_method_status
741 component_class_seek_ns_from_origin(
742 bt_self_message_iterator
*self_message_iterator
,
743 int64_t ns_from_origin
)
747 bt_component_class_message_iterator_seek_ns_from_origin_method_status status
;
749 py_iter
= bt_self_message_iterator_get_data(self_message_iterator
);
752 py_result
= PyObject_CallMethod(py_iter
,
753 "_bt_seek_ns_from_origin_from_native", "L", ns_from_origin
);
755 status
= py_exc_to_status_message_iterator_clear(self_message_iterator
);
760 BT_ASSERT(py_result
== Py_None
);
762 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_SEEK_NS_FROM_ORIGIN_METHOD_STATUS_OK
;
765 Py_XDECREF(py_result
);
771 bt_component_class_port_connected_method_status
component_class_port_connected(
772 bt_self_component
*self_component
,
773 void *self_component_port
,
774 swig_type_info
*self_component_port_swig_type
,
775 bt_port_type self_component_port_type
,
776 const void *other_port
,
777 swig_type_info
*other_port_swig_type
)
779 bt_component_class_port_connected_method_status status
;
780 PyObject
*py_comp
= NULL
;
781 PyObject
*py_self_port_ptr
= NULL
;
782 PyObject
*py_other_port_ptr
= NULL
;
783 PyObject
*py_method_result
= NULL
;
784 bt_logging_level log_level
= get_self_component_log_level(
787 py_comp
= bt_self_component_get_data(self_component
);
789 py_self_port_ptr
= SWIG_NewPointerObj(SWIG_as_voidptr(self_component_port
),
790 self_component_port_swig_type
, 0);
791 if (!py_self_port_ptr
) {
792 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
793 "Failed to create a SWIG pointer object.");
794 status
= __BT_FUNC_STATUS_MEMORY_ERROR
;
798 py_other_port_ptr
= SWIG_NewPointerObj(SWIG_as_voidptr(other_port
),
799 other_port_swig_type
, 0);
800 if (!py_other_port_ptr
) {
801 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
802 "Failed to create a SWIG pointer object.");
803 status
= __BT_FUNC_STATUS_MEMORY_ERROR
;
807 py_method_result
= PyObject_CallMethod(py_comp
,
808 "_bt_port_connected_from_native", "(OiO)", py_self_port_ptr
,
809 self_component_port_type
, py_other_port_ptr
);
810 if (!py_method_result
) {
811 status
= py_exc_to_status_component_clear(self_component
);
815 BT_ASSERT(py_method_result
== Py_None
);
817 status
= BT_COMPONENT_CLASS_PORT_CONNECTED_METHOD_STATUS_OK
;
820 Py_XDECREF(py_self_port_ptr
);
821 Py_XDECREF(py_other_port_ptr
);
822 Py_XDECREF(py_method_result
);
828 bt_component_class_port_connected_method_status
829 component_class_source_output_port_connected(
830 bt_self_component_source
*self_component_source
,
831 bt_self_component_port_output
*self_component_port_output
,
832 const bt_port_input
*other_port_input
)
834 bt_self_component
*self_component
= bt_self_component_source_as_self_component(self_component_source
);
836 return component_class_port_connected(
838 self_component_port_output
,
839 SWIGTYPE_p_bt_self_component_port_output
,
842 SWIGTYPE_p_bt_port_input
);
846 bt_component_class_port_connected_method_status
847 component_class_filter_input_port_connected(
848 bt_self_component_filter
*self_component_filter
,
849 bt_self_component_port_input
*self_component_port_input
,
850 const bt_port_output
*other_port_output
)
852 bt_self_component
*self_component
= bt_self_component_filter_as_self_component(self_component_filter
);
854 return component_class_port_connected(
856 self_component_port_input
,
857 SWIGTYPE_p_bt_self_component_port_input
,
860 SWIGTYPE_p_bt_port_output
);
864 bt_component_class_port_connected_method_status
865 component_class_filter_output_port_connected(
866 bt_self_component_filter
*self_component_filter
,
867 bt_self_component_port_output
*self_component_port_output
,
868 const bt_port_input
*other_port_input
)
870 bt_self_component
*self_component
= bt_self_component_filter_as_self_component(self_component_filter
);
872 return component_class_port_connected(
874 self_component_port_output
,
875 SWIGTYPE_p_bt_self_component_port_output
,
878 SWIGTYPE_p_bt_port_input
);
882 bt_component_class_port_connected_method_status
883 component_class_sink_input_port_connected(
884 bt_self_component_sink
*self_component_sink
,
885 bt_self_component_port_input
*self_component_port_input
,
886 const bt_port_output
*other_port_output
)
888 bt_self_component
*self_component
= bt_self_component_sink_as_self_component(self_component_sink
);
890 return component_class_port_connected(
892 self_component_port_input
,
893 SWIGTYPE_p_bt_self_component_port_input
,
896 SWIGTYPE_p_bt_port_output
);
900 bt_component_class_sink_graph_is_configured_method_status
901 component_class_sink_graph_is_configured(
902 bt_self_component_sink
*self_component_sink
)
904 PyObject
*py_comp
= NULL
;
905 PyObject
*py_method_result
= NULL
;
906 bt_component_class_sink_graph_is_configured_method_status status
;
907 bt_self_component
*self_component
= bt_self_component_sink_as_self_component(self_component_sink
);
909 py_comp
= bt_self_component_get_data(self_component
);
911 py_method_result
= PyObject_CallMethod(py_comp
,
912 "_bt_graph_is_configured_from_native", NULL
);
913 if (!py_method_result
) {
914 status
= py_exc_to_status_component_clear(self_component
);
918 BT_ASSERT(py_method_result
== Py_None
);
920 status
= BT_COMPONENT_CLASS_SINK_GRAPH_IS_CONFIGURED_METHOD_STATUS_OK
;;
923 Py_XDECREF(py_method_result
);
928 bt_component_class_query_method_status
component_class_query(
929 const bt_component_class
*component_class
,
930 bt_self_component_class
*self_component_class
,
931 bt_private_query_executor
*priv_query_executor
,
932 const char *object
, const bt_value
*params
, void *method_data
,
933 const bt_value
**result
)
935 PyObject
*py_cls
= NULL
;
936 PyObject
*py_params_ptr
= NULL
;
937 PyObject
*py_priv_query_exec_ptr
= NULL
;
938 PyObject
*py_query_func
= NULL
;
939 PyObject
*py_object
= NULL
;
940 PyObject
*py_results_addr
= NULL
;
941 bt_component_class_query_method_status status
= __BT_FUNC_STATUS_OK
;
942 const bt_query_executor
*query_exec
=
943 bt_private_query_executor_as_query_executor_const(
944 priv_query_executor
);
945 bt_logging_level log_level
=
946 bt_query_executor_get_logging_level(query_exec
);
949 * If there's any `method_data`, assume this component class is
950 * getting queried from Python, so that `method_data` is a
951 * Python object to pass to the user's _user_query() method.
953 BT_ASSERT(!method_data
||
954 bt_bt2_is_python_component_class(component_class
));
956 py_cls
= lookup_cc_ptr_to_py_cls(component_class
);
958 BT_LOG_WRITE_CUR_LVL(BT_LOG_ERROR
, log_level
, BT_LOG_TAG
,
959 "Cannot find Python class associated to native component class: "
960 "comp-cls-addr=%p", component_class
);
964 py_params_ptr
= SWIG_NewPointerObj(SWIG_as_voidptr(params
),
965 SWIGTYPE_p_bt_value
, 0);
966 if (!py_params_ptr
) {
967 BT_LOG_WRITE_CUR_LVL(BT_LOG_ERROR
, log_level
, BT_LOG_TAG
,
968 "Failed to create a SWIG pointer object.");
972 py_priv_query_exec_ptr
= SWIG_NewPointerObj(
973 SWIG_as_voidptr(priv_query_executor
),
974 SWIGTYPE_p_bt_private_query_executor
, 0);
975 if (!py_priv_query_exec_ptr
) {
976 BT_LOG_WRITE_CUR_LVL(BT_LOG_ERROR
, log_level
, BT_LOG_TAG
,
977 "Failed to create a SWIG pointer object.");
981 py_object
= SWIG_FromCharPtr(object
);
983 BT_LOG_WRITE_CUR_LVL(BT_LOG_ERROR
, log_level
, BT_LOG_TAG
,
984 "Failed to create a Python string.");
989 * We don't take any reference on `method_data` which, if not
990 * `NULL`, is assumed to be a `PyObject *`: the user's
991 * _user_query() function will eventually take a reference if
992 * needed. If `method_data` is `NULL`, then we pass `Py_None` as
993 * the initialization's Python object.
995 py_results_addr
= PyObject_CallMethod(py_cls
,
996 "_bt_query_from_native", "(OOOO)", py_priv_query_exec_ptr
,
997 py_object
, py_params_ptr
,
998 method_data
? method_data
: Py_None
);
999 if (!py_results_addr
) {
1000 status
= py_exc_to_status_component_class_clear(self_component_class
,
1003 static const char *fmt
=
1004 "Failed to call Python class's _bt_query_from_native() method: py-cls-addr=%p";
1005 BT_LOG_WRITE_CUR_LVL(BT_LOG_WARNING
, log_level
, BT_LOG_TAG
,
1007 BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_COMPONENT_CLASS(
1008 self_component_class
, fmt
, py_cls
);
1014 * The returned object, on success, is an integer object
1015 * (PyLong) containing the address of a BT value object (new
1018 *result
= PyLong_AsVoidPtr(py_results_addr
);
1019 BT_ASSERT(!PyErr_Occurred());
1025 status
= __BT_FUNC_STATUS_ERROR
;
1028 Py_XDECREF(py_params_ptr
);
1029 Py_XDECREF(py_priv_query_exec_ptr
);
1030 Py_XDECREF(py_query_func
);
1031 Py_XDECREF(py_object
);
1032 Py_XDECREF(py_results_addr
);
1037 bt_component_class_query_method_status
component_class_source_query(
1038 bt_self_component_class_source
*self_component_class_source
,
1039 bt_private_query_executor
*priv_query_executor
,
1040 const char *object
, const bt_value
*params
, void *method_data
,
1041 const bt_value
**result
)
1043 const bt_component_class_source
*component_class_source
= bt_self_component_class_source_as_component_class_source(self_component_class_source
);
1044 const bt_component_class
*component_class
= bt_component_class_source_as_component_class_const(component_class_source
);
1045 bt_self_component_class
*self_component_class
= bt_self_component_class_source_as_self_component_class(self_component_class_source
);
1047 return component_class_query(component_class
, self_component_class
,
1048 priv_query_executor
, object
, params
, method_data
, result
);
1052 bt_component_class_query_method_status
component_class_filter_query(
1053 bt_self_component_class_filter
*self_component_class_filter
,
1054 bt_private_query_executor
*priv_query_executor
,
1055 const char *object
, const bt_value
*params
, void *method_data
,
1056 const bt_value
**result
)
1058 const bt_component_class_filter
*component_class_filter
= bt_self_component_class_filter_as_component_class_filter(self_component_class_filter
);
1059 const bt_component_class
*component_class
= bt_component_class_filter_as_component_class_const(component_class_filter
);
1060 bt_self_component_class
*self_component_class
= bt_self_component_class_filter_as_self_component_class(self_component_class_filter
);
1062 return component_class_query(component_class
, self_component_class
,
1063 priv_query_executor
, object
, params
, method_data
, result
);
1067 bt_component_class_query_method_status
component_class_sink_query(
1068 bt_self_component_class_sink
*self_component_class_sink
,
1069 bt_private_query_executor
*priv_query_executor
,
1070 const char *object
, const bt_value
*params
, void *method_data
,
1071 const bt_value
**result
)
1073 const bt_component_class_sink
*component_class_sink
= bt_self_component_class_sink_as_component_class_sink(self_component_class_sink
);
1074 const bt_component_class
*component_class
= bt_component_class_sink_as_component_class_const(component_class_sink
);
1075 bt_self_component_class
*self_component_class
= bt_self_component_class_sink_as_self_component_class(self_component_class_sink
);
1077 return component_class_query(component_class
, self_component_class
,
1078 priv_query_executor
, object
, params
, method_data
, result
);
1082 bt_component_class_message_iterator_initialize_method_status
1083 component_class_message_iterator_init(
1084 bt_self_message_iterator
*self_message_iterator
,
1085 bt_self_message_iterator_configuration
*config
,
1086 bt_self_component
*self_component
,
1087 bt_self_component_port_output
*self_component_port_output
)
1089 bt_component_class_message_iterator_initialize_method_status status
= __BT_FUNC_STATUS_OK
;
1090 PyObject
*py_comp_cls
= NULL
;
1091 PyObject
*py_iter_cls
= NULL
;
1092 PyObject
*py_iter_ptr
= NULL
;
1093 PyObject
*py_config_ptr
= NULL
;
1094 PyObject
*py_component_port_output_ptr
= NULL
;
1095 PyObject
*py_init_method_result
= NULL
;
1096 PyObject
*py_iter
= NULL
;
1098 bt_logging_level log_level
= get_self_component_log_level(
1101 py_comp
= bt_self_component_get_data(self_component
);
1103 /* Find user's Python message iterator class */
1104 py_comp_cls
= PyObject_GetAttrString(py_comp
, "__class__");
1106 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
1107 "Cannot get Python object's `__class__` attribute.");
1111 py_iter_cls
= PyObject_GetAttrString(py_comp_cls
, "_iter_cls");
1113 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
1114 "Cannot get Python class's `_iter_cls` attribute.");
1118 py_iter_ptr
= SWIG_NewPointerObj(SWIG_as_voidptr(self_message_iterator
),
1119 SWIGTYPE_p_bt_self_message_iterator
, 0);
1121 const char *err
= "Failed to create a SWIG pointer object.";
1123 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
1125 BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_MESSAGE_ITERATOR(
1126 self_message_iterator
, err
);
1131 * Create object with borrowed native message iterator
1134 * py_iter = py_iter_cls.__new__(py_iter_cls, py_iter_ptr)
1136 py_iter
= PyObject_CallMethod(py_iter_cls
, "__new__",
1137 "(OO)", py_iter_cls
, py_iter_ptr
);
1139 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
1140 "Failed to call Python class's __new__() method: "
1141 "py-cls-addr=%p", py_iter_cls
);
1146 * Initialize object:
1148 * py_iter.__init__(config, self_output_port)
1150 * through the _init_from_native helper static method.
1152 * At this point, py_iter._ptr is set, so this initialization
1153 * function has access to self._component (which gives it the
1154 * user Python component object from which the iterator was
1157 py_config_ptr
= SWIG_NewPointerObj(SWIG_as_voidptr(config
),
1158 SWIGTYPE_p_bt_self_message_iterator_configuration
, 0);
1159 if (!py_config_ptr
) {
1160 const char *err
= "Failed to create a SWIG pointer object";
1162 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
1164 BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_MESSAGE_ITERATOR(
1165 self_message_iterator
, err
);
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 const char *err
= "Failed to create a SWIG pointer object.";
1175 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
1177 BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_MESSAGE_ITERATOR(
1178 self_message_iterator
, err
);
1182 py_init_method_result
= PyObject_CallMethod(py_iter
,
1183 "_bt_init_from_native", "OO", py_config_ptr
,
1184 py_component_port_output_ptr
);
1185 if (!py_init_method_result
) {
1186 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_component
,
1187 "User's __init__() method failed:");
1192 * Since the Python code can never instantiate a user-defined
1193 * message iterator class, the native message iterator
1194 * object does NOT belong to a user Python message iterator
1195 * object (borrowed reference). However this Python object is
1196 * owned by this native message iterator object.
1198 * In the Python world, the lifetime of the native message
1199 * iterator is managed by a _GenericMessageIterator
1202 * _GenericMessageIterator instance:
1203 * owns a native bt_message_iterator object (iter)
1204 * owns a _UserMessageIterator instance (py_iter)
1205 * self._ptr is a borrowed reference to the
1206 * native bt_private_connection_private_message_iterator
1209 bt_self_message_iterator_set_data(self_message_iterator
, py_iter
);
1214 /* Handling of errors that cause a Python exception to be set. */
1215 status
= py_exc_to_status_message_iterator_clear(self_message_iterator
);
1219 /* Handling of errors that don't cause a Python exception to be set. */
1220 status
= __BT_FUNC_STATUS_ERROR
;
1223 BT_ASSERT(!PyErr_Occurred());
1225 Py_XDECREF(py_comp_cls
);
1226 Py_XDECREF(py_iter_cls
);
1227 Py_XDECREF(py_iter_ptr
);
1228 Py_XDECREF(py_component_port_output_ptr
);
1229 Py_XDECREF(py_init_method_result
);
1230 Py_XDECREF(py_iter
);
1235 bt_component_class_message_iterator_initialize_method_status
1236 component_class_source_message_iterator_init(
1237 bt_self_message_iterator
*self_message_iterator
,
1238 bt_self_message_iterator_configuration
*config
,
1239 bt_self_component_source
*self_component_source
,
1240 bt_self_component_port_output
*self_component_port_output
)
1242 bt_self_component
*self_component
=
1243 bt_self_component_source_as_self_component(self_component_source
);
1245 return component_class_message_iterator_init(self_message_iterator
,
1246 config
, self_component
, self_component_port_output
);
1250 bt_component_class_message_iterator_initialize_method_status
1251 component_class_filter_message_iterator_init(
1252 bt_self_message_iterator
*self_message_iterator
,
1253 bt_self_message_iterator_configuration
*config
,
1254 bt_self_component_filter
*self_component_filter
,
1255 bt_self_component_port_output
*self_component_port_output
)
1257 bt_self_component
*self_component
=
1258 bt_self_component_filter_as_self_component(self_component_filter
);
1260 return component_class_message_iterator_init(self_message_iterator
,
1261 config
, self_component
, self_component_port_output
);
1265 void component_class_message_iterator_finalize(
1266 bt_self_message_iterator
*message_iterator
)
1268 PyObject
*py_message_iter
= bt_self_message_iterator_get_data(
1270 PyObject
*py_method_result
= NULL
;
1272 BT_ASSERT(py_message_iter
);
1274 /* Call user's _user_finalize() method */
1275 py_method_result
= PyObject_CallMethod(py_message_iter
,
1276 "_user_finalize", NULL
);
1277 if (!py_method_result
) {
1278 bt_self_component
*self_comp
=
1279 bt_self_message_iterator_borrow_component(
1281 bt_logging_level log_level
= get_self_component_log_level(
1285 * Ignore any exception raised by the _user_finalize() method
1286 * because it won't change anything at this point: the component
1287 * is being destroyed anyway.
1289 BT_COMP_LOG_CUR_LVL(BT_LOG_WARNING
, log_level
, self_comp
,
1290 "User's _user_finalize() method raised an exception: ignoring:");
1291 logw_exception_clear(get_self_message_iterator_log_level(
1295 Py_XDECREF(py_method_result
);
1296 Py_DECREF(py_message_iter
);
1299 /* Valid for both sources and filters. */
1302 bt_component_class_message_iterator_next_method_status
1303 component_class_message_iterator_next(
1304 bt_self_message_iterator
*message_iterator
,
1305 bt_message_array_const msgs
, uint64_t capacity
,
1308 bt_component_class_message_iterator_next_method_status status
;
1309 PyObject
*py_message_iter
= bt_self_message_iterator_get_data(message_iterator
);
1310 PyObject
*py_method_result
= NULL
;
1312 BT_ASSERT_DBG(py_message_iter
);
1313 py_method_result
= PyObject_CallMethod(py_message_iter
,
1314 "_bt_next_from_native", NULL
);
1315 if (!py_method_result
) {
1316 status
= py_exc_to_status_message_iterator_clear(message_iterator
);
1321 * The returned object, on success, is an integer object
1322 * (PyLong) containing the address of a native message
1323 * object (which is now ours).
1325 msgs
[0] = PyLong_AsVoidPtr(py_method_result
);
1328 /* Overflow errors should never happen. */
1329 BT_ASSERT_DBG(!PyErr_Occurred());
1331 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK
;
1334 Py_XDECREF(py_method_result
);
1339 bt_component_class_sink_consume_method_status
1340 component_class_sink_consume(bt_self_component_sink
*self_component_sink
)
1342 bt_self_component
*self_component
= bt_self_component_sink_as_self_component(self_component_sink
);
1343 PyObject
*py_comp
= bt_self_component_get_data(self_component
);
1344 PyObject
*py_method_result
= NULL
;
1345 bt_component_class_sink_consume_method_status status
;
1347 BT_ASSERT_DBG(py_comp
);
1349 py_method_result
= PyObject_CallMethod(py_comp
,
1350 "_user_consume", NULL
);
1351 if (!py_method_result
) {
1352 status
= py_exc_to_status_component_clear(self_component
);
1356 status
= BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_OK
;
1359 Py_XDECREF(py_method_result
);
1364 int component_class_set_help_and_desc(
1365 bt_component_class
*component_class
,
1366 const char *description
, const char *help
)
1371 ret
= bt_component_class_set_description(component_class
, description
);
1373 BT_LOGE("Cannot set component class's description: "
1374 "comp-cls-addr=%p", component_class
);
1380 ret
= bt_component_class_set_help(component_class
, help
);
1382 BT_LOGE("Cannot set component class's help text: "
1383 "comp-cls-addr=%p", component_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
;
1400 bt_component_class
*component_class
;
1404 component_class_source
= bt_component_class_source_create(name
,
1405 component_class_message_iterator_next
);
1406 if (!component_class_source
) {
1407 BT_LOGE_STR("Cannot create source component class.");
1411 component_class
= bt_component_class_source_as_component_class(component_class_source
);
1413 if (component_class_set_help_and_desc(component_class
, description
, help
)) {
1417 ret
= bt_component_class_source_set_initialize_method(component_class_source
, component_class_source_init
);
1418 BT_ASSERT(ret
== 0);
1419 ret
= bt_component_class_source_set_finalize_method(component_class_source
, component_class_source_finalize
);
1420 BT_ASSERT(ret
== 0);
1421 ret
= bt_component_class_source_set_message_iterator_seek_beginning_methods(component_class_source
,
1422 component_class_seek_beginning
, component_class_can_seek_beginning
);
1423 ret
= bt_component_class_source_set_message_iterator_seek_ns_from_origin_methods(
1424 component_class_source
, component_class_seek_ns_from_origin
,
1425 component_class_can_seek_ns_from_origin
);
1426 BT_ASSERT(ret
== 0);
1427 ret
= bt_component_class_source_set_output_port_connected_method(component_class_source
,
1428 component_class_source_output_port_connected
);
1429 BT_ASSERT(ret
== 0);
1430 ret
= bt_component_class_source_set_query_method(component_class_source
, component_class_source_query
);
1431 BT_ASSERT(ret
== 0);
1432 ret
= bt_component_class_source_set_get_supported_mip_versions_method(component_class_source
, component_class_source_get_supported_mip_versions
);
1433 BT_ASSERT(ret
== 0);
1434 ret
= bt_component_class_source_set_message_iterator_initialize_method(
1435 component_class_source
, component_class_source_message_iterator_init
);
1436 BT_ASSERT(ret
== 0);
1437 ret
= bt_component_class_source_set_message_iterator_finalize_method(
1438 component_class_source
, component_class_message_iterator_finalize
);
1439 BT_ASSERT(ret
== 0);
1440 register_cc_ptr_to_py_cls(component_class
, py_cls
);
1443 return component_class_source
;
1447 bt_component_class_filter
*bt_bt2_component_class_filter_create(
1448 PyObject
*py_cls
, const char *name
, const char *description
,
1451 bt_component_class
*component_class
;
1452 bt_component_class_filter
*component_class_filter
;
1456 component_class_filter
= bt_component_class_filter_create(name
,
1457 component_class_message_iterator_next
);
1458 if (!component_class_filter
) {
1459 BT_LOGE_STR("Cannot create filter component class.");
1463 component_class
= bt_component_class_filter_as_component_class(component_class_filter
);
1465 if (component_class_set_help_and_desc(component_class
, description
, help
)) {
1469 ret
= bt_component_class_filter_set_initialize_method(component_class_filter
, component_class_filter_init
);
1470 BT_ASSERT(ret
== 0);
1471 ret
= bt_component_class_filter_set_finalize_method (component_class_filter
, component_class_filter_finalize
);
1472 BT_ASSERT(ret
== 0);
1473 ret
= bt_component_class_filter_set_message_iterator_seek_beginning_methods(component_class_filter
,
1474 component_class_seek_beginning
, component_class_can_seek_beginning
);
1475 BT_ASSERT(ret
== 0);
1476 ret
= bt_component_class_filter_set_message_iterator_seek_ns_from_origin_methods(
1477 component_class_filter
, component_class_seek_ns_from_origin
,
1478 component_class_can_seek_ns_from_origin
);
1479 ret
= bt_component_class_filter_set_input_port_connected_method(component_class_filter
,
1480 component_class_filter_input_port_connected
);
1481 BT_ASSERT(ret
== 0);
1482 ret
= bt_component_class_filter_set_output_port_connected_method(component_class_filter
,
1483 component_class_filter_output_port_connected
);
1484 BT_ASSERT(ret
== 0);
1485 ret
= bt_component_class_filter_set_query_method(component_class_filter
, component_class_filter_query
);
1486 BT_ASSERT(ret
== 0);
1487 ret
= bt_component_class_filter_set_get_supported_mip_versions_method(component_class_filter
, component_class_filter_get_supported_mip_versions
);
1488 BT_ASSERT(ret
== 0);
1489 ret
= bt_component_class_filter_set_message_iterator_initialize_method(
1490 component_class_filter
, component_class_filter_message_iterator_init
);
1491 BT_ASSERT(ret
== 0);
1492 ret
= bt_component_class_filter_set_message_iterator_finalize_method(
1493 component_class_filter
, component_class_message_iterator_finalize
);
1494 BT_ASSERT(ret
== 0);
1495 register_cc_ptr_to_py_cls(component_class
, py_cls
);
1498 return component_class_filter
;
1502 bt_component_class_sink
*bt_bt2_component_class_sink_create(
1503 PyObject
*py_cls
, const char *name
, const char *description
,
1506 bt_component_class_sink
*component_class_sink
;
1507 bt_component_class
*component_class
;
1511 component_class_sink
= bt_component_class_sink_create(name
, component_class_sink_consume
);
1513 if (!component_class_sink
) {
1514 BT_LOGE_STR("Cannot create sink component class.");
1518 component_class
= bt_component_class_sink_as_component_class(component_class_sink
);
1520 if (component_class_set_help_and_desc(component_class
, description
, help
)) {
1524 ret
= bt_component_class_sink_set_initialize_method(component_class_sink
, component_class_sink_init
);
1525 BT_ASSERT(ret
== 0);
1526 ret
= bt_component_class_sink_set_finalize_method(component_class_sink
, component_class_sink_finalize
);
1527 BT_ASSERT(ret
== 0);
1528 ret
= bt_component_class_sink_set_input_port_connected_method(component_class_sink
,
1529 component_class_sink_input_port_connected
);
1530 BT_ASSERT(ret
== 0);
1531 ret
= bt_component_class_sink_set_graph_is_configured_method(component_class_sink
,
1532 component_class_sink_graph_is_configured
);
1533 BT_ASSERT(ret
== 0);
1534 ret
= bt_component_class_sink_set_query_method(component_class_sink
, component_class_sink_query
);
1535 BT_ASSERT(ret
== 0);
1536 ret
= bt_component_class_sink_set_get_supported_mip_versions_method(component_class_sink
, component_class_sink_get_supported_mip_versions
);
1537 BT_ASSERT(ret
== 0);
1538 register_cc_ptr_to_py_cls(component_class
, py_cls
);
1541 return component_class_sink
;