SoW-2019-0007-2: Dynamic Snapshot: Triggers send partial event payload with notifications
[lttng-tools.git] / include / lttng / trigger / trigger-internal.h
1 /*
2 * Copyright (C) 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 *
4 * SPDX-License-Identifier: LGPL-2.1-only
5 *
6 */
7
8 #ifndef LTTNG_TRIGGER_INTERNAL_H
9 #define LTTNG_TRIGGER_INTERNAL_H
10
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>
17 #include <stdint.h>
18 #include <stdbool.h>
19 #include <sys/types.h>
20 #include <urcu/ref.h>
21
22 struct lttng_trigger {
23 struct urcu_ref ref; /* internal use only */
24 bool owns_internal_objects; /* internal use only */
25
26 struct lttng_condition *condition;
27 struct lttng_action *action;
28 char *name;
29 struct { /* Internal use only */
30 bool set;
31 uint64_t value;
32 } key;
33 struct { /* internal use only */
34 struct lttng_credentials credentials;
35 bool set;
36 } creds;
37 struct {
38 enum lttng_trigger_firing_policy_type type;
39 uint64_t threshold;
40 uint64_t current_count;
41 } firing_policy;
42
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
49 */
50 struct lttng_dynamic_pointer_array capture_bytecode_set;
51 };
52
53 struct lttng_triggers {
54 struct lttng_dynamic_pointer_array array;
55 };
56
57 struct lttng_trigger_comm {
58 /* length excludes its own length. */
59 uint32_t name_length /* Includes '\0' */;
60 uint32_t length;
61 uint8_t policy_type;
62 uint64_t policy_threshold;
63 /* A name, condition and action object follow. */
64 char payload[];
65 } LTTNG_PACKED;
66
67 struct lttng_triggers_comm {
68 uint32_t count;
69 uint32_t length;
70 /* Count * lttng_trigger_comm structure */
71 char payload[];
72 };
73
74 LTTNG_HIDDEN
75 ssize_t lttng_trigger_create_from_buffer(const struct lttng_buffer_view *view,
76 struct lttng_trigger **trigger);
77
78 LTTNG_HIDDEN
79 int lttng_trigger_serialize(const struct lttng_trigger *trigger,
80 struct lttng_dynamic_buffer *buf,
81 int *fd_to_send);
82
83 LTTNG_HIDDEN
84 bool lttng_trigger_validate(const struct lttng_trigger *trigger);
85
86 LTTNG_HIDDEN
87 int lttng_trigger_assign(struct lttng_trigger *dst,
88 const struct lttng_trigger *src);
89
90 LTTNG_HIDDEN
91 void lttng_trigger_set_key(struct lttng_trigger *trigger, uint64_t key);
92
93 LTTNG_HIDDEN
94 uint64_t lttng_trigger_get_key(const struct lttng_trigger *trigger);
95
96 LTTNG_HIDDEN
97 int lttng_trigger_generate_name(struct lttng_trigger *trigger, uint64_t offset);
98
99 LTTNG_HIDDEN
100 bool lttng_trigger_is_equal(const struct lttng_trigger *a,
101 const struct lttng_trigger *b);
102
103 LTTNG_HIDDEN
104 void lttng_trigger_get(struct lttng_trigger *trigger);
105
106 LTTNG_HIDDEN
107 void lttng_trigger_put(struct lttng_trigger *trigger);
108
109 /*
110 * Allocate a new list of lttng_trigger.
111 * The returned object must be freed via lttng_triggers_destroy.
112 */
113 LTTNG_HIDDEN
114 struct lttng_triggers *lttng_triggers_create(void);
115
116 /*
117 * Return the non-const pointer of an element at index "index" of a
118 * lttng_triggers.
119 *
120 * The ownership of the lttng_triggers element is NOT transfered.
121 * The returned object can NOT be freed via lttng_trigger_destroy.
122 */
123 LTTNG_HIDDEN
124 struct lttng_trigger *lttng_triggers_get_pointer_of_index(
125 const struct lttng_triggers *triggers, unsigned int index);
126
127 /*
128 * TODO:
129 */
130 LTTNG_HIDDEN
131 int lttng_triggers_add(
132 struct lttng_triggers *triggers, struct lttng_trigger *trigger);
133
134 /*
135 * Serialize a trigger collection to a lttng_dynamic_buffer.
136 * Return LTTNG_OK on success, negative lttng error code on error.
137 */
138 LTTNG_HIDDEN
139 int lttng_triggers_serialize(const struct lttng_triggers *triggers,
140 struct lttng_dynamic_buffer *buffer);
141
142 LTTNG_HIDDEN
143 ssize_t lttng_triggers_create_from_buffer(const struct lttng_buffer_view *view,
144 struct lttng_triggers **triggers);
145
146 LTTNG_HIDDEN
147 const struct lttng_credentials *lttng_trigger_get_credentials(
148 const struct lttng_trigger *trigger);
149
150 LTTNG_HIDDEN
151 void lttng_trigger_set_credentials(
152 struct lttng_trigger *trigger, uid_t uid, gid_t git);
153
154 LTTNG_HIDDEN
155 bool lttng_trigger_is_ready_to_fire(
156 struct lttng_trigger *trigger);
157
158 /*
159 * Return the type of any uderlying domain requirement. If no particular
160 * requirement is needed return LTTNG_DOMAIN_NONE.
161 */
162 LTTNG_HIDDEN
163 enum lttng_domain_type lttng_trigger_get_underlying_domain_type_restriction(
164 const struct lttng_trigger *trigger);
165
166 LTTNG_HIDDEN
167 unsigned int lttng_trigger_get_capture_bytecode_count(
168 const struct lttng_trigger *trigger);
169
170 LTTNG_HIDDEN
171 const struct lttng_bytecode *
172 lttng_trigger_get_capture_bytecode_at_index(
173 const struct lttng_trigger *trigger, unsigned int index);
174
175 #endif /* LTTNG_TRIGGER_INTERNAL_H */
This page took 0.032892 seconds and 5 git commands to generate.