lib: compile liblttng-ctl 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 #include <lttng/lttng-export.h>
16
17 struct lttng_action;
18 struct lttng_condition;
19 struct lttng_trigger;
20 /* A set of triggers. */
21 struct lttng_triggers;
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26
27 enum lttng_register_trigger_status {
28 LTTNG_REGISTER_TRIGGER_STATUS_OK = 0,
29 LTTNG_REGISTER_TRIGGER_STATUS_INVALID = -1,
30 };
31
32 enum lttng_trigger_status {
33 LTTNG_TRIGGER_STATUS_OK = 0,
34 LTTNG_TRIGGER_STATUS_ERROR = -1,
35 LTTNG_TRIGGER_STATUS_UNKNOWN = -2,
36 LTTNG_TRIGGER_STATUS_INVALID = -3,
37 LTTNG_TRIGGER_STATUS_UNSET = -4,
38 LTTNG_TRIGGER_STATUS_UNSUPPORTED = -5,
39 LTTNG_TRIGGER_STATUS_PERMISSION_DENIED = -6,
40 };
41
42 /*
43 * Create a trigger object associating a condition and an action.
44 *
45 * A trigger associates a condition and an action to take whenever the
46 * condition evaluates to true. Such actions can, for example, consist
47 * in the emission of a notification to clients listening through
48 * notification channels.
49 *
50 * Prior to 2.13, the caller had to retain the ownership of both the condition
51 * and action. Both objects had to be kept alive for the lifetime of the trigger
52 * object. This is no longer the case as the condition and action objects are
53 * internally reference counted. It is safe to destroy a condition and an action
54 * after using them to create a trigger. However, they should no longer be used.
55 *
56 * If the action is a notification action with capture descriptors,
57 * the condition must be an event rule condition.
58 *
59 * A trigger must be registered in order to become activate and can
60 * be destroyed after its registration.
61 *
62 * Returns a trigger object on success, NULL on error.
63 * Trigger objects must be destroyed using the lttng_trigger_destroy()
64 * function.
65 */
66 LTTNG_EXPORT extern struct lttng_trigger *lttng_trigger_create(
67 struct lttng_condition *condition, struct lttng_action *action);
68
69 /*
70 * Set the user identity (uid) of a trigger.
71 *
72 * Only available for the root user (uid 0).
73 *
74 * Returns LTTNG_TRIGGER_STATUS_OK on success,
75 * LTTNG_TRIGGER_STATUS_EPERM if not authorized,
76 * LTTNG_TRIGGER_STATUS_INVALID if invalid parameters are passed.
77 */
78 LTTNG_EXPORT extern enum lttng_trigger_status lttng_trigger_set_owner_uid(
79 struct lttng_trigger *trigger, uid_t uid);
80
81 /*
82 * Get the user identity (uid) of a trigger.
83 *
84 * Returns LTTNG_TRIGGER_STATUS_OK on success,
85 * LTTNG_TRIGGER_STATUS_UNSET if unset,
86 * LTTNG_TRIGGER_STATUS_INVALID if invalid parameters are passed.
87 */
88 LTTNG_EXPORT extern enum lttng_trigger_status lttng_trigger_get_owner_uid(
89 const struct lttng_trigger *trigger, uid_t *uid);
90
91 /*
92 * Get the condition of a trigger.
93 *
94 * The caller acquires no ownership of the returned condition.
95 *
96 * Returns a condition on success, NULL on error.
97 */
98 LTTNG_EXPORT extern struct lttng_condition *lttng_trigger_get_condition(
99 struct lttng_trigger *trigger);
100
101 LTTNG_EXPORT extern const struct lttng_condition *lttng_trigger_get_const_condition(
102 const struct lttng_trigger *trigger);
103
104 /*
105 * Get the action of a trigger.
106 *
107 * The caller acquires no ownership of the returned action.
108 *
109 * Returns an action on success, NULL on error.
110 */
111 LTTNG_EXPORT extern struct lttng_action *lttng_trigger_get_action(
112 struct lttng_trigger *trigger);
113
114 LTTNG_EXPORT extern const struct lttng_action *lttng_trigger_get_const_action(
115 const struct lttng_trigger *trigger);
116
117 /*
118 * Get the name of a trigger.
119 *
120 * The caller does not assume the ownership of the returned name.
121 * The name shall only only be used for the duration of the trigger's
122 * lifetime, or until a different name is set.
123 *
124 * Returns LTTNG_TRIGGER_STATUS_OK and a pointer to the trigger's name on
125 * success, LTTNG_TRIGGER_STATUS_INVALID if an invalid parameter is passed,
126 * or LTTNG_TRIGGER_STATUS_UNSET if the trigger is unnamed.
127 */
128 LTTNG_EXPORT extern enum lttng_trigger_status lttng_trigger_get_name(
129 const struct lttng_trigger *trigger, const char **name);
130
131 /*
132 * Destroy (frees) a trigger object.
133 */
134 LTTNG_EXPORT extern void lttng_trigger_destroy(struct lttng_trigger *trigger);
135
136 /*
137 * Register a trigger to the session daemon with a given name.
138 *
139 * The trigger object can be destroyed after this call.
140 * On success, this function will set the trigger's name to `name`.
141 *
142 * Returns an LTTng status code.
143 */
144 LTTNG_EXPORT extern enum lttng_error_code lttng_register_trigger_with_name(
145 struct lttng_trigger *trigger,
146 const char *name);
147
148 /*
149 * Register a trigger to the session daemon, generating a unique name for its
150 * owner.
151 *
152 * The trigger can be destroyed after this call.
153 * On success, this function will set the trigger's name to the generated
154 * name.
155 *
156 * Returns an LTTng status code.
157 */
158 LTTNG_EXPORT extern enum lttng_error_code lttng_register_trigger_with_automatic_name(
159 struct lttng_trigger *trigger);
160
161 /*
162 * Unregister a trigger from the session daemon.
163 *
164 * The trigger can be destroyed after this call.
165 *
166 * Return 0 on success, a negative LTTng error code on error.
167 */
168 LTTNG_EXPORT extern int lttng_unregister_trigger(const struct lttng_trigger *trigger);
169
170 /*
171 * List triggers for the current user.
172 *
173 * On success, a newly-allocated trigger set is returned.
174 *
175 * The trigger set must be destroyed by the caller (see
176 * lttng_triggers_destroy()).
177 *
178 * Returns LTTNG_OK on success, else a suitable LTTng error code.
179 */
180 LTTNG_EXPORT extern enum lttng_error_code lttng_list_triggers(
181 struct lttng_triggers **triggers);
182
183 /*
184 * Get a trigger from the set at a given index.
185 *
186 * Note that the trigger set maintains the ownership of the returned trigger.
187 * It must not be destroyed by the user, nor should a reference to it be held
188 * beyond the lifetime of the trigger set.
189 *
190 * Returns a trigger, or NULL on error.
191 */
192 LTTNG_EXPORT extern const struct lttng_trigger *lttng_triggers_get_at_index(
193 const struct lttng_triggers *triggers, unsigned int index);
194
195 /*
196 * Get the number of triggers in a trigger set.
197 *
198 * Return LTTNG_TRIGGER_STATUS_OK on success,
199 * LTTNG_TRIGGER_STATUS_INVALID when invalid parameters are passed.
200 */
201 LTTNG_EXPORT extern enum lttng_trigger_status lttng_triggers_get_count(
202 const struct lttng_triggers *triggers, unsigned int *count);
203
204 /*
205 * Destroy a trigger set.
206 */
207 LTTNG_EXPORT extern void lttng_triggers_destroy(struct lttng_triggers *triggers);
208
209 /*
210 * Deprecated: invocations should be replaced by
211 * lttng_register_trigger_with_automatic_name().
212 *
213 * Register a trigger to the session daemon.
214 *
215 * The trigger can be destroyed after this call.
216 *
217 * Return 0 on success, a negative LTTng error code on error.
218 */
219 LTTNG_DEPRECATED("Use lttng_register_trigger_with_automatic_name")
220 LTTNG_EXPORT extern int lttng_register_trigger(struct lttng_trigger *trigger);
221
222 #ifdef __cplusplus
223 }
224 #endif
225
226 #endif /* LTTNG_TRIGGER_H */
This page took 0.032668 seconds and 4 git commands to generate.