Commit | Line | Data |
---|---|---|
668ba131 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/trigger/trigger-internal.h> | |
2a38b722 JG |
19 | #include <lttng/condition/condition-internal.h> |
20 | #include <lttng/action/action-internal.h> | |
668ba131 JG |
21 | #include <assert.h> |
22 | ||
23 | struct lttng_trigger *lttng_trigger_create( | |
24 | struct lttng_condition *condition, | |
25 | struct lttng_action *action) | |
26 | { | |
27 | struct lttng_trigger *trigger = NULL; | |
28 | ||
29 | if (!condition || !action) { | |
30 | goto end; | |
31 | } | |
32 | ||
33 | trigger = zmalloc(sizeof(struct lttng_trigger)); | |
34 | if (!trigger) { | |
35 | goto end; | |
36 | } | |
37 | ||
38 | trigger->condition = condition; | |
39 | trigger->action = action; | |
40 | end: | |
41 | return trigger; | |
42 | } | |
43 | ||
44 | void lttng_trigger_destroy(struct lttng_trigger *trigger) | |
45 | { | |
46 | if (!trigger) { | |
47 | return; | |
48 | } | |
49 | ||
50 | lttng_condition_destroy(trigger->condition); | |
51 | lttng_action_destroy(trigger->action); | |
52 | free(trigger); | |
53 | } | |
2a38b722 JG |
54 | |
55 | ssize_t lttng_trigger_serialize(struct lttng_trigger *trigger, char *buf) | |
56 | { | |
57 | ssize_t action_size, condition_size, ret; | |
58 | ||
59 | if (!trigger) { | |
60 | ret = -1; | |
61 | goto end; | |
62 | } | |
63 | ||
64 | condition_size = lttng_condition_serialize(trigger->condition, buf); | |
65 | if (condition_size < 0) { | |
66 | ret = -1; | |
67 | goto end; | |
68 | } | |
69 | ||
70 | action_size = lttng_action_serialize(trigger->action, buf); | |
71 | if (action_size < 0) { | |
72 | ret = -1; | |
73 | goto end; | |
74 | } | |
75 | ret = action_size + condition_size; | |
76 | end: | |
77 | return ret; | |
78 | } |