2 * Copyright (C) 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * SPDX-License-Identifier: LGPL-2.1-only
8 #include <lttng/condition/evaluation-internal.h>
9 #include <lttng/condition/buffer-usage-internal.h>
10 #include <lttng/condition/session-consumed-size-internal.h>
11 #include <lttng/condition/session-rotation-internal.h>
12 #include <lttng/condition/event-rule-internal.h>
13 #include <common/macros.h>
14 #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 struct lttng_payload_view
*src_view
,
53 struct lttng_evaluation
**evaluation
)
55 ssize_t ret
, evaluation_size
= 0;
56 const struct lttng_evaluation_comm
*evaluation_comm
;
57 struct lttng_payload_view evaluation_comm_view
=
58 lttng_payload_view_from_view(
59 src_view
, 0, sizeof(*evaluation_comm
));
60 struct lttng_payload_view evaluation_view
=
61 lttng_payload_view_from_view(src_view
,
62 sizeof(*evaluation_comm
), -1);
64 if (!src_view
|| !evaluation
) {
69 if (!lttng_payload_view_is_valid(&evaluation_comm_view
)) {
74 evaluation_comm
= (typeof(evaluation_comm
)) evaluation_comm_view
.buffer
.data
;
75 evaluation_size
+= sizeof(*evaluation_comm
);
77 switch ((enum lttng_condition_type
) evaluation_comm
->type
) {
78 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW
:
79 ret
= lttng_evaluation_buffer_usage_low_create_from_payload(
80 &evaluation_view
, evaluation
);
84 evaluation_size
+= ret
;
86 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH
:
87 ret
= lttng_evaluation_buffer_usage_high_create_from_payload(
88 &evaluation_view
, evaluation
);
92 evaluation_size
+= ret
;
94 case LTTNG_CONDITION_TYPE_SESSION_CONSUMED_SIZE
:
95 ret
= lttng_evaluation_session_consumed_size_create_from_payload(
96 &evaluation_view
, evaluation
);
100 evaluation_size
+= ret
;
102 case LTTNG_CONDITION_TYPE_SESSION_ROTATION_ONGOING
:
103 ret
= lttng_evaluation_session_rotation_ongoing_create_from_payload(
104 &evaluation_view
, evaluation
);
108 evaluation_size
+= ret
;
110 case LTTNG_CONDITION_TYPE_SESSION_ROTATION_COMPLETED
:
111 ret
= lttng_evaluation_session_rotation_completed_create_from_payload(
112 &evaluation_view
, evaluation
);
116 evaluation_size
+= ret
;
118 case LTTNG_CONDITION_TYPE_EVENT_RULE_HIT
:
119 ret
= lttng_evaluation_event_rule_create_from_payload(&evaluation_view
, evaluation
);
123 evaluation_size
+= ret
;
126 ERR("Attempted to create evaluation of unknown type (%i)",
127 (int) evaluation_comm
->type
);
132 ret
= evaluation_size
;
137 enum lttng_condition_type
lttng_evaluation_get_type(
138 const struct lttng_evaluation
*evaluation
)
140 return evaluation
? evaluation
->type
: LTTNG_CONDITION_TYPE_UNKNOWN
;
143 void lttng_evaluation_destroy(struct lttng_evaluation
*evaluation
)
149 assert(evaluation
->destroy
);
150 evaluation
->destroy(evaluation
);