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
;
34 enum lttng_trigger_firing_policy type
;
36 uint64_t current_count
;
40 * The unique token passed to the tracer to identify an event-rule
43 LTTNG_OPTIONAL(uint64_t) tracer_token
;
46 struct lttng_triggers
{
47 struct lttng_dynamic_pointer_array array
;
50 struct lttng_trigger_comm
{
52 * Credentials, only the uid portion is used for now.
53 * Used as an override when desired by the root user.
57 * Length of the variable length payload (name, condition, and
61 /* Includes '\0' terminator. */
64 /* Maps to enum lttng_trigger_firing_policy. */
65 uint8_t firing_policy_type
;
66 uint64_t firing_policy_threshold
;
67 /* A null-terminated name, a condition, and an action follow. */
71 struct lttng_triggers_comm
{
74 /* Count * lttng_trigger_comm structure */
79 ssize_t
lttng_trigger_create_from_payload(struct lttng_payload_view
*view
,
80 struct lttng_trigger
**trigger
);
83 int lttng_trigger_serialize(const struct lttng_trigger
*trigger
,
84 struct lttng_payload
*payload
);
87 const struct lttng_condition
*lttng_trigger_get_const_condition(
88 const struct lttng_trigger
*trigger
);
91 const struct lttng_action
*lttng_trigger_get_const_action(
92 const struct lttng_trigger
*trigger
);
95 bool lttng_trigger_validate(struct lttng_trigger
*trigger
);
98 int lttng_trigger_assign_name(
99 struct lttng_trigger
*dst
, const struct lttng_trigger
*src
);
102 void lttng_trigger_set_tracer_token(
103 struct lttng_trigger
*trigger
, uint64_t token
);
106 uint64_t lttng_trigger_get_tracer_token(const struct lttng_trigger
*trigger
);
109 int lttng_trigger_generate_name(struct lttng_trigger
*trigger
,
113 bool lttng_trigger_is_equal(
114 const struct lttng_trigger
*a
, const struct lttng_trigger
*b
);
117 void lttng_trigger_get(struct lttng_trigger
*trigger
);
120 void lttng_trigger_put(struct lttng_trigger
*trigger
);
123 * Allocate a new set of triggers.
124 * The returned object must be freed via lttng_triggers_destroy.
127 struct lttng_triggers
*lttng_triggers_create(void);
130 * Return the a pointer to a mutable element at index "index" of an
131 * lttng_triggers set.
133 * This differs from the public `lttng_triggers_get_at_index` in that
134 * the returned pointer to a mutable trigger.
136 * The ownership of the trigger set element is NOT transfered.
137 * The returned object can NOT be freed via lttng_trigger_destroy.
140 struct lttng_trigger
*lttng_triggers_borrow_mutable_at_index(
141 const struct lttng_triggers
*triggers
, unsigned int index
);
144 * Add a trigger to the triggers set.
146 * A reference to the added trigger is acquired on behalf of the trigger set
150 int lttng_triggers_add(
151 struct lttng_triggers
*triggers
, struct lttng_trigger
*trigger
);
154 * Serialize a trigger set to an lttng_payload object.
155 * Return LTTNG_OK on success, negative lttng error code on error.
158 int lttng_triggers_serialize(const struct lttng_triggers
*triggers
,
159 struct lttng_payload
*payload
);
162 ssize_t
lttng_triggers_create_from_payload(struct lttng_payload_view
*view
,
163 struct lttng_triggers
**triggers
);
166 const struct lttng_credentials
*lttng_trigger_get_credentials(
167 const struct lttng_trigger
*trigger
);
170 void lttng_trigger_set_credentials(struct lttng_trigger
*trigger
,
171 const struct lttng_credentials
*creds
);
176 * Increments the occurrence count.
179 void lttng_trigger_fire(struct lttng_trigger
*trigger
);
182 * Check if the trigger would fire.
185 bool lttng_trigger_should_fire(const struct lttng_trigger
*trigger
);
188 * Return the type of any underlying domain restriction. If no particular
189 * requirement is present, returns LTTNG_DOMAIN_NONE.
192 enum lttng_domain_type
lttng_trigger_get_underlying_domain_type_restriction(
193 const struct lttng_trigger
*trigger
);
195 #endif /* LTTNG_TRIGGER_INTERNAL_H */