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/macros.h>
13 #include <common/buffer-view.h>
14 #include <common/dynamic-buffer.h>
15 #include <common/dynamic-array.h>
16 #include <common/credentials.h>
19 #include <sys/types.h>
22 struct lttng_trigger
{
23 struct urcu_ref ref
; /* internal use only */
24 bool owns_internal_objects
; /* internal use only */
26 struct lttng_condition
*condition
;
27 struct lttng_action
*action
;
29 struct { /* Internal use only */
33 struct { /* internal use only */
34 struct lttng_credentials credentials
;
38 enum lttng_trigger_firing_policy_type type
;
40 uint64_t current_count
;
43 /* This ordered set is used to hold the capture bytecodoes and their
44 * expression. lttng_action_capture_bytecode_element.
45 * We could only have bytecodes here... the expression are a left over
46 * from the generation process of the set. They are used for comparison
47 * during the gathering process. They are refcounted (TODO) and are the same
48 * object that are present un the underlying action object/s
50 struct lttng_dynamic_pointer_array capture_bytecode_set
;
53 struct lttng_triggers
{
54 struct lttng_dynamic_pointer_array array
;
57 struct lttng_trigger_comm
{
58 /* length excludes its own length. */
59 uint32_t name_length
/* Includes '\0' */;
62 uint64_t policy_threshold
;
63 /* A name, condition and action object follow. */
67 struct lttng_triggers_comm
{
70 /* Count * lttng_trigger_comm structure */
75 ssize_t
lttng_trigger_create_from_buffer(const struct lttng_buffer_view
*view
,
76 struct lttng_trigger
**trigger
);
79 int lttng_trigger_serialize(const struct lttng_trigger
*trigger
,
80 struct lttng_dynamic_buffer
*buf
,
84 bool lttng_trigger_validate(const struct lttng_trigger
*trigger
);
87 int lttng_trigger_assign(struct lttng_trigger
*dst
,
88 const struct lttng_trigger
*src
);
91 void lttng_trigger_set_key(struct lttng_trigger
*trigger
, uint64_t key
);
94 uint64_t lttng_trigger_get_key(const struct lttng_trigger
*trigger
);
97 int lttng_trigger_generate_name(struct lttng_trigger
*trigger
, uint64_t offset
);
100 bool lttng_trigger_is_equal(const struct lttng_trigger
*a
,
101 const struct lttng_trigger
*b
);
104 void lttng_trigger_get(struct lttng_trigger
*trigger
);
107 void lttng_trigger_put(struct lttng_trigger
*trigger
);
110 * Allocate a new list of lttng_trigger.
111 * The returned object must be freed via lttng_triggers_destroy.
114 struct lttng_triggers
*lttng_triggers_create(void);
117 * Return the non-const pointer of an element at index "index" of a
120 * The ownership of the lttng_triggers element is NOT transfered.
121 * The returned object can NOT be freed via lttng_trigger_destroy.
124 struct lttng_trigger
*lttng_triggers_get_pointer_of_index(
125 const struct lttng_triggers
*triggers
, unsigned int index
);
131 int lttng_triggers_add(
132 struct lttng_triggers
*triggers
, struct lttng_trigger
*trigger
);
135 * Serialize a trigger collection to a lttng_dynamic_buffer.
136 * Return LTTNG_OK on success, negative lttng error code on error.
139 int lttng_triggers_serialize(const struct lttng_triggers
*triggers
,
140 struct lttng_dynamic_buffer
*buffer
);
143 ssize_t
lttng_triggers_create_from_buffer(const struct lttng_buffer_view
*view
,
144 struct lttng_triggers
**triggers
);
147 const struct lttng_credentials
*lttng_trigger_get_credentials(
148 const struct lttng_trigger
*trigger
);
151 void lttng_trigger_set_credentials(
152 struct lttng_trigger
*trigger
, uid_t uid
, gid_t git
);
155 bool lttng_trigger_is_ready_to_fire(
156 struct lttng_trigger
*trigger
);
159 * Return the type of any uderlying domain requirement. If no particular
160 * requirement is needed return LTTNG_DOMAIN_NONE.
163 enum lttng_domain_type
lttng_trigger_get_underlying_domain_type_restriction(
164 const struct lttng_trigger
*trigger
);
167 unsigned int lttng_trigger_get_capture_bytecode_count(
168 const struct lttng_trigger
*trigger
);
171 const struct lttng_bytecode
*
172 lttng_trigger_get_capture_bytecode_at_index(
173 const struct lttng_trigger
*trigger
, unsigned int index
);
175 #endif /* LTTNG_TRIGGER_INTERNAL_H */