wip: receive trigger registration in session daemon
[lttng-tools.git] / src / lib / lttng-ctl / action.c
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 <lttng/action/notify-internal.h>
20 #include <assert.h>
21
22 enum lttng_action_type lttng_action_get_type(struct lttng_action *action)
23 {
24 return action ? action->type : LTTNG_ACTION_TYPE_UNKNOWN;
25 }
26
27 void lttng_action_destroy(struct lttng_action *action)
28 {
29 if (!action) {
30 return;
31 }
32
33 assert(action->destroy);
34 action->destroy(action);
35 }
36
37 LTTNG_HIDDEN
38 bool lttng_action_validate(struct lttng_action *action)
39 {
40 bool valid;
41
42 if (!action) {
43 valid = false;
44 goto end;
45 }
46
47 if (!action->validate) {
48 /* Sub-class guarantees that it can never be invalid. */
49 valid = true;
50 goto end;
51 }
52
53 valid = action->validate(action);
54 end:
55 return valid;
56 }
57
58 LTTNG_HIDDEN
59 ssize_t lttng_action_serialize(struct lttng_action *action, char *buf)
60 {
61 ssize_t ret, action_size;
62 struct lttng_action_comm action_comm;
63
64 if (!action) {
65 ret = -1;
66 goto end;
67 }
68
69 action_comm.action_type = (int8_t) action->type;
70 ret = sizeof(struct lttng_action_comm);
71 if (buf) {
72 memcpy(buf, &action_comm, ret);
73 buf += ret;
74 }
75
76 action_size = action->serialize(action, buf);
77 if (action_size < 0) {
78 ret = action_size;
79 goto end;
80 }
81 ret += action_size;
82 end:
83 return ret;
84 }
85
86 LTTNG_HIDDEN
87 ssize_t lttng_action_create_from_buffer(const char *buf,
88 struct lttng_action **_action)
89 {
90 ssize_t ret, action_size = sizeof(struct lttng_action_comm);
91 struct lttng_action *action;
92 struct lttng_action_comm *action_comm =
93 (struct lttng_action_comm *) buf;
94
95 if (!buf || !_action) {
96 ret = -1;
97 goto end;
98 }
99
100 switch (action_comm->action_type) {
101 case LTTNG_ACTION_TYPE_NOTIFY:
102 action = lttng_action_notify_create();
103 break;
104 default:
105 ret = -1;
106 goto end;
107 }
108
109 if (!action) {
110 ret = -1;
111 goto end;
112 }
113 ret = action_size;
114 *_action = action;
115 end:
116 return ret;
117 }
This page took 0.039684 seconds and 5 git commands to generate.