SoW-2019-0002: Dynamic Snapshot
[lttng-tools.git] / include / lttng / event-rule / event-rule-internal.h
1 /*
2 * Copyright (C) 2019 - Jonathan Rajotte-Julien
3 * <jonathan.rajotte-julien@efficios.com>
4 *
5 * This library is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU Lesser General Public License, version 2.1 only,
7 * as published by the Free Software Foundation.
8 *
9 * This library is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
12 * for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #ifndef LTTNG_EVENT_RULE_INTERNAL_H
20 #define LTTNG_EVENT_RULE_INTERNAL_H
21
22 #include <common/buffer-view.h>
23 #include <common/dynamic-buffer.h>
24 #include <common/macros.h>
25 #include <lttng/event.h>
26 #include <lttng/event-rule/event-rule.h>
27 #include <lttng/lttng-error.h>
28 #include <stdbool.h>
29 #include <stdint.h>
30 #include <sys/types.h>
31 #include <urcu/ref.h>
32
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_dynamic_buffer *buf,
39 int *fd_to_send);
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_buffer_cb)(
43 const struct lttng_buffer_view *view,
44 struct lttng_event_rule **event_rule);
45 typedef enum lttng_error_code (*event_rule_populate_cb)(
46 struct lttng_event_rule *event_rule, uid_t uid, gid_t gid);
47 typedef const char *(*event_rule_get_filter_cb)(
48 const struct lttng_event_rule *event_rule);
49 typedef const struct lttng_filter_bytecode *(
50 *event_rule_get_filter_bytecode_cb)(
51 const struct lttng_event_rule *event_rule);
52 typedef struct lttng_event_exclusion *(*event_rule_generate_exclusions_cb)(
53 struct lttng_event_rule *event_rule);
54 typedef struct lttng_event *(*event_rule_generate_lttng_event_cb)(
55 const struct lttng_event_rule *event_rule);
56
57 struct lttng_event_rule {
58 struct urcu_ref ref;
59 enum lttng_event_rule_type type;
60 event_rule_validate_cb validate;
61 event_rule_serialize_cb serialize;
62 event_rule_equal_cb equal;
63 event_rule_destroy_cb destroy;
64 event_rule_populate_cb populate;
65 /* Optional */
66 event_rule_get_filter_cb get_filter;
67 event_rule_get_filter_bytecode_cb get_filter_bytecode;
68 event_rule_generate_exclusions_cb generate_exclusions;
69 event_rule_generate_lttng_event_cb generate_lttng_event;
70 };
71
72 struct lttng_event_rule_comm {
73 /* enum lttng_event_rule_type */
74 int8_t event_rule_type;
75 char payload[];
76 };
77
78 LTTNG_HIDDEN
79 void lttng_event_rule_init(struct lttng_event_rule *event_rule,
80 enum lttng_event_rule_type type);
81
82 LTTNG_HIDDEN
83 bool lttng_event_rule_validate(const struct lttng_event_rule *event_rule);
84
85 LTTNG_HIDDEN
86 ssize_t lttng_event_rule_create_from_buffer(
87 const struct lttng_buffer_view *buffer,
88 struct lttng_event_rule **event_rule);
89
90 LTTNG_HIDDEN
91 int lttng_event_rule_serialize(const struct lttng_event_rule *event_rule,
92 struct lttng_dynamic_buffer *buf,
93 int *fd_to_send);
94
95 LTTNG_HIDDEN
96 bool lttng_event_rule_is_equal(const struct lttng_event_rule *a,
97 const struct lttng_event_rule *b);
98
99 LTTNG_HIDDEN
100 bool lttng_event_rule_get(struct lttng_event_rule *rule);
101
102 LTTNG_HIDDEN
103 void lttng_event_rule_put(struct lttng_event_rule *rule);
104
105 LTTNG_HIDDEN
106 enum lttng_domain_type lttng_event_rule_get_domain_type(
107 const struct lttng_event_rule *rule);
108
109 LTTNG_HIDDEN
110 enum lttng_error_code lttng_event_rule_populate(
111 struct lttng_event_rule *rule, uid_t uid, gid_t gid);
112
113 /* If not present return NULL
114 * Caller DO NOT own the returned object
115 */
116 LTTNG_HIDDEN
117 const char *lttng_event_rule_get_filter(const struct lttng_event_rule *rule);
118
119 /* If not present return NULL
120 * Caller DO NOT own the returned object
121 */
122 LTTNG_HIDDEN
123 const struct lttng_filter_bytecode *lttng_event_rule_get_filter_bytecode(
124 const struct lttng_event_rule *rule);
125
126 /*
127 * If not present return NULL
128 * Caller OWN the returned object
129 * TODO: should this be done another way?
130 */
131 LTTNG_HIDDEN
132 struct lttng_event_exclusion *lttng_event_rule_generate_exclusions(
133 struct lttng_event_rule *rule);
134
135 /*
136 * This is compatibility helper, allowing us to generate a sessiond side (not
137 * communication) struct lttng_event object. This facilitate integration with
138 * current code.
139 * Caller OWN the returned object
140 */
141 LTTNG_HIDDEN
142 struct lttng_event *lttng_event_rule_generate_lttng_event(
143 const struct lttng_event_rule *rule);
144
145 /* Quick helper to test if the event rule apply to an agent domain */
146 LTTNG_HIDDEN
147 bool lttng_event_rule_is_agent(const struct lttng_event_rule *rule);
148
149 LTTNG_HIDDEN
150 const char *lttng_event_rule_type_str(enum lttng_event_rule_type type);
151
152 #endif /* LTTNG_EVENT_RULE_INTERNAL_H */
This page took 0.035314 seconds and 6 git commands to generate.