SoW-2019-0002: Dynamic Snapshot
[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 struct lttng_action;
12 struct lttng_condition;
13 struct lttng_trigger;
14 /* A collection of trigger */
15 struct lttng_triggers;
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
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
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 *
51 * A trigger must be registered in order to become activate and can
52 * be destroyed after its registration.
53 *
54 * Returns a trigger object on success, NULL on error.
55 * Trigger objects must be destroyed using the lttng_trigger_destroy()
56 * function.
57 */
58 extern struct lttng_trigger *lttng_trigger_create(
59 struct lttng_condition *condition, struct lttng_action *action);
60
61 /*
62 * Get the condition of a trigger.
63 *
64 * The caller acquires no ownership of the returned condition.
65 *
66 * Returns a condition on success, NULL on error.
67 */
68 extern struct lttng_condition *lttng_trigger_get_condition(
69 struct lttng_trigger *trigger);
70
71 const struct lttng_condition *lttng_trigger_get_const_condition(
72 const struct lttng_trigger *trigger);
73
74 /*
75 * Get the action of a trigger.
76 *
77 * The caller acquires no ownership of the returned action.
78 *
79 * Returns an action on success, NULL on error.
80 */
81 extern struct lttng_action *lttng_trigger_get_action(
82 struct lttng_trigger *trigger);
83
84 const struct lttng_action *lttng_trigger_get_const_action(
85 const struct lttng_trigger *trigger);
86
87 /*
88 * Get the name of a trigger.
89 *
90 * The caller does not assume the ownership of the returned name.
91 * The name shall only only be used for the duration of the trigger's
92 * lifetime, or before a different name is set.
93 *
94 * Returns LTTNG_TRIGGER_STATUS_OK and a pointer to the trigger's name on
95 * success, LTTNG_TRIGGER_STATUS_INVALID if an invalid parameter is passed,
96 * or LTTNG_TRIGGER_STATUS_UNSET if a name was not set prior to this call.
97 */
98 extern enum lttng_trigger_status lttng_trigger_get_name(
99 const struct lttng_trigger *trigger, const char **name);
100
101 /*
102 * Set the trigger name.
103 *
104 * A name is optional.
105 * A name will be assigned on trigger registration if no name is set.
106 *
107 * The name is copied.
108 *
109 * Return LTTNG_TRIGGER_STATUS_OK on success, LTTNG_TRIGGER_STATUS_INVALID
110 * if invalid parameters are passed.
111 */
112 extern enum lttng_trigger_status lttng_trigger_set_name(
113 struct lttng_trigger *trigger, const char *name);
114
115 /*
116 * Set the trigger firing policy.
117 *
118 * This is optional. By default a trigger is set to fire each time the
119 * associated condition occurs.
120 *
121 * Threshold is the number of time the condition must be hit before the policy is
122 * enacted.
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_firing_policy(
128 struct lttng_trigger *trigger,
129 enum lttng_trigger_firing_policy_type policy_type,
130 unsigned long long threshold);
131 extern enum lttng_trigger_status lttng_trigger_get_firing_policy(
132 const struct lttng_trigger *trigger,
133 enum lttng_trigger_firing_policy_type *policy_type,
134 unsigned long long *threshold);
135
136 /*
137 * Destroy (frees) a trigger object.
138 */
139 extern void lttng_trigger_destroy(struct lttng_trigger *trigger);
140
141 /*
142 * Register a trigger to the session daemon.
143 *
144 * The trigger can be destroyed after this call.
145 *
146 * Return 0 on success, a negative LTTng error code on error.
147 */
148 extern int lttng_register_trigger(struct lttng_trigger *trigger);
149
150 /*
151 * Unregister a trigger from the session daemon.
152 *
153 * The trigger can be destroyed after this call.
154 *
155 * Return 0 on success, a negative LTTng error code on error.
156 */
157 extern int lttng_unregister_trigger(const struct lttng_trigger *trigger);
158
159 /*
160 * List current triggers.
161 *
162 * On success, triggers is allocated.
163 * The trigger collection must be free by the caller with lttng_destroy_triggers
164 *
165 * Returns 0 on success, else a negative LTTng error code.
166 */
167 extern int lttng_list_triggers(struct lttng_triggers **triggers);
168
169 /*
170 * Get a trigger from the collection at a given index.
171 *
172 * Note that the collection maintains the ownership of the returned trigger.
173 * It must not be destroyed by the user, nor should it be held beyond the
174 * lifetime of the trigger collection.
175 *
176 * Returns a trigger, or NULL on error.
177 */
178 extern const struct lttng_trigger *lttng_triggers_get_at_index(
179 const struct lttng_triggers *triggers, unsigned int index);
180
181 /*
182 * Get the number of trigger in a tracker id list.
183 *
184 * Return LTTNG_TRIGGER_STATUS_OK on success,
185 * LTTNG_TRIGGER_STATUS_INVALID when passed invalid parameters.
186 */
187 extern enum lttng_trigger_status lttng_triggers_get_count(
188 const struct lttng_triggers *triggers, unsigned int *count);
189
190 /*
191 * Destroy a trigger collection.
192 */
193 extern void lttng_triggers_destroy(struct lttng_triggers *ids);
194
195
196 #ifdef __cplusplus
197 }
198 #endif
199
200 #endif /* LTTNG_TRIGGER_H */
This page took 0.051057 seconds and 5 git commands to generate.