2 * Copyright (C) 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * SPDX-License-Identifier: LGPL-2.1-only
8 #ifndef LTTNG_TRIGGER_INTERNAL_H
9 #define LTTNG_TRIGGER_INTERNAL_H
11 #include <lttng/trigger/trigger.h>
12 #include <common/credentials.h>
13 #include <common/dynamic-array.h>
14 #include <common/macros.h>
15 #include <common/optional.h>
18 #include <sys/types.h>
22 struct lttng_payload_view
;
24 struct lttng_trigger
{
25 /* Reference counting is only exposed to internal users. */
28 struct lttng_condition
*condition
;
29 struct lttng_action
*action
;
31 /* For now only the uid portion of the credentials is used. */
32 struct lttng_credentials creds
;
33 LTTNG_OPTIONAL(uint64_t) error_count
;
35 enum lttng_trigger_firing_policy_type type
;
37 uint64_t current_count
;
41 * The unique token passed to the tracer to identify a event-rule
44 LTTNG_OPTIONAL(uint64_t) tracer_token
;
47 * Error accounting counter index.
49 LTTNG_OPTIONAL(uint64_t) error_counter_index
;
52 * This ordered set is used to hold the capture bytecodoes and their
53 * expression. lttng_action_capture_bytecode_element.
54 * We could only have bytecodes here... the expression are a left over
55 * from the generation process of the set. They are used for comparison
56 * during the gathering process. They are refcounted (TODO) and are the same
57 * object that are present un the underlying action object/s
59 struct lttng_dynamic_pointer_array capture_bytecode_set
;
62 struct lttng_triggers
{
63 struct lttng_dynamic_pointer_array array
;
66 struct lttng_trigger_comm
{
67 /* length excludes its own length. */
68 uint32_t name_length
/* Includes '\0' */;
70 /* Credentials, only the uid portion is used for now */
73 /* Maps to enum lttng_trigger_firing_policy_type. */
75 uint64_t policy_threshold
;
77 /* A name, condition and action object follow. */
81 struct lttng_triggers_comm
{
84 /* Count * lttng_trigger_comm structure */
89 ssize_t
lttng_trigger_create_from_payload(struct lttng_payload_view
*view
,
90 struct lttng_trigger
**trigger
);
93 int lttng_trigger_serialize(const struct lttng_trigger
*trigger
,
94 struct lttng_payload
*payload
);
97 bool lttng_trigger_validate(const struct lttng_trigger
*trigger
);
100 int lttng_trigger_assign_name(
101 struct lttng_trigger
*dst
, const struct lttng_trigger
*src
);
104 void lttng_trigger_set_tracer_token(
105 struct lttng_trigger
*trigger
, uint64_t token
);
108 uint64_t lttng_trigger_get_tracer_token(const struct lttng_trigger
*trigger
);
111 void lttng_trigger_set_error_counter_index(
112 struct lttng_trigger
*trigger
, uint64_t error_counter_index
);
115 uint64_t lttng_trigger_get_error_counter_index(
116 const struct lttng_trigger
*trigger
);
119 int lttng_trigger_generate_name(struct lttng_trigger
*trigger
, uint64_t offset
);
122 bool lttng_trigger_is_equal(
123 const struct lttng_trigger
*a
, const struct lttng_trigger
*b
);
126 void lttng_trigger_get(struct lttng_trigger
*trigger
);
129 void lttng_trigger_put(struct lttng_trigger
*trigger
);
132 * Allocate a new set of lttng_trigger.
133 * The returned object must be freed via lttng_triggers_destroy.
136 struct lttng_triggers
*lttng_triggers_create(void);
139 * Return the non-const pointer of an element at index "index" of a
142 * The ownership of the lttng_triggers element is NOT transfered.
143 * The returned object can NOT be freed via lttng_trigger_destroy.
146 struct lttng_trigger
*lttng_triggers_get_pointer_of_index(
147 const struct lttng_triggers
*triggers
, unsigned int index
);
150 * Add a trigger to the triggers object.
153 int lttng_triggers_add(
154 struct lttng_triggers
*triggers
, struct lttng_trigger
*trigger
);
157 * Serialize a trigger set to a lttng_payload object.
158 * Return LTTNG_OK on success, negative lttng error code on error.
161 int lttng_triggers_serialize(const struct lttng_triggers
*triggers
,
162 struct lttng_payload
*payload
);
165 ssize_t
lttng_triggers_create_from_payload(struct lttng_payload_view
*view
,
166 struct lttng_triggers
**triggers
);
169 const struct lttng_credentials
*lttng_trigger_get_credentials(
170 const struct lttng_trigger
*trigger
);
173 void lttng_trigger_set_credentials(struct lttng_trigger
*trigger
,
174 const struct lttng_credentials
*creds
);
179 * Increment the firing count.
182 void lttng_trigger_fire(struct lttng_trigger
*trigger
);
185 * Check if the trigger would fire.
188 bool lttng_trigger_should_fire(const struct lttng_trigger
*trigger
);
191 bool lttng_trigger_is_ready_to_fire(
192 struct lttng_trigger
*trigger
);
195 uint64_t lttng_trigger_get_error_count(
196 const struct lttng_trigger
*trigger
);
199 void lttng_trigger_set_error_count(struct lttng_trigger
*trigger
,
200 uint64_t error_count
);
203 * Return the type of any uderlying domain requirement. If no particular
204 * requirement is needed return LTTNG_DOMAIN_NONE.
207 enum lttng_domain_type
lttng_trigger_get_underlying_domain_type_restriction(
208 const struct lttng_trigger
*trigger
);
211 struct lttng_trigger
*lttng_trigger_copy(const struct lttng_trigger
*trigger
);
214 unsigned int lttng_trigger_get_capture_bytecode_count(
215 const struct lttng_trigger
*trigger
);
218 const struct lttng_bytecode
*
219 lttng_trigger_get_capture_bytecode_at_index(
220 const struct lttng_trigger
*trigger
, unsigned int index
);
222 #endif /* LTTNG_TRIGGER_INTERNAL_H */