b36ee13a286f0d1d785a83da0c1ec85031776c4f
[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 /*
98 * Get the action of a trigger.
99 *
100 * The caller acquires no ownership of the returned action.
101 *
102 * Returns an action on success, NULL on error.
103 */
104 extern struct lttng_action *lttng_trigger_get_action(
105 struct lttng_trigger *trigger);
106
107
108 /*
109 * Get the name of a trigger.
110 *
111 * The caller does not assume the ownership of the returned name.
112 * The name shall only only be used for the duration of the trigger's
113 * lifetime, or until a different name is set.
114 *
115 * Returns LTTNG_TRIGGER_STATUS_OK and a pointer to the trigger's name on
116 * success, LTTNG_TRIGGER_STATUS_INVALID if an invalid parameter is passed,
117 * or LTTNG_TRIGGER_STATUS_UNSET if a name was not set prior to this call.
118 */
119 extern enum lttng_trigger_status lttng_trigger_get_name(
120 const struct lttng_trigger *trigger, const char **name);
121
122 /*
123 * Set the trigger name.
124 *
125 * A name is optional.
126 * A name will be assigned on trigger registration if no name is set.
127 *
128 * The name is copied.
129 *
130 * Return LTTNG_TRIGGER_STATUS_OK on success, LTTNG_TRIGGER_STATUS_INVALID
131 * if invalid parameters are passed.
132 */
133 extern enum lttng_trigger_status lttng_trigger_set_name(
134 struct lttng_trigger *trigger, const char *name);
135
136 /*
137 * Set the trigger firing policy.
138 *
139 * This is optional. By default a trigger is set to fire each time the
140 * associated condition occurs.
141 *
142 * Threshold is the number of times the condition must be hit before the policy
143 * is enacted.
144 *
145 * Return LTTNG_TRIGGER_STATUS_OK on success, LTTNG_TRIGGER_STATUS_INVALID
146 * if invalid parameters are passed.
147 */
148 extern enum lttng_trigger_status lttng_trigger_set_firing_policy(
149 struct lttng_trigger *trigger,
150 enum lttng_trigger_firing_policy policy_type,
151 uint64_t threshold);
152
153 /*
154 * Get the trigger firing policy.
155 *
156 * Threshold is the number of time the condition must be hit before the policy is
157 * enacted.
158 *
159 * Return LTTNG_TRIGGER_STATUS_OK on success, LTTNG_TRIGGER_STATUS_INVALID
160 * if invalid parameters are passed.
161 */
162 extern enum lttng_trigger_status lttng_trigger_get_firing_policy(
163 const struct lttng_trigger *trigger,
164 enum lttng_trigger_firing_policy *policy_type,
165 uint64_t *threshold);
166
167 /*
168 * Destroy (frees) a trigger object.
169 */
170 extern void lttng_trigger_destroy(struct lttng_trigger *trigger);
171
172 /*
173 * Register a trigger to the session daemon.
174 *
175 * The trigger can be destroyed after this call.
176 *
177 * Return 0 on success, a negative LTTng error code on error.
178 */
179 extern int lttng_register_trigger(struct lttng_trigger *trigger);
180
181 /*
182 * Unregister a trigger from the session daemon.
183 *
184 * The trigger can be destroyed after this call.
185 *
186 * Return 0 on success, a negative LTTng error code on error.
187 */
188 extern int lttng_unregister_trigger(struct lttng_trigger *trigger);
189
190 /*
191 * List triggers for the current user.
192 *
193 * On success, a newly-allocated trigger set is returned.
194 *
195 * The trigger set must be destroyed by the caller (see
196 * lttng_triggers_destroy()).
197 *
198 * Returns LTTNG_OK on success, else a suitable LTTng error code.
199 */
200 extern enum lttng_error_code lttng_list_triggers(
201 struct lttng_triggers **triggers);
202
203 /*
204 * Get a trigger from the set at a given index.
205 *
206 * Note that the trigger set maintains the ownership of the returned trigger.
207 * It must not be destroyed by the user, nor should a reference to it be held
208 * beyond the lifetime of the trigger set.
209 *
210 * Returns a trigger, or NULL on error.
211 */
212 extern const struct lttng_trigger *lttng_triggers_get_at_index(
213 const struct lttng_triggers *triggers, unsigned int index);
214
215 /*
216 * Get the number of triggers in a trigger set.
217 *
218 * Return LTTNG_TRIGGER_STATUS_OK on success,
219 * LTTNG_TRIGGER_STATUS_INVALID when invalid parameters are passed.
220 */
221 extern enum lttng_trigger_status lttng_triggers_get_count(
222 const struct lttng_triggers *triggers, unsigned int *count);
223
224 /*
225 * Destroy a trigger set.
226 */
227 extern void lttng_triggers_destroy(struct lttng_triggers *triggers);
228
229
230 #ifdef __cplusplus
231 }
232 #endif
233
234 #endif /* LTTNG_TRIGGER_H */
This page took 0.049636 seconds and 3 git commands to generate.