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.hpp>
9 #include <lttng/condition/evaluation-internal.hpp>
10 #include <lttng/condition/buffer-usage-internal.hpp>
11 #include <lttng/condition/session-consumed-size-internal.hpp>
12 #include <lttng/condition/session-rotation-internal.hpp>
13 #include <lttng/condition/event-rule-matches-internal.hpp>
14 #include <common/macros.hpp>
15 #include <common/error.hpp>
18 void lttng_evaluation_init(struct lttng_evaluation
*evaluation
,
19 enum lttng_condition_type type
)
21 evaluation
->type
= type
;
24 int lttng_evaluation_serialize(const struct lttng_evaluation
*evaluation
,
25 struct lttng_payload
*payload
)
28 struct lttng_evaluation_comm evaluation_comm
= {
29 .type
= (int8_t) evaluation
->type
32 ret
= lttng_dynamic_buffer_append(&payload
->buffer
, &evaluation_comm
,
33 sizeof(evaluation_comm
));
38 if (evaluation
->serialize
) {
39 ret
= evaluation
->serialize(evaluation
, payload
);
48 ssize_t
lttng_evaluation_create_from_payload(
49 const struct lttng_condition
*condition
,
50 struct lttng_payload_view
*src_view
,
51 struct lttng_evaluation
**evaluation
)
53 ssize_t ret
, evaluation_size
= 0;
54 const struct lttng_evaluation_comm
*evaluation_comm
;
55 struct lttng_payload_view evaluation_comm_view
=
56 lttng_payload_view_from_view(
57 src_view
, 0, sizeof(*evaluation_comm
));
58 struct lttng_payload_view evaluation_view
=
59 lttng_payload_view_from_view(src_view
,
60 sizeof(*evaluation_comm
), -1);
62 if (!src_view
|| !evaluation
) {
67 if (!lttng_payload_view_is_valid(&evaluation_comm_view
)) {
72 evaluation_comm
= (typeof(evaluation_comm
)) evaluation_comm_view
.buffer
.data
;
73 evaluation_size
+= sizeof(*evaluation_comm
);
75 switch ((enum lttng_condition_type
) evaluation_comm
->type
) {
76 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW
:
77 ret
= lttng_evaluation_buffer_usage_low_create_from_payload(
78 &evaluation_view
, evaluation
);
82 evaluation_size
+= ret
;
84 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH
:
85 ret
= lttng_evaluation_buffer_usage_high_create_from_payload(
86 &evaluation_view
, evaluation
);
90 evaluation_size
+= ret
;
92 case LTTNG_CONDITION_TYPE_SESSION_CONSUMED_SIZE
:
93 ret
= lttng_evaluation_session_consumed_size_create_from_payload(
94 &evaluation_view
, evaluation
);
98 evaluation_size
+= ret
;
100 case LTTNG_CONDITION_TYPE_SESSION_ROTATION_ONGOING
:
101 ret
= lttng_evaluation_session_rotation_ongoing_create_from_payload(
102 &evaluation_view
, evaluation
);
106 evaluation_size
+= ret
;
108 case LTTNG_CONDITION_TYPE_SESSION_ROTATION_COMPLETED
:
109 ret
= lttng_evaluation_session_rotation_completed_create_from_payload(
110 &evaluation_view
, evaluation
);
114 evaluation_size
+= ret
;
116 case LTTNG_CONDITION_TYPE_EVENT_RULE_MATCHES
:
117 LTTNG_ASSERT(condition
);
118 LTTNG_ASSERT(condition
->type
==
119 LTTNG_CONDITION_TYPE_EVENT_RULE_MATCHES
);
120 ret
= lttng_evaluation_event_rule_matches_create_from_payload(
121 container_of(condition
,
122 const struct lttng_condition_event_rule_matches
,
124 &evaluation_view
, evaluation
);
128 evaluation_size
+= ret
;
131 ERR("Attempted to create evaluation of unknown type (%i)",
132 (int) evaluation_comm
->type
);
137 ret
= evaluation_size
;
142 enum lttng_condition_type
lttng_evaluation_get_type(
143 const struct lttng_evaluation
*evaluation
)
145 return evaluation
? evaluation
->type
: LTTNG_CONDITION_TYPE_UNKNOWN
;
148 void lttng_evaluation_destroy(struct lttng_evaluation
*evaluation
)
154 LTTNG_ASSERT(evaluation
->destroy
);
155 evaluation
->destroy(evaluation
);