Commit | Line | Data |
---|---|---|
a87af0fd 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/action/action-internal.h> | |
19 | #include <assert.h> | |
20 | ||
21 | enum lttng_action_type lttng_action_get_type(struct lttng_action *action) | |
22 | { | |
23 | return action ? action->type : LTTNG_ACTION_TYPE_UNKNOWN; | |
24 | } | |
25 | ||
26 | void lttng_action_destroy(struct lttng_action *action) | |
27 | { | |
28 | if (!action) { | |
29 | return; | |
30 | } | |
31 | ||
32 | assert(action->destroy); | |
33 | action->destroy(action); | |
34 | } | |
35 | ||
36 | LTTNG_HIDDEN | |
37 | bool lttng_action_validate(struct lttng_action *action) | |
38 | { | |
39 | bool valid; | |
40 | ||
41 | if (!action) { | |
42 | valid = false; | |
43 | goto end; | |
44 | } | |
45 | ||
46 | if (!action->validate) { | |
47 | /* Sub-class guarantees that it can never be invalid. */ | |
48 | valid = true; | |
49 | goto end; | |
50 | } | |
51 | ||
52 | valid = action->validate(action); | |
53 | end: | |
54 | return valid; | |
55 | } | |
2a38b722 JG |
56 | |
57 | LTTNG_HIDDEN | |
58 | ssize_t lttng_action_serialize(struct lttng_action *action, char *buf) | |
59 | { | |
60 | ssize_t ret, action_size; | |
61 | struct lttng_action_comm action_comm; | |
62 | ||
63 | if (!action) { | |
64 | ret = -1; | |
65 | goto end; | |
66 | } | |
67 | ||
68 | action_comm.action_type = (int8_t) action->type; | |
69 | ret = sizeof(struct lttng_action_comm); | |
70 | if (buf) { | |
71 | memcpy(buf, &action_comm, ret); | |
72 | buf += ret; | |
73 | } | |
74 | ||
75 | action_size = action->serialize(action, buf); | |
76 | if (action_size < 0) { | |
77 | ret = action_size; | |
78 | goto end; | |
79 | } | |
80 | ret += action_size; | |
81 | end: | |
82 | return ret; | |
83 | } |