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