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