MI: implement all objects related to trigger machine interface
[lttng-tools.git] / include / lttng / event-rule / event-rule-internal.h
1 /*
2 * Copyright (C) 2019 Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
3 *
4 * SPDX-License-Identifier: LGPL-2.1-only
5 *
6 */
7
8 #ifndef LTTNG_EVENT_RULE_INTERNAL_H
9 #define LTTNG_EVENT_RULE_INTERNAL_H
10
11 #include <common/macros.h>
12 #include <common/credentials.h>
13 #include <common/sessiond-comm/sessiond-comm.h>
14 #include <lttng/domain.h>
15 #include <lttng/event.h>
16 #include <lttng/event-rule/event-rule.h>
17 #include <lttng/lttng-error.h>
18 #include <stdbool.h>
19 #include <stdint.h>
20 #include <sys/types.h>
21 #include <urcu/ref.h>
22
23 struct lttng_payload;
24 struct lttng_payload_view;
25 struct mi_writer;
26
27 enum lttng_event_rule_generate_exclusions_status {
28 LTTNG_EVENT_RULE_GENERATE_EXCLUSIONS_STATUS_OK,
29 LTTNG_EVENT_RULE_GENERATE_EXCLUSIONS_STATUS_NONE,
30 LTTNG_EVENT_RULE_GENERATE_EXCLUSIONS_STATUS_ERROR,
31 LTTNG_EVENT_RULE_GENERATE_EXCLUSIONS_STATUS_OUT_OF_MEMORY,
32 };
33
34 typedef void (*event_rule_destroy_cb)(struct lttng_event_rule *event_rule);
35 typedef bool (*event_rule_validate_cb)(
36 const struct lttng_event_rule *event_rule);
37 typedef int (*event_rule_serialize_cb)(
38 const struct lttng_event_rule *event_rule,
39 struct lttng_payload *payload);
40 typedef bool (*event_rule_equal_cb)(const struct lttng_event_rule *a,
41 const struct lttng_event_rule *b);
42 typedef ssize_t (*event_rule_create_from_payload_cb)(
43 struct lttng_payload_view *view,
44 struct lttng_event_rule **event_rule);
45 typedef enum lttng_error_code (*event_rule_generate_filter_bytecode_cb)(
46 struct lttng_event_rule *event_rule,
47 const struct lttng_credentials *creds);
48 typedef const char *(*event_rule_get_filter_cb)(
49 const struct lttng_event_rule *event_rule);
50 typedef const struct lttng_bytecode *(
51 *event_rule_get_filter_bytecode_cb)(
52 const struct lttng_event_rule *event_rule);
53 typedef enum lttng_event_rule_generate_exclusions_status (
54 *event_rule_generate_exclusions_cb)(
55 const struct lttng_event_rule *event_rule,
56 struct lttng_event_exclusion **exclusions);
57 typedef unsigned long (*event_rule_hash_cb)(
58 const struct lttng_event_rule *event_rule);
59 typedef struct lttng_event *(*event_rule_generate_lttng_event_cb)(
60 const struct lttng_event_rule *event_rule);
61 typedef enum lttng_error_code (*event_rule_mi_serialize_cb)(
62 const struct lttng_event_rule *event_rule,
63 struct mi_writer *writer);
64
65 struct lttng_event_rule {
66 struct urcu_ref ref;
67 enum lttng_event_rule_type type;
68 event_rule_validate_cb validate;
69 event_rule_serialize_cb serialize;
70 event_rule_equal_cb equal;
71 event_rule_destroy_cb destroy;
72 event_rule_generate_filter_bytecode_cb generate_filter_bytecode;
73 event_rule_get_filter_cb get_filter;
74 event_rule_get_filter_bytecode_cb get_filter_bytecode;
75 event_rule_generate_exclusions_cb generate_exclusions;
76 event_rule_hash_cb hash;
77 event_rule_generate_lttng_event_cb generate_lttng_event;
78 event_rule_mi_serialize_cb mi_serialize;
79 };
80
81 struct lttng_event_rule_comm {
82 /* enum lttng_event_rule_type */
83 int8_t event_rule_type;
84 char payload[];
85 };
86
87 LTTNG_HIDDEN
88 void lttng_event_rule_init(struct lttng_event_rule *event_rule,
89 enum lttng_event_rule_type type);
90
91 LTTNG_HIDDEN
92 bool lttng_event_rule_validate(const struct lttng_event_rule *event_rule);
93
94 LTTNG_HIDDEN
95 ssize_t lttng_event_rule_create_from_payload(
96 struct lttng_payload_view *payload,
97 struct lttng_event_rule **event_rule);
98
99 LTTNG_HIDDEN
100 int lttng_event_rule_serialize(const struct lttng_event_rule *event_rule,
101 struct lttng_payload *payload);
102
103 LTTNG_HIDDEN
104 bool lttng_event_rule_is_equal(const struct lttng_event_rule *a,
105 const struct lttng_event_rule *b);
106
107 LTTNG_HIDDEN
108 bool lttng_event_rule_get(struct lttng_event_rule *rule);
109
110 LTTNG_HIDDEN
111 void lttng_event_rule_put(struct lttng_event_rule *rule);
112
113 LTTNG_HIDDEN
114 enum lttng_domain_type lttng_event_rule_get_domain_type(
115 const struct lttng_event_rule *rule);
116
117 LTTNG_HIDDEN
118 enum lttng_error_code lttng_event_rule_generate_filter_bytecode(
119 struct lttng_event_rule *rule,
120 const struct lttng_credentials *creds);
121
122 /*
123 * If not present/implemented returns NULL.
124 * Caller DOES NOT own the returned object.
125 */
126 LTTNG_HIDDEN
127 const char *lttng_event_rule_get_filter(const struct lttng_event_rule *rule);
128
129 /*
130 * If not present/implemented returns NULL.
131 * Caller DOES NOT own the returned object.
132 */
133 LTTNG_HIDDEN
134 const struct lttng_bytecode *lttng_event_rule_get_filter_bytecode(
135 const struct lttng_event_rule *rule);
136
137 /*
138 * If not present/implemented return NULL.
139 * Caller OWNS the returned object.
140 */
141 LTTNG_HIDDEN
142 enum lttng_event_rule_generate_exclusions_status
143 lttng_event_rule_generate_exclusions(const struct lttng_event_rule *rule,
144 struct lttng_event_exclusion **exclusions);
145
146 LTTNG_HIDDEN
147 const char *lttng_event_rule_type_str(enum lttng_event_rule_type type);
148
149 LTTNG_HIDDEN
150 unsigned long lttng_event_rule_hash(const struct lttng_event_rule *rule);
151
152 /*
153 * This is a compatibility helper allowing us to generate a sessiond-side (not
154 * communication) `struct lttng_event` object from an event rule.
155 *
156 * This effectively bridges older parts of the code using those structures and
157 * new event-rule based code.
158 *
159 * The caller owns the returned object.
160 */
161 LTTNG_HIDDEN
162 struct lttng_event *lttng_event_rule_generate_lttng_event(
163 const struct lttng_event_rule *rule);
164
165 /* Test if an event rule targets an agent domain. */
166 LTTNG_HIDDEN
167 bool lttng_event_rule_targets_agent_domain(const struct lttng_event_rule *rule);
168
169 LTTNG_HIDDEN
170 enum lttng_error_code lttng_event_rule_mi_serialize(
171 const struct lttng_event_rule *rule, struct mi_writer *writer);
172
173 #endif /* LTTNG_EVENT_RULE_INTERNAL_H */
This page took 0.034646 seconds and 5 git commands to generate.