trigger: lttng_triggers: implement a container for multiple triggers
[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/credentials.h>
13 #include <common/dynamic-array.h>
14 #include <common/macros.h>
15 #include <common/optional.h>
16 #include <stdint.h>
17 #include <stdbool.h>
18 #include <sys/types.h>
19 #include <urcu/ref.h>
20
21 struct lttng_payload;
22 struct lttng_payload_view;
23
24 struct lttng_trigger {
25 /* Reference counting is only exposed to internal users. */
26 struct urcu_ref ref;
27
28 struct lttng_condition *condition;
29 struct lttng_action *action;
30 char *name;
31 /* For now only the uid portion of the credentials is used. */
32 struct lttng_credentials creds;
33 /*
34 * Internal use only.
35 * The unique token passed to the tracer to identify an event-rule
36 * notification.
37 */
38 LTTNG_OPTIONAL(uint64_t) tracer_token;
39 };
40
41 struct lttng_triggers {
42 struct lttng_dynamic_pointer_array array;
43 };
44
45 struct lttng_trigger_comm {
46 /*
47 * Credentials, only the uid portion is used for now.
48 * Used as an override when desired by the root user.
49 */
50 uint64_t uid;
51 /*
52 * Length of the variable length payload (name, condition, and
53 * an action).
54 */
55 uint32_t length;
56 /* Includes '\0' terminator. */
57 uint32_t name_length;
58 /* A null-terminated name, a condition, and an action follow. */
59 char payload[];
60 } LTTNG_PACKED;
61
62 struct lttng_triggers_comm {
63 uint32_t count;
64 uint32_t length;
65 /* Count * lttng_trigger_comm structure */
66 char payload[];
67 };
68
69 LTTNG_HIDDEN
70 ssize_t lttng_trigger_create_from_payload(struct lttng_payload_view *view,
71 struct lttng_trigger **trigger);
72
73 LTTNG_HIDDEN
74 int lttng_trigger_serialize(const struct lttng_trigger *trigger,
75 struct lttng_payload *payload);
76
77 LTTNG_HIDDEN
78 const struct lttng_condition *lttng_trigger_get_const_condition(
79 const struct lttng_trigger *trigger);
80
81 LTTNG_HIDDEN
82 const struct lttng_action *lttng_trigger_get_const_action(
83 const struct lttng_trigger *trigger);
84
85 LTTNG_HIDDEN
86 bool lttng_trigger_validate(struct lttng_trigger *trigger);
87
88 LTTNG_HIDDEN
89 int lttng_trigger_assign_name(
90 struct lttng_trigger *dst, const struct lttng_trigger *src);
91
92 LTTNG_HIDDEN
93 void lttng_trigger_set_tracer_token(
94 struct lttng_trigger *trigger, uint64_t token);
95
96 LTTNG_HIDDEN
97 uint64_t lttng_trigger_get_tracer_token(const struct lttng_trigger *trigger);
98
99 LTTNG_HIDDEN
100 int lttng_trigger_generate_name(struct lttng_trigger *trigger,
101 uint64_t unique_id);
102
103 LTTNG_HIDDEN
104 bool lttng_trigger_is_equal(
105 const struct lttng_trigger *a, const struct lttng_trigger *b);
106
107 LTTNG_HIDDEN
108 void lttng_trigger_get(struct lttng_trigger *trigger);
109
110 LTTNG_HIDDEN
111 void lttng_trigger_put(struct lttng_trigger *trigger);
112
113 /*
114 * Allocate a new set of triggers.
115 * The returned object must be freed via lttng_triggers_destroy.
116 */
117 LTTNG_HIDDEN
118 struct lttng_triggers *lttng_triggers_create(void);
119
120 /*
121 * Return the a pointer to a mutable element at index "index" of an
122 * lttng_triggers set.
123 *
124 * This differs from the public `lttng_triggers_get_at_index` in that
125 * the returned pointer to a mutable trigger.
126 *
127 * The ownership of the trigger set element is NOT transfered.
128 * The returned object can NOT be freed via lttng_trigger_destroy.
129 */
130 LTTNG_HIDDEN
131 struct lttng_trigger *lttng_triggers_borrow_mutable_at_index(
132 const struct lttng_triggers *triggers, unsigned int index);
133
134 /*
135 * Add a trigger to the triggers set.
136 *
137 * A reference to the added trigger is acquired on behalf of the trigger set
138 * on success.
139 */
140 LTTNG_HIDDEN
141 int lttng_triggers_add(
142 struct lttng_triggers *triggers, struct lttng_trigger *trigger);
143
144 /*
145 * Serialize a trigger set to an lttng_payload object.
146 * Return LTTNG_OK on success, negative lttng error code on error.
147 */
148 LTTNG_HIDDEN
149 int lttng_triggers_serialize(const struct lttng_triggers *triggers,
150 struct lttng_payload *payload);
151
152 LTTNG_HIDDEN
153 ssize_t lttng_triggers_create_from_payload(struct lttng_payload_view *view,
154 struct lttng_triggers **triggers);
155
156 LTTNG_HIDDEN
157 const struct lttng_credentials *lttng_trigger_get_credentials(
158 const struct lttng_trigger *trigger);
159
160 LTTNG_HIDDEN
161 void lttng_trigger_set_credentials(struct lttng_trigger *trigger,
162 const struct lttng_credentials *creds);
163
164 #endif /* LTTNG_TRIGGER_INTERNAL_H */
This page took 0.032671 seconds and 5 git commands to generate.