bt2: add support for the "query info" API
[babeltrace.git] / bindings / python / bt2 / native_btcomponentclass.i
index a7df3a7a3e1ba5394339ad477962b87bdb0fe0e7..6acfdb6e3d0f4d9cf04c919f014000f9420ddd2d 100644 (file)
@@ -49,6 +49,11 @@ const char *bt_component_class_get_name(
                struct bt_component_class *component_class);
 const char *bt_component_class_get_description(
                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_component_class *component_class,
+               const char *action, struct bt_value *params);
 enum bt_component_class_type bt_component_class_get_type(
                struct bt_component_class *component_class);
 
@@ -558,6 +563,70 @@ static void bt_py3_cc_destroy(struct bt_component *component)
        }
 }
 
+static struct bt_value *bt_py3_cc_query_info(
+               struct bt_component_class *component_class,
+               const char *action, struct bt_value *params)
+{
+       PyObject *py_cls = NULL;
+       PyObject *py_params = NULL;
+       PyObject *py_query_info_func = NULL;
+       PyObject *py_action = NULL;
+       PyObject *py_results_addr = NULL;
+       struct bt_value *results = NULL;
+
+       py_cls = lookup_cc_ptr_to_py_cls(component_class);
+       if (!py_cls) {
+               goto error;
+       }
+
+       py_params = bt_py3_bt_value_from_ptr(params);
+       if (!py_params) {
+               goto error;
+       }
+
+       py_action = SWIG_FromCharPtr(action);
+       if (!py_action) {
+               goto error;
+       }
+
+       py_results_addr = PyObject_CallMethod(py_cls,
+               "_query_info_from_bt", "(OO)", py_action, py_params);
+       if (!py_results_addr) {
+               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) {
+               goto error;
+       }
+
+       goto end;
+
+error:
+       BT_PUT(results);
+       PyErr_Clear();
+
+end:
+       Py_XDECREF(py_params);
+       Py_XDECREF(py_query_info_func);
+       Py_XDECREF(py_action);
+       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 =
@@ -726,13 +795,14 @@ static struct bt_notification *bt_py3_cc_notification_iterator_get(
        /*
         * The returned object, on success, is an integer object
         * (PyLong) containing the address of a BT notification
-        * object (which is not ours).
+        * object (which is now ours).
         */
        notif = (struct bt_notification *) PyLong_AsUnsignedLongLong(
                py_get_method_result);
 
        /* Clear potential overflow error; should never happen */
        if (PyErr_Occurred()) {
+               notif = NULL;
                goto error;
        }
 
@@ -884,7 +954,7 @@ end:
 /* Component class creation functions (called from Python module) */
 
 static int bt_py3_cc_set_optional_attrs_methods(struct bt_component_class *cc,
-               const char *description)
+               const char *description, const char *help)
 {
        int ret = 0;
 
@@ -895,6 +965,13 @@ static int bt_py3_cc_set_optional_attrs_methods(struct bt_component_class *cc,
                }
        }
 
+       if (help) {
+               ret = bt_component_class_set_help(cc, help);
+               if (ret) {
+                       goto end;
+               }
+       }
+
        ret = bt_component_class_set_init_method(cc, bt_py3_cc_init);
        if (ret) {
                goto end;
@@ -905,6 +982,12 @@ static int bt_py3_cc_set_optional_attrs_methods(struct bt_component_class *cc,
                goto end;
        }
 
+       ret = bt_component_class_set_query_info_method(cc,
+               bt_py3_cc_query_info);
+       if (ret) {
+               goto end;
+       }
+
 end:
        return ret;
 }
@@ -943,7 +1026,7 @@ end:
 
 static struct bt_component_class *bt_py3_component_class_source_create(
                PyObject *py_cls, const char *name, const char *description,
-               bool has_seek_time)
+               const char *help, bool has_seek_time)
 {
        struct bt_component_class *cc;
        int ret;
@@ -956,7 +1039,7 @@ static struct bt_component_class *bt_py3_component_class_source_create(
                goto end;
        }
 
-       ret = bt_py3_cc_set_optional_attrs_methods(cc, description);
+       ret = bt_py3_cc_set_optional_attrs_methods(cc, description, help);
        if (ret) {
                BT_PUT(cc);
                goto end;
@@ -980,7 +1063,7 @@ end:
 
 static struct bt_component_class *bt_py3_component_class_filter_create(
                PyObject *py_cls, const char *name, const char *description,
-               bool has_seek_time)
+               const char *help, bool has_seek_time)
 {
        struct bt_component_class *cc;
        int ret;
@@ -993,7 +1076,7 @@ static struct bt_component_class *bt_py3_component_class_filter_create(
                goto end;
        }
 
-       ret = bt_py3_cc_set_optional_attrs_methods(cc, description);
+       ret = bt_py3_cc_set_optional_attrs_methods(cc, description, help);
        if (ret) {
                BT_PUT(cc);
                goto end;
@@ -1023,7 +1106,8 @@ end:
 }
 
 static struct bt_component_class *bt_py3_component_class_sink_create(
-               PyObject *py_cls, const char *name, const char *description)
+               PyObject *py_cls, const char *name, const char *description,
+               const char *help)
 {
        struct bt_component_class *cc;
        int ret;
@@ -1034,7 +1118,7 @@ static struct bt_component_class *bt_py3_component_class_sink_create(
                goto end;
        }
 
-       ret = bt_py3_cc_set_optional_attrs_methods(cc, description);
+       ret = bt_py3_cc_set_optional_attrs_methods(cc, description, help);
        if (ret) {
                BT_PUT(cc);
                goto end;
@@ -1107,12 +1191,13 @@ static void bt_py3_component_on_del(PyObject *py_comp)
 
 struct bt_component_class *bt_py3_component_class_source_create(
                PyObject *py_cls, const char *name, const char *description,
-               bool has_seek_time);
+               const char *help, bool has_seek_time);
 struct bt_component_class *bt_py3_component_class_filter_create(
                PyObject *py_cls, const char *name, const char *description,
-               bool has_seek_time);
+               const char *help, bool has_seek_time);
 struct bt_component_class *bt_py3_component_class_sink_create(
-               PyObject *py_cls, const char *name, const char *description);
+               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);
This page took 0.025534 seconds and 4 git commands to generate.