Add a basic .clang-tidy file and fix typedef warnings
[lttng-tools.git] / include / lttng / trigger / trigger-internal.hpp
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
c9e313bc
SM
11#include <common/credentials.hpp>
12#include <common/dynamic-array.hpp>
13#include <common/macros.hpp>
14#include <common/optional.hpp>
588c4b0d 15#include <lttng/lttng.h>
9c374932 16#include <pthread.h>
a58c490f 17#include <stdbool.h>
9c374932 18#include <stdint.h>
72756a3f 19#include <sys/types.h>
f01d28b4 20#include <urcu/ref.h>
a58c490f 21
c0a66c84
JG
22struct lttng_payload;
23struct lttng_payload_view;
6a751b95
JR
24struct mi_writer;
25struct mi_lttng_error_query_callbacks;
c0a66c84 26
a58c490f 27struct lttng_trigger {
f01d28b4
JR
28 /* Reference counting is only exposed to internal users. */
29 struct urcu_ref ref;
30
a58c490f
JG
31 struct lttng_condition *condition;
32 struct lttng_action *action;
242388e4 33 char *name;
64eafdf6
JR
34 /* For now only the uid portion of the credentials is used. */
35 struct lttng_credentials creds;
e6887944
JR
36 /*
37 * Internal use only.
38 * The unique token passed to the tracer to identify an event-rule
39 * notification.
40 */
41 LTTNG_OPTIONAL(uint64_t) tracer_token;
9c374932
JR
42
43 /*
44 * Is the trigger registered?
45 *
46 * This is necessary since a reference holder might be interested in the
47 * overall state of the trigger from the point of view of its owner.
48 *
49 * The main user is the action executor since we want to prevent the
50 * execution of actions related to a trigger that is unregistered.
51 *
52 * Not considered for `is_equal`.
53 */
54 bool registered;
55
f2bda80e
JG
56 /*
57 * A "hidden" trigger is a trigger that is not externally listed.
58 * It is used to hide triggers that are used internally by the session
59 * daemon so that they can't be listed nor unregistered by external
60 * clients.
61 *
62 * This is a property that can only be set internally by the session
f4d2c26a 63 * daemon.
f2bda80e
JG
64 *
65 * The hidden property is preserved by copies.
66 *
67 * Note that notifications originating from an "hidden" trigger will not
68 * be sent to clients that are not within the session daemon's process.
69 */
70 bool is_hidden;
71
9c374932
JR
72 /*
73 * The lock is used to protect against concurrent trigger execution and
74 * trigger removal.
75 */
76 pthread_mutex_t lock;
a58c490f
JG
77};
78
a02903c0
JR
79struct lttng_triggers {
80 struct lttng_dynamic_pointer_array array;
81};
82
a58c490f 83struct lttng_trigger_comm {
64eafdf6
JR
84 /*
85 * Credentials, only the uid portion is used for now.
86 * Used as an override when desired by the root user.
87 */
88 uint64_t uid;
242388e4
JR
89 /*
90 * Length of the variable length payload (name, condition, and
91 * an action).
92 */
93 uint32_t length;
94 /* Includes '\0' terminator. */
95 uint32_t name_length;
f4d2c26a
JG
96 /* Hidden property. */
97 uint8_t is_hidden;
242388e4 98 /* A null-terminated name, a condition, and an action follow. */
a58c490f
JG
99 char payload[];
100} LTTNG_PACKED;
101
a02903c0
JR
102struct lttng_triggers_comm {
103 uint32_t count;
104 uint32_t length;
105 /* Count * lttng_trigger_comm structure */
106 char payload[];
107};
108
c0a66c84 109ssize_t lttng_trigger_create_from_payload(struct lttng_payload_view *view,
a58c490f
JG
110 struct lttng_trigger **trigger);
111
a02903c0 112int lttng_trigger_serialize(const struct lttng_trigger *trigger,
c0a66c84 113 struct lttng_payload *payload);
a58c490f 114
b61776fb 115bool lttng_trigger_validate(const struct lttng_trigger *trigger);
a58c490f 116
242388e4
JR
117int lttng_trigger_assign_name(
118 struct lttng_trigger *dst, const struct lttng_trigger *src);
119
e6887944
JR
120void lttng_trigger_set_tracer_token(
121 struct lttng_trigger *trigger, uint64_t token);
122
e6887944
JR
123uint64_t lttng_trigger_get_tracer_token(const struct lttng_trigger *trigger);
124
242388e4
JR
125int lttng_trigger_generate_name(struct lttng_trigger *trigger,
126 uint64_t unique_id);
127
85c06c44
JR
128bool lttng_trigger_is_equal(
129 const struct lttng_trigger *a, const struct lttng_trigger *b);
130
f2bda80e
JG
131bool lttng_trigger_is_hidden(const struct lttng_trigger *trigger);
132
f2bda80e
JG
133void lttng_trigger_set_hidden(struct lttng_trigger *trigger);
134
f01d28b4
JR
135void lttng_trigger_get(struct lttng_trigger *trigger);
136
f01d28b4
JR
137void lttng_trigger_put(struct lttng_trigger *trigger);
138
6a751b95
JR
139/*
140 * Serialize a trigger to a mi_writer.
141 * Return LTTNG_OK in success, other enum lttng_error_code on error.
142 */
6a751b95
JR
143enum lttng_error_code lttng_trigger_mi_serialize(const struct lttng_trigger *trigger,
144 struct mi_writer *writer,
145 const struct mi_lttng_error_query_callbacks
146 *error_query_callbacks);
147
a02903c0
JR
148/*
149 * Allocate a new set of triggers.
150 * The returned object must be freed via lttng_triggers_destroy.
151 */
a02903c0
JR
152struct lttng_triggers *lttng_triggers_create(void);
153
154/*
155 * Return the a pointer to a mutable element at index "index" of an
156 * lttng_triggers set.
157 *
158 * This differs from the public `lttng_triggers_get_at_index` in that
159 * the returned pointer to a mutable trigger.
160 *
161 * The ownership of the trigger set element is NOT transfered.
162 * The returned object can NOT be freed via lttng_trigger_destroy.
163 */
a02903c0
JR
164struct lttng_trigger *lttng_triggers_borrow_mutable_at_index(
165 const struct lttng_triggers *triggers, unsigned int index);
166
167/*
168 * Add a trigger to the triggers set.
169 *
170 * A reference to the added trigger is acquired on behalf of the trigger set
171 * on success.
172 */
a02903c0
JR
173int lttng_triggers_add(
174 struct lttng_triggers *triggers, struct lttng_trigger *trigger);
175
f2bda80e
JG
176/*
177 * Remove all triggers marked as hidden from the provided trigger set.
178 */
f2bda80e
JG
179int lttng_triggers_remove_hidden_triggers(struct lttng_triggers *triggers);
180
a02903c0
JR
181/*
182 * Serialize a trigger set to an lttng_payload object.
183 * Return LTTNG_OK on success, negative lttng error code on error.
184 */
a02903c0
JR
185int lttng_triggers_serialize(const struct lttng_triggers *triggers,
186 struct lttng_payload *payload);
187
a02903c0
JR
188ssize_t lttng_triggers_create_from_payload(struct lttng_payload_view *view,
189 struct lttng_triggers **triggers);
190
6a751b95
JR
191/*
192 * Serialize a trigger set to a mi_writer.
193 * Return LTTNG_OK in success, other enum lttng_error_code on error.
194 */
6a751b95
JR
195enum lttng_error_code lttng_triggers_mi_serialize(const struct lttng_triggers *triggers,
196 struct mi_writer *writer,
197 const struct mi_lttng_error_query_callbacks
198 *error_query_callbacks);
199
3da864a9
JR
200const struct lttng_credentials *lttng_trigger_get_credentials(
201 const struct lttng_trigger *trigger);
202
64eafdf6 203void lttng_trigger_set_credentials(struct lttng_trigger *trigger,
3da864a9
JR
204 const struct lttng_credentials *creds);
205
91c96f62
JR
206/*
207 * Return the type of any underlying domain restriction. If no particular
208 * requirement is present, returns LTTNG_DOMAIN_NONE.
209 */
91c96f62
JR
210enum lttng_domain_type lttng_trigger_get_underlying_domain_type_restriction(
211 const struct lttng_trigger *trigger);
212
58daac01
JR
213/*
214 * Generate any bytecode related to the trigger.
215 * On success LTTNG_OK. On error, returns lttng_error code.
216 */
58daac01
JR
217enum lttng_error_code lttng_trigger_generate_bytecode(
218 struct lttng_trigger *trigger,
219 const struct lttng_credentials *creds);
220
94dbd8e4
JG
221/*
222 * Note that the trigger object is not locked by "copy" as it is const and
223 * used with a number of 'const' triggers. If the trigger could be shared at
224 * the moment of the copy, it is the caller's responsability to lock it for
225 * the duration of the copy.
226 */
b61776fb
SM
227struct lttng_trigger *lttng_trigger_copy(const struct lttng_trigger *trigger);
228
c738df17
FD
229/*
230 * A given trigger needs a tracer notifier if
231 * it has an event-rule condition,
232 * AND
233 * it has one or more sessiond-execution action.
234 */
c738df17
FD
235bool lttng_trigger_needs_tracer_notifier(const struct lttng_trigger *trigger);
236
9c374932
JR
237void lttng_trigger_set_as_registered(struct lttng_trigger *trigger);
238
9c374932
JR
239void lttng_trigger_set_as_unregistered(struct lttng_trigger *trigger);
240
241/*
242 * The trigger must be locked before calling lttng_trigger_is_registered.
243 *
244 * The lock is necessary since a trigger can be unregistered at any time.
245 *
246 * Manipulations requiring that the trigger be registered must always acquire
247 * the trigger lock for the duration of the manipulation using
248 * `lttng_trigger_lock` and `lttng_trigger_unlock`.
249 */
9c374932
JR
250bool lttng_trigger_is_registered(struct lttng_trigger *trigger);
251
9c374932
JR
252void lttng_trigger_lock(struct lttng_trigger *trigger);
253
9c374932
JR
254void lttng_trigger_unlock(struct lttng_trigger *trigger);
255
588c4b0d
JG
256enum lttng_trigger_status lttng_trigger_add_error_results(
257 const struct lttng_trigger *trigger,
258 struct lttng_error_query_results *results);
259
63dd3d7b
JG
260enum lttng_trigger_status lttng_trigger_condition_add_error_results(
261 const struct lttng_trigger *trigger,
262 struct lttng_error_query_results *results);
263
588c4b0d
JG
264enum lttng_trigger_status lttng_trigger_add_action_error_query_results(
265 struct lttng_trigger *trigger,
266 struct lttng_error_query_results *results);
267
a5c2d2a7
JG
268/*
269 * Set the trigger name.
270 *
271 * A name is optional.
272 * A name will be assigned on trigger registration if no name is set.
273 *
274 * The name is copied.
275 *
276 * Return LTTNG_TRIGGER_STATUS_OK on success, LTTNG_TRIGGER_STATUS_INVALID
277 * if invalid parameters are passed.
278 */
a5c2d2a7
JG
279enum lttng_trigger_status lttng_trigger_set_name(
280 struct lttng_trigger *trigger, const char *name);
281
a58c490f 282#endif /* LTTNG_TRIGGER_INTERNAL_H */
This page took 0.0556 seconds and 4 git commands to generate.