X-Git-Url: http://git.efficios.com/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fcommon%2Fevaluation.c;h=479b8b3e51edab7ddf18f9f3d31847f77710c99a;hp=f07c81b18cf9747250bc3284ff04cf713d4ebbb7;hb=2463b7879c00298daa79744cdaae82ac061a4ed8;hpb=3647288fe42b25340f905046f3bd9aef21e12aaa diff --git a/src/common/evaluation.c b/src/common/evaluation.c index f07c81b18..479b8b3e5 100644 --- a/src/common/evaluation.c +++ b/src/common/evaluation.c @@ -1,45 +1,45 @@ /* - * Copyright (C) 2017 - Jérémie Galarneau + * Copyright (C) 2017 Jérémie Galarneau * - * This library is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License, version 2.1 only, - * as published by the Free Software Foundation. + * SPDX-License-Identifier: LGPL-2.1-only * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include #include #include #include +#include +#include #include #include #include #include LTTNG_HIDDEN -int lttng_evaluation_serialize(struct lttng_evaluation *evaluation, - struct lttng_dynamic_buffer *buf) +void lttng_evaluation_init(struct lttng_evaluation *evaluation, + enum lttng_condition_type type) +{ + evaluation->type = type; +} + +LTTNG_HIDDEN +int lttng_evaluation_serialize(const struct lttng_evaluation *evaluation, + 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; } @@ -49,27 +49,29 @@ 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_view = src_view ? + lttng_payload_view_from_view(src_view, + sizeof(*evaluation_comm), -1) : + (typeof(evaluation_view)) {}; if (!src_view || !evaluation) { ret = -1; goto end; } - evaluation_comm = (const struct lttng_evaluation_comm *) src_view->data; + evaluation_comm = (typeof(evaluation_comm)) src_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; @@ -77,7 +79,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; @@ -85,7 +87,36 @@ 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; + } + evaluation_size += ret; + break; + case LTTNG_CONDITION_TYPE_SESSION_ROTATION_ONGOING: + ret = lttng_evaluation_session_rotation_ongoing_create_from_payload( + &evaluation_view, evaluation); + if (ret < 0) { + goto end; + } + evaluation_size += ret; + break; + case LTTNG_CONDITION_TYPE_SESSION_ROTATION_COMPLETED: + 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_EVENT_RULE_HIT: + assert(condition); + assert(condition->type == LTTNG_CONDITION_TYPE_EVENT_RULE_HIT); + ret = lttng_evaluation_event_rule_create_from_payload( + container_of(condition, + struct lttng_condition_event_rule, + parent), &evaluation_view, evaluation); if (ret < 0) { goto end; @@ -98,6 +129,7 @@ ssize_t lttng_evaluation_create_from_buffer( ret = -1; goto end; } + ret = evaluation_size; end: return ret;