From: Jonathan Rajotte Date: Wed, 29 Apr 2020 19:36:00 +0000 (-0400) Subject: condition: implement lttng_condition_event_rule_get_internal_capture_descriptor_at_index X-Git-Tag: v2.13.0-rc1~250 X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=commitdiff_plain;h=6fb7c69074b6884da56bb0758e92e1c7f7859859 condition: implement lttng_condition_event_rule_get_internal_capture_descriptor_at_index The lttng_capture_descriptor object is only exposed internally. A getter is necessary to allow more control on the lttng_capture_descriptor object. This will be reused to set the bytecode later in the patchset. Signed-off-by: Jonathan Rajotte Signed-off-by: Jérémie Galarneau Change-Id: I7fdfdc9d2ac1920bcf1a098352dfd105949e1062 Depends-on: lttng-ust: I5a800fc92e588c2a6a0e26282b0ad5f31c044479 --- diff --git a/src/common/conditions/event-rule.c b/src/common/conditions/event-rule.c index a08b3eb41..8d3f1cd53 100644 --- a/src/common/conditions/event-rule.c +++ b/src/common/conditions/event-rule.c @@ -192,6 +192,39 @@ end: return ret; } +static +struct lttng_capture_descriptor * +lttng_condition_event_rule_get_internal_capture_descriptor_at_index( + const struct lttng_condition *condition, unsigned int index) +{ + const struct lttng_condition_event_rule *event_rule_cond = + container_of(condition, + const struct lttng_condition_event_rule, + parent); + struct lttng_capture_descriptor *desc = NULL; + unsigned int count; + enum lttng_condition_status status; + + if (!condition || !IS_EVENT_RULE_CONDITION(condition)) { + goto end; + } + + status = lttng_condition_event_rule_get_capture_descriptor_count( + condition, &count); + if (status != LTTNG_CONDITION_STATUS_OK) { + goto end; + } + + if (index >= count) { + goto end; + } + + desc = lttng_dynamic_pointer_array_get_pointer( + &event_rule_cond->capture_descriptors, index); +end: + return desc; +} + static int lttng_condition_event_rule_serialize( const struct lttng_condition *condition, struct lttng_payload *payload) @@ -233,13 +266,13 @@ static int lttng_condition_event_rule_serialize( } for (i = 0; i < capture_descr_count; i++) { - const struct lttng_event_expr *expr = - lttng_condition_event_rule_get_capture_descriptor_at_index( + const struct lttng_capture_descriptor *desc = + lttng_condition_event_rule_get_internal_capture_descriptor_at_index( condition, i); DBG("Serializing event rule condition's capture descriptor %" PRIu32, i); - ret = serialize_event_expr(expr, payload); + ret = serialize_event_expr(desc->event_expression, payload); if (ret) { goto end; } @@ -586,9 +619,9 @@ ssize_t lttng_condition_event_rule_create_from_payload( /* Capture descriptors. */ for (i = 0; i < capture_descr_count; i++) { + enum lttng_condition_status status; struct lttng_event_expr *expr = event_expr_from_payload( view, &offset); - enum lttng_condition_status status; if (!expr) { goto error; @@ -724,30 +757,14 @@ const struct lttng_event_expr * lttng_condition_event_rule_get_capture_descriptor_at_index( const struct lttng_condition *condition, unsigned int index) { - const struct lttng_condition_event_rule *event_rule_cond = - container_of(condition, - const struct lttng_condition_event_rule, - parent); const struct lttng_event_expr *expr = NULL; - struct lttng_capture_descriptor *desc = NULL; - unsigned int count; - enum lttng_condition_status status; + const struct lttng_capture_descriptor *desc = NULL; - if (!condition || !IS_EVENT_RULE_CONDITION(condition)) { - goto end; - } - - status = lttng_condition_event_rule_get_capture_descriptor_count(condition, &count); - if (status != LTTNG_CONDITION_STATUS_OK) { - goto end; - } - - if (index >= count) { + desc = lttng_condition_event_rule_get_internal_capture_descriptor_at_index( + condition, index); + if (desc == NULL) { goto end; } - - desc = lttng_dynamic_pointer_array_get_pointer( - &event_rule_cond->capture_descriptors, index); expr = desc->event_expression; end: