2 * Copyright (C) 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * SPDX-License-Identifier: LGPL-2.1-only
8 #ifndef LTTNG_TRIGGER_H
9 #define LTTNG_TRIGGER_H
12 struct lttng_condition
;
14 /* A collection of trigger */
15 struct lttng_triggers
;
21 enum lttng_register_trigger_status
{
22 LTTNG_REGISTER_TRIGGER_STATUS_OK
= 0,
23 LTTNG_REGISTER_TRIGGER_STATUS_INVALID
= -1,
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,
35 enum lttng_trigger_firing_policy_type
{
36 LTTNG_TRIGGER_FIRE_EVERY_N
= 0,
37 LTTNG_TRIGGER_FIRE_ONCE_AFTER_N
= 1,
41 * Create a trigger object associating a condition and an action.
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.
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.
51 * If the action is a notification action with capture descriptors,
52 * the condition must be an event rule condition.
54 * A trigger must be registered in order to become activate and can
55 * be destroyed after its registration.
57 * Returns a trigger object on success, NULL on error.
58 * Trigger objects must be destroyed using the lttng_trigger_destroy()
61 extern struct lttng_trigger
*lttng_trigger_create(
62 struct lttng_condition
*condition
, struct lttng_action
*action
);
65 * Get the condition of a trigger.
67 * The caller acquires no ownership of the returned condition.
69 * Returns a condition on success, NULL on error.
71 extern struct lttng_condition
*lttng_trigger_get_condition(
72 struct lttng_trigger
*trigger
);
74 const struct lttng_condition
*lttng_trigger_get_const_condition(
75 const struct lttng_trigger
*trigger
);
78 * Get the action of a trigger.
80 * The caller acquires no ownership of the returned action.
82 * Returns an action on success, NULL on error.
84 extern struct lttng_action
*lttng_trigger_get_action(
85 struct lttng_trigger
*trigger
);
87 const struct lttng_action
*lttng_trigger_get_const_action(
88 const struct lttng_trigger
*trigger
);
91 * Get the name of a trigger.
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.
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.
101 extern enum lttng_trigger_status
lttng_trigger_get_name(
102 const struct lttng_trigger
*trigger
, const char **name
);
105 * Set the trigger name.
107 * A name is optional.
108 * A name will be assigned on trigger registration if no name is set.
110 * The name is copied.
112 * Return LTTNG_TRIGGER_STATUS_OK on success, LTTNG_TRIGGER_STATUS_INVALID
113 * if invalid parameters are passed.
115 extern enum lttng_trigger_status
lttng_trigger_set_name(
116 struct lttng_trigger
*trigger
, const char *name
);
119 * Set the trigger firing policy.
121 * This is optional. By default a trigger is set to fire each time the
122 * associated condition occurs.
124 * Threshold is the number of time the condition must be hit before the policy is
127 * Return LTTNG_TRIGGER_STATUS_OK on success, LTTNG_TRIGGER_STATUS_INVALID
128 * if invalid parameters are passed.
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
);
140 * Destroy (frees) a trigger object.
142 extern void lttng_trigger_destroy(struct lttng_trigger
*trigger
);
145 * Register a trigger to the session daemon.
147 * The trigger can be destroyed after this call.
149 * Return 0 on success, a negative LTTng error code on error.
151 extern int lttng_register_trigger(struct lttng_trigger
*trigger
);
154 * Unregister a trigger from the session daemon.
156 * The trigger can be destroyed after this call.
158 * Return 0 on success, a negative LTTng error code on error.
160 extern int lttng_unregister_trigger(const struct lttng_trigger
*trigger
);
163 * List current triggers.
165 * On success, triggers is allocated.
166 * The trigger collection must be free by the caller with lttng_destroy_triggers
168 * Returns 0 on success, else a negative LTTng error code.
170 extern int lttng_list_triggers(struct lttng_triggers
**triggers
);
173 * Get a trigger from the collection at a given index.
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.
179 * Returns a trigger, or NULL on error.
181 extern const struct lttng_trigger
*lttng_triggers_get_at_index(
182 const struct lttng_triggers
*triggers
, unsigned int index
);
185 * Get the number of trigger in a tracker id list.
187 * Return LTTNG_TRIGGER_STATUS_OK on success,
188 * LTTNG_TRIGGER_STATUS_INVALID when passed invalid parameters.
190 extern enum lttng_trigger_status
lttng_triggers_get_count(
191 const struct lttng_triggers
*triggers
, unsigned int *count
);
194 * Destroy a trigger collection.
196 extern void lttng_triggers_destroy(struct lttng_triggers
*ids
);
203 #endif /* LTTNG_TRIGGER_H */