2 * Copyright (C) 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * SPDX-License-Identifier: LGPL-2.1-only
8 #include <lttng/action/action-internal.h>
9 #include <lttng/action/notify-internal.h>
10 #include <common/error.h>
13 enum lttng_action_type
lttng_action_get_type(struct lttng_action
*action
)
15 return action
? action
->type
: LTTNG_ACTION_TYPE_UNKNOWN
;
19 enum lttng_action_type
lttng_action_get_type_const(
20 const struct lttng_action
*action
)
25 void lttng_action_destroy(struct lttng_action
*action
)
31 assert(action
->destroy
);
32 action
->destroy(action
);
36 bool lttng_action_validate(struct lttng_action
*action
)
45 if (!action
->validate
) {
46 /* Sub-class guarantees that it can never be invalid. */
51 valid
= action
->validate(action
);
57 int lttng_action_serialize(struct lttng_action
*action
,
58 struct lttng_dynamic_buffer
*buf
)
61 struct lttng_action_comm action_comm
= {
62 .action_type
= (int8_t) action
->type
,
65 ret
= lttng_dynamic_buffer_append(buf
, &action_comm
,
71 ret
= action
->serialize(action
, buf
);
80 ssize_t
lttng_action_create_from_buffer(const struct lttng_buffer_view
*view
,
81 struct lttng_action
**_action
)
83 ssize_t ret
, action_size
= sizeof(struct lttng_action_comm
);
84 struct lttng_action
*action
;
85 const struct lttng_action_comm
*action_comm
;
87 if (!view
|| !_action
) {
92 action_comm
= (const struct lttng_action_comm
*) view
->data
;
93 DBG("Deserializing action from buffer");
94 switch (action_comm
->action_type
) {
95 case LTTNG_ACTION_TYPE_NOTIFY
:
96 action
= lttng_action_notify_create();