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>
21 #include <common/error.h>
25 bool lttng_trigger_validate(struct lttng_trigger
*trigger
)
34 valid
= lttng_condition_validate(trigger
->condition
) &&
35 lttng_action_validate(trigger
->action
);
40 struct lttng_trigger
*lttng_trigger_create(
41 struct lttng_condition
*condition
,
42 struct lttng_action
*action
)
44 struct lttng_trigger
*trigger
= NULL
;
46 if (!condition
|| !action
) {
50 trigger
= zmalloc(sizeof(struct lttng_trigger
));
55 trigger
->condition
= condition
;
56 trigger
->action
= action
;
61 void lttng_trigger_destroy(struct lttng_trigger
*trigger
)
67 lttng_condition_destroy(trigger
->condition
);
68 lttng_action_destroy(trigger
->action
);
73 ssize_t
lttng_trigger_create_from_buffer(const char *buf
,
74 struct lttng_trigger
**trigger
)
76 ssize_t ret
, trigger_size
;
77 struct lttng_condition
*condition
= NULL
;
78 struct lttng_action
*action
= NULL
;
80 if (!buf
|| !trigger
) {
85 DBG("Deserializing trigger from buffer");
86 ret
= lttng_condition_create_from_buffer(buf
, &condition
);
93 ret
= lttng_action_create_from_buffer(buf
, &action
);
99 *trigger
= lttng_trigger_create(condition
, action
);
107 lttng_condition_destroy(condition
);
108 lttng_action_destroy(action
);
113 * Returns the size of a trigger's condition and action.
114 * Both elements are stored contiguously, see their "*_comm" structure
115 * for the detailed format.
118 ssize_t
lttng_trigger_serialize(struct lttng_trigger
*trigger
, char *buf
)
120 ssize_t action_size
, condition_size
, ret
;
127 condition_size
= lttng_condition_serialize(trigger
->condition
, NULL
);
128 if (condition_size
< 0) {
133 action_size
= lttng_action_serialize(trigger
->action
, NULL
);
134 if (action_size
< 0) {
139 ret
= action_size
+ condition_size
;
144 condition_size
= lttng_condition_serialize(trigger
->condition
, buf
);
145 if (condition_size
< 0) {
150 buf
+= condition_size
;
151 action_size
= lttng_action_serialize(trigger
->action
, buf
);
152 if (action_size
< 0) {
This page took 0.035009 seconds and 5 git commands to generate.