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