X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fcommon%2Fconditions%2Fevent-rule-matches.c;h=52bb6ae19f00752d38ae45fb1315af370528e4a2;hb=a0377dfefe40662ba7d68617bce6ff467114136c;hp=8877966421996f86661a375f6320e3bfe319cb00;hpb=695f70446965aeac8b1118bb08d572630c96114d;p=lttng-tools.git diff --git a/src/common/conditions/event-rule-matches.c b/src/common/conditions/event-rule-matches.c index 887796642..52bb6ae19 100644 --- a/src/common/conditions/event-rule-matches.c +++ b/src/common/conditions/event-rule-matches.c @@ -5,10 +5,9 @@ * */ -#include #include -#include #include +#include #include #include #include @@ -434,6 +433,81 @@ void destroy_capture_descriptor(void *ptr) free(desc); } +static enum lttng_error_code lttng_condition_event_rule_matches_mi_serialize( + const struct lttng_condition *condition, + struct mi_writer *writer) +{ + int ret; + enum lttng_error_code ret_code; + enum lttng_condition_status status; + const struct lttng_event_rule *rule = NULL; + unsigned int capture_descriptor_count, i; + + LTTNG_ASSERT(condition); + LTTNG_ASSERT(writer); + LTTNG_ASSERT(IS_EVENT_RULE_MATCHES_CONDITION(condition)); + + status = lttng_condition_event_rule_matches_get_rule(condition, &rule); + LTTNG_ASSERT(status == LTTNG_CONDITION_STATUS_OK); + LTTNG_ASSERT(rule != NULL); + + status = lttng_condition_event_rule_matches_get_capture_descriptor_count( + condition, &capture_descriptor_count); + LTTNG_ASSERT(status == LTTNG_CONDITION_STATUS_OK); + + /* Open condition event rule matches element. */ + ret = mi_lttng_writer_open_element( + writer, mi_lttng_element_condition_event_rule_matches); + if (ret) { + goto mi_error; + } + + /* Serialize the event rule. */ + ret_code = lttng_event_rule_mi_serialize(rule, writer); + if (ret_code != LTTNG_OK) { + goto end; + } + + /* Open the capture descriptors element. */ + ret = mi_lttng_writer_open_element( + writer, mi_lttng_element_capture_descriptors); + if (ret) { + goto mi_error; + } + + for (i = 0; i < capture_descriptor_count; i++) { + const struct lttng_event_expr *descriptor = NULL; + + descriptor = lttng_condition_event_rule_matches_get_capture_descriptor_at_index( + condition, i); + LTTNG_ASSERT(descriptor); + + ret_code = lttng_event_expr_mi_serialize(descriptor, writer); + if (ret_code != LTTNG_OK) { + goto end; + } + } + + /* Close capture descriptors element. */ + ret = mi_lttng_writer_close_element(writer); + if (ret) { + goto mi_error; + } + + /* Close condition_event_rule_matches. */ + ret = mi_lttng_writer_close_element(writer); + if (ret) { + goto mi_error; + } + ret_code = LTTNG_OK; + goto end; + +mi_error: + ret_code = LTTNG_ERR_MI_IO_FAIL; +end: + return ret_code; +} + struct lttng_condition *lttng_condition_event_rule_matches_create( struct lttng_event_rule *rule) { @@ -457,6 +531,7 @@ struct lttng_condition *lttng_condition_event_rule_matches_create( lttng_condition_event_rule_matches_serialize, condition->parent.equal = lttng_condition_event_rule_matches_is_equal, condition->parent.destroy = lttng_condition_event_rule_matches_destroy, + condition->parent.mi_serialize = lttng_condition_event_rule_matches_mi_serialize, lttng_event_rule_get(rule); condition->rule = rule; @@ -665,7 +740,7 @@ ssize_t lttng_condition_event_rule_matches_create_from_payload( } /* Capture descriptor count. */ - assert(event_rule_length >= 0); + LTTNG_ASSERT(event_rule_length >= 0); capture_descr_count = uint_from_buffer(&view->buffer, sizeof(uint32_t), &offset); if (capture_descr_count == UINT32_C(-1)) { goto error; @@ -975,7 +1050,7 @@ bool msgpack_str_is_equal(const struct msgpack_object *obj, const char *str) { bool is_equal = true; - assert(obj->type == MSGPACK_OBJECT_STR); + LTTNG_ASSERT(obj->type == MSGPACK_OBJECT_STR); if (obj->via.str.size != strlen(str)) { is_equal = false; @@ -998,12 +1073,12 @@ const msgpack_object *get_msgpack_map_obj(const struct msgpack_object *map_obj, const msgpack_object *ret = NULL; size_t i; - assert(map_obj->type == MSGPACK_OBJECT_MAP); + LTTNG_ASSERT(map_obj->type == MSGPACK_OBJECT_MAP); for (i = 0; i < map_obj->via.map.size; i++) { const struct msgpack_object_kv *kv = &map_obj->via.map.ptr[i]; - assert(kv->key.type == MSGPACK_OBJECT_STR); + LTTNG_ASSERT(kv->key.type == MSGPACK_OBJECT_STR); if (msgpack_str_is_equal(&kv->key, name)) { ret = &kv->val; @@ -1033,8 +1108,8 @@ int event_field_value_from_obj(const msgpack_object *obj, { int ret = 0; - assert(obj); - assert(field_val); + LTTNG_ASSERT(obj); + LTTNG_ASSERT(field_val); switch (obj->type) { case MSGPACK_OBJECT_NIL: @@ -1216,8 +1291,8 @@ static struct lttng_event_field_value *event_field_value_from_capture_payload( size_t i; size_t count; - assert(condition); - assert(capture_payload); + LTTNG_ASSERT(condition); + LTTNG_ASSERT(capture_payload); /* Initialize value. */ msgpack_unpacked_init(&unpacked); @@ -1262,7 +1337,7 @@ static struct lttng_event_field_value *event_field_value_from_capture_payload( */ count = lttng_dynamic_pointer_array_get_count( &condition->capture_descriptors); - assert(count > 0); + LTTNG_ASSERT(count > 0); for (i = 0; i < count; i++) { const struct lttng_capture_descriptor *capture_descriptor = @@ -1272,7 +1347,7 @@ static struct lttng_event_field_value *event_field_value_from_capture_payload( struct lttng_event_field_value *elem_field_val; int iret; - assert(capture_descriptor); + LTTNG_ASSERT(capture_descriptor); elem_obj = &root_array_obj->ptr[i]; iret = event_field_value_from_obj(elem_obj,