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 * A trigger must be registered in order to become activate and can
52 * be destroyed after its registration.
54 * Returns a trigger object on success, NULL on error.
55 * Trigger objects must be destroyed using the lttng_trigger_destroy()
58 extern struct lttng_trigger
*lttng_trigger_create(
59 struct lttng_condition
*condition
, struct lttng_action
*action
);
62 * Get the condition of a trigger.
64 * The caller acquires no ownership of the returned condition.
66 * Returns a condition on success, NULL on error.
68 extern struct lttng_condition
*lttng_trigger_get_condition(
69 struct lttng_trigger
*trigger
);
71 const struct lttng_condition
*lttng_trigger_get_const_condition(
72 const struct lttng_trigger
*trigger
);
75 * Get the action of a trigger.
77 * The caller acquires no ownership of the returned action.
79 * Returns an action on success, NULL on error.
81 extern struct lttng_action
*lttng_trigger_get_action(
82 struct lttng_trigger
*trigger
);
84 const struct lttng_action
*lttng_trigger_get_const_action(
85 const struct lttng_trigger
*trigger
);
88 * Get the name of a trigger.
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.
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.
98 extern enum lttng_trigger_status
lttng_trigger_get_name(
99 const struct lttng_trigger
*trigger
, const char **name
);
102 * Set the trigger name.
104 * A name is optional.
105 * A name will be assigned on trigger registration if no name is set.
107 * The name is copied.
109 * Return LTTNG_TRIGGER_STATUS_OK on success, LTTNG_TRIGGER_STATUS_INVALID
110 * if invalid parameters are passed.
112 extern enum lttng_trigger_status
lttng_trigger_set_name(
113 struct lttng_trigger
*trigger
, const char *name
);
116 * Set the trigger firing policy.
118 * This is optional. By default a trigger is set to fire each time the
119 * associated condition occurs.
121 * Threshold is the number of time the condition must be hit before the policy is
124 * Return LTTNG_TRIGGER_STATUS_OK on success, LTTNG_TRIGGER_STATUS_INVALID
125 * if invalid parameters are passed.
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
);
137 * Destroy (frees) a trigger object.
139 extern void lttng_trigger_destroy(struct lttng_trigger
*trigger
);
142 * Register a trigger to the session daemon.
144 * The trigger can be destroyed after this call.
146 * Return 0 on success, a negative LTTng error code on error.
148 extern int lttng_register_trigger(struct lttng_trigger
*trigger
);
151 * Unregister a trigger from the session daemon.
153 * The trigger can be destroyed after this call.
155 * Return 0 on success, a negative LTTng error code on error.
157 extern int lttng_unregister_trigger(const struct lttng_trigger
*trigger
);
160 * List current triggers.
162 * On success, triggers is allocated.
163 * The trigger collection must be free by the caller with lttng_destroy_triggers
165 * Returns 0 on success, else a negative LTTng error code.
167 extern int lttng_list_triggers(struct lttng_triggers
**triggers
);
170 * Get a trigger from the collection at a given index.
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.
176 * Returns a trigger, or NULL on error.
178 extern const struct lttng_trigger
*lttng_triggers_get_at_index(
179 const struct lttng_triggers
*triggers
, unsigned int index
);
182 * Get the number of trigger in a tracker id list.
184 * Return LTTNG_TRIGGER_STATUS_OK on success,
185 * LTTNG_TRIGGER_STATUS_INVALID when passed invalid parameters.
187 extern enum lttng_trigger_status
lttng_triggers_get_count(
188 const struct lttng_triggers
*triggers
, unsigned int *count
);
191 * Destroy a trigger collection.
193 extern void lttng_triggers_destroy(struct lttng_triggers
*ids
);
200 #endif /* LTTNG_TRIGGER_H */