Fix: use the correct condition type in logging statements
[lttng-tools.git] / src / common / evaluation.c
CommitLineData
a58c490f
JG
1/*
2 * Copyright (C) 2017 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 *
4 * This library is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License, version 2.1 only,
6 * as published by the Free Software Foundation.
7 *
8 * This library is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
11 * for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this library; if not, write to the Free Software Foundation,
15 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17
18#include <lttng/condition/evaluation-internal.h>
19#include <lttng/condition/buffer-usage-internal.h>
e8360425 20#include <lttng/condition/session-consumed-size-internal.h>
a58c490f
JG
21#include <common/macros.h>
22#include <common/error.h>
23#include <stdbool.h>
24#include <assert.h>
25
26LTTNG_HIDDEN
3647288f
JG
27int lttng_evaluation_serialize(struct lttng_evaluation *evaluation,
28 struct lttng_dynamic_buffer *buf)
a58c490f 29{
3647288f 30 int ret;
db315d75
JG
31 struct lttng_evaluation_comm evaluation_comm = {
32 .type = (int8_t) evaluation->type
33 };
a58c490f 34
3647288f
JG
35 ret = lttng_dynamic_buffer_append(buf, &evaluation_comm,
36 sizeof(evaluation_comm));
37 if (ret) {
38 goto end;
a58c490f 39 }
a58c490f
JG
40
41 if (evaluation->serialize) {
3647288f
JG
42 ret = evaluation->serialize(evaluation, buf);
43 if (ret) {
a58c490f
JG
44 goto end;
45 }
a58c490f 46 }
a58c490f
JG
47end:
48 return ret;
49}
50
51LTTNG_HIDDEN
52ssize_t lttng_evaluation_create_from_buffer(
53 const struct lttng_buffer_view *src_view,
54 struct lttng_evaluation **evaluation)
55{
56 ssize_t ret, evaluation_size = 0;
57 const struct lttng_evaluation_comm *evaluation_comm;
58 const struct lttng_buffer_view evaluation_view =
59 lttng_buffer_view_from_view(src_view,
60 sizeof(*evaluation_comm), -1);
61
62 if (!src_view || !evaluation) {
63 ret = -1;
64 goto end;
65 }
66
67 evaluation_comm = (const struct lttng_evaluation_comm *) src_view->data;
68 evaluation_size += sizeof(*evaluation_comm);
69
70 switch ((enum lttng_condition_type) evaluation_comm->type) {
71 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW:
72 ret = lttng_evaluation_buffer_usage_low_create_from_buffer(
73 &evaluation_view, evaluation);
74 if (ret < 0) {
75 goto end;
76 }
77 evaluation_size += ret;
78 break;
79 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH:
80 ret = lttng_evaluation_buffer_usage_high_create_from_buffer(
81 &evaluation_view, evaluation);
82 if (ret < 0) {
83 goto end;
84 }
85 evaluation_size += ret;
86 break;
e8360425
JD
87 case LTTNG_CONDITION_TYPE_SESSION_CONSUMED_SIZE:
88 ret = lttng_evaluation_session_consumed_size_create_from_buffer(
89 &evaluation_view, evaluation);
90 if (ret < 0) {
91 goto end;
92 }
93 evaluation_size += ret;
94 break;
a58c490f
JG
95 default:
96 ERR("Attempted to create evaluation of unknown type (%i)",
97 (int) evaluation_comm->type);
98 ret = -1;
99 goto end;
100 }
101 ret = evaluation_size;
102end:
103 return ret;
104}
105
106enum lttng_condition_type lttng_evaluation_get_type(
107 const struct lttng_evaluation *evaluation)
108{
109 return evaluation ? evaluation->type : LTTNG_CONDITION_TYPE_UNKNOWN;
110}
111
112void lttng_evaluation_destroy(struct lttng_evaluation *evaluation)
113{
114 if (!evaluation) {
115 return;
116 }
117
118 assert(evaluation->destroy);
119 evaluation->destroy(evaluation);
120}
This page took 0.047917 seconds and 5 git commands to generate.