X-Git-Url: http://git.efficios.com/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fcommon%2Fevaluation.c;h=c51ec2bd9a316d1946e1900437031cd3a0a30678;hp=efd2129217e8829816808901ecf3351baa173d38;hb=refs%2Fheads%2Fsow-2020-0002-rev3;hpb=ab5be9fa2eb5ba9600a82cd18fd3cfcbac69169a diff --git a/src/common/evaluation.c b/src/common/evaluation.c index efd212921..c51ec2bd9 100644 --- a/src/common/evaluation.c +++ b/src/common/evaluation.c @@ -5,10 +5,12 @@ * */ +#include #include #include #include #include +#include #include #include #include @@ -23,21 +25,21 @@ void lttng_evaluation_init(struct lttng_evaluation *evaluation, LTTNG_HIDDEN int lttng_evaluation_serialize(const struct lttng_evaluation *evaluation, - struct lttng_dynamic_buffer *buf) + struct lttng_payload *payload) { int ret; struct lttng_evaluation_comm evaluation_comm = { .type = (int8_t) evaluation->type }; - ret = lttng_dynamic_buffer_append(buf, &evaluation_comm, + ret = lttng_dynamic_buffer_append(&payload->buffer, &evaluation_comm, sizeof(evaluation_comm)); if (ret) { goto end; } if (evaluation->serialize) { - ret = evaluation->serialize(evaluation, buf); + ret = evaluation->serialize(evaluation, payload); if (ret) { goto end; } @@ -47,27 +49,36 @@ end: } LTTNG_HIDDEN -ssize_t lttng_evaluation_create_from_buffer( - const struct lttng_buffer_view *src_view, +ssize_t lttng_evaluation_create_from_payload( + const struct lttng_condition *condition, + struct lttng_payload_view *src_view, struct lttng_evaluation **evaluation) { ssize_t ret, evaluation_size = 0; const struct lttng_evaluation_comm *evaluation_comm; - const struct lttng_buffer_view evaluation_view = - lttng_buffer_view_from_view(src_view, - sizeof(*evaluation_comm), -1); + struct lttng_payload_view evaluation_comm_view = + lttng_payload_view_from_view( + src_view, 0, sizeof(*evaluation_comm)); + struct lttng_payload_view evaluation_view = + lttng_payload_view_from_view(src_view, + sizeof(*evaluation_comm), -1); if (!src_view || !evaluation) { ret = -1; goto end; } - evaluation_comm = (const struct lttng_evaluation_comm *) src_view->data; + if (!lttng_payload_view_is_valid(&evaluation_comm_view)) { + ret = -1; + goto end; + } + + evaluation_comm = (typeof(evaluation_comm)) evaluation_comm_view.buffer.data; evaluation_size += sizeof(*evaluation_comm); switch ((enum lttng_condition_type) evaluation_comm->type) { case LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW: - ret = lttng_evaluation_buffer_usage_low_create_from_buffer( + ret = lttng_evaluation_buffer_usage_low_create_from_payload( &evaluation_view, evaluation); if (ret < 0) { goto end; @@ -75,7 +86,7 @@ ssize_t lttng_evaluation_create_from_buffer( evaluation_size += ret; break; case LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH: - ret = lttng_evaluation_buffer_usage_high_create_from_buffer( + ret = lttng_evaluation_buffer_usage_high_create_from_payload( &evaluation_view, evaluation); if (ret < 0) { goto end; @@ -83,7 +94,7 @@ ssize_t lttng_evaluation_create_from_buffer( evaluation_size += ret; break; case LTTNG_CONDITION_TYPE_SESSION_CONSUMED_SIZE: - ret = lttng_evaluation_session_consumed_size_create_from_buffer( + ret = lttng_evaluation_session_consumed_size_create_from_payload( &evaluation_view, evaluation); if (ret < 0) { goto end; @@ -91,7 +102,7 @@ ssize_t lttng_evaluation_create_from_buffer( evaluation_size += ret; break; case LTTNG_CONDITION_TYPE_SESSION_ROTATION_ONGOING: - ret = lttng_evaluation_session_rotation_ongoing_create_from_buffer( + ret = lttng_evaluation_session_rotation_ongoing_create_from_payload( &evaluation_view, evaluation); if (ret < 0) { goto end; @@ -99,7 +110,20 @@ ssize_t lttng_evaluation_create_from_buffer( evaluation_size += ret; break; case LTTNG_CONDITION_TYPE_SESSION_ROTATION_COMPLETED: - ret = lttng_evaluation_session_rotation_completed_create_from_buffer( + ret = lttng_evaluation_session_rotation_completed_create_from_payload( + &evaluation_view, evaluation); + if (ret < 0) { + goto end; + } + evaluation_size += ret; + break; + case LTTNG_CONDITION_TYPE_ON_EVENT: + assert(condition); + assert(condition->type == LTTNG_CONDITION_TYPE_ON_EVENT); + ret = lttng_evaluation_event_rule_create_from_payload( + container_of(condition, + const struct lttng_condition_on_event, + parent), &evaluation_view, evaluation); if (ret < 0) { goto end; @@ -112,6 +136,7 @@ ssize_t lttng_evaluation_create_from_buffer( ret = -1; goto end; } + ret = evaluation_size; end: return ret;