2 * Copyright (C) 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * SPDX-License-Identifier: LGPL-2.1-only
8 #include <common/error.hpp>
9 #include <common/macros.hpp>
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>
20 void lttng_evaluation_init(struct lttng_evaluation
*evaluation
, enum lttng_condition_type type
)
22 evaluation
->type
= type
;
25 int lttng_evaluation_serialize(const struct lttng_evaluation
*evaluation
,
26 struct lttng_payload
*payload
)
29 struct lttng_evaluation_comm evaluation_comm
;
31 evaluation_comm
.type
= (int8_t) evaluation
->type
;
33 ret
= lttng_dynamic_buffer_append(
34 &payload
->buffer
, &evaluation_comm
, sizeof(evaluation_comm
));
39 if (evaluation
->serialize
) {
40 ret
= evaluation
->serialize(evaluation
, payload
);
49 ssize_t
lttng_evaluation_create_from_payload(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(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);
60 if (!src_view
|| !evaluation
) {
65 if (!lttng_payload_view_is_valid(&evaluation_comm_view
)) {
70 evaluation_comm
= (typeof(evaluation_comm
)) evaluation_comm_view
.buffer
.data
;
71 evaluation_size
+= sizeof(*evaluation_comm
);
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
,
80 evaluation_size
+= ret
;
82 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH
:
83 ret
= lttng_evaluation_buffer_usage_high_create_from_payload(&evaluation_view
,
88 evaluation_size
+= ret
;
90 case LTTNG_CONDITION_TYPE_SESSION_CONSUMED_SIZE
:
91 ret
= lttng_evaluation_session_consumed_size_create_from_payload(&evaluation_view
,
96 evaluation_size
+= ret
;
98 case LTTNG_CONDITION_TYPE_SESSION_ROTATION_ONGOING
:
99 ret
= lttng_evaluation_session_rotation_ongoing_create_from_payload(
100 &evaluation_view
, evaluation
);
104 evaluation_size
+= ret
;
106 case LTTNG_CONDITION_TYPE_SESSION_ROTATION_COMPLETED
:
107 ret
= lttng_evaluation_session_rotation_completed_create_from_payload(
108 &evaluation_view
, evaluation
);
112 evaluation_size
+= ret
;
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 <tng_condition_event_rule_matches::parent
),
125 evaluation_size
+= ret
;
128 ERR("Attempted to create evaluation of unknown type (%i)",
129 (int) evaluation_comm
->type
);
134 ret
= evaluation_size
;
139 enum lttng_condition_type
lttng_evaluation_get_type(const struct lttng_evaluation
*evaluation
)
141 return evaluation
? evaluation
->type
: LTTNG_CONDITION_TYPE_UNKNOWN
;
144 void lttng_evaluation_destroy(struct lttng_evaluation
*evaluation
)
150 LTTNG_ASSERT(evaluation
->destroy
);
151 evaluation
->destroy(evaluation
);