lib, bt2: make query method receive custom data
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Tue, 6 Aug 2019 00:31:35 +0000 (20:31 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Tue, 6 Aug 2019 20:17:46 +0000 (16:17 -0400)
commit7c14d64103ff43ddeb43aaa04df17beb107f1f78
tree87a298e66935d7ff53a37782fd058442f6e51c26
parent8c20dd54512444781307a70f88c51ab60ba6cb2d
lib, bt2: make query method receive custom data

Just like a component class initialization method can receive custom
user data (`init_method_data`) along with generic parameters, this patch
makes this possible for a query operation.

Library changes
===============
On the library side, this patch introduces the new
bt_query_executor_create_with_method_data() function which is like
bt_query_executor_create(), but accepts a `void *` user data parameter.

Internally, bt_query_executor_create() calls
bt_query_executor_create_with_method_data() with `NULL` as the
`method_data` parameter.

The component class query method type is changed to:

    typedef bt_component_class_query_method_status
    (*bt_component_class_*_query_method)(
        bt_self_component_class_* *comp_class,
        bt_private_query_executor *query_executor,
        const char *object, const bt_value *params,
        void *method_data, const bt_value **result);

The component class is guaranteed, for a given query executor, to always
being passed the same `method_data` value to its query method.

Python bindings changes
=======================
QueryExecutor.__init__() accepts a new, optional `method_obj` parameter
which defaults to `None`.

`None` gets translated to `NULL` as the `method_data` parameter, and
vice versa when a Python query method is called from the native part.

QueryExecutor.__init__() validates that you can only pass a Python
method object when the component class you query is a Python component
class.

Because you build the query executor and then make a query operation in
two steps, a Python reference to the method object must exist as long as
the query executor exists. This patch makes it reside within the Python
query executor wrapper (`_method_obj` attribute) as there's no way
currently to lose the Python wrapper and retrieve it through a library
call. If this becomes possible in the future, then we can introduce
query executor destruction listeners and add one from the Python
bindings to put the `PyObject *` reference when the query executor is
destroyed. A new test checks this
(test_query_with_method_obj_del_ref()), deleting the test's reference
between the query executor's construction and the actual query
operation. I tried without making the query executor keep a strong
reference and the test causes a segmentation fault, as expected, which
shows that the test is valuable.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I454cdad039fab5b7d46e46762243f212c200f114
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1831
Tested-by: jenkins <jenkins@lttng.org>
22 files changed:
include/babeltrace2/graph/component-class-filter.h
include/babeltrace2/graph/component-class-sink.h
include/babeltrace2/graph/component-class-source.h
include/babeltrace2/graph/query-executor.h
src/bindings/python/bt2/Makefile.am
src/bindings/python/bt2/bt2/component.py
src/bindings/python/bt2/bt2/native_bt_component_class.i.h
src/bindings/python/bt2/bt2/native_bt_query_exec.i
src/bindings/python/bt2/bt2/native_bt_query_exec.i.h [new file with mode: 0644]
src/bindings/python/bt2/bt2/query_executor.py
src/lib/graph/query-executor.c
src/lib/graph/query-executor.h
src/plugins/ctf/fs-src/fs.c
src/plugins/ctf/fs-src/fs.h
src/plugins/ctf/lttng-live/lttng-live.c
src/plugins/ctf/lttng-live/lttng-live.h
tests/bindings/python/bt2/test_component_class.py
tests/bindings/python/bt2/test_error.py
tests/bindings/python/bt2/test_query_executor.py
tests/data/cli/convert/auto-source-discovery-grouping/bt_plugin_test.py
tests/data/cli/convert/auto-source-discovery-params-log-level/bt_plugin_test.py
tests/lib/test-plugin-plugins/sfs.c
This page took 0.026695 seconds and 4 git commands to generate.