* THE SOFTWARE.
*/
-%{
-#include <babeltrace/component/component-class.h>
-#include <babeltrace/component/component-class-source.h>
-#include <babeltrace/component/component-class-sink.h>
-#include <babeltrace/component/component-class-filter.h>
-#include <babeltrace/component/notification/iterator.h>
-#include <babeltrace/component/notification/notification.h>
-#include <assert.h>
-#include <glib.h>
-%}
-
/* Types */
struct bt_component_class;
/* Status */
enum bt_component_class_type {
- BT_COMPONENT_CLASS_TYPE_UNKNOWN = -1,
- BT_COMPONENT_CLASS_TYPE_SOURCE = 0,
- BT_COMPONENT_CLASS_TYPE_SINK = 1,
- BT_COMPONENT_CLASS_TYPE_FILTER = 2,
+ BT_COMPONENT_CLASS_TYPE_UNKNOWN = -1,
+ BT_COMPONENT_CLASS_TYPE_SOURCE = 0,
+ BT_COMPONENT_CLASS_TYPE_SINK = 1,
+ BT_COMPONENT_CLASS_TYPE_FILTER = 2,
};
/* General functions */
struct bt_component_class *component_class);
const char *bt_component_class_get_help(
struct bt_component_class *component_class);
-struct bt_value *bt_component_class_query_info(
+struct bt_value *bt_component_class_query(
struct bt_component_class *component_class,
- const char *action, struct bt_value *params);
+ const char *object, struct bt_value *params);
enum bt_component_class_type bt_component_class_get_type(
struct bt_component_class *component_class);
static void register_cc_ptr_to_py_cls(struct bt_component_class *bt_cc,
PyObject *py_cls)
{
+ if (!bt_cc_ptr_to_py_cls) {
+ /*
+ * Lazy-initializing this GHashTable because GLib
+ * might not be initialized yet and it needs to be
+ * before we call g_hash_table_new()
+ */
+ BT_LOGD_STR("Creating native component class to Python component class hash table.");
+ bt_cc_ptr_to_py_cls = g_hash_table_new(g_direct_hash, g_direct_equal);
+ assert(bt_cc_ptr_to_py_cls);
+ }
+
g_hash_table_insert(bt_cc_ptr_to_py_cls, (gpointer) bt_cc,
(gpointer) py_cls);
}
static PyObject *lookup_cc_ptr_to_py_cls(struct bt_component_class *bt_cc)
{
+ if (!bt_cc_ptr_to_py_cls) {
+ BT_LOGW("Cannot look up Python component class because hash table is NULL: "
+ "comp-cls-addr=%p", bt_cc);
+ return NULL;
+ }
+
return (PyObject *) g_hash_table_lookup(bt_cc_ptr_to_py_cls,
(gconstpointer) bt_cc);
}
static PyObject *py_mod_bt2_exc_unsupported_feature_type = NULL;
static PyObject *py_mod_bt2_exc_try_again_type = NULL;
static PyObject *py_mod_bt2_exc_stop_type = NULL;
-static PyObject *py_mod_bt2_values = NULL;
-static PyObject *py_mod_bt2_values_create_from_ptr_func = NULL;
+static PyObject *py_mod_bt2_exc_port_connection_refused_type = NULL;
+static PyObject *py_mod_bt2_exc_graph_canceled_type = NULL;
+static PyObject *py_mod_bt2_exc_notif_iter_canceled_type = NULL;
+static PyObject *py_mod_bt2_exc_connection_ended_type = NULL;
static void bt_py3_cc_init_from_bt2(void)
{
*/
py_mod_bt2 = PyImport_ImportModule("bt2");
assert(py_mod_bt2);
- py_mod_bt2_values = PyImport_ImportModule("bt2.values");
- assert(py_mod_bt2_values);
- py_mod_bt2_values_create_from_ptr_func =
- PyObject_GetAttrString(py_mod_bt2_values,
- "_create_from_ptr");
- assert(py_mod_bt2_values_create_from_ptr_func);
py_mod_bt2_exc_error_type =
PyObject_GetAttrString(py_mod_bt2, "Error");
assert(py_mod_bt2_exc_error_type);
PyObject_GetAttrString(py_mod_bt2, "TryAgain");
py_mod_bt2_exc_stop_type =
PyObject_GetAttrString(py_mod_bt2, "Stop");
+ py_mod_bt2_exc_port_connection_refused_type =
+ PyObject_GetAttrString(py_mod_bt2, "PortConnectionRefused");
+ py_mod_bt2_exc_graph_canceled_type =
+ PyObject_GetAttrString(py_mod_bt2, "GraphCanceled");
+ py_mod_bt2_exc_connection_ended_type =
+ PyObject_GetAttrString(py_mod_bt2, "ConnectionEnded");
assert(py_mod_bt2_exc_stop_type);
}
* bt_py3_cc_init_from_bt2() here. The global variables continue
* to exist for the code of this file, but they are now borrowed
* references. If this code is executed, it means that somehow
- * to modules are still loaded, so it should be safe to use them
- * even without a strong reference.
+ * the modules are still loaded, so it should be safe to use
+ * them even without a strong reference.
*
* We cannot do this in the library's destructor because it
* gets executed once Python is already finalized.
*/
- Py_XDECREF(py_mod_bt2_values_create_from_ptr_func);
- Py_XDECREF(py_mod_bt2_values);
Py_XDECREF(py_mod_bt2);
Py_XDECREF(py_mod_bt2_exc_error_type);
Py_XDECREF(py_mod_bt2_exc_unsupported_feature_type);
Py_XDECREF(py_mod_bt2_exc_try_again_type);
Py_XDECREF(py_mod_bt2_exc_stop_type);
+ Py_XDECREF(py_mod_bt2_exc_port_connection_refused_type);
+ Py_XDECREF(py_mod_bt2_exc_graph_canceled_type);
+ Py_XDECREF(py_mod_bt2_exc_notif_iter_canceled_type);
+ Py_XDECREF(py_mod_bt2_exc_connection_ended_type);
}
-/* Library constructor and destructor */
-
-__attribute__((constructor))
-static void bt_py3_native_comp_class_ctor(void) {
- /* Initialize component class association hash table */
- bt_cc_ptr_to_py_cls = g_hash_table_new(g_direct_hash, g_direct_equal);
- assert(bt_cc_ptr_to_py_cls);
-}
+/* Library destructor */
__attribute__((destructor))
static void bt_py3_native_comp_class_dtor(void) {
/* Destroy component class association hash table */
if (bt_cc_ptr_to_py_cls) {
+ BT_LOGD_STR("Destroying native component class to Python component class hash table.");
g_hash_table_destroy(bt_cc_ptr_to_py_cls);
}
}
-/* Converts a BT value object to a bt2.values object */
+/* Component class proxy methods (delegate to the attached Python object) */
-static PyObject *bt_py3_bt_value_from_ptr(struct bt_value *value)
+static enum bt_notification_iterator_status bt_py3_exc_to_notif_iter_status(void)
{
- PyObject *py_create_from_ptr_func = NULL;
- PyObject *py_value = NULL;
- PyObject *py_ptr = NULL;
+ enum bt_notification_iterator_status status =
+ BT_NOTIFICATION_ITERATOR_STATUS_OK;
+ PyObject *exc = PyErr_Occurred();
- py_ptr = SWIG_NewPointerObj(SWIG_as_voidptr(value),
- SWIGTYPE_p_bt_value, 0);
- py_value = PyObject_CallFunctionObjArgs(
- py_mod_bt2_values_create_from_ptr_func, py_ptr, NULL);
- if (!py_value) {
+ if (!exc) {
goto end;
}
- /*
- * _create_from_ptr() only wraps an existing reference. `value`
- * is a borrowed reference here, so increment its reference
- * count for this new owner.
- */
- bt_get(value);
+ if (PyErr_GivenExceptionMatches(exc,
+ py_mod_bt2_exc_unsupported_feature_type)) {
+ status = BT_NOTIFICATION_ITERATOR_STATUS_UNSUPPORTED;
+ } else if (PyErr_GivenExceptionMatches(exc,
+ py_mod_bt2_exc_stop_type)) {
+ status = BT_NOTIFICATION_ITERATOR_STATUS_END;
+ } else if (PyErr_GivenExceptionMatches(exc,
+ py_mod_bt2_exc_try_again_type)) {
+ status = BT_NOTIFICATION_ITERATOR_STATUS_AGAIN;
+ } else {
+ status = BT_NOTIFICATION_ITERATOR_STATUS_ERROR;
+ }
end:
- Py_XDECREF(py_ptr);
PyErr_Clear();
- return py_value;
+ return status;
}
-
-/* self.__init__(*args, **kwargs) */
-
-static int bt_py3_call_self_init(PyObject *py_self, PyObject *py_args,
- PyObject *py_kwargs)
+static enum bt_component_status bt_py3_exc_to_component_status(void)
{
- int ret = 0;
- size_t i;
- PyObject *py_init_method_result = NULL;
- PyObject *py_init_method = NULL;
- PyObject *py_init_method_args = NULL;
- PyObject *py_class = NULL;
+ enum bt_component_status status = BT_COMPONENT_STATUS_OK;
+ PyObject *exc = PyErr_Occurred();
- py_class = PyObject_GetAttrString(py_self, "__class__");
- if (!py_class) {
- goto error;
+ if (!exc) {
+ goto end;
}
- py_init_method = PyObject_GetAttrString(py_class, "__init__");
- if (!py_init_method) {
- goto error;
+ if (PyErr_GivenExceptionMatches(exc,
+ py_mod_bt2_exc_unsupported_feature_type)) {
+ status = BT_COMPONENT_STATUS_UNSUPPORTED;
+ } else if (PyErr_GivenExceptionMatches(exc,
+ py_mod_bt2_exc_try_again_type)) {
+ status = BT_COMPONENT_STATUS_AGAIN;
+ } else if (PyErr_GivenExceptionMatches(exc,
+ py_mod_bt2_exc_stop_type)) {
+ status = BT_COMPONENT_STATUS_END;
+ } else if (PyErr_GivenExceptionMatches(exc,
+ py_mod_bt2_exc_port_connection_refused_type)) {
+ status = BT_COMPONENT_STATUS_REFUSE_PORT_CONNECTION;
+ } else {
+ status = BT_COMPONENT_STATUS_ERROR;
}
- /* Prepend py_self to the arguments (copy them to new tuple) */
- py_init_method_args = PyTuple_New(PyTuple_Size(py_args) + 1);
- if (!py_init_method_args) {
+end:
+ PyErr_Clear();
+ return status;
+}
+
+static enum bt_component_status bt_py3_cc_init(
+ struct bt_private_component *priv_comp,
+ struct bt_value *params, void *init_method_data)
+{
+ struct bt_component *comp =
+ bt_component_from_private_component(priv_comp);
+ struct bt_component_class *comp_cls = bt_component_get_class(comp);
+ enum bt_component_status status = BT_COMPONENT_STATUS_OK;
+ PyObject *py_cls = NULL;
+ PyObject *py_comp = NULL;
+ PyObject *py_params_ptr = NULL;
+ PyObject *py_comp_ptr = NULL;
+
+ (void) init_method_data;
+ assert(comp);
+ assert(comp_cls);
+
+ /*
+ * Get the user-defined Python class which created this
+ * component's class in the first place (borrowed
+ * reference).
+ */
+ py_cls = lookup_cc_ptr_to_py_cls(comp_cls);
+ if (!py_cls) {
+ BT_LOGE("Cannot find Python class associated to native component class: "
+ "comp-cls-addr=%p", comp_cls);
goto error;
}
- Py_INCREF(py_self);
- ret = PyTuple_SetItem(py_init_method_args, 0, py_self);
- if (ret < 0) {
- Py_DECREF(py_self);
+ /* Parameters pointer -> SWIG pointer Python object */
+ py_params_ptr = SWIG_NewPointerObj(SWIG_as_voidptr(params),
+ SWIGTYPE_p_bt_value, 0);
+ if (!py_params_ptr) {
+ BT_LOGE_STR("Failed to create a SWIG pointer object.");
goto error;
}
- for (i = 0; i < PyTuple_Size(py_args); i++) {
- PyObject *obj = PyTuple_GetItem(py_args, i);
- if (!obj) {
- goto error;
- }
-
- Py_INCREF(obj);
- ret = PyTuple_SetItem(py_init_method_args, i + 1, obj);
- if (ret < 0) {
- Py_DECREF(obj);
- goto error;
- }
+ /* Private component pointer -> SWIG pointer Python object */
+ py_comp_ptr = SWIG_NewPointerObj(SWIG_as_voidptr(priv_comp),
+ SWIGTYPE_p_bt_private_component, 0);
+ if (!py_comp_ptr) {
+ BT_LOGE_STR("Failed to create a SWIG pointer object.");
+ goto error;
}
- py_init_method_result = PyObject_Call(py_init_method,
- py_init_method_args, py_kwargs);
- if (!py_init_method_result) {
+ /*
+ * Do the equivalent of this:
+ *
+ * py_comp = py_cls._init_from_native(py_comp_ptr, py_params_ptr)
+ *
+ * _UserComponentType._init_from_native() calls the Python
+ * component object's __init__() function.
+ */
+ py_comp = PyObject_CallMethod(py_cls,
+ "_init_from_native", "(OO)", py_comp_ptr, py_params_ptr);
+ if (!py_comp) {
+ BT_LOGE("Failed to call Python class's _init_from_native() method: "
+ "py-cls-addr=%p", py_cls);
goto error;
}
+ /*
+ * Our user Python component object is now fully created and
+ * initialized by the user. Since we just created it, this
+ * native component is its only (persistent) owner.
+ */
+ bt_private_component_set_user_data(priv_comp, py_comp);
+ py_comp = NULL;
goto end;
error:
- ret = -1;
-
-end:
- Py_XDECREF(py_init_method_args);
- Py_XDECREF(py_init_method_result);
- Py_XDECREF(py_init_method);
- Py_XDECREF(py_class);
- return ret;
-}
-
-
-/* Component class proxy methods (delegate to the attached Python object) */
-
-static enum bt_component_status bt_py3_cc_init(
- struct bt_component *component, struct bt_value *params,
- void *init_method_data)
-{
- enum bt_component_status status = BT_COMPONENT_STATUS_OK;
- int ret;
+ status = BT_COMPONENT_STATUS_ERROR;
/*
- * This function is either called from
- * _UserComponentType.__call__() (when init_method_data contains
- * the PyObject * currently creating this component) or from
- * other code (init_method_data is NULL).
+ * Clear any exception: we're returning a bad status anyway. If
+ * this call originated from Python (creation from a plugin's
+ * component class, for example), then the user gets an
+ * appropriate creation error.
*/
- if (init_method_data) {
- /*
- * Called from _UserComponentType.__call__().
- *
- * The `params` argument is completely ignored here,
- * because if the user creating the component object
- * from the component class object wants parameters,
- * they'll be in the keyword arguments anyway.
- */
- PyObject *py_comp = init_method_data;
- PyObject *py_comp_ptr = NULL;
- PyObject *py_init_args = NULL;
- PyObject *py_init_kwargs = NULL;
+ PyErr_Clear();
- /*
- * No need to take a Python reference on py_comp here:
- * we store it as a _borrowed_ reference. When all the
- * Python references are dropped, the object's __del__()
- * method is called. This method calls this side
- * (bt_py3_component_on_del()) to swap the ownership:
- * this BT component becomes the only owner of the
- * Python object.
- */
- bt_component_set_private_data(component, py_comp);
+end:
+ bt_put(comp_cls);
+ bt_put(comp);
+ Py_XDECREF(py_comp);
+ Py_XDECREF(py_params_ptr);
+ Py_XDECREF(py_comp_ptr);
+ return status;
+}
- /*
- * Set this BT component pointer as py_comp._ptr, and
- * take a reference on it (on success, at the end).
- *
- * This reference is put in the Python component
- * object's __del__() method.
- */
- py_comp_ptr = SWIG_NewPointerObj(SWIG_as_voidptr(component),
- SWIGTYPE_p_bt_component, 0);
- if (!py_comp_ptr) {
- PyErr_Clear();
- goto with_init_method_data_error;
- }
+static void bt_py3_cc_finalize(struct bt_private_component *priv_comp)
+{
+ PyObject *py_comp = bt_private_component_get_user_data(priv_comp);
+ PyObject *py_method_result = NULL;
- ret = PyObject_SetAttrString(py_comp, "_ptr", py_comp_ptr);
- if (ret < 0) {
- PyErr_Clear();
- goto with_init_method_data_error;
- }
+ assert(py_comp);
- /*
- * _UserComponentType.__call__() puts the arguments and
- * keyword arguments to use for the py_comp.__init__()
- * call in py_comp._init_args and py_comp._init_kwargs.
- *
- * We need to get them and remove them from py_comp before
- * calling py_comp.__init__().
- */
- py_init_args = PyObject_GetAttrString(py_comp, "_init_args");
- if (!py_init_args) {
- PyErr_Clear();
- goto with_init_method_data_error;
- }
+ /* Call user's _finalize() method */
+ py_method_result = PyObject_CallMethod(py_comp,
+ "_finalize", NULL);
- py_init_kwargs = PyObject_GetAttrString(py_comp, "_init_kwargs");
- if (!py_init_kwargs) {
- PyErr_Clear();
- goto with_init_method_data_error;
- }
+ if (PyErr_Occurred()) {
+ BT_LOGW("User's _finalize() method raised an exception: ignoring.");
+ }
- ret = PyObject_DelAttrString(py_comp, "_init_args");
- if (ret < 0) {
- PyErr_Clear();
- goto with_init_method_data_error;
- }
+ /*
+ * Ignore any exception raised by the _finalize() method because
+ * it won't change anything at this point: the component is
+ * being destroyed anyway.
+ */
+ PyErr_Clear();
+ Py_XDECREF(py_method_result);
+ Py_DECREF(py_comp);
+}
- ret = PyObject_DelAttrString(py_comp, "_init_kwargs");
- if (ret < 0) {
- PyErr_Clear();
- goto with_init_method_data_error;
- }
+static enum bt_component_status bt_py3_cc_accept_port_connection(
+ struct bt_private_component *priv_comp,
+ struct bt_private_port *self_priv_port,
+ struct bt_port *other_port)
+{
+ enum bt_component_status status;
+ PyObject *py_comp = NULL;
+ PyObject *py_self_port_ptr = NULL;
+ PyObject *py_other_port_ptr = NULL;
+ PyObject *py_method_result = NULL;
- /* Ready to call py_comp.__init__() */
- ret = bt_py3_call_self_init(py_comp, py_init_args,
- py_init_kwargs);
- if (ret) {
- /*
- * We do not clear any raised exception here
- * so that the Python caller (the one who is
- * instantiating the class) gets the exception
- * from the __init__() method.
- */
- goto with_init_method_data_error;
- }
+ py_comp = bt_private_component_get_user_data(priv_comp);
+ assert(py_comp);
+ py_self_port_ptr = SWIG_NewPointerObj(SWIG_as_voidptr(self_priv_port),
+ SWIGTYPE_p_bt_private_port, 0);
+ if (!py_self_port_ptr) {
+ BT_LOGE_STR("Failed to create a SWIG pointer object.");
+ goto error;
+ }
- /*
- * py_comp.__init__() went well: get the native BT
- * component object reference for the Python object.
- */
- bt_get(component);
- goto with_init_method_data_end;
+ py_other_port_ptr = SWIG_NewPointerObj(SWIG_as_voidptr(other_port),
+ SWIGTYPE_p_bt_port, 0);
+ if (!py_other_port_ptr) {
+ BT_LOGE_STR("Failed to create a SWIG pointer object.");
+ goto error;
+ }
-with_init_method_data_error:
- status = BT_COMPONENT_STATUS_ERROR;
+ py_method_result = PyObject_CallMethod(py_comp,
+ "_accept_port_connection_from_native", "(OO)", py_self_port_ptr,
+ py_other_port_ptr);
+ status = bt_py3_exc_to_component_status();
+ if (!py_method_result && status == BT_COMPONENT_STATUS_OK) {
+ /* Pretty sure this should never happen, but just in case */
+ BT_LOGE("User's _accept_port_connection() method failed without raising an exception: "
+ "status=%d", status);
+ goto error;
+ }
+ if (status == BT_COMPONENT_STATUS_REFUSE_PORT_CONNECTION) {
/*
- * Reset py_comp._ptr to None to signal the error to
- * _UserComponentType.__call__(). For exceptions raised
- * from py_comp.__init__(), this is not important,
- * because __call__() will also raise before even
- * checking py_comp._ptr.
+ * Looks like the user method raised
+ * PortConnectionRefused: accept this like if it
+ * returned False.
*/
- if (PyObject_HasAttrString(py_comp, "_ptr")) {
- PyObject *py_err_type, *py_err_value, *py_err_traceback;
- PyErr_Fetch(&py_err_type, &py_err_value,
- &py_err_traceback);
- Py_INCREF(Py_None);
- PyObject_SetAttrString(py_comp, "_ptr", Py_None);
- PyErr_Restore(py_err_type, py_err_value,
- py_err_traceback);
- }
+ goto end;
+ } else if (status != BT_COMPONENT_STATUS_OK) {
+ BT_LOGE("User's _accept_port_connection() raised an unexpected exception: "
+ "status=%d", status);
+ goto error;
+ }
- /*
- * Important: remove py_comp from our the BT component's
- * private data. Since we're failing,
- * bt_py3_cc_destroy() is about to be called: it must
- * not consider py_comp. py_comp's __del__() method
- * will be called (because the instance exists), but
- * since py_comp._ptr is None, it won't do anything.
- */
- bt_component_set_private_data(component, NULL);
+ assert(PyBool_Check(py_method_result));
-with_init_method_data_end:
- Py_XDECREF(py_comp_ptr);
- Py_XDECREF(py_init_args);
- Py_XDECREF(py_init_kwargs);
+ if (py_method_result == Py_True) {
+ status = BT_COMPONENT_STATUS_OK;
} else {
- /*
- * Not called from _UserComponentType.__call__().
- *
- * In this case we need to instantiate the user-defined
- * Python class. To do this we call the user-defined
- * class manually with this already-created BT component
- * object pointer as the __comp_ptr keyword argument.
- *
- * We keep a reference, the only existing one, to the
- * created Python object. bt_py3_component_on_del() will
- * never be called by the object's __del__() method
- * because _UserComponentType.__call__() marks the
- * object as owned by the native BT component object.
- */
- PyObject *py_cls = NULL;
- PyObject *py_comp = NULL;
- PyObject *py_params = NULL;
- PyObject *py_comp_ptr = NULL;
- PyObject *py_cls_ctor_args = NULL;
- PyObject *py_cls_ctor_kwargs = NULL;
-
- /*
- * Get the user-defined Python class which created this
- * component's class in the first place (borrowed
- * reference).
- */
- py_cls = lookup_cc_ptr_to_py_cls(bt_component_get_class(component));
- if (!py_cls) {
- goto without_init_method_data_error;
- }
-
- /* BT value object -> Python bt2.values object */
- py_params = bt_py3_bt_value_from_ptr(params);
- if (!py_params) {
- goto without_init_method_data_error;
- }
-
- /* Component pointer -> SWIG pointer Python object */
- py_comp_ptr = SWIG_NewPointerObj(SWIG_as_voidptr(component),
- SWIGTYPE_p_bt_component, 0);
- if (!py_comp_ptr) {
- goto without_init_method_data_error;
- }
-
- /*
- * Do the equivalent of this:
- *
- * py_comp = py_cls(__comp_ptr=py_comp_ptr, params=py_params)
- *
- * _UserComponentType.__call__() calls the Python
- * component object's __init__() function itself in this
- * case.
- */
- py_cls_ctor_args = PyTuple_New(0);
- if (!py_cls_ctor_args) {
- goto without_init_method_data_error;
- }
-
- py_cls_ctor_kwargs = PyDict_New();
- if (!py_cls_ctor_kwargs) {
- goto without_init_method_data_error;
- }
-
- ret = PyDict_SetItemString(py_cls_ctor_kwargs, "__comp_ptr",
- py_comp_ptr);
- if (ret < 0) {
- goto without_init_method_data_error;
- }
-
- ret = PyDict_SetItemString(py_cls_ctor_kwargs, "params",
- py_params);
- if (ret < 0) {
- goto without_init_method_data_error;
- }
-
- py_comp = PyObject_Call(py_cls, py_cls_ctor_args,
- py_cls_ctor_kwargs);
- if (!py_comp) {
- goto without_init_method_data_error;
- }
+ status = BT_COMPONENT_STATUS_REFUSE_PORT_CONNECTION;
+ }
- /*
- * Our user Python component object is now fully created
- * and initialized by the user. Since we just created
- * it, this BT component is its only (persistent) owner.
- */
- bt_component_set_private_data(component, py_comp);
- py_comp = NULL;
- goto without_init_method_data_end;
+ goto end;
-without_init_method_data_error:
- status = BT_COMPONENT_STATUS_ERROR;
+error:
+ status = BT_COMPONENT_STATUS_ERROR;
- /*
- * Clear any exception: we're returning a bad status
- * anyway. If this call originated from Python (creation
- * from a plugin's component class, for example), then
- * the user gets an appropriate creation error.
- */
- PyErr_Clear();
-
-without_init_method_data_end:
- Py_XDECREF(py_comp);
- Py_XDECREF(py_params);
- Py_XDECREF(py_comp_ptr);
- Py_XDECREF(py_cls_ctor_args);
- Py_XDECREF(py_cls_ctor_kwargs);
- }
+ /*
+ * Clear any exception: we're returning a bad status anyway. If
+ * this call originated from Python, then the user gets an
+ * appropriate error.
+ */
+ PyErr_Clear();
+end:
+ Py_XDECREF(py_self_port_ptr);
+ Py_XDECREF(py_other_port_ptr);
+ Py_XDECREF(py_method_result);
return status;
}
-static void bt_py3_cc_destroy(struct bt_component *component)
+static void bt_py3_cc_port_connected(
+ struct bt_private_component *priv_comp,
+ struct bt_private_port *self_priv_port,
+ struct bt_port *other_port)
{
- PyObject *py_comp = bt_component_get_private_data(component);
- PyObject *py_destroy_method_result = NULL;
+ PyObject *py_comp = NULL;
+ PyObject *py_self_port_ptr = NULL;
+ PyObject *py_other_port_ptr = NULL;
+ PyObject *py_method_result = NULL;
- if (py_comp) {
- /*
- * If we're here, this BT component is the only owner of
- * its private user Python object. It is safe to
- * decrement its reference count, and thus destroy it.
- *
- * We call its _destroy() method before doing so to notify
- * the Python user.
- */
- py_destroy_method_result = PyObject_CallMethod(py_comp,
- "_destroy", NULL);
+ py_comp = bt_private_component_get_user_data(priv_comp);
+ assert(py_comp);
+ py_self_port_ptr = SWIG_NewPointerObj(SWIG_as_voidptr(self_priv_port),
+ SWIGTYPE_p_bt_private_port, 0);
+ if (!py_self_port_ptr) {
+ BT_LOGF_STR("Failed to create a SWIG pointer object.");
+ abort();
+ }
+
+ py_other_port_ptr = SWIG_NewPointerObj(SWIG_as_voidptr(other_port),
+ SWIGTYPE_p_bt_port, 0);
+ if (!py_other_port_ptr) {
+ BT_LOGF_STR("Failed to create a SWIG pointer object.");
+ abort();
+ }
+
+ py_method_result = PyObject_CallMethod(py_comp,
+ "_port_connected_from_native", "(OO)", py_self_port_ptr,
+ py_other_port_ptr);
+ assert(py_method_result == Py_None);
+ Py_XDECREF(py_self_port_ptr);
+ Py_XDECREF(py_other_port_ptr);
+ Py_XDECREF(py_method_result);
+}
- /*
- * Ignore any exception raised by the _destroy() method
- * because it won't change anything at this point: the
- * component is being destroyed anyway.
- */
- PyErr_Clear();
- Py_XDECREF(py_destroy_method_result);
- Py_DECREF(py_comp);
- }
+static void bt_py3_cc_port_disconnected(
+ struct bt_private_component *priv_comp,
+ struct bt_private_port *priv_port)
+{
+ PyObject *py_comp = NULL;
+ PyObject *py_port_ptr = NULL;
+ PyObject *py_method_result = NULL;
+
+ py_comp = bt_private_component_get_user_data(priv_comp);
+ assert(py_comp);
+ py_port_ptr = SWIG_NewPointerObj(SWIG_as_voidptr(priv_port),
+ SWIGTYPE_p_bt_private_port, 0);
+ if (!py_port_ptr) {
+ BT_LOGF_STR("Failed to create a SWIG pointer object.");
+ abort();
+ }
+
+ py_method_result = PyObject_CallMethod(py_comp,
+ "_port_disconnected_from_native", "(O)", py_port_ptr);
+ assert(py_method_result == Py_None);
+ Py_XDECREF(py_port_ptr);
+ Py_XDECREF(py_method_result);
}
-static struct bt_value *bt_py3_cc_query_info(
- struct bt_component_class *component_class,
- const char *action, struct bt_value *params)
+static struct bt_value *bt_py3_cc_query(
+ struct bt_component_class *comp_cls,
+ const char *object, struct bt_value *params)
{
PyObject *py_cls = NULL;
- PyObject *py_params = NULL;
- PyObject *py_query_info_func = NULL;
- PyObject *py_action = NULL;
+ PyObject *py_params_ptr = NULL;
+ PyObject *py_query_func = NULL;
+ PyObject *py_object = NULL;
PyObject *py_results_addr = NULL;
struct bt_value *results = NULL;
- py_cls = lookup_cc_ptr_to_py_cls(component_class);
+ py_cls = lookup_cc_ptr_to_py_cls(comp_cls);
if (!py_cls) {
+ BT_LOGE("Cannot find Python class associated to native component class: "
+ "comp-cls-addr=%p", comp_cls);
goto error;
}
- py_params = bt_py3_bt_value_from_ptr(params);
- if (!py_params) {
+ py_params_ptr = SWIG_NewPointerObj(SWIG_as_voidptr(params),
+ SWIGTYPE_p_bt_value, 0);
+ if (!py_params_ptr) {
+ BT_LOGE_STR("Failed to create a SWIG pointer object.");
goto error;
}
- py_action = SWIG_FromCharPtr(action);
- if (!py_action) {
+ py_object = SWIG_FromCharPtr(object);
+ if (!py_object) {
+ BT_LOGE_STR("Failed to create a Python string.");
goto error;
}
py_results_addr = PyObject_CallMethod(py_cls,
- "_query_info_from_bt", "(OO)", py_action, py_params);
- if (!py_results_addr) {
+ "_query_from_native", "(OO)", py_object, py_params_ptr);
+ if (!py_results_addr || py_results_addr == Py_None) {
+ BT_LOGE_STR("User's _query() method failed.");
goto error;
}
- /*
- * The returned object, on success, is an integer object
- * (PyLong) containing the address of a BT value object
- * (which is now ours).
- */
- results = (struct bt_value *) PyLong_AsUnsignedLongLong(
- py_results_addr);
-
- /* Clear potential overflow error; should never happen */
- if (PyErr_Occurred()) {
- results = NULL;
- goto error;
- }
-
- if (!results) {
+ if (py_results_addr == Py_NotImplemented) {
+ BT_LOGE_STR("User's _query() method is not implemented.");
goto error;
}
+ /*
+ * The returned object, on success, is an integer object
+ * (PyLong) containing the address of a BT value object (new
+ * reference).
+ */
+ results = (void *) PyLong_AsUnsignedLongLong(py_results_addr);
+ assert(!PyErr_Occurred());
+ assert(results);
goto end;
error:
PyErr_Clear();
end:
- Py_XDECREF(py_params);
- Py_XDECREF(py_query_info_func);
- Py_XDECREF(py_action);
+ Py_XDECREF(py_params_ptr);
+ Py_XDECREF(py_query_func);
+ Py_XDECREF(py_object);
Py_XDECREF(py_results_addr);
return results;
}
-static enum bt_notification_iterator_status bt_py3_exc_to_notif_iter_status(void)
-{
- enum bt_notification_iterator_status status =
- BT_NOTIFICATION_ITERATOR_STATUS_OK;
- PyObject *exc = PyErr_Occurred();
-
- if (!exc) {
- goto end;
- }
-
- if (PyErr_GivenExceptionMatches(exc,
- py_mod_bt2_exc_unsupported_feature_type)) {
- status = BT_NOTIFICATION_ITERATOR_STATUS_UNSUPPORTED;
- } else if (PyErr_GivenExceptionMatches(exc,
- py_mod_bt2_exc_stop_type)) {
- status = BT_NOTIFICATION_ITERATOR_STATUS_END;
- } else {
- status = BT_NOTIFICATION_ITERATOR_STATUS_ERROR;
- }
-
-end:
- PyErr_Clear();
- return status;
-}
-
static enum bt_notification_iterator_status bt_py3_cc_notification_iterator_init(
- struct bt_component *component,
- struct bt_notification_iterator *iter, void *init_method_data)
+ struct bt_private_notification_iterator *priv_notif_iter,
+ struct bt_private_port *priv_port)
{
enum bt_notification_iterator_status status =
BT_NOTIFICATION_ITERATOR_STATUS_OK;
PyObject *py_iter_ptr = NULL;
PyObject *py_init_method_result = NULL;
PyObject *py_iter = NULL;
- PyObject *py_comp = bt_component_get_private_data(component);
+ struct bt_private_component *priv_comp =
+ bt_private_notification_iterator_get_private_component(
+ priv_notif_iter);
+ PyObject *py_comp;
+
+ assert(priv_comp);
+ py_comp = bt_private_component_get_user_data(priv_comp);
/* Find user's Python notification iterator class */
py_comp_cls = PyObject_GetAttrString(py_comp, "__class__");
if (!py_comp_cls) {
+ BT_LOGE_STR("Cannot get Python object's `__class__` attribute.");
goto error;
}
py_iter_cls = PyObject_GetAttrString(py_comp_cls, "_iter_cls");
if (!py_iter_cls) {
+ BT_LOGE_STR("Cannot get Python class's `_iter_cls` attribute.");
+ goto error;
+ }
+
+ py_iter_ptr = SWIG_NewPointerObj(SWIG_as_voidptr(priv_notif_iter),
+ SWIGTYPE_p_bt_private_notification_iterator, 0);
+ if (!py_iter_ptr) {
+ BT_LOGE_STR("Failed to create a SWIG pointer object.");
goto error;
}
/*
- * Create object with borrowed BT notification iterator
+ * Create object with borrowed native notification iterator
* reference:
*
* py_iter = py_iter_cls.__new__(py_iter_cls, py_iter_ptr)
*/
- py_iter_ptr = SWIG_NewPointerObj(SWIG_as_voidptr(iter),
- SWIGTYPE_p_bt_notification_iterator, 0);
- if (!py_iter_ptr) {
- goto error;
- }
-
py_iter = PyObject_CallMethod(py_iter_cls, "__new__",
"(OO)", py_iter_cls, py_iter_ptr);
if (!py_iter) {
+ BT_LOGE("Failed to call Python class's __new__() method: "
+ "py-cls-addr=%p", py_iter_cls);
goto error;
}
* py_iter.__init__()
*
* At this point, py_iter._ptr is set, so this initialization
- * function has access to the py_iter.component property (which
- * gives it the user Python component object from which the
- * iterator was created).
+ * function has access to self._component (which gives it the
+ * user Python component object from which the iterator was
+ * created).
*/
py_init_method_result = PyObject_CallMethod(py_iter, "__init__", NULL);
if (!py_init_method_result) {
+ BT_LOGE_STR("User's __init__() method failed.");
goto error;
}
/*
* Since the Python code can never instantiate a user-defined
- * notification iterator class, the BT notification iterator
+ * notification iterator class, the native notification iterator
* object does NOT belong to a user Python notification iterator
* object (borrowed reference). However this Python object is
- * owned by this BT notification iterator object.
+ * owned by this native notification iterator object.
*
- * In the Python world, the lifetime of the BT notification
+ * In the Python world, the lifetime of the native notification
* iterator is managed by a _GenericNotificationIterator
* instance:
*
* _GenericNotificationIterator instance:
* owns a native bt_notification_iterator object (iter)
- * owns a UserNotificationIterator instance (py_iter)
+ * owns a _UserNotificationIterator instance (py_iter)
* self._ptr is a borrowed reference to the
- * native bt_notification_iterator object (iter)
+ * native bt_private_notification_iterator
+ * object (iter)
*/
- bt_notification_iterator_set_private_data(iter, py_iter);
+ bt_private_notification_iterator_set_user_data(priv_notif_iter,
+ py_iter);
py_iter = NULL;
goto end;
PyErr_Clear();
end:
+ bt_put(priv_comp);
Py_XDECREF(py_comp_cls);
Py_XDECREF(py_iter_cls);
Py_XDECREF(py_iter_ptr);
return status;
}
-static void bt_py3_cc_notification_iterator_destroy(
- struct bt_notification_iterator *iter)
+static void bt_py3_cc_notification_iterator_finalize(
+ struct bt_private_notification_iterator *priv_notif_iter)
{
PyObject *py_notif_iter =
- bt_notification_iterator_get_private_data(iter);
- PyObject *py_destroy_method_result = NULL;
+ bt_private_notification_iterator_get_user_data(priv_notif_iter);
+ PyObject *py_method_result = NULL;
assert(py_notif_iter);
- py_destroy_method_result = PyObject_CallMethod(py_notif_iter,
- "_destroy", NULL);
+
+ /* Call user's _finalize() method */
+ py_method_result = PyObject_CallMethod(py_notif_iter,
+ "_finalize", NULL);
+
+ if (PyErr_Occurred()) {
+ BT_LOGW("User's _finalize() method raised an exception: ignoring.");
+ }
/*
- * Ignore any exception raised by the _destroy() method because
- * it won't change anything at this point. The notification
- * iterator is being destroyed anyway.
+ * Ignore any exception raised by the _finalize() method because
+ * it won't change anything at this point: the component is
+ * being destroyed anyway.
*/
PyErr_Clear();
- Py_XDECREF(py_destroy_method_result);
+ Py_XDECREF(py_method_result);
Py_DECREF(py_notif_iter);
}
-static struct bt_notification *bt_py3_cc_notification_iterator_get(
- struct bt_notification_iterator *iter)
+static struct bt_notification_iterator_next_return
+bt_py3_cc_notification_iterator_next(
+ struct bt_private_notification_iterator *priv_notif_iter)
{
+ struct bt_notification_iterator_next_return next_ret = {
+ .status = BT_NOTIFICATION_ITERATOR_STATUS_OK,
+ .notification = NULL,
+ };
PyObject *py_notif_iter =
- bt_notification_iterator_get_private_data(iter);
- PyObject *py_get_method_result = NULL;
- struct bt_notification *notif = NULL;
+ bt_private_notification_iterator_get_user_data(priv_notif_iter);
+ PyObject *py_method_result = NULL;
assert(py_notif_iter);
- py_get_method_result = PyObject_CallMethod(py_notif_iter,
- "_get_from_bt", NULL);
- if (!py_get_method_result) {
- goto error;
+ py_method_result = PyObject_CallMethod(py_notif_iter,
+ "_next_from_native", NULL);
+ if (!py_method_result) {
+ next_ret.status = bt_py3_exc_to_notif_iter_status();
+ assert(next_ret.status != BT_NOTIFICATION_ITERATOR_STATUS_OK);
+ goto end;
}
/*
* The returned object, on success, is an integer object
- * (PyLong) containing the address of a BT notification
+ * (PyLong) containing the address of a native notification
* object (which is now ours).
*/
- notif = (struct bt_notification *) PyLong_AsUnsignedLongLong(
- py_get_method_result);
+ next_ret.notification =
+ (struct bt_notification *) PyLong_AsUnsignedLongLong(
+ py_method_result);
/* Clear potential overflow error; should never happen */
- if (PyErr_Occurred()) {
- notif = NULL;
- goto error;
- }
-
- if (!notif) {
- goto error;
- }
-
+ assert(!PyErr_Occurred());
+ assert(next_ret.notification);
goto end;
-error:
- BT_PUT(notif);
-
- /*
- * Clear any exception: we're returning NULL anyway. If this
- * call originated from Python, then the user gets an
- * appropriate error.
- */
- PyErr_Clear();
-
end:
- Py_XDECREF(py_get_method_result);
- return notif;
-}
-
-static enum bt_notification_iterator_status bt_py3_cc_notification_iterator_next(
- struct bt_notification_iterator *iter)
-{
- enum bt_notification_iterator_status status;
- PyObject *py_notif_iter =
- bt_notification_iterator_get_private_data(iter);
- PyObject *py_next_method_result = NULL;
-
- assert(py_notif_iter);
- py_next_method_result = PyObject_CallMethod(py_notif_iter,
- "_next", NULL);
- status = bt_py3_exc_to_notif_iter_status();
- if (!py_next_method_result
- && status == BT_NOTIFICATION_ITERATOR_STATUS_OK) {
- /* Pretty sure this should never happen, but just in case */
- status = BT_NOTIFICATION_ITERATOR_STATUS_ERROR;
- }
-
- Py_XDECREF(py_next_method_result);
- return status;
-}
-
-static enum bt_notification_iterator_status bt_py3_cc_notification_iterator_seek_time(
- struct bt_notification_iterator *iter, int64_t time)
-{
- enum bt_notification_iterator_status status;
- PyObject *py_notif_iter =
- bt_notification_iterator_get_private_data(iter);
- PyObject *py_seek_to_time_method_result = NULL;
-
- assert(py_notif_iter);
- py_seek_to_time_method_result = PyObject_CallMethod(py_notif_iter,
- "_seek_to_time", "(L)", time);
- status = bt_py3_exc_to_notif_iter_status();
- if (!py_seek_to_time_method_result
- && status == BT_NOTIFICATION_ITERATOR_STATUS_OK) {
- /* Pretty sure this should never happen, but just in case */
- status = BT_NOTIFICATION_ITERATOR_STATUS_ERROR;
- }
-
- Py_XDECREF(py_seek_to_time_method_result);
- return status;
-}
-
-static enum bt_component_status bt_py3_exc_to_component_status(void)
-{
- enum bt_component_status status = BT_COMPONENT_STATUS_OK;
- PyObject *exc = PyErr_Occurred();
-
- if (!exc) {
- goto end;
- }
-
- if (PyErr_GivenExceptionMatches(exc,
- py_mod_bt2_exc_unsupported_feature_type)) {
- status = BT_COMPONENT_STATUS_UNSUPPORTED;
- } else if (PyErr_GivenExceptionMatches(exc,
- py_mod_bt2_exc_try_again_type)) {
- status = BT_COMPONENT_STATUS_AGAIN;
- } else if (PyErr_GivenExceptionMatches(exc,
- py_mod_bt2_exc_stop_type)) {
- status = BT_COMPONENT_STATUS_END;
- } else {
- status = BT_COMPONENT_STATUS_ERROR;
- }
-
-end:
- PyErr_Clear();
- return status;
+ Py_XDECREF(py_method_result);
+ return next_ret;
}
static enum bt_component_status bt_py3_cc_sink_consume(
- struct bt_component *component)
+ struct bt_private_component *priv_comp)
{
- PyObject *py_comp = bt_component_get_private_data(component);
- PyObject *py_consume_method_result = NULL;
+ PyObject *py_comp = bt_private_component_get_user_data(priv_comp);
+ PyObject *py_method_result = NULL;
enum bt_component_status status;
- py_consume_method_result = PyObject_CallMethod(py_comp,
+ assert(py_comp);
+ py_method_result = PyObject_CallMethod(py_comp,
"_consume", NULL);
status = bt_py3_exc_to_component_status();
- if (!py_consume_method_result && status == BT_COMPONENT_STATUS_OK) {
- /* Pretty sure this should never happen, but just in case */
- status = BT_COMPONENT_STATUS_ERROR;
- }
-
- Py_XDECREF(py_consume_method_result);
- return status;
-}
-
-static enum bt_component_status bt_py3_cc_sink_filter_add_iterator(
- struct bt_component *component,
- struct bt_notification_iterator *iter)
-{
- PyObject *py_comp = bt_component_get_private_data(component);
- PyObject *py_add_iterator_method_result = NULL;
- PyObject *py_notif_iter_ptr = NULL;
- enum bt_component_status status;
-
- py_notif_iter_ptr = SWIG_NewPointerObj(SWIG_as_voidptr(iter),
- SWIGTYPE_p_bt_notification_iterator, 0);
- if (!py_notif_iter_ptr) {
- PyErr_Clear();
- status = BT_COMPONENT_STATUS_ERROR;
- goto end;
- }
-
- bt_get(iter);
- py_add_iterator_method_result = PyObject_CallMethod(py_comp,
- "_add_iterator_from_bt", "(O)", py_notif_iter_ptr);
- status = bt_py3_exc_to_component_status();
- if (!py_add_iterator_method_result
- && status == BT_COMPONENT_STATUS_OK) {
+ if (!py_method_result && status == BT_COMPONENT_STATUS_OK) {
/* Pretty sure this should never happen, but just in case */
+ BT_LOGE("User's _consume() method failed without raising an exception: "
+ "status=%d", status);
status = BT_COMPONENT_STATUS_ERROR;
}
-end:
- Py_XDECREF(py_notif_iter_ptr);
- Py_XDECREF(py_add_iterator_method_result);
+ Py_XDECREF(py_method_result);
return status;
}
if (description) {
ret = bt_component_class_set_description(cc, description);
if (ret) {
+ BT_LOGE("Cannot set component class's description: "
+ "comp-cls-addr=%p", cc);
goto end;
}
}
if (help) {
ret = bt_component_class_set_help(cc, help);
if (ret) {
+ BT_LOGE("Cannot set component class's help text: "
+ "comp-cls-addr=%p", cc);
goto end;
}
}
ret = bt_component_class_set_init_method(cc, bt_py3_cc_init);
- if (ret) {
- goto end;
- }
-
- ret = bt_component_class_set_destroy_method(cc, bt_py3_cc_destroy);
- if (ret) {
- goto end;
- }
-
- ret = bt_component_class_set_query_info_method(cc,
- bt_py3_cc_query_info);
- if (ret) {
- goto end;
- }
+ assert(ret == 0);
+ ret = bt_component_class_set_finalize_method(cc, bt_py3_cc_finalize);
+ assert(ret == 0);
+ ret = bt_component_class_set_accept_port_connection_method(cc,
+ bt_py3_cc_accept_port_connection);
+ assert(ret == 0);
+ ret = bt_component_class_set_port_connected_method(cc,
+ bt_py3_cc_port_connected);
+ assert(ret == 0);
+ ret = bt_component_class_set_port_disconnected_method(cc,
+ bt_py3_cc_port_disconnected);
+ assert(ret == 0);
+ ret = bt_component_class_set_query_method(cc, bt_py3_cc_query);
+ assert(ret == 0);
end:
return ret;
}
-static int bt_py3_cc_set_optional_iter_methods(struct bt_component_class *cc,
- bool has_seek_time,
+static void bt_py3_cc_set_optional_iter_methods(struct bt_component_class *cc,
int (*set_notif_iter_init_method)(struct bt_component_class *, bt_component_class_notification_iterator_init_method),
- int (*set_notif_iter_destroy_method)(struct bt_component_class *, bt_component_class_notification_iterator_destroy_method),
- int (*set_notif_iter_seek_time_method)(struct bt_component_class *, bt_component_class_notification_iterator_seek_time_method))
+ int (*set_notif_iter_finalize_method)(struct bt_component_class *, bt_component_class_notification_iterator_finalize_method))
{
int ret;
ret = set_notif_iter_init_method(
cc, bt_py3_cc_notification_iterator_init);
- if (ret) {
- goto end;
- }
-
- ret = set_notif_iter_destroy_method(
- cc, bt_py3_cc_notification_iterator_destroy);
- if (ret) {
- goto end;
- }
-
- if (has_seek_time) {
- ret = set_notif_iter_seek_time_method(
- cc, bt_py3_cc_notification_iterator_seek_time);
- if (ret) {
- goto end;
- }
- }
-
-end:
- return ret;
+ assert(ret == 0);
+ ret = set_notif_iter_finalize_method(
+ cc, bt_py3_cc_notification_iterator_finalize);
+ assert(ret == 0);
}
static struct bt_component_class *bt_py3_component_class_source_create(
PyObject *py_cls, const char *name, const char *description,
- const char *help, bool has_seek_time)
+ const char *help)
{
struct bt_component_class *cc;
int ret;
assert(py_cls);
cc = bt_component_class_source_create(name,
- bt_py3_cc_notification_iterator_get,
bt_py3_cc_notification_iterator_next);
if (!cc) {
+ BT_LOGE_STR("Cannot create source component class.");
goto end;
}
ret = bt_py3_cc_set_optional_attrs_methods(cc, description, help);
if (ret) {
+ BT_LOGE_STR("Cannot set source component class's optional attributes and methods.");
BT_PUT(cc);
goto end;
}
- ret = bt_py3_cc_set_optional_iter_methods(cc, has_seek_time,
+ bt_py3_cc_set_optional_iter_methods(cc,
bt_component_class_source_set_notification_iterator_init_method,
- bt_component_class_source_set_notification_iterator_destroy_method,
- bt_component_class_source_set_notification_iterator_seek_time_method);
- if (ret) {
- BT_PUT(cc);
- goto end;
- }
-
+ bt_component_class_source_set_notification_iterator_finalize_method);
register_cc_ptr_to_py_cls(cc, py_cls);
bt_component_class_freeze(cc);
static struct bt_component_class *bt_py3_component_class_filter_create(
PyObject *py_cls, const char *name, const char *description,
- const char *help, bool has_seek_time)
+ const char *help)
{
struct bt_component_class *cc;
int ret;
assert(py_cls);
cc = bt_component_class_filter_create(name,
- bt_py3_cc_notification_iterator_get,
bt_py3_cc_notification_iterator_next);
if (!cc) {
+ BT_LOGE_STR("Cannot create filter component class.");
goto end;
}
ret = bt_py3_cc_set_optional_attrs_methods(cc, description, help);
if (ret) {
+ BT_LOGE_STR("Cannot set filter component class's optional attributes and methods.");
BT_PUT(cc);
goto end;
}
- ret = bt_py3_cc_set_optional_iter_methods(cc, has_seek_time,
+ bt_py3_cc_set_optional_iter_methods(cc,
bt_component_class_filter_set_notification_iterator_init_method,
- bt_component_class_filter_set_notification_iterator_destroy_method,
- bt_component_class_filter_set_notification_iterator_seek_time_method);
- if (ret) {
- BT_PUT(cc);
- goto end;
- }
-
- ret = bt_component_class_filter_set_add_iterator_method(cc,
- bt_py3_cc_sink_filter_add_iterator);
- if (ret) {
- BT_PUT(cc);
- goto end;
- }
-
+ bt_component_class_filter_set_notification_iterator_finalize_method);
register_cc_ptr_to_py_cls(cc, py_cls);
bt_component_class_freeze(cc);
assert(py_cls);
cc = bt_component_class_sink_create(name, bt_py3_cc_sink_consume);
if (!cc) {
+ BT_LOGE_STR("Cannot create sink component class.");
goto end;
}
ret = bt_py3_cc_set_optional_attrs_methods(cc, description, help);
if (ret) {
- BT_PUT(cc);
- goto end;
- }
-
- ret = bt_component_class_sink_set_add_iterator_method(cc,
- bt_py3_cc_sink_filter_add_iterator);
- if (ret) {
+ BT_LOGE_STR("Cannot set sink component class's optional attributes and methods.");
BT_PUT(cc);
goto end;
}
end:
return cc;
}
-
-
-/* Component creation function (called from Python module) */
-
-static void bt_py3_component_create(
- struct bt_component_class *comp_class, PyObject *py_self,
- const char *name)
-{
- struct bt_component *component =
- bt_component_create_with_init_method_data(comp_class,
- name, NULL, py_self);
-
- /*
- * Our component initialization function, bt_py3_cc_init(), sets
- * a new reference to the created component in the user's Python
- * object (py_self._ptr). This is where the reference is kept.
- * We don't need the returned component in this case (if any,
- * because it might be NULL if the creation failed, most
- * probably because py_self.__init__() raised something).
- */
- bt_put(component);
-}
-
-
-/* Component delete notification */
-
-static void bt_py3_component_on_del(PyObject *py_comp)
-{
- /*
- * The Python component's __del__() function calls this to
- * indicate that there's no more reference on it from the
- * Python world.
- *
- * Since the BT component can continue to live once the Python
- * component object is deleted, we increment the Python
- * component's reference count so that it now only belong to the
- * BT component. We will decrement this reference count once
- * the BT component is destroyed in bt_py3_cc_destroy().
- */
- assert(py_comp);
- Py_INCREF(py_comp);
-}
%}
-%exception bt_py3_component_create {
- $action
- if (PyErr_Occurred()) {
- /* Exception is already set by bt_py3_component_create() */
- SWIG_fail;
- }
-}
-
struct bt_component_class *bt_py3_component_class_source_create(
PyObject *py_cls, const char *name, const char *description,
- const char *help, bool has_seek_time);
+ const char *help);
struct bt_component_class *bt_py3_component_class_filter_create(
PyObject *py_cls, const char *name, const char *description,
- const char *help, bool has_seek_time);
+ const char *help);
struct bt_component_class *bt_py3_component_class_sink_create(
PyObject *py_cls, const char *name, const char *description,
const char *help);
-void bt_py3_component_create(
- struct bt_component_class *comp_class, PyObject *py_self,
- const char *name);
-void bt_py3_component_on_del(PyObject *py_comp);
void bt_py3_cc_init_from_bt2(void);
void bt_py3_cc_exit_handler(void);