Commit | Line | Data |
---|---|---|
7a3dcaf6 JR |
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> | |
58daac01 | 12 | #include <common/credentials.h> |
993578ff | 13 | #include <common/sessiond-comm/sessiond-comm.h> |
7a3dcaf6 | 14 | #include <lttng/domain.h> |
44760c20 | 15 | #include <lttng/event.h> |
7a3dcaf6 JR |
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 | ||
993578ff JR |
26 | enum lttng_event_rule_generate_exclusions_status { |
27 | LTTNG_EVENT_RULE_GENERATE_EXCLUSIONS_STATUS_OK, | |
28 | LTTNG_EVENT_RULE_GENERATE_EXCLUSIONS_STATUS_NONE, | |
29 | LTTNG_EVENT_RULE_GENERATE_EXCLUSIONS_STATUS_ERROR, | |
30 | LTTNG_EVENT_RULE_GENERATE_EXCLUSIONS_STATUS_OUT_OF_MEMORY, | |
31 | }; | |
32 | ||
7a3dcaf6 JR |
33 | typedef void (*event_rule_destroy_cb)(struct lttng_event_rule *event_rule); |
34 | typedef bool (*event_rule_validate_cb)( | |
35 | const struct lttng_event_rule *event_rule); | |
36 | typedef int (*event_rule_serialize_cb)( | |
37 | const struct lttng_event_rule *event_rule, | |
38 | struct lttng_payload *payload); | |
39 | typedef bool (*event_rule_equal_cb)(const struct lttng_event_rule *a, | |
40 | const struct lttng_event_rule *b); | |
41 | typedef ssize_t (*event_rule_create_from_payload_cb)( | |
42 | struct lttng_payload_view *view, | |
43 | struct lttng_event_rule **event_rule); | |
44 | typedef enum lttng_error_code (*event_rule_generate_filter_bytecode_cb)( | |
58daac01 JR |
45 | struct lttng_event_rule *event_rule, |
46 | const struct lttng_credentials *creds); | |
7a3dcaf6 JR |
47 | typedef const char *(*event_rule_get_filter_cb)( |
48 | const struct lttng_event_rule *event_rule); | |
2b00d462 | 49 | typedef const struct lttng_bytecode *( |
7a3dcaf6 JR |
50 | *event_rule_get_filter_bytecode_cb)( |
51 | const struct lttng_event_rule *event_rule); | |
993578ff JR |
52 | typedef enum lttng_event_rule_generate_exclusions_status ( |
53 | *event_rule_generate_exclusions_cb)( | |
54 | const struct lttng_event_rule *event_rule, | |
55 | struct lttng_event_exclusion **exclusions); | |
959e3c66 JR |
56 | typedef unsigned long (*event_rule_hash_cb)( |
57 | const struct lttng_event_rule *event_rule); | |
44760c20 JR |
58 | typedef struct lttng_event *(*event_rule_generate_lttng_event_cb)( |
59 | const struct lttng_event_rule *event_rule); | |
7a3dcaf6 JR |
60 | |
61 | struct lttng_event_rule { | |
62 | struct urcu_ref ref; | |
63 | enum lttng_event_rule_type type; | |
64 | event_rule_validate_cb validate; | |
65 | event_rule_serialize_cb serialize; | |
66 | event_rule_equal_cb equal; | |
67 | event_rule_destroy_cb destroy; | |
68 | event_rule_generate_filter_bytecode_cb generate_filter_bytecode; | |
69 | event_rule_get_filter_cb get_filter; | |
70 | event_rule_get_filter_bytecode_cb get_filter_bytecode; | |
71 | event_rule_generate_exclusions_cb generate_exclusions; | |
959e3c66 | 72 | event_rule_hash_cb hash; |
44760c20 | 73 | event_rule_generate_lttng_event_cb generate_lttng_event; |
7a3dcaf6 JR |
74 | }; |
75 | ||
76 | struct lttng_event_rule_comm { | |
77 | /* enum lttng_event_rule_type */ | |
78 | int8_t event_rule_type; | |
79 | char payload[]; | |
80 | }; | |
81 | ||
82 | LTTNG_HIDDEN | |
83 | void lttng_event_rule_init(struct lttng_event_rule *event_rule, | |
84 | enum lttng_event_rule_type type); | |
85 | ||
86 | LTTNG_HIDDEN | |
87 | bool lttng_event_rule_validate(const struct lttng_event_rule *event_rule); | |
88 | ||
89 | LTTNG_HIDDEN | |
90 | ssize_t lttng_event_rule_create_from_payload( | |
91 | struct lttng_payload_view *payload, | |
92 | struct lttng_event_rule **event_rule); | |
93 | ||
94 | LTTNG_HIDDEN | |
95 | int lttng_event_rule_serialize(const struct lttng_event_rule *event_rule, | |
96 | struct lttng_payload *payload); | |
97 | ||
98 | LTTNG_HIDDEN | |
99 | bool lttng_event_rule_is_equal(const struct lttng_event_rule *a, | |
100 | const struct lttng_event_rule *b); | |
101 | ||
102 | LTTNG_HIDDEN | |
103 | bool lttng_event_rule_get(struct lttng_event_rule *rule); | |
104 | ||
105 | LTTNG_HIDDEN | |
106 | void lttng_event_rule_put(struct lttng_event_rule *rule); | |
107 | ||
108 | LTTNG_HIDDEN | |
109 | enum lttng_domain_type lttng_event_rule_get_domain_type( | |
110 | const struct lttng_event_rule *rule); | |
111 | ||
112 | LTTNG_HIDDEN | |
113 | enum lttng_error_code lttng_event_rule_generate_filter_bytecode( | |
58daac01 JR |
114 | struct lttng_event_rule *rule, |
115 | const struct lttng_credentials *creds); | |
7a3dcaf6 JR |
116 | |
117 | /* | |
118 | * If not present/implemented returns NULL. | |
119 | * Caller DOES NOT own the returned object. | |
120 | */ | |
121 | LTTNG_HIDDEN | |
122 | const char *lttng_event_rule_get_filter(const struct lttng_event_rule *rule); | |
123 | ||
124 | /* | |
125 | * If not present/implemented returns NULL. | |
126 | * Caller DOES NOT own the returned object. | |
127 | */ | |
128 | LTTNG_HIDDEN | |
2b00d462 | 129 | const struct lttng_bytecode *lttng_event_rule_get_filter_bytecode( |
7a3dcaf6 JR |
130 | const struct lttng_event_rule *rule); |
131 | ||
132 | /* | |
133 | * If not present/implemented return NULL. | |
134 | * Caller OWNS the returned object. | |
135 | */ | |
136 | LTTNG_HIDDEN | |
993578ff JR |
137 | enum lttng_event_rule_generate_exclusions_status |
138 | lttng_event_rule_generate_exclusions(const struct lttng_event_rule *rule, | |
139 | struct lttng_event_exclusion **exclusions); | |
7a3dcaf6 JR |
140 | |
141 | LTTNG_HIDDEN | |
142 | const char *lttng_event_rule_type_str(enum lttng_event_rule_type type); | |
143 | ||
959e3c66 JR |
144 | LTTNG_HIDDEN |
145 | unsigned long lttng_event_rule_hash(const struct lttng_event_rule *rule); | |
146 | ||
44760c20 JR |
147 | /* |
148 | * This is a compatibility helper allowing us to generate a sessiond-side (not | |
149 | * communication) `struct lttng_event` object from an event rule. | |
150 | * | |
151 | * This effectively bridges older parts of the code using those structures and | |
152 | * new event-rule based code. | |
153 | * | |
154 | * The caller owns the returned object. | |
155 | */ | |
156 | LTTNG_HIDDEN | |
157 | struct lttng_event *lttng_event_rule_generate_lttng_event( | |
158 | const struct lttng_event_rule *rule); | |
159 | ||
160 | /* Test if an event rule targets an agent domain. */ | |
161 | LTTNG_HIDDEN | |
162 | bool lttng_event_rule_targets_agent_domain(const struct lttng_event_rule *rule); | |
163 | ||
7a3dcaf6 | 164 | #endif /* LTTNG_EVENT_RULE_INTERNAL_H */ |