sessiond: notification: maintain an id to notification_client ht
[lttng-tools.git] / src / common / evaluation.c
CommitLineData
a58c490f 1/*
ab5be9fa 2 * Copyright (C) 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
a58c490f 3 *
ab5be9fa 4 * SPDX-License-Identifier: LGPL-2.1-only
a58c490f 5 *
a58c490f
JG
6 */
7
8#include <lttng/condition/evaluation-internal.h>
9#include <lttng/condition/buffer-usage-internal.h>
e8360425 10#include <lttng/condition/session-consumed-size-internal.h>
c19092cd 11#include <lttng/condition/session-rotation-internal.h>
a58c490f
JG
12#include <common/macros.h>
13#include <common/error.h>
14#include <stdbool.h>
15#include <assert.h>
16
c19092cd
JG
17LTTNG_HIDDEN
18void lttng_evaluation_init(struct lttng_evaluation *evaluation,
19 enum lttng_condition_type type)
20{
21 evaluation->type = type;
22}
23
a58c490f 24LTTNG_HIDDEN
9b63a4aa 25int lttng_evaluation_serialize(const struct lttng_evaluation *evaluation,
c0a66c84 26 struct lttng_payload *payload)
a58c490f 27{
3647288f 28 int ret;
db315d75
JG
29 struct lttng_evaluation_comm evaluation_comm = {
30 .type = (int8_t) evaluation->type
31 };
a58c490f 32
c0a66c84 33 ret = lttng_dynamic_buffer_append(&payload->buffer, &evaluation_comm,
3647288f
JG
34 sizeof(evaluation_comm));
35 if (ret) {
36 goto end;
a58c490f 37 }
a58c490f
JG
38
39 if (evaluation->serialize) {
c0a66c84 40 ret = evaluation->serialize(evaluation, payload);
3647288f 41 if (ret) {
a58c490f
JG
42 goto end;
43 }
a58c490f 44 }
a58c490f
JG
45end:
46 return ret;
47}
48
49LTTNG_HIDDEN
c0a66c84
JG
50ssize_t lttng_evaluation_create_from_payload(
51 struct lttng_payload_view *src_view,
a58c490f
JG
52 struct lttng_evaluation **evaluation)
53{
54 ssize_t ret, evaluation_size = 0;
55 const struct lttng_evaluation_comm *evaluation_comm;
2f571d6f
JG
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)) {};
a58c490f
JG
60
61 if (!src_view || !evaluation) {
62 ret = -1;
63 goto end;
64 }
65
c0a66c84 66 evaluation_comm = (typeof(evaluation_comm)) src_view->buffer.data;
a58c490f
JG
67 evaluation_size += sizeof(*evaluation_comm);
68
69 switch ((enum lttng_condition_type) evaluation_comm->type) {
70 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW:
c0a66c84 71 ret = lttng_evaluation_buffer_usage_low_create_from_payload(
a58c490f
JG
72 &evaluation_view, evaluation);
73 if (ret < 0) {
74 goto end;
75 }
76 evaluation_size += ret;
77 break;
78 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH:
c0a66c84 79 ret = lttng_evaluation_buffer_usage_high_create_from_payload(
a58c490f
JG
80 &evaluation_view, evaluation);
81 if (ret < 0) {
82 goto end;
83 }
84 evaluation_size += ret;
85 break;
e8360425 86 case LTTNG_CONDITION_TYPE_SESSION_CONSUMED_SIZE:
c0a66c84 87 ret = lttng_evaluation_session_consumed_size_create_from_payload(
e8360425
JD
88 &evaluation_view, evaluation);
89 if (ret < 0) {
90 goto end;
91 }
92 evaluation_size += ret;
93 break;
c19092cd 94 case LTTNG_CONDITION_TYPE_SESSION_ROTATION_ONGOING:
c0a66c84 95 ret = lttng_evaluation_session_rotation_ongoing_create_from_payload(
c19092cd
JG
96 &evaluation_view, evaluation);
97 if (ret < 0) {
98 goto end;
99 }
100 evaluation_size += ret;
101 break;
102 case LTTNG_CONDITION_TYPE_SESSION_ROTATION_COMPLETED:
c0a66c84 103 ret = lttng_evaluation_session_rotation_completed_create_from_payload(
c19092cd
JG
104 &evaluation_view, evaluation);
105 if (ret < 0) {
106 goto end;
107 }
108 evaluation_size += ret;
109 break;
a58c490f
JG
110 default:
111 ERR("Attempted to create evaluation of unknown type (%i)",
112 (int) evaluation_comm->type);
113 ret = -1;
114 goto end;
115 }
c0a66c84 116
a58c490f
JG
117 ret = evaluation_size;
118end:
119 return ret;
120}
121
122enum lttng_condition_type lttng_evaluation_get_type(
123 const struct lttng_evaluation *evaluation)
124{
125 return evaluation ? evaluation->type : LTTNG_CONDITION_TYPE_UNKNOWN;
126}
127
128void lttng_evaluation_destroy(struct lttng_evaluation *evaluation)
129{
130 if (!evaluation) {
131 return;
132 }
133
134 assert(evaluation->destroy);
135 evaluation->destroy(evaluation);
136}
This page took 0.038136 seconds and 4 git commands to generate.