Commit | Line | Data |
---|---|---|
a58c490f | 1 | /* |
ab5be9fa | 2 | * Copyright (C) 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
a58c490f | 3 | * |
ab5be9fa | 4 | * SPDX-License-Identifier: LGPL-2.1-only |
a58c490f | 5 | * |
a58c490f JG |
6 | */ |
7 | ||
8 | #ifndef LTTNG_TRIGGER_H | |
9 | #define LTTNG_TRIGGER_H | |
10 | ||
64eafdf6 | 11 | #include <sys/types.h> |
5c504c41 | 12 | #include <inttypes.h> |
64eafdf6 | 13 | |
a58c490f JG |
14 | struct lttng_action; |
15 | struct lttng_condition; | |
16 | struct lttng_trigger; | |
a02903c0 JR |
17 | /* A set of triggers. */ |
18 | struct lttng_triggers; | |
a58c490f JG |
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 | ||
64eafdf6 JR |
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 | ||
5c504c41 JR |
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 | ||
75984389 JG |
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 | * | |
38114013 PP |
55 | * If the action is a notification action with capture descriptors, |
56 | * the condition must be an event rule condition. | |
57 | * | |
75984389 JG |
58 | * A trigger must be registered in order to become activate and can |
59 | * be destroyed after its registration. | |
60 | * | |
61 | * Returns a trigger object on success, NULL on error. | |
62 | * Trigger objects must be destroyed using the lttng_trigger_destroy() | |
63 | * function. | |
64 | */ | |
a58c490f JG |
65 | extern struct lttng_trigger *lttng_trigger_create( |
66 | struct lttng_condition *condition, struct lttng_action *action); | |
67 | ||
64eafdf6 JR |
68 | /* |
69 | * Set the user identity (uid) of a trigger. | |
70 | * | |
71 | * Only available for the root user (uid 0). | |
72 | * | |
73 | * Returns LTTNG_TRIGGER_STATUS_OK on success, | |
74 | * LTTNG_TRIGGER_STATUS_EPERM if not authorized, | |
75 | * LTTNG_TRIGGER_STATUS_INVALID if invalid parameters are passed. | |
76 | */ | |
77 | extern enum lttng_trigger_status lttng_trigger_set_owner_uid( | |
78 | struct lttng_trigger *trigger, uid_t uid); | |
79 | ||
80 | /* | |
81 | * Get the user identity (uid) of a trigger. | |
82 | * | |
83 | * Returns LTTNG_TRIGGER_STATUS_OK on success, | |
84 | * LTTNG_TRIGGER_STATUS_UNSET if unset, | |
85 | * LTTNG_TRIGGER_STATUS_INVALID if invalid parameters are passed. | |
86 | */ | |
87 | extern enum lttng_trigger_status lttng_trigger_get_owner_uid( | |
88 | const struct lttng_trigger *trigger, uid_t *uid); | |
89 | ||
75984389 JG |
90 | /* |
91 | * Get the condition of a trigger. | |
92 | * | |
93 | * The caller acquires no ownership of the returned condition. | |
94 | * | |
95 | * Returns a condition on success, NULL on error. | |
96 | */ | |
a58c490f JG |
97 | extern struct lttng_condition *lttng_trigger_get_condition( |
98 | struct lttng_trigger *trigger); | |
99 | ||
0de2479d SM |
100 | const struct lttng_condition *lttng_trigger_get_const_condition( |
101 | const struct lttng_trigger *trigger); | |
102 | ||
75984389 JG |
103 | /* |
104 | * Get the action of a trigger. | |
105 | * | |
106 | * The caller acquires no ownership of the returned action. | |
107 | * | |
108 | * Returns an action on success, NULL on error. | |
109 | */ | |
a58c490f JG |
110 | extern struct lttng_action *lttng_trigger_get_action( |
111 | struct lttng_trigger *trigger); | |
112 | ||
0de2479d SM |
113 | const struct lttng_action *lttng_trigger_get_const_action( |
114 | const struct lttng_trigger *trigger); | |
242388e4 JR |
115 | |
116 | /* | |
117 | * Get the name of a trigger. | |
118 | * | |
119 | * The caller does not assume the ownership of the returned name. | |
120 | * The name shall only only be used for the duration of the trigger's | |
121 | * lifetime, or until a different name is set. | |
122 | * | |
123 | * Returns LTTNG_TRIGGER_STATUS_OK and a pointer to the trigger's name on | |
124 | * success, LTTNG_TRIGGER_STATUS_INVALID if an invalid parameter is passed, | |
125 | * or LTTNG_TRIGGER_STATUS_UNSET if a name was not set prior to this call. | |
126 | */ | |
127 | extern enum lttng_trigger_status lttng_trigger_get_name( | |
128 | const struct lttng_trigger *trigger, const char **name); | |
129 | ||
130 | /* | |
131 | * Set the trigger name. | |
132 | * | |
133 | * A name is optional. | |
134 | * A name will be assigned on trigger registration if no name is set. | |
135 | * | |
136 | * The name is copied. | |
137 | * | |
138 | * Return LTTNG_TRIGGER_STATUS_OK on success, LTTNG_TRIGGER_STATUS_INVALID | |
139 | * if invalid parameters are passed. | |
140 | */ | |
141 | extern enum lttng_trigger_status lttng_trigger_set_name( | |
142 | struct lttng_trigger *trigger, const char *name); | |
143 | ||
5c504c41 JR |
144 | /* |
145 | * Set the trigger firing policy. | |
146 | * | |
147 | * This is optional. By default a trigger is set to fire each time the | |
148 | * associated condition occurs. | |
149 | * | |
150 | * Threshold is the number of times the condition must be hit before the policy | |
151 | * is enacted. | |
152 | * | |
153 | * Return LTTNG_TRIGGER_STATUS_OK on success, LTTNG_TRIGGER_STATUS_INVALID | |
154 | * if invalid parameters are passed. | |
155 | */ | |
156 | extern enum lttng_trigger_status lttng_trigger_set_firing_policy( | |
157 | struct lttng_trigger *trigger, | |
158 | enum lttng_trigger_firing_policy policy_type, | |
159 | uint64_t threshold); | |
160 | ||
161 | /* | |
162 | * Get the trigger firing policy. | |
163 | * | |
164 | * Threshold is the number of time the condition must be hit before the policy is | |
165 | * enacted. | |
166 | * | |
167 | * Return LTTNG_TRIGGER_STATUS_OK on success, LTTNG_TRIGGER_STATUS_INVALID | |
168 | * if invalid parameters are passed. | |
169 | */ | |
170 | extern enum lttng_trigger_status lttng_trigger_get_firing_policy( | |
171 | const struct lttng_trigger *trigger, | |
172 | enum lttng_trigger_firing_policy *policy_type, | |
173 | uint64_t *threshold); | |
174 | ||
75984389 JG |
175 | /* |
176 | * Destroy (frees) a trigger object. | |
177 | */ | |
a58c490f JG |
178 | extern void lttng_trigger_destroy(struct lttng_trigger *trigger); |
179 | ||
75984389 JG |
180 | /* |
181 | * Register a trigger to the session daemon. | |
182 | * | |
183 | * The trigger can be destroyed after this call. | |
184 | * | |
185 | * Return 0 on success, a negative LTTng error code on error. | |
186 | */ | |
a58c490f JG |
187 | extern int lttng_register_trigger(struct lttng_trigger *trigger); |
188 | ||
75984389 JG |
189 | /* |
190 | * Unregister a trigger from the session daemon. | |
191 | * | |
192 | * The trigger can be destroyed after this call. | |
193 | * | |
194 | * Return 0 on success, a negative LTTng error code on error. | |
195 | */ | |
b61776fb | 196 | extern int lttng_unregister_trigger(const struct lttng_trigger *trigger); |
a58c490f | 197 | |
fbc9f37d JR |
198 | /* |
199 | * List triggers for the current user. | |
200 | * | |
201 | * On success, a newly-allocated trigger set is returned. | |
202 | * | |
203 | * The trigger set must be destroyed by the caller (see | |
204 | * lttng_triggers_destroy()). | |
205 | * | |
206 | * Returns LTTNG_OK on success, else a suitable LTTng error code. | |
207 | */ | |
208 | extern enum lttng_error_code lttng_list_triggers( | |
209 | struct lttng_triggers **triggers); | |
210 | ||
a02903c0 JR |
211 | /* |
212 | * Get a trigger from the set at a given index. | |
213 | * | |
214 | * Note that the trigger set maintains the ownership of the returned trigger. | |
215 | * It must not be destroyed by the user, nor should a reference to it be held | |
216 | * beyond the lifetime of the trigger set. | |
217 | * | |
218 | * Returns a trigger, or NULL on error. | |
219 | */ | |
220 | extern const struct lttng_trigger *lttng_triggers_get_at_index( | |
221 | const struct lttng_triggers *triggers, unsigned int index); | |
222 | ||
223 | /* | |
224 | * Get the number of triggers in a trigger set. | |
225 | * | |
226 | * Return LTTNG_TRIGGER_STATUS_OK on success, | |
227 | * LTTNG_TRIGGER_STATUS_INVALID when invalid parameters are passed. | |
228 | */ | |
229 | extern enum lttng_trigger_status lttng_triggers_get_count( | |
230 | const struct lttng_triggers *triggers, unsigned int *count); | |
231 | ||
232 | /* | |
233 | * Destroy a trigger set. | |
234 | */ | |
235 | extern void lttng_triggers_destroy(struct lttng_triggers *triggers); | |
236 | ||
237 | ||
a58c490f JG |
238 | #ifdef __cplusplus |
239 | } | |
240 | #endif | |
241 | ||
242 | #endif /* LTTNG_TRIGGER_H */ |