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/trigger/trigger-internal.h>
19 #include <lttng/condition/condition-internal.h>
20 #include <lttng/action/action-internal.h>
24 bool lttng_trigger_validate(struct lttng_trigger
*trigger
)
33 valid
= lttng_condition_validate(trigger
->condition
) &&
34 lttng_action_validate(trigger
->action
);
39 struct lttng_trigger
*lttng_trigger_create(
40 struct lttng_condition
*condition
,
41 struct lttng_action
*action
)
43 struct lttng_trigger
*trigger
= NULL
;
45 if (!condition
|| !action
) {
49 trigger
= zmalloc(sizeof(struct lttng_trigger
));
54 trigger
->condition
= condition
;
55 trigger
->action
= action
;
60 void lttng_trigger_destroy(struct lttng_trigger
*trigger
)
66 lttng_condition_destroy(trigger
->condition
);
67 lttng_action_destroy(trigger
->action
);
72 ssize_t
lttng_trigger_create_from_buffer(const char *buf
,
73 struct lttng_trigger
**trigger
)
75 ssize_t ret
, trigger_size
;
76 struct lttng_condition
*condition
= NULL
;
77 struct lttng_action
*action
= NULL
;
79 if (!buf
|| !trigger
) {
84 ret
= lttng_condition_create_from_buffer(buf
, &condition
);
91 ret
= lttng_action_create_from_buffer(buf
, &action
);
97 *trigger
= lttng_trigger_create(condition
, action
);
105 lttng_condition_destroy(condition
);
106 lttng_action_destroy(action
);
111 * Returns the size of a trigger's condition and action.
112 * Both elements are stored contiguously, see their "*_comm" structure
113 * for the detailed format.
116 ssize_t
lttng_trigger_serialize(struct lttng_trigger
*trigger
, char *buf
)
118 ssize_t action_size
, condition_size
, ret
;
125 condition_size
= lttng_condition_serialize(trigger
->condition
, NULL
);
126 if (condition_size
< 0) {
131 action_size
= lttng_action_serialize(trigger
->action
, NULL
);
132 if (action_size
< 0) {
137 ret
= action_size
+ condition_size
;
142 condition_size
= lttng_condition_serialize(trigger
->condition
, buf
);
143 if (condition_size
< 0) {
148 buf
+= condition_size
;
149 action_size
= lttng_action_serialize(trigger
->action
, buf
);
150 if (action_size
< 0) {
This page took 0.033075 seconds and 5 git commands to generate.