- PyObject *py_listener_ids = NULL;
- PyObject *py_listener_id = NULL;
- bt_listener_id listener_id;
- bt_graph_add_listener_status status;
- const char * const module_name =
- "graph_add_ports_connected_listener() (Python)";
-
- BT_ASSERT(graph);
- BT_ASSERT(py_callable);
-
- /* Behind the scene, we will be registering 4 different listeners and
- * return all of their ids. */
- py_listener_ids = PyTuple_New(4);
- if (!py_listener_ids) {
- BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_UNKNOWN(module_name,
- "Failed to allocate one PyTuple.");
- goto error;
- }
-
- /* source -> filter connection */
- status = bt_graph_add_source_filter_component_ports_connected_listener(
- graph, source_filter_component_ports_connected_listener,
- graph_listener_removed, py_callable, &listener_id);
- if (status != __BT_FUNC_STATUS_OK) {
- /*
- * bt_graph_add_source_filter_component_ports_connected_listener
- * has already logged/appended an error cause.
- */
- goto error;
- }
-
- py_listener_id = PyLong_FromUnsignedLongLong(listener_id);
- if (!py_listener_id) {
- BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_UNKNOWN(module_name,
- "Failed to allocate one PyLong.");
- goto error;
- }
-
- PyTuple_SET_ITEM(py_listener_ids, 0, py_listener_id);
- py_listener_id = NULL;
-
- /* source -> sink connection */
- status = bt_graph_add_source_sink_component_ports_connected_listener(
- graph, source_sink_component_ports_connected_listener,
- graph_listener_removed, py_callable, &listener_id);
- if (status != __BT_FUNC_STATUS_OK) {
- /*
- * bt_graph_add_source_sink_component_ports_connected_listener
- * has already logged/appended an error cause.
- */
- goto error;
- }
-
- py_listener_id = PyLong_FromUnsignedLongLong(listener_id);
- if (!py_listener_id) {
- BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_UNKNOWN(module_name,
- "Failed to allocate one PyLong.");
- goto error;
- }
-
- PyTuple_SET_ITEM(py_listener_ids, 1, py_listener_id);
- py_listener_id = NULL;
-
- /* filter -> filter connection */
- status = bt_graph_add_filter_filter_component_ports_connected_listener(
- graph, filter_filter_component_ports_connected_listener,
- graph_listener_removed, py_callable, &listener_id);
- if (status != __BT_FUNC_STATUS_OK) {
- /*
- * bt_graph_add_filter_filter_component_ports_connected_listener
- * has already logged/appended an error cause.
- */
- goto error;
- }
-
- py_listener_id = PyLong_FromUnsignedLongLong(listener_id);
- if (!py_listener_id) {
- BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_UNKNOWN(module_name,
- "Failed to allocate one PyLong.");
- goto error;
- }
-
- PyTuple_SET_ITEM(py_listener_ids, 2, py_listener_id);
- py_listener_id = NULL;
-
- /* filter -> sink connection */
- status = bt_graph_add_filter_sink_component_ports_connected_listener(
- graph, filter_sink_component_ports_connected_listener,
- graph_listener_removed, py_callable, &listener_id);
- if (status != __BT_FUNC_STATUS_OK) {
- /*
- * bt_graph_add_filter_sink_component_ports_connected_listener
- * has already logged/appended an error cause.
- */
- goto error;
- }
-
- py_listener_id = PyLong_FromUnsignedLongLong(listener_id);
- if (!py_listener_id) {
- BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_UNKNOWN(module_name,
- "Failed to allocate one PyLong.");
- goto error;
- }
-
- PyTuple_SET_ITEM(py_listener_ids, 3, py_listener_id);
- py_listener_id = NULL;
-
- Py_INCREF(py_callable);
- Py_INCREF(py_callable);
- Py_INCREF(py_callable);
- Py_INCREF(py_callable);
-
- goto end;
-
-error:
- Py_XDECREF(py_listener_ids);
- py_listener_ids = Py_None;
- Py_INCREF(py_listener_ids);
-
-end:
-
- Py_XDECREF(py_listener_id);
- return py_listener_ids;