lttng-ctl: add event expression API
[lttng-tools.git] / include / lttng / trigger / trigger.h
1 /*
2 * Copyright (C) 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 *
4 * SPDX-License-Identifier: LGPL-2.1-only
5 *
6 */
7
8 #ifndef LTTNG_TRIGGER_H
9 #define LTTNG_TRIGGER_H
10
11 #include <sys/types.h>
12 #include <inttypes.h>
13
14 struct lttng_action;
15 struct lttng_condition;
16 struct lttng_trigger;
17 /* A set of triggers. */
18 struct lttng_triggers;
19
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23
24 enum lttng_register_trigger_status {
25 LTTNG_REGISTER_TRIGGER_STATUS_OK = 0,
26 LTTNG_REGISTER_TRIGGER_STATUS_INVALID = -1,
27 };
28
29 enum lttng_trigger_status {
30 LTTNG_TRIGGER_STATUS_OK = 0,
31 LTTNG_TRIGGER_STATUS_ERROR = -1,
32 LTTNG_TRIGGER_STATUS_UNKNOWN = -2,
33 LTTNG_TRIGGER_STATUS_INVALID = -3,
34 LTTNG_TRIGGER_STATUS_UNSET = -4,
35 LTTNG_TRIGGER_STATUS_UNSUPPORTED = -5,
36 LTTNG_TRIGGER_STATUS_PERMISSION_DENIED = -6,
37 };
38
39 enum lttng_trigger_firing_policy {
40 LTTNG_TRIGGER_FIRING_POLICY_EVERY_N = 0,
41 LTTNG_TRIGGER_FIRING_POLICY_ONCE_AFTER_N = 1,
42 };
43
44 /*
45 * Create a trigger object associating a condition and an action.
46 *
47 * A trigger associates a condition and an action to take whenever the
48 * condition evaluates to true. Such actions can, for example, consist
49 * in the emission of a notification to clients listening through
50 * notification channels.
51 *
52 * The caller retains the ownership of both the condition and action
53 * and both must be kept alive for the lifetime of the trigger object.
54 *
55 * A trigger must be registered in order to become activate and can
56 * be destroyed after its registration.
57 *
58 * Returns a trigger object on success, NULL on error.
59 * Trigger objects must be destroyed using the lttng_trigger_destroy()
60 * function.
61 */
62 extern struct lttng_trigger *lttng_trigger_create(
63 struct lttng_condition *condition, struct lttng_action *action);
64
65 /*
66 * Set the user identity (uid) of a trigger.
67 *
68 * Only available for the root user (uid 0).
69 *
70 * Returns LTTNG_TRIGGER_STATUS_OK on success,
71 * LTTNG_TRIGGER_STATUS_EPERM if not authorized,
72 * LTTNG_TRIGGER_STATUS_INVALID if invalid parameters are passed.
73 */
74 extern enum lttng_trigger_status lttng_trigger_set_owner_uid(
75 struct lttng_trigger *trigger, uid_t uid);
76
77 /*
78 * Get the user identity (uid) of a trigger.
79 *
80 * Returns LTTNG_TRIGGER_STATUS_OK on success,
81 * LTTNG_TRIGGER_STATUS_UNSET if unset,
82 * LTTNG_TRIGGER_STATUS_INVALID if invalid parameters are passed.
83 */
84 extern enum lttng_trigger_status lttng_trigger_get_owner_uid(
85 const struct lttng_trigger *trigger, uid_t *uid);
86
87 /*
88 * Get the condition of a trigger.
89 *
90 * The caller acquires no ownership of the returned condition.
91 *
92 * Returns a condition on success, NULL on error.
93 */
94 extern struct lttng_condition *lttng_trigger_get_condition(
95 struct lttng_trigger *trigger);
96
97 const struct lttng_condition *lttng_trigger_get_const_condition(
98 const struct lttng_trigger *trigger);
99
100 /*
101 * Get the action of a trigger.
102 *
103 * The caller acquires no ownership of the returned action.
104 *
105 * Returns an action on success, NULL on error.
106 */
107 extern struct lttng_action *lttng_trigger_get_action(
108 struct lttng_trigger *trigger);
109
110 const struct lttng_action *lttng_trigger_get_const_action(
111 const struct lttng_trigger *trigger);
112
113 /*
114 * Get the name of a trigger.
115 *
116 * The caller does not assume the ownership of the returned name.
117 * The name shall only only be used for the duration of the trigger's
118 * lifetime, or until a different name is set.
119 *
120 * Returns LTTNG_TRIGGER_STATUS_OK and a pointer to the trigger's name on
121 * success, LTTNG_TRIGGER_STATUS_INVALID if an invalid parameter is passed,
122 * or LTTNG_TRIGGER_STATUS_UNSET if a name was not set prior to this call.
123 */
124 extern enum lttng_trigger_status lttng_trigger_get_name(
125 const struct lttng_trigger *trigger, const char **name);
126
127 /*
128 * Set the trigger name.
129 *
130 * A name is optional.
131 * A name will be assigned on trigger registration if no name is set.
132 *
133 * The name is copied.
134 *
135 * Return LTTNG_TRIGGER_STATUS_OK on success, LTTNG_TRIGGER_STATUS_INVALID
136 * if invalid parameters are passed.
137 */
138 extern enum lttng_trigger_status lttng_trigger_set_name(
139 struct lttng_trigger *trigger, const char *name);
140
141 /*
142 * Set the trigger firing policy.
143 *
144 * This is optional. By default a trigger is set to fire each time the
145 * associated condition occurs.
146 *
147 * Threshold is the number of times the condition must be hit before the policy
148 * is enacted.
149 *
150 * Return LTTNG_TRIGGER_STATUS_OK on success, LTTNG_TRIGGER_STATUS_INVALID
151 * if invalid parameters are passed.
152 */
153 extern enum lttng_trigger_status lttng_trigger_set_firing_policy(
154 struct lttng_trigger *trigger,
155 enum lttng_trigger_firing_policy policy_type,
156 uint64_t threshold);
157
158 /*
159 * Get the trigger firing policy.
160 *
161 * Threshold is the number of time the condition must be hit before the policy is
162 * enacted.
163 *
164 * Return LTTNG_TRIGGER_STATUS_OK on success, LTTNG_TRIGGER_STATUS_INVALID
165 * if invalid parameters are passed.
166 */
167 extern enum lttng_trigger_status lttng_trigger_get_firing_policy(
168 const struct lttng_trigger *trigger,
169 enum lttng_trigger_firing_policy *policy_type,
170 uint64_t *threshold);
171
172 /*
173 * Destroy (frees) a trigger object.
174 */
175 extern void lttng_trigger_destroy(struct lttng_trigger *trigger);
176
177 /*
178 * Register a trigger to the session daemon.
179 *
180 * The trigger can be destroyed after this call.
181 *
182 * Return 0 on success, a negative LTTng error code on error.
183 */
184 extern int lttng_register_trigger(struct lttng_trigger *trigger);
185
186 /*
187 * Unregister a trigger from the session daemon.
188 *
189 * The trigger can be destroyed after this call.
190 *
191 * Return 0 on success, a negative LTTng error code on error.
192 */
193 extern int lttng_unregister_trigger(const struct lttng_trigger *trigger);
194
195 /*
196 * List triggers for the current user.
197 *
198 * On success, a newly-allocated trigger set is returned.
199 *
200 * The trigger set must be destroyed by the caller (see
201 * lttng_triggers_destroy()).
202 *
203 * Returns LTTNG_OK on success, else a suitable LTTng error code.
204 */
205 extern enum lttng_error_code lttng_list_triggers(
206 struct lttng_triggers **triggers);
207
208 /*
209 * Get a trigger from the set at a given index.
210 *
211 * Note that the trigger set maintains the ownership of the returned trigger.
212 * It must not be destroyed by the user, nor should a reference to it be held
213 * beyond the lifetime of the trigger set.
214 *
215 * Returns a trigger, or NULL on error.
216 */
217 extern const struct lttng_trigger *lttng_triggers_get_at_index(
218 const struct lttng_triggers *triggers, unsigned int index);
219
220 /*
221 * Get the number of triggers in a trigger set.
222 *
223 * Return LTTNG_TRIGGER_STATUS_OK on success,
224 * LTTNG_TRIGGER_STATUS_INVALID when invalid parameters are passed.
225 */
226 extern enum lttng_trigger_status lttng_triggers_get_count(
227 const struct lttng_triggers *triggers, unsigned int *count);
228
229 /*
230 * Destroy a trigger set.
231 */
232 extern void lttng_triggers_destroy(struct lttng_triggers *triggers);
233
234
235 #ifdef __cplusplus
236 }
237 #endif
238
239 #endif /* LTTNG_TRIGGER_H */
This page took 0.064834 seconds and 4 git commands to generate.