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:
This page took 0.027702 seconds and 4 git commands to generate.