2 * Copyright (C) 2019 Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
4 * SPDX-License-Identifier: LGPL-2.1-only
8 #ifndef LTTNG_EVENT_RULE_INTERNAL_H
9 #define LTTNG_EVENT_RULE_INTERNAL_H
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>
20 #include <sys/types.h>
24 struct lttng_payload_view
;
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
,
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
);
65 struct lttng_event_rule
{
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
;
81 struct lttng_event_rule_comm
{
82 /* enum lttng_event_rule_type */
83 int8_t event_rule_type
;
88 void lttng_event_rule_init(struct lttng_event_rule
*event_rule
,
89 enum lttng_event_rule_type type
);
92 bool lttng_event_rule_validate(const struct lttng_event_rule
*event_rule
);
95 ssize_t
lttng_event_rule_create_from_payload(
96 struct lttng_payload_view
*payload
,
97 struct lttng_event_rule
**event_rule
);
100 int lttng_event_rule_serialize(const struct lttng_event_rule
*event_rule
,
101 struct lttng_payload
*payload
);
104 bool lttng_event_rule_is_equal(const struct lttng_event_rule
*a
,
105 const struct lttng_event_rule
*b
);
108 bool lttng_event_rule_get(struct lttng_event_rule
*rule
);
111 void lttng_event_rule_put(struct lttng_event_rule
*rule
);
114 enum lttng_domain_type
lttng_event_rule_get_domain_type(
115 const struct lttng_event_rule
*rule
);
118 enum lttng_error_code
lttng_event_rule_generate_filter_bytecode(
119 struct lttng_event_rule
*rule
,
120 const struct lttng_credentials
*creds
);
123 * If not present/implemented returns NULL.
124 * Caller DOES NOT own the returned object.
127 const char *lttng_event_rule_get_filter(const struct lttng_event_rule
*rule
);
130 * If not present/implemented returns NULL.
131 * Caller DOES NOT own the returned object.
134 const struct lttng_bytecode
*lttng_event_rule_get_filter_bytecode(
135 const struct lttng_event_rule
*rule
);
138 * If not present/implemented return NULL.
139 * Caller OWNS the returned object.
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
);
147 const char *lttng_event_rule_type_str(enum lttng_event_rule_type type
);
150 unsigned long lttng_event_rule_hash(const struct lttng_event_rule
*rule
);
153 * This is a compatibility helper allowing us to generate a sessiond-side (not
154 * communication) `struct lttng_event` object from an event rule.
156 * This effectively bridges older parts of the code using those structures and
157 * new event-rule based code.
159 * The caller owns the returned object.
162 struct lttng_event
*lttng_event_rule_generate_lttng_event(
163 const struct lttng_event_rule
*rule
);
165 /* Test if an event rule targets an agent domain. */
167 bool lttng_event_rule_targets_agent_domain(const struct lttng_event_rule
*rule
);
170 enum lttng_error_code
lttng_event_rule_mi_serialize(
171 const struct lttng_event_rule
*rule
, struct mi_writer
*writer
);
173 #endif /* LTTNG_EVENT_RULE_INTERNAL_H */