2 * Copyright (C) 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * SPDX-License-Identifier: LGPL-2.1-only
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>
19 void lttng_evaluation_init(struct lttng_evaluation
*evaluation
,
20 enum lttng_condition_type type
)
22 evaluation
->type
= type
;
26 int lttng_evaluation_serialize(const struct lttng_evaluation
*evaluation
,
27 struct lttng_payload
*payload
)
30 struct lttng_evaluation_comm evaluation_comm
= {
31 .type
= (int8_t) evaluation
->type
34 ret
= lttng_dynamic_buffer_append(&payload
->buffer
, &evaluation_comm
,
35 sizeof(evaluation_comm
));
40 if (evaluation
->serialize
) {
41 ret
= evaluation
->serialize(evaluation
, payload
);
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
)
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);
65 if (!src_view
|| !evaluation
) {
70 if (!lttng_payload_view_is_valid(&evaluation_comm_view
)) {
75 evaluation_comm
= (typeof(evaluation_comm
)) evaluation_comm_view
.buffer
.data
;
76 evaluation_size
+= sizeof(*evaluation_comm
);
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
);
85 evaluation_size
+= ret
;
87 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH
:
88 ret
= lttng_evaluation_buffer_usage_high_create_from_payload(
89 &evaluation_view
, evaluation
);
93 evaluation_size
+= ret
;
95 case LTTNG_CONDITION_TYPE_SESSION_CONSUMED_SIZE
:
96 ret
= lttng_evaluation_session_consumed_size_create_from_payload(
97 &evaluation_view
, evaluation
);
101 evaluation_size
+= ret
;
103 case LTTNG_CONDITION_TYPE_SESSION_ROTATION_ONGOING
:
104 ret
= lttng_evaluation_session_rotation_ongoing_create_from_payload(
105 &evaluation_view
, evaluation
);
109 evaluation_size
+= ret
;
111 case LTTNG_CONDITION_TYPE_SESSION_ROTATION_COMPLETED
:
112 ret
= lttng_evaluation_session_rotation_completed_create_from_payload(
113 &evaluation_view
, evaluation
);
117 evaluation_size
+= ret
;
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
,
127 &evaluation_view
, evaluation
);
131 evaluation_size
+= ret
;
134 ERR("Attempted to create evaluation of unknown type (%i)",
135 (int) evaluation_comm
->type
);
140 ret
= evaluation_size
;
145 enum lttng_condition_type
lttng_evaluation_get_type(
146 const struct lttng_evaluation
*evaluation
)
148 return evaluation
? evaluation
->type
: LTTNG_CONDITION_TYPE_UNKNOWN
;
151 void lttng_evaluation_destroy(struct lttng_evaluation
*evaluation
)
157 LTTNG_ASSERT(evaluation
->destroy
);
158 evaluation
->destroy(evaluation
);