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 <common/macros.h>
13 #include <common/error.h>
18 void lttng_evaluation_init(struct lttng_evaluation
*evaluation
,
19 enum lttng_condition_type type
)
21 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
= {
30 .type
= (int8_t) evaluation
->type
33 ret
= lttng_dynamic_buffer_append(&payload
->buffer
, &evaluation_comm
,
34 sizeof(evaluation_comm
));
39 if (evaluation
->serialize
) {
40 ret
= evaluation
->serialize(evaluation
, payload
);
50 ssize_t
lttng_evaluation_create_from_payload(
51 struct lttng_payload_view
*src_view
,
52 struct lttng_evaluation
**evaluation
)
54 ssize_t ret
, evaluation_size
= 0;
55 const struct lttng_evaluation_comm
*evaluation_comm
;
56 struct lttng_payload_view evaluation_view
= src_view
?
57 lttng_payload_view_from_view(src_view
,
58 sizeof(*evaluation_comm
), -1) :
59 (typeof(evaluation_view
)) {};
61 if (!src_view
|| !evaluation
) {
66 evaluation_comm
= (typeof(evaluation_comm
)) src_view
->buffer
.data
;
67 evaluation_size
+= sizeof(*evaluation_comm
);
69 switch ((enum lttng_condition_type
) evaluation_comm
->type
) {
70 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW
:
71 ret
= lttng_evaluation_buffer_usage_low_create_from_payload(
72 &evaluation_view
, evaluation
);
76 evaluation_size
+= ret
;
78 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH
:
79 ret
= lttng_evaluation_buffer_usage_high_create_from_payload(
80 &evaluation_view
, evaluation
);
84 evaluation_size
+= ret
;
86 case LTTNG_CONDITION_TYPE_SESSION_CONSUMED_SIZE
:
87 ret
= lttng_evaluation_session_consumed_size_create_from_payload(
88 &evaluation_view
, evaluation
);
92 evaluation_size
+= ret
;
94 case LTTNG_CONDITION_TYPE_SESSION_ROTATION_ONGOING
:
95 ret
= lttng_evaluation_session_rotation_ongoing_create_from_payload(
96 &evaluation_view
, evaluation
);
100 evaluation_size
+= ret
;
102 case LTTNG_CONDITION_TYPE_SESSION_ROTATION_COMPLETED
:
103 ret
= lttng_evaluation_session_rotation_completed_create_from_payload(
104 &evaluation_view
, evaluation
);
108 evaluation_size
+= ret
;
111 ERR("Attempted to create evaluation of unknown type (%i)",
112 (int) evaluation_comm
->type
);
117 ret
= evaluation_size
;
122 enum lttng_condition_type
lttng_evaluation_get_type(
123 const struct lttng_evaluation
*evaluation
)
125 return evaluation
? evaluation
->type
: LTTNG_CONDITION_TYPE_UNKNOWN
;
128 void lttng_evaluation_destroy(struct lttng_evaluation
*evaluation
)
134 assert(evaluation
->destroy
);
135 evaluation
->destroy(evaluation
);