Add client notification API
[lttng-tools.git] / src / common / evaluation.c
CommitLineData
a58c490f
JG
1/*
2 * Copyright (C) 2017 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 *
4 * This library is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License, version 2.1 only,
6 * as published by the Free Software Foundation.
7 *
8 * This library is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
11 * for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this library; if not, write to the Free Software Foundation,
15 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17
18#include <lttng/condition/evaluation-internal.h>
19#include <lttng/condition/buffer-usage-internal.h>
20#include <common/macros.h>
21#include <common/error.h>
22#include <stdbool.h>
23#include <assert.h>
24
25LTTNG_HIDDEN
26ssize_t lttng_evaluation_serialize(struct lttng_evaluation *evaluation,
27 char *buf)
28{
29 ssize_t ret, offset = 0;
30 struct lttng_evaluation_comm evaluation_comm;
31
32 evaluation_comm.type = (int8_t) evaluation->type;
33 if (buf) {
34 memcpy(buf, &evaluation_comm, sizeof(evaluation_comm));
35 }
36 offset += sizeof(evaluation_comm);
37
38 if (evaluation->serialize) {
39 ret = evaluation->serialize(evaluation,
40 buf ? (buf + offset) : NULL);
41 if (ret < 0) {
42 goto end;
43 }
44 offset += ret;
45 }
46
47 ret = offset;
48end:
49 return ret;
50}
51
52LTTNG_HIDDEN
53ssize_t lttng_evaluation_create_from_buffer(
54 const struct lttng_buffer_view *src_view,
55 struct lttng_evaluation **evaluation)
56{
57 ssize_t ret, evaluation_size = 0;
58 const struct lttng_evaluation_comm *evaluation_comm;
59 const struct lttng_buffer_view evaluation_view =
60 lttng_buffer_view_from_view(src_view,
61 sizeof(*evaluation_comm), -1);
62
63 if (!src_view || !evaluation) {
64 ret = -1;
65 goto end;
66 }
67
68 evaluation_comm = (const struct lttng_evaluation_comm *) src_view->data;
69 evaluation_size += sizeof(*evaluation_comm);
70
71 switch ((enum lttng_condition_type) evaluation_comm->type) {
72 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW:
73 ret = lttng_evaluation_buffer_usage_low_create_from_buffer(
74 &evaluation_view, evaluation);
75 if (ret < 0) {
76 goto end;
77 }
78 evaluation_size += ret;
79 break;
80 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH:
81 ret = lttng_evaluation_buffer_usage_high_create_from_buffer(
82 &evaluation_view, evaluation);
83 if (ret < 0) {
84 goto end;
85 }
86 evaluation_size += ret;
87 break;
88 default:
89 ERR("Attempted to create evaluation of unknown type (%i)",
90 (int) evaluation_comm->type);
91 ret = -1;
92 goto end;
93 }
94 ret = evaluation_size;
95end:
96 return ret;
97}
98
99enum lttng_condition_type lttng_evaluation_get_type(
100 const struct lttng_evaluation *evaluation)
101{
102 return evaluation ? evaluation->type : LTTNG_CONDITION_TYPE_UNKNOWN;
103}
104
105void lttng_evaluation_destroy(struct lttng_evaluation *evaluation)
106{
107 if (!evaluation) {
108 return;
109 }
110
111 assert(evaluation->destroy);
112 evaluation->destroy(evaluation);
113}
This page took 0.026336 seconds and 4 git commands to generate.