2 * Copyright (C) 2017 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
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.
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
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
18 #include <lttng/condition/condition-internal.h>
19 #include <lttng/condition/buffer-usage-internal.h>
20 #include <common/macros.h>
24 enum lttng_condition_type
lttng_condition_get_type(
25 struct lttng_condition
*condition
)
27 return condition
? condition
->type
: LTTNG_CONDITION_TYPE_UNKNOWN
;
30 void lttng_condition_destroy(struct lttng_condition
*condition
)
36 assert(condition
->destroy
);
37 condition
->destroy(condition
);
41 bool lttng_condition_validate(struct lttng_condition
*condition
)
50 if (!condition
->validate
) {
51 /* Sub-class guarantees that it can never be invalid. */
56 valid
= condition
->validate(condition
);
62 ssize_t
lttng_condition_serialize(struct lttng_condition
*condition
, char *buf
)
64 ssize_t ret
, condition_size
;
65 struct lttng_condition_comm condition_comm
;
72 condition_comm
.condition_type
= (int8_t) condition
->type
;
73 ret
= sizeof(struct lttng_condition_comm
);
75 memcpy(buf
, &condition_comm
, ret
);
79 condition_size
= condition
->serialize(condition
, buf
);
80 if (condition_size
< 0) {
84 ret
+= condition_size
;
90 ssize_t
lttng_condition_create_from_buffer(const char *buf
,
91 struct lttng_condition
**condition
)
93 ssize_t ret
, condition_size
= 0;
94 struct lttng_condition_comm
*condition_comm
=
95 (struct lttng_condition_comm
*) buf
;
97 if (!buf
|| !condition
) {
102 condition_size
+= sizeof(*condition_comm
);
103 buf
+= condition_size
;
105 switch (condition_comm
->condition_type
) {
106 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW
:
107 ret
= lttng_condition_buffer_usage_low_create_from_buffer(buf
,
112 condition_size
+= ret
;
114 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH
:
115 ret
= lttng_condition_buffer_usage_high_create_from_buffer(buf
,
120 condition_size
+= ret
;
126 ret
= condition_size
;