b8e6080d9519a7edaaab43ca291c7c45f56e685d
[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
13 struct lttng_action;
14 struct lttng_condition;
15 struct lttng_trigger;
16 /* A set of triggers. */
17 struct lttng_triggers;
18
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22
23 enum lttng_register_trigger_status {
24 LTTNG_REGISTER_TRIGGER_STATUS_OK = 0,
25 LTTNG_REGISTER_TRIGGER_STATUS_INVALID = -1,
26 };
27
28 enum lttng_trigger_status {
29 LTTNG_TRIGGER_STATUS_OK = 0,
30 LTTNG_TRIGGER_STATUS_ERROR = -1,
31 LTTNG_TRIGGER_STATUS_UNKNOWN = -2,
32 LTTNG_TRIGGER_STATUS_INVALID = -3,
33 LTTNG_TRIGGER_STATUS_UNSET = -4,
34 LTTNG_TRIGGER_STATUS_UNSUPPORTED = -5,
35 LTTNG_TRIGGER_STATUS_PERMISSION_DENIED = -6,
36 };
37
38 /*
39 * Create a trigger object associating a condition and an action.
40 *
41 * A trigger associates a condition and an action to take whenever the
42 * condition evaluates to true. Such actions can, for example, consist
43 * in the emission of a notification to clients listening through
44 * notification channels.
45 *
46 * The caller retains the ownership of both the condition and action
47 * and both must be kept alive for the lifetime of the trigger object.
48 *
49 * A trigger must be registered in order to become activate and can
50 * be destroyed after its registration.
51 *
52 * Returns a trigger object on success, NULL on error.
53 * Trigger objects must be destroyed using the lttng_trigger_destroy()
54 * function.
55 */
56 extern struct lttng_trigger *lttng_trigger_create(
57 struct lttng_condition *condition, struct lttng_action *action);
58
59 /*
60 * Set the user identity (uid) of a trigger.
61 *
62 * Only available for the root user (uid 0).
63 *
64 * Returns LTTNG_TRIGGER_STATUS_OK on success,
65 * LTTNG_TRIGGER_STATUS_EPERM if not authorized,
66 * LTTNG_TRIGGER_STATUS_INVALID if invalid parameters are passed.
67 */
68 extern enum lttng_trigger_status lttng_trigger_set_owner_uid(
69 struct lttng_trigger *trigger, uid_t uid);
70
71 /*
72 * Get the user identity (uid) of a trigger.
73 *
74 * Returns LTTNG_TRIGGER_STATUS_OK on success,
75 * LTTNG_TRIGGER_STATUS_UNSET if unset,
76 * LTTNG_TRIGGER_STATUS_INVALID if invalid parameters are passed.
77 */
78 extern enum lttng_trigger_status lttng_trigger_get_owner_uid(
79 const struct lttng_trigger *trigger, uid_t *uid);
80
81 /*
82 * Get the condition of a trigger.
83 *
84 * The caller acquires no ownership of the returned condition.
85 *
86 * Returns a condition on success, NULL on error.
87 */
88 extern struct lttng_condition *lttng_trigger_get_condition(
89 struct lttng_trigger *trigger);
90
91 /*
92 * Get the action of a trigger.
93 *
94 * The caller acquires no ownership of the returned action.
95 *
96 * Returns an action on success, NULL on error.
97 */
98 extern struct lttng_action *lttng_trigger_get_action(
99 struct lttng_trigger *trigger);
100
101
102 /*
103 * Get the name of a trigger.
104 *
105 * The caller does not assume the ownership of the returned name.
106 * The name shall only only be used for the duration of the trigger's
107 * lifetime, or until a different name is set.
108 *
109 * Returns LTTNG_TRIGGER_STATUS_OK and a pointer to the trigger's name on
110 * success, LTTNG_TRIGGER_STATUS_INVALID if an invalid parameter is passed,
111 * or LTTNG_TRIGGER_STATUS_UNSET if a name was not set prior to this call.
112 */
113 extern enum lttng_trigger_status lttng_trigger_get_name(
114 const struct lttng_trigger *trigger, const char **name);
115
116 /*
117 * Set the trigger name.
118 *
119 * A name is optional.
120 * A name will be assigned on trigger registration if no name is set.
121 *
122 * The name is copied.
123 *
124 * Return LTTNG_TRIGGER_STATUS_OK on success, LTTNG_TRIGGER_STATUS_INVALID
125 * if invalid parameters are passed.
126 */
127 extern enum lttng_trigger_status lttng_trigger_set_name(
128 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.
137 *
138 * The trigger can be destroyed after this call.
139 *
140 * Return 0 on success, a negative LTTng error code on error.
141 */
142 extern int lttng_register_trigger(struct lttng_trigger *trigger);
143
144 /*
145 * Unregister a trigger from the session daemon.
146 *
147 * The trigger can be destroyed after this call.
148 *
149 * Return 0 on success, a negative LTTng error code on error.
150 */
151 extern int lttng_unregister_trigger(struct lttng_trigger *trigger);
152
153 /*
154 * Get a trigger from the set at a given index.
155 *
156 * Note that the trigger set maintains the ownership of the returned trigger.
157 * It must not be destroyed by the user, nor should a reference to it be held
158 * beyond the lifetime of the trigger set.
159 *
160 * Returns a trigger, or NULL on error.
161 */
162 extern const struct lttng_trigger *lttng_triggers_get_at_index(
163 const struct lttng_triggers *triggers, unsigned int index);
164
165 /*
166 * Get the number of triggers in a trigger set.
167 *
168 * Return LTTNG_TRIGGER_STATUS_OK on success,
169 * LTTNG_TRIGGER_STATUS_INVALID when invalid parameters are passed.
170 */
171 extern enum lttng_trigger_status lttng_triggers_get_count(
172 const struct lttng_triggers *triggers, unsigned int *count);
173
174 /*
175 * Destroy a trigger set.
176 */
177 extern void lttng_triggers_destroy(struct lttng_triggers *triggers);
178
179
180 #ifdef __cplusplus
181 }
182 #endif
183
184 #endif /* LTTNG_TRIGGER_H */
This page took 0.03227 seconds and 4 git commands to generate.