/* From graph.h */
-typedef void (*bt_graph_filter_component_input_port_added_listener_func)(
+typedef enum bt_graph_listener_status {
+ BT_GRAPH_LISTENER_STATUS_OK = 0,
+ BT_GRAPH_LISTENER_STATUS_ERROR = -1,
+ BT_GRAPH_LISTENER_STATUS_NOMEM = -12,
+} bt_graph_listener_status;
+
+
+typedef bt_graph_listener_status
+(*bt_graph_filter_component_input_port_added_listener_func)(
const bt_component_filter *component,
const bt_port_input *port, void *data);
-typedef void (*bt_graph_sink_component_input_port_added_listener_func)(
+typedef bt_graph_listener_status
+(*bt_graph_sink_component_input_port_added_listener_func)(
const bt_component_sink *component,
const bt_port_input *port, void *data);
-typedef void (*bt_graph_source_component_output_port_added_listener_func)(
+typedef bt_graph_listener_status
+(*bt_graph_source_component_output_port_added_listener_func)(
const bt_component_source *component,
const bt_port_output *port, void *data);
-typedef void (*bt_graph_filter_component_output_port_added_listener_func)(
+typedef bt_graph_listener_status
+(*bt_graph_filter_component_output_port_added_listener_func)(
const bt_component_filter *component,
const bt_port_output *port, void *data);
-typedef void (*bt_graph_source_filter_component_ports_connected_listener_func)(
+typedef bt_graph_listener_status
+(*bt_graph_source_filter_component_ports_connected_listener_func)(
const bt_component_source *source_component,
const bt_component_filter *filter_component,
const bt_port_output *upstream_port,
const bt_port_input *downstream_port, void *data);
-typedef void (*bt_graph_source_sink_component_ports_connected_listener_func)(
+typedef bt_graph_listener_status
+(*bt_graph_source_sink_component_ports_connected_listener_func)(
const bt_component_source *source_component,
const bt_component_sink *sink_component,
const bt_port_output *upstream_port,
const bt_port_input *downstream_port, void *data);
-typedef void (*bt_graph_filter_filter_component_ports_connected_listener_func)(
+typedef bt_graph_listener_status
+(*bt_graph_filter_filter_component_ports_connected_listener_func)(
const bt_component_filter *filter_component_upstream,
const bt_component_filter *filter_component_downstream,
const bt_port_output *upstream_port,
const bt_port_input *downstream_port,
void *data);
-typedef void (*bt_graph_filter_sink_component_ports_connected_listener_func)(
+typedef bt_graph_listener_status
+(*bt_graph_filter_sink_component_ports_connected_listener_func)(
const bt_component_filter *filter_component,
const bt_component_sink *sink_component,
const bt_port_output *upstream_port,
Py_DECREF(py_callable);
}
-static void
+static bt_graph_listener_status
port_added_listener(
const void *component,
swig_type_info *component_swig_type,
- bt_component_class_type component_class_type,
+ bt_component_class_type component_class_type,
const void *port,
swig_type_info *port_swig_type,
bt_port_type port_type,
PyObject *py_component_ptr = NULL;
PyObject *py_port_ptr = NULL;
PyObject *py_res = NULL;
+ bt_graph_listener_status status;
py_component_ptr = SWIG_NewPointerObj(SWIG_as_voidptr(component), component_swig_type, 0);
if (!py_component_ptr) {
BT_LOGF_STR("Failed to create component SWIG pointer object.");
+ status = BT_GRAPH_LISTENER_STATUS_NOMEM;
goto end;
}
py_port_ptr = SWIG_NewPointerObj(SWIG_as_voidptr(port), port_swig_type, 0);
if (!py_port_ptr) {
BT_LOGF_STR("Failed to create port SWIG pointer object.");
+ status = BT_GRAPH_LISTENER_STATUS_NOMEM;
goto end;
}
if (!py_res) {
bt2_py_loge_exception();
PyErr_Clear();
- } else {
- BT_ASSERT(py_res == Py_None);
+ status = BT_GRAPH_LISTENER_STATUS_ERROR;
+ goto end;
}
+
+ BT_ASSERT(py_res == Py_None);
+ status = BT_GRAPH_LISTENER_STATUS_OK;
end:
Py_XDECREF(py_res);
Py_XDECREF(py_port_ptr);
Py_XDECREF(py_component_ptr);
+
+ return status;
}
-static void
+static bt_graph_listener_status
source_component_output_port_added_listener(const bt_component_source *component_source,
const bt_port_output *port_output, void *py_callable)
{
- port_added_listener(
+ return port_added_listener(
component_source, SWIGTYPE_p_bt_component_source, BT_COMPONENT_CLASS_TYPE_SOURCE,
port_output, SWIGTYPE_p_bt_port_output, BT_PORT_TYPE_OUTPUT, py_callable);
}
-static void
+static bt_graph_listener_status
filter_component_input_port_added_listener(const bt_component_filter *component_filter,
const bt_port_input *port_input, void *py_callable)
{
- port_added_listener(
+ return port_added_listener(
component_filter, SWIGTYPE_p_bt_component_filter, BT_COMPONENT_CLASS_TYPE_FILTER,
port_input, SWIGTYPE_p_bt_port_input, BT_PORT_TYPE_INPUT, py_callable);
}
-static void
+static bt_graph_listener_status
filter_component_output_port_added_listener(const bt_component_filter *component_filter,
const bt_port_output *port_output, void *py_callable)
{
- port_added_listener(
+ return port_added_listener(
component_filter, SWIGTYPE_p_bt_component_filter, BT_COMPONENT_CLASS_TYPE_FILTER,
port_output, SWIGTYPE_p_bt_port_output, BT_PORT_TYPE_OUTPUT, py_callable);
}
-static void
+static bt_graph_listener_status
sink_component_input_port_added_listener(const bt_component_sink *component_sink,
const bt_port_input *port_input, void *py_callable)
{
- port_added_listener(
+ return port_added_listener(
component_sink, SWIGTYPE_p_bt_component_sink, BT_COMPONENT_CLASS_TYPE_SINK,
port_input, SWIGTYPE_p_bt_port_input, BT_PORT_TYPE_INPUT, py_callable);
}
return py_listener_ids;
}
-static void
-ports_connected_listener(const bt_port_output *upstream_port,
- const bt_port_input *downstream_port,
- void *py_callable)
+static bt_graph_listener_status
+ports_connected_listener(
+ const void *upstream_component,
+ swig_type_info *upstream_component_swig_type,
+ bt_component_class_type upstream_component_class_type,
+ const bt_port_output *upstream_port,
+ const void *downstream_component,
+ swig_type_info *downstream_component_swig_type,
+ bt_component_class_type downstream_component_class_type,
+ const bt_port_input *downstream_port,
+ void *py_callable)
{
+ PyObject *py_upstream_component_ptr = NULL;
PyObject *py_upstream_port_ptr = NULL;
+ PyObject *py_downstream_component_ptr = NULL;
PyObject *py_downstream_port_ptr = NULL;
PyObject *py_res = NULL;
+ bt_graph_listener_status status;
+
+ py_upstream_component_ptr = SWIG_NewPointerObj(SWIG_as_voidptr(upstream_component),
+ upstream_component_swig_type, 0);
+ if (!py_upstream_component_ptr) {
+ BT_LOGF_STR("Failed to create upstream component SWIG pointer object.");
+ status = BT_GRAPH_LISTENER_STATUS_NOMEM;
+ goto end;
+ }
py_upstream_port_ptr = SWIG_NewPointerObj(
SWIG_as_voidptr(upstream_port), SWIGTYPE_p_bt_port_output, 0);
if (!py_upstream_port_ptr) {
- BT_LOGF_STR("Failed to create a SWIG pointer object.");
- abort();
+ BT_LOGF_STR("Failed to create upstream port SWIG pointer object.");
+ status = BT_GRAPH_LISTENER_STATUS_NOMEM;
+ goto end;
+ }
+
+ py_downstream_component_ptr = SWIG_NewPointerObj(SWIG_as_voidptr(downstream_component),
+ downstream_component_swig_type, 0);
+ if (!py_downstream_component_ptr) {
+ BT_LOGF_STR("Failed to create downstream component SWIG pointer object.");
+ status = BT_GRAPH_LISTENER_STATUS_NOMEM;
+ goto end;
}
py_downstream_port_ptr = SWIG_NewPointerObj(
SWIG_as_voidptr(downstream_port), SWIGTYPE_p_bt_port_input, 0);
if (!py_downstream_port_ptr) {
- BT_LOGF_STR("Failed to create a SWIG pointer object.");
- abort();
+ BT_LOGF_STR("Failed to create downstream port SWIG pointer object.");
+ status = BT_GRAPH_LISTENER_STATUS_NOMEM;
+ goto end;
}
- py_res = PyObject_CallFunction(py_callable, "(OO)",
- py_upstream_port_ptr, py_downstream_port_ptr);
+ py_res = PyObject_CallFunction(py_callable, "(OiOOiO)",
+ py_upstream_component_ptr, upstream_component_class_type,
+ py_upstream_port_ptr,
+ py_downstream_component_ptr, downstream_component_class_type,
+ py_downstream_port_ptr);
if (!py_res) {
bt2_py_loge_exception();
PyErr_Clear();
- } else {
- BT_ASSERT(py_res == Py_None);
+ status = BT_GRAPH_LISTENER_STATUS_ERROR;
+ goto end;
}
+
+ BT_ASSERT(py_res == Py_None);
+ status = BT_GRAPH_LISTENER_STATUS_OK;
- Py_DECREF(py_upstream_port_ptr);
- Py_DECREF(py_downstream_port_ptr);
+end:
+ Py_XDECREF(py_upstream_component_ptr);
+ Py_XDECREF(py_upstream_port_ptr);
+ Py_XDECREF(py_downstream_component_ptr);
+ Py_XDECREF(py_downstream_port_ptr);
Py_XDECREF(py_res);
+
+ return status;
}
-static void
+static bt_graph_listener_status
source_filter_component_ports_connected_listener(
const bt_component_source *source_component,
const bt_component_filter *filter_component,
const bt_port_output *upstream_port,
const bt_port_input *downstream_port, void *py_callable)
{
- ports_connected_listener(upstream_port, downstream_port, py_callable);
+ return ports_connected_listener(
+ source_component, SWIGTYPE_p_bt_component_source, BT_COMPONENT_CLASS_TYPE_SOURCE,
+ upstream_port,
+ filter_component, SWIGTYPE_p_bt_component_filter, BT_COMPONENT_CLASS_TYPE_FILTER,
+ downstream_port,
+ py_callable);
}
-static void
+static bt_graph_listener_status
source_sink_component_ports_connected_listener(
const bt_component_source *source_component,
const bt_component_sink *sink_component,
const bt_port_output *upstream_port,
const bt_port_input *downstream_port, void *py_callable)
{
- ports_connected_listener(upstream_port, downstream_port, py_callable);
+ return ports_connected_listener(
+ source_component, SWIGTYPE_p_bt_component_source, BT_COMPONENT_CLASS_TYPE_SOURCE,
+ upstream_port,
+ sink_component, SWIGTYPE_p_bt_component_sink, BT_COMPONENT_CLASS_TYPE_SINK,
+ downstream_port,
+ py_callable);
}
-static void
+static bt_graph_listener_status
filter_filter_component_ports_connected_listener(
const bt_component_filter *filter_component_left,
const bt_component_filter *filter_component_right,
const bt_port_output *upstream_port,
const bt_port_input *downstream_port, void *py_callable)
{
- ports_connected_listener(upstream_port, downstream_port, py_callable);
+ return ports_connected_listener(
+ filter_component_left, SWIGTYPE_p_bt_component_filter, BT_COMPONENT_CLASS_TYPE_FILTER,
+ upstream_port,
+ filter_component_right, SWIGTYPE_p_bt_component_filter, BT_COMPONENT_CLASS_TYPE_FILTER,
+ downstream_port,
+ py_callable);
}
-static void
+static bt_graph_listener_status
filter_sink_component_ports_connected_listener(
const bt_component_filter *filter_component,
const bt_component_sink *sink_component,
const bt_port_output *upstream_port,
const bt_port_input *downstream_port, void *py_callable)
{
- ports_connected_listener(upstream_port, downstream_port, py_callable);
+ return ports_connected_listener(
+ filter_component, SWIGTYPE_p_bt_component_filter, BT_COMPONENT_CLASS_TYPE_FILTER,
+ upstream_port,
+ sink_component, SWIGTYPE_p_bt_component_sink, BT_COMPONENT_CLASS_TYPE_SINK,
+ downstream_port,
+ py_callable);
}
-
static PyObject*
bt_py3_graph_add_ports_connected_listener(struct bt_graph *graph,
PyObject *py_callable)