action-executor: missing include of internal event-rule header
[lttng-tools.git] / include / lttng / trigger / trigger-internal.h
CommitLineData
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_INTERNAL_H
9#define LTTNG_TRIGGER_INTERNAL_H
10
11#include <lttng/trigger/trigger.h>
3da864a9 12#include <common/credentials.h>
a02903c0 13#include <common/dynamic-array.h>
a58c490f 14#include <common/macros.h>
3da864a9 15#include <common/optional.h>
a58c490f
JG
16#include <stdint.h>
17#include <stdbool.h>
72756a3f 18#include <sys/types.h>
f01d28b4 19#include <urcu/ref.h>
a58c490f 20
c0a66c84
JG
21struct lttng_payload;
22struct lttng_payload_view;
23
a58c490f 24struct lttng_trigger {
f01d28b4
JR
25 /* Reference counting is only exposed to internal users. */
26 struct urcu_ref ref;
27
a58c490f
JG
28 struct lttng_condition *condition;
29 struct lttng_action *action;
242388e4 30 char *name;
64eafdf6
JR
31 /* For now only the uid portion of the credentials is used. */
32 struct lttng_credentials creds;
5c504c41
JR
33 struct {
34 enum lttng_trigger_firing_policy type;
35 uint64_t threshold;
36 uint64_t current_count;
37 } firing_policy;
e6887944
JR
38 /*
39 * Internal use only.
40 * The unique token passed to the tracer to identify an event-rule
41 * notification.
42 */
43 LTTNG_OPTIONAL(uint64_t) tracer_token;
a58c490f
JG
44};
45
a02903c0
JR
46struct lttng_triggers {
47 struct lttng_dynamic_pointer_array array;
48};
49
a58c490f 50struct lttng_trigger_comm {
64eafdf6
JR
51 /*
52 * Credentials, only the uid portion is used for now.
53 * Used as an override when desired by the root user.
54 */
55 uint64_t uid;
242388e4
JR
56 /*
57 * Length of the variable length payload (name, condition, and
58 * an action).
59 */
60 uint32_t length;
61 /* Includes '\0' terminator. */
62 uint32_t name_length;
5c504c41
JR
63 /* Firing policy. */
64 /* Maps to enum lttng_trigger_firing_policy. */
65 uint8_t firing_policy_type;
66 uint64_t firing_policy_threshold;
242388e4 67 /* A null-terminated name, a condition, and an action follow. */
a58c490f
JG
68 char payload[];
69} LTTNG_PACKED;
70
a02903c0
JR
71struct lttng_triggers_comm {
72 uint32_t count;
73 uint32_t length;
74 /* Count * lttng_trigger_comm structure */
75 char payload[];
76};
77
a58c490f 78LTTNG_HIDDEN
c0a66c84 79ssize_t lttng_trigger_create_from_payload(struct lttng_payload_view *view,
a58c490f
JG
80 struct lttng_trigger **trigger);
81
82LTTNG_HIDDEN
a02903c0 83int lttng_trigger_serialize(const struct lttng_trigger *trigger,
c0a66c84 84 struct lttng_payload *payload);
a58c490f 85
9b63a4aa
JG
86LTTNG_HIDDEN
87const struct lttng_condition *lttng_trigger_get_const_condition(
88 const struct lttng_trigger *trigger);
89
90LTTNG_HIDDEN
91const struct lttng_action *lttng_trigger_get_const_action(
92 const struct lttng_trigger *trigger);
93
a58c490f
JG
94LTTNG_HIDDEN
95bool lttng_trigger_validate(struct lttng_trigger *trigger);
96
242388e4
JR
97LTTNG_HIDDEN
98int lttng_trigger_assign_name(
99 struct lttng_trigger *dst, const struct lttng_trigger *src);
100
e6887944
JR
101LTTNG_HIDDEN
102void lttng_trigger_set_tracer_token(
103 struct lttng_trigger *trigger, uint64_t token);
104
105LTTNG_HIDDEN
106uint64_t lttng_trigger_get_tracer_token(const struct lttng_trigger *trigger);
107
242388e4
JR
108LTTNG_HIDDEN
109int lttng_trigger_generate_name(struct lttng_trigger *trigger,
110 uint64_t unique_id);
111
85c06c44
JR
112LTTNG_HIDDEN
113bool lttng_trigger_is_equal(
114 const struct lttng_trigger *a, const struct lttng_trigger *b);
115
f01d28b4
JR
116LTTNG_HIDDEN
117void lttng_trigger_get(struct lttng_trigger *trigger);
118
119LTTNG_HIDDEN
120void lttng_trigger_put(struct lttng_trigger *trigger);
121
a02903c0
JR
122/*
123 * Allocate a new set of triggers.
124 * The returned object must be freed via lttng_triggers_destroy.
125 */
126LTTNG_HIDDEN
127struct lttng_triggers *lttng_triggers_create(void);
128
129/*
130 * Return the a pointer to a mutable element at index "index" of an
131 * lttng_triggers set.
132 *
133 * This differs from the public `lttng_triggers_get_at_index` in that
134 * the returned pointer to a mutable trigger.
135 *
136 * The ownership of the trigger set element is NOT transfered.
137 * The returned object can NOT be freed via lttng_trigger_destroy.
138 */
139LTTNG_HIDDEN
140struct lttng_trigger *lttng_triggers_borrow_mutable_at_index(
141 const struct lttng_triggers *triggers, unsigned int index);
142
143/*
144 * Add a trigger to the triggers set.
145 *
146 * A reference to the added trigger is acquired on behalf of the trigger set
147 * on success.
148 */
149LTTNG_HIDDEN
150int lttng_triggers_add(
151 struct lttng_triggers *triggers, struct lttng_trigger *trigger);
152
153/*
154 * Serialize a trigger set to an lttng_payload object.
155 * Return LTTNG_OK on success, negative lttng error code on error.
156 */
157LTTNG_HIDDEN
158int lttng_triggers_serialize(const struct lttng_triggers *triggers,
159 struct lttng_payload *payload);
160
161LTTNG_HIDDEN
162ssize_t lttng_triggers_create_from_payload(struct lttng_payload_view *view,
163 struct lttng_triggers **triggers);
164
3da864a9
JR
165LTTNG_HIDDEN
166const struct lttng_credentials *lttng_trigger_get_credentials(
167 const struct lttng_trigger *trigger);
168
169LTTNG_HIDDEN
64eafdf6 170void lttng_trigger_set_credentials(struct lttng_trigger *trigger,
3da864a9
JR
171 const struct lttng_credentials *creds);
172
5c504c41
JR
173
174/*
175 * Fire the trigger.
176 * Increments the occurrence count.
177 */
178LTTNG_HIDDEN
179void lttng_trigger_fire(struct lttng_trigger *trigger);
180
181/*
182 * Check if the trigger would fire.
183 */
184LTTNG_HIDDEN
185bool lttng_trigger_should_fire(const struct lttng_trigger *trigger);
186
a58c490f 187#endif /* LTTNG_TRIGGER_INTERNAL_H */
This page took 0.05631 seconds and 4 git commands to generate.