Build fix: Missing message in LTTNG_DEPRECATED invocation
[lttng-tools.git] / src / common / evaluation.c
CommitLineData
a58c490f 1/*
ab5be9fa 2 * Copyright (C) 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
a58c490f 3 *
ab5be9fa 4 * SPDX-License-Identifier: LGPL-2.1-only
a58c490f 5 *
a58c490f
JG
6 */
7
7c920b63 8#include <lttng/condition/condition-internal.h>
a58c490f
JG
9#include <lttng/condition/evaluation-internal.h>
10#include <lttng/condition/buffer-usage-internal.h>
e8360425 11#include <lttng/condition/session-consumed-size-internal.h>
c19092cd 12#include <lttng/condition/session-rotation-internal.h>
670a26e4 13#include <lttng/condition/event-rule-matches-internal.h>
a58c490f
JG
14#include <common/macros.h>
15#include <common/error.h>
16#include <stdbool.h>
a58c490f 17
c19092cd
JG
18void lttng_evaluation_init(struct lttng_evaluation *evaluation,
19 enum lttng_condition_type type)
20{
21 evaluation->type = type;
22}
23
9b63a4aa 24int lttng_evaluation_serialize(const struct lttng_evaluation *evaluation,
c0a66c84 25 struct lttng_payload *payload)
a58c490f 26{
3647288f 27 int ret;
db315d75
JG
28 struct lttng_evaluation_comm evaluation_comm = {
29 .type = (int8_t) evaluation->type
30 };
a58c490f 31
c0a66c84 32 ret = lttng_dynamic_buffer_append(&payload->buffer, &evaluation_comm,
3647288f
JG
33 sizeof(evaluation_comm));
34 if (ret) {
35 goto end;
a58c490f 36 }
a58c490f
JG
37
38 if (evaluation->serialize) {
c0a66c84 39 ret = evaluation->serialize(evaluation, payload);
3647288f 40 if (ret) {
a58c490f
JG
41 goto end;
42 }
a58c490f 43 }
a58c490f
JG
44end:
45 return ret;
46}
47
c0a66c84 48ssize_t lttng_evaluation_create_from_payload(
7c920b63 49 const struct lttng_condition *condition,
c0a66c84 50 struct lttng_payload_view *src_view,
a58c490f
JG
51 struct lttng_evaluation **evaluation)
52{
53 ssize_t ret, evaluation_size = 0;
54 const struct lttng_evaluation_comm *evaluation_comm;
3e6e0df2
JG
55 struct lttng_payload_view evaluation_comm_view =
56 lttng_payload_view_from_view(
57 src_view, 0, sizeof(*evaluation_comm));
58 struct lttng_payload_view evaluation_view =
2f571d6f 59 lttng_payload_view_from_view(src_view,
3e6e0df2 60 sizeof(*evaluation_comm), -1);
a58c490f
JG
61
62 if (!src_view || !evaluation) {
63 ret = -1;
64 goto end;
65 }
66
3e6e0df2
JG
67 if (!lttng_payload_view_is_valid(&evaluation_comm_view)) {
68 ret = -1;
69 goto end;
70 }
71
72 evaluation_comm = (typeof(evaluation_comm)) evaluation_comm_view.buffer.data;
a58c490f
JG
73 evaluation_size += sizeof(*evaluation_comm);
74
75 switch ((enum lttng_condition_type) evaluation_comm->type) {
76 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW:
c0a66c84 77 ret = lttng_evaluation_buffer_usage_low_create_from_payload(
a58c490f
JG
78 &evaluation_view, evaluation);
79 if (ret < 0) {
80 goto end;
81 }
82 evaluation_size += ret;
83 break;
84 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH:
c0a66c84 85 ret = lttng_evaluation_buffer_usage_high_create_from_payload(
a58c490f
JG
86 &evaluation_view, evaluation);
87 if (ret < 0) {
88 goto end;
89 }
90 evaluation_size += ret;
91 break;
e8360425 92 case LTTNG_CONDITION_TYPE_SESSION_CONSUMED_SIZE:
c0a66c84 93 ret = lttng_evaluation_session_consumed_size_create_from_payload(
e8360425
JD
94 &evaluation_view, evaluation);
95 if (ret < 0) {
96 goto end;
97 }
98 evaluation_size += ret;
99 break;
c19092cd 100 case LTTNG_CONDITION_TYPE_SESSION_ROTATION_ONGOING:
c0a66c84 101 ret = lttng_evaluation_session_rotation_ongoing_create_from_payload(
c19092cd
JG
102 &evaluation_view, evaluation);
103 if (ret < 0) {
104 goto end;
105 }
106 evaluation_size += ret;
107 break;
108 case LTTNG_CONDITION_TYPE_SESSION_ROTATION_COMPLETED:
c0a66c84 109 ret = lttng_evaluation_session_rotation_completed_create_from_payload(
c19092cd
JG
110 &evaluation_view, evaluation);
111 if (ret < 0) {
112 goto end;
113 }
114 evaluation_size += ret;
115 break;
8dbb86b8 116 case LTTNG_CONDITION_TYPE_EVENT_RULE_MATCHES:
a0377dfe
FD
117 LTTNG_ASSERT(condition);
118 LTTNG_ASSERT(condition->type ==
8dbb86b8
JR
119 LTTNG_CONDITION_TYPE_EVENT_RULE_MATCHES);
120 ret = lttng_evaluation_event_rule_matches_create_from_payload(
7c920b63 121 container_of(condition,
8dbb86b8 122 const struct lttng_condition_event_rule_matches,
7c920b63
PP
123 parent),
124 &evaluation_view, evaluation);
f1446131
JR
125 if (ret < 0) {
126 goto end;
127 }
128 evaluation_size += ret;
129 break;
a58c490f
JG
130 default:
131 ERR("Attempted to create evaluation of unknown type (%i)",
132 (int) evaluation_comm->type);
133 ret = -1;
134 goto end;
135 }
c0a66c84 136
a58c490f
JG
137 ret = evaluation_size;
138end:
139 return ret;
140}
141
142enum lttng_condition_type lttng_evaluation_get_type(
143 const struct lttng_evaluation *evaluation)
144{
145 return evaluation ? evaluation->type : LTTNG_CONDITION_TYPE_UNKNOWN;
146}
147
148void lttng_evaluation_destroy(struct lttng_evaluation *evaluation)
149{
150 if (!evaluation) {
151 return;
152 }
153
a0377dfe 154 LTTNG_ASSERT(evaluation->destroy);
a58c490f
JG
155 evaluation->destroy(evaluation);
156}
This page took 0.043767 seconds and 4 git commands to generate.