Tests: Fix: Use '.logfile' instead of '.log' for test app output
[lttng-tools.git] / src / common / evaluation.cpp
... / ...
CommitLineData
1/*
2 * Copyright (C) 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 *
4 * SPDX-License-Identifier: LGPL-2.1-only
5 *
6 */
7
8#include <common/error.hpp>
9#include <common/macros.hpp>
10
11#include <lttng/condition/buffer-usage-internal.hpp>
12#include <lttng/condition/condition-internal.hpp>
13#include <lttng/condition/evaluation-internal.hpp>
14#include <lttng/condition/event-rule-matches-internal.hpp>
15#include <lttng/condition/session-consumed-size-internal.hpp>
16#include <lttng/condition/session-rotation-internal.hpp>
17
18#include <stdbool.h>
19
20void lttng_evaluation_init(struct lttng_evaluation *evaluation, enum lttng_condition_type type)
21{
22 evaluation->type = type;
23}
24
25int lttng_evaluation_serialize(const struct lttng_evaluation *evaluation,
26 struct lttng_payload *payload)
27{
28 int ret;
29 struct lttng_evaluation_comm evaluation_comm;
30
31 evaluation_comm.type = (int8_t) evaluation->type;
32
33 ret = lttng_dynamic_buffer_append(
34 &payload->buffer, &evaluation_comm, sizeof(evaluation_comm));
35 if (ret) {
36 goto end;
37 }
38
39 if (evaluation->serialize) {
40 ret = evaluation->serialize(evaluation, payload);
41 if (ret) {
42 goto end;
43 }
44 }
45end:
46 return ret;
47}
48
49ssize_t lttng_evaluation_create_from_payload(const struct lttng_condition *condition,
50 struct lttng_payload_view *src_view,
51 struct lttng_evaluation **evaluation)
52{
53 ssize_t ret, evaluation_size = 0;
54 const struct lttng_evaluation_comm *evaluation_comm;
55 const lttng_payload_view evaluation_comm_view =
56 lttng_payload_view_from_view(src_view, 0, sizeof(*evaluation_comm));
57 struct lttng_payload_view evaluation_view =
58 lttng_payload_view_from_view(src_view, sizeof(*evaluation_comm), -1);
59
60 if (!src_view || !evaluation) {
61 ret = -1;
62 goto end;
63 }
64
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;
71 evaluation_size += sizeof(*evaluation_comm);
72
73 switch ((enum lttng_condition_type) evaluation_comm->type) {
74 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW:
75 ret = lttng_evaluation_buffer_usage_low_create_from_payload(&evaluation_view,
76 evaluation);
77 if (ret < 0) {
78 goto end;
79 }
80 evaluation_size += ret;
81 break;
82 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH:
83 ret = lttng_evaluation_buffer_usage_high_create_from_payload(&evaluation_view,
84 evaluation);
85 if (ret < 0) {
86 goto end;
87 }
88 evaluation_size += ret;
89 break;
90 case LTTNG_CONDITION_TYPE_SESSION_CONSUMED_SIZE:
91 ret = lttng_evaluation_session_consumed_size_create_from_payload(&evaluation_view,
92 evaluation);
93 if (ret < 0) {
94 goto end;
95 }
96 evaluation_size += ret;
97 break;
98 case LTTNG_CONDITION_TYPE_SESSION_ROTATION_ONGOING:
99 ret = lttng_evaluation_session_rotation_ongoing_create_from_payload(
100 &evaluation_view, evaluation);
101 if (ret < 0) {
102 goto end;
103 }
104 evaluation_size += ret;
105 break;
106 case LTTNG_CONDITION_TYPE_SESSION_ROTATION_COMPLETED:
107 ret = lttng_evaluation_session_rotation_completed_create_from_payload(
108 &evaluation_view, evaluation);
109 if (ret < 0) {
110 goto end;
111 }
112 evaluation_size += ret;
113 break;
114 case LTTNG_CONDITION_TYPE_EVENT_RULE_MATCHES:
115 LTTNG_ASSERT(condition);
116 LTTNG_ASSERT(condition->type == LTTNG_CONDITION_TYPE_EVENT_RULE_MATCHES);
117 ret = lttng_evaluation_event_rule_matches_create_from_payload(
118 lttng::utils::container_of(condition,
119 &lttng_condition_event_rule_matches::parent),
120 &evaluation_view,
121 evaluation);
122 if (ret < 0) {
123 goto end;
124 }
125 evaluation_size += ret;
126 break;
127 default:
128 ERR("Attempted to create evaluation of unknown type (%i)",
129 (int) evaluation_comm->type);
130 ret = -1;
131 goto end;
132 }
133
134 ret = evaluation_size;
135end:
136 return ret;
137}
138
139enum lttng_condition_type lttng_evaluation_get_type(const struct lttng_evaluation *evaluation)
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
150 LTTNG_ASSERT(evaluation->destroy);
151 evaluation->destroy(evaluation);
152}
This page took 0.027143 seconds and 5 git commands to generate.