bin: compile lttng-sessiond as C++
[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 <lttng/constant.h>
13 #include <inttypes.h>
14 #include <lttng/lttng-error.h>
15
16 struct lttng_action;
17 struct lttng_condition;
18 struct lttng_trigger;
19 /* A set of triggers. */
20 struct lttng_triggers;
21
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25
26 enum lttng_register_trigger_status {
27 LTTNG_REGISTER_TRIGGER_STATUS_OK = 0,
28 LTTNG_REGISTER_TRIGGER_STATUS_INVALID = -1,
29 };
30
31 enum lttng_trigger_status {
32 LTTNG_TRIGGER_STATUS_OK = 0,
33 LTTNG_TRIGGER_STATUS_ERROR = -1,
34 LTTNG_TRIGGER_STATUS_UNKNOWN = -2,
35 LTTNG_TRIGGER_STATUS_INVALID = -3,
36 LTTNG_TRIGGER_STATUS_UNSET = -4,
37 LTTNG_TRIGGER_STATUS_UNSUPPORTED = -5,
38 LTTNG_TRIGGER_STATUS_PERMISSION_DENIED = -6,
39 };
40
41 /*
42 * Create a trigger object associating a condition and an action.
43 *
44 * A trigger associates a condition and an action to take whenever the
45 * condition evaluates to true. Such actions can, for example, consist
46 * in the emission of a notification to clients listening through
47 * notification channels.
48 *
49 * Prior to 2.13, the caller had to retain the ownership of both the condition
50 * and action. Both objects had to be kept alive for the lifetime of the trigger
51 * object. This is no longer the case as the condition and action objects are
52 * internally reference counted. It is safe to destroy a condition and an action
53 * after using them to create a trigger. However, they should no longer be used.
54 *
55 * If the action is a notification action with capture descriptors,
56 * the condition must be an event rule condition.
57 *
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 */
65 extern struct lttng_trigger *lttng_trigger_create(
66 struct lttng_condition *condition, struct lttng_action *action);
67
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
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 */
97 extern struct lttng_condition *lttng_trigger_get_condition(
98 struct lttng_trigger *trigger);
99
100 extern const struct lttng_condition *lttng_trigger_get_const_condition(
101 const struct lttng_trigger *trigger);
102
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 */
110 extern struct lttng_action *lttng_trigger_get_action(
111 struct lttng_trigger *trigger);
112
113 extern const 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 the trigger is unnamed.
126 */
127 extern enum lttng_trigger_status lttng_trigger_get_name(
128 const struct lttng_trigger *trigger, const char **name);
129
130 /*
131 * Destroy (frees) a trigger object.
132 */
133 extern void lttng_trigger_destroy(struct lttng_trigger *trigger);
134
135 /*
136 * Register a trigger to the session daemon with a given name.
137 *
138 * The trigger object can be destroyed after this call.
139 * On success, this function will set the trigger's name to `name`.
140 *
141 * Returns an LTTng status code.
142 */
143 extern enum lttng_error_code lttng_register_trigger_with_name(
144 struct lttng_trigger *trigger,
145 const char *name);
146
147 /*
148 * Register a trigger to the session daemon, generating a unique name for its
149 * owner.
150 *
151 * The trigger can be destroyed after this call.
152 * On success, this function will set the trigger's name to the generated
153 * name.
154 *
155 * Returns an LTTng status code.
156 */
157 extern enum lttng_error_code lttng_register_trigger_with_automatic_name(
158 struct lttng_trigger *trigger);
159
160 /*
161 * Unregister a trigger from the session daemon.
162 *
163 * The trigger can be destroyed after this call.
164 *
165 * Return 0 on success, a negative LTTng error code on error.
166 */
167 extern int lttng_unregister_trigger(const struct lttng_trigger *trigger);
168
169 /*
170 * List triggers for the current user.
171 *
172 * On success, a newly-allocated trigger set is returned.
173 *
174 * The trigger set must be destroyed by the caller (see
175 * lttng_triggers_destroy()).
176 *
177 * Returns LTTNG_OK on success, else a suitable LTTng error code.
178 */
179 extern enum lttng_error_code lttng_list_triggers(
180 struct lttng_triggers **triggers);
181
182 /*
183 * Get a trigger from the set at a given index.
184 *
185 * Note that the trigger set maintains the ownership of the returned trigger.
186 * It must not be destroyed by the user, nor should a reference to it be held
187 * beyond the lifetime of the trigger set.
188 *
189 * Returns a trigger, or NULL on error.
190 */
191 extern const struct lttng_trigger *lttng_triggers_get_at_index(
192 const struct lttng_triggers *triggers, unsigned int index);
193
194 /*
195 * Get the number of triggers in a trigger set.
196 *
197 * Return LTTNG_TRIGGER_STATUS_OK on success,
198 * LTTNG_TRIGGER_STATUS_INVALID when invalid parameters are passed.
199 */
200 extern enum lttng_trigger_status lttng_triggers_get_count(
201 const struct lttng_triggers *triggers, unsigned int *count);
202
203 /*
204 * Destroy a trigger set.
205 */
206 extern void lttng_triggers_destroy(struct lttng_triggers *triggers);
207
208 /*
209 * Deprecated: invocations should be replaced by
210 * lttng_register_trigger_with_automatic_name().
211 *
212 * Register a trigger to the session daemon.
213 *
214 * The trigger can be destroyed after this call.
215 *
216 * Return 0 on success, a negative LTTng error code on error.
217 */
218 LTTNG_DEPRECATED("Use lttng_register_trigger_with_automatic_name")
219 extern int lttng_register_trigger(struct lttng_trigger *trigger);
220
221 #ifdef __cplusplus
222 }
223 #endif
224
225 #endif /* LTTNG_TRIGGER_H */
This page took 0.032928 seconds and 4 git commands to generate.