SoW-2020-0002: Trace Hit Counters: trigger error reporting integration
[lttng-tools.git] / include / lttng / trigger / trigger.h
CommitLineData
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
2463b787
JR
11#include <sys/types.h>
12#include <inttypes.h>
13
a58c490f
JG
14struct lttng_action;
15struct lttng_condition;
16struct lttng_trigger;
2463b787
JR
17/* A set of triggers */
18struct lttng_triggers;
a58c490f
JG
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
24enum lttng_register_trigger_status {
25 LTTNG_REGISTER_TRIGGER_STATUS_OK = 0,
26 LTTNG_REGISTER_TRIGGER_STATUS_INVALID = -1,
27};
28
2463b787
JR
29enum 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_EPERM = -6,
37};
38
39enum lttng_trigger_firing_policy_type {
40 LTTNG_TRIGGER_FIRE_EVERY_N = 0,
41 LTTNG_TRIGGER_FIRE_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 *
2463b787
JR
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
65extern struct lttng_trigger *lttng_trigger_create(
66 struct lttng_condition *condition, struct lttng_action *action);
67
2463b787
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 */
77extern enum lttng_trigger_status lttng_trigger_set_user_identity(
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 */
87extern enum lttng_trigger_status lttng_trigger_get_user_identity(
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
97extern struct lttng_condition *lttng_trigger_get_condition(
98 struct lttng_trigger *trigger);
99
2463b787
JR
100const 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
110extern struct lttng_action *lttng_trigger_get_action(
111 struct lttng_trigger *trigger);
112
2463b787
JR
113const struct lttng_action *lttng_trigger_get_const_action(
114 const struct lttng_trigger *trigger);
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 */
127extern 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 */
141extern enum lttng_trigger_status lttng_trigger_set_name(
142 struct lttng_trigger *trigger, const char *name);
143
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 time the condition must be hit before the policy is
151 * enacted.
152 *
153 * Return LTTNG_TRIGGER_STATUS_OK on success, LTTNG_TRIGGER_STATUS_INVALID
154 * if invalid parameters are passed.
155 */
156extern enum lttng_trigger_status lttng_trigger_set_firing_policy(
157 struct lttng_trigger *trigger,
158 enum lttng_trigger_firing_policy_type 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 */
170extern enum lttng_trigger_status lttng_trigger_get_firing_policy(
171 const struct lttng_trigger *trigger,
172 enum lttng_trigger_firing_policy_type *policy_type,
173 uint64_t *threshold);
174
75984389
JG
175/*
176 * Destroy (frees) a trigger object.
177 */
a58c490f
JG
178extern 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
187extern 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 */
2463b787
JR
196extern int lttng_unregister_trigger(const struct lttng_trigger *trigger);
197
198/*
199 * List current triggers.
200 *
201 * On success, a newly-allocated trigger set is returned.
202 * The trigger set must be destroyed by the caller (see
203 * lttng_triggers_destroy()).
204 *
205 * Returns LTTNG_OK on success, else a negative LTTng error code.
206 */
207extern enum lttng_error_code lttng_list_triggers(
208 struct lttng_triggers **triggers);
209
210/*
211 * Get a trigger from the set at a given index.
212 *
213 * Note that the set maintains the ownership of the returned trigger.
214 * It must not be destroyed by the user, nor should it be held beyond the
215 * lifetime of the trigger set.
216 *
217 * Returns a trigger, or NULL on error.
218 */
219extern const struct lttng_trigger *lttng_triggers_get_at_index(
220 const struct lttng_triggers *triggers, unsigned int index);
221
222/*
223 * Get the number of trigger in a trigger set.
224 *
225 * Return LTTNG_TRIGGER_STATUS_OK on success,
226 * LTTNG_TRIGGER_STATUS_INVALID when passed invalid parameters.
227 */
228extern enum lttng_trigger_status lttng_triggers_get_count(
229 const struct lttng_triggers *triggers, unsigned int *count);
230
231/*
232 * Destroy a trigger set.
233 */
234extern void lttng_triggers_destroy(struct lttng_triggers *ids);
235
a58c490f
JG
236
237#ifdef __cplusplus
238}
239#endif
240
241#endif /* LTTNG_TRIGGER_H */
This page took 0.069804 seconds and 5 git commands to generate.