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 | ||
11 | struct lttng_action; | |
12 | struct lttng_condition; | |
13 | struct lttng_trigger; | |
5024c2ac JR |
14 | /* A collection of trigger */ |
15 | struct lttng_triggers; | |
a58c490f JG |
16 | |
17 | #ifdef __cplusplus | |
18 | extern "C" { | |
19 | #endif | |
20 | ||
21 | enum lttng_register_trigger_status { | |
22 | LTTNG_REGISTER_TRIGGER_STATUS_OK = 0, | |
23 | LTTNG_REGISTER_TRIGGER_STATUS_INVALID = -1, | |
24 | }; | |
25 | ||
5024c2ac JR |
26 | enum lttng_trigger_status { |
27 | LTTNG_TRIGGER_STATUS_OK = 0, | |
28 | LTTNG_TRIGGER_STATUS_ERROR = -1, | |
29 | LTTNG_TRIGGER_STATUS_UNKNOWN = -2, | |
30 | LTTNG_TRIGGER_STATUS_INVALID = -3, | |
31 | LTTNG_TRIGGER_STATUS_UNSET = -4, | |
32 | LTTNG_TRIGGER_STATUS_UNSUPPORTED = -5, | |
33 | }; | |
34 | ||
35 | enum lttng_trigger_firing_policy_type { | |
36 | LTTNG_TRIGGER_FIRE_EVERY_N = 0, | |
37 | LTTNG_TRIGGER_FIRE_ONCE_AFTER_N = 1, | |
38 | }; | |
39 | ||
75984389 JG |
40 | /* |
41 | * Create a trigger object associating a condition and an action. | |
42 | * | |
43 | * A trigger associates a condition and an action to take whenever the | |
44 | * condition evaluates to true. Such actions can, for example, consist | |
45 | * in the emission of a notification to clients listening through | |
46 | * notification channels. | |
47 | * | |
48 | * The caller retains the ownership of both the condition and action | |
49 | * and both must be kept alive for the lifetime of the trigger object. | |
50 | * | |
5024c2ac JR |
51 | * If the action is a notification action with capture descriptors, |
52 | * the condition must be an event rule condition. | |
53 | * | |
75984389 JG |
54 | * A trigger must be registered in order to become activate and can |
55 | * be destroyed after its registration. | |
56 | * | |
57 | * Returns a trigger object on success, NULL on error. | |
58 | * Trigger objects must be destroyed using the lttng_trigger_destroy() | |
59 | * function. | |
60 | */ | |
a58c490f JG |
61 | extern struct lttng_trigger *lttng_trigger_create( |
62 | struct lttng_condition *condition, struct lttng_action *action); | |
63 | ||
75984389 JG |
64 | /* |
65 | * Get the condition of a trigger. | |
66 | * | |
67 | * The caller acquires no ownership of the returned condition. | |
68 | * | |
69 | * Returns a condition on success, NULL on error. | |
70 | */ | |
a58c490f JG |
71 | extern struct lttng_condition *lttng_trigger_get_condition( |
72 | struct lttng_trigger *trigger); | |
73 | ||
5024c2ac JR |
74 | const struct lttng_condition *lttng_trigger_get_const_condition( |
75 | const struct lttng_trigger *trigger); | |
76 | ||
75984389 JG |
77 | /* |
78 | * Get the action of a trigger. | |
79 | * | |
80 | * The caller acquires no ownership of the returned action. | |
81 | * | |
82 | * Returns an action on success, NULL on error. | |
83 | */ | |
a58c490f JG |
84 | extern struct lttng_action *lttng_trigger_get_action( |
85 | struct lttng_trigger *trigger); | |
86 | ||
5024c2ac JR |
87 | const struct lttng_action *lttng_trigger_get_const_action( |
88 | const struct lttng_trigger *trigger); | |
89 | ||
90 | /* | |
91 | * Get the name of a trigger. | |
92 | * | |
93 | * The caller does not assume the ownership of the returned name. | |
94 | * The name shall only only be used for the duration of the trigger's | |
95 | * lifetime, or before a different name is set. | |
96 | * | |
97 | * Returns LTTNG_TRIGGER_STATUS_OK and a pointer to the trigger's name on | |
98 | * success, LTTNG_TRIGGER_STATUS_INVALID if an invalid parameter is passed, | |
99 | * or LTTNG_TRIGGER_STATUS_UNSET if a name was not set prior to this call. | |
100 | */ | |
101 | extern enum lttng_trigger_status lttng_trigger_get_name( | |
102 | const struct lttng_trigger *trigger, const char **name); | |
103 | ||
104 | /* | |
105 | * Set the trigger name. | |
106 | * | |
107 | * A name is optional. | |
108 | * A name will be assigned on trigger registration if no name is set. | |
109 | * | |
110 | * The name is copied. | |
111 | * | |
112 | * Return LTTNG_TRIGGER_STATUS_OK on success, LTTNG_TRIGGER_STATUS_INVALID | |
113 | * if invalid parameters are passed. | |
114 | */ | |
115 | extern enum lttng_trigger_status lttng_trigger_set_name( | |
116 | struct lttng_trigger *trigger, const char *name); | |
117 | ||
118 | /* | |
119 | * Set the trigger firing policy. | |
120 | * | |
121 | * This is optional. By default a trigger is set to fire each time the | |
122 | * associated condition occurs. | |
123 | * | |
124 | * Threshold is the number of time the condition must be hit before the policy is | |
125 | * enacted. | |
126 | * | |
127 | * Return LTTNG_TRIGGER_STATUS_OK on success, LTTNG_TRIGGER_STATUS_INVALID | |
128 | * if invalid parameters are passed. | |
129 | */ | |
130 | extern enum lttng_trigger_status lttng_trigger_set_firing_policy( | |
131 | struct lttng_trigger *trigger, | |
132 | enum lttng_trigger_firing_policy_type policy_type, | |
133 | unsigned long long threshold); | |
134 | extern enum lttng_trigger_status lttng_trigger_get_firing_policy( | |
135 | const struct lttng_trigger *trigger, | |
136 | enum lttng_trigger_firing_policy_type *policy_type, | |
137 | unsigned long long *threshold); | |
138 | ||
75984389 JG |
139 | /* |
140 | * Destroy (frees) a trigger object. | |
141 | */ | |
a58c490f JG |
142 | extern void lttng_trigger_destroy(struct lttng_trigger *trigger); |
143 | ||
75984389 JG |
144 | /* |
145 | * Register a trigger to 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 | */ | |
a58c490f JG |
151 | extern int lttng_register_trigger(struct lttng_trigger *trigger); |
152 | ||
75984389 JG |
153 | /* |
154 | * Unregister a trigger from the session daemon. | |
155 | * | |
156 | * The trigger can be destroyed after this call. | |
157 | * | |
158 | * Return 0 on success, a negative LTTng error code on error. | |
159 | */ | |
5024c2ac JR |
160 | extern int lttng_unregister_trigger(const struct lttng_trigger *trigger); |
161 | ||
162 | /* | |
163 | * List current triggers. | |
164 | * | |
165 | * On success, triggers is allocated. | |
166 | * The trigger collection must be free by the caller with lttng_destroy_triggers | |
167 | * | |
168 | * Returns 0 on success, else a negative LTTng error code. | |
169 | */ | |
170 | extern int lttng_list_triggers(struct lttng_triggers **triggers); | |
171 | ||
172 | /* | |
173 | * Get a trigger from the collection at a given index. | |
174 | * | |
175 | * Note that the collection maintains the ownership of the returned trigger. | |
176 | * It must not be destroyed by the user, nor should it be held beyond the | |
177 | * lifetime of the trigger collection. | |
178 | * | |
179 | * Returns a trigger, or NULL on error. | |
180 | */ | |
181 | extern const struct lttng_trigger *lttng_triggers_get_at_index( | |
182 | const struct lttng_triggers *triggers, unsigned int index); | |
183 | ||
184 | /* | |
185 | * Get the number of trigger in a tracker id list. | |
186 | * | |
187 | * Return LTTNG_TRIGGER_STATUS_OK on success, | |
188 | * LTTNG_TRIGGER_STATUS_INVALID when passed invalid parameters. | |
189 | */ | |
190 | extern enum lttng_trigger_status lttng_triggers_get_count( | |
191 | const struct lttng_triggers *triggers, unsigned int *count); | |
192 | ||
193 | /* | |
194 | * Destroy a trigger collection. | |
195 | */ | |
196 | extern void lttng_triggers_destroy(struct lttng_triggers *ids); | |
197 | ||
a58c490f JG |
198 | |
199 | #ifdef __cplusplus | |
200 | } | |
201 | #endif | |
202 | ||
203 | #endif /* LTTNG_TRIGGER_H */ |