Commit | Line | Data |
---|---|---|
a58c490f | 1 | /* |
ab5be9fa | 2 | * Copyright (C) 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
a58c490f | 3 | * |
ab5be9fa | 4 | * SPDX-License-Identifier: LGPL-2.1-only |
a58c490f | 5 | * |
a58c490f JG |
6 | */ |
7 | ||
8 | #ifndef LTTNG_ACTION_INTERNAL_H | |
9 | #define LTTNG_ACTION_INTERNAL_H | |
10 | ||
c9e313bc SM |
11 | #include <common/buffer-view.hpp> |
12 | #include <common/dynamic-buffer.hpp> | |
13 | #include <common/macros.hpp> | |
14 | #include <common/payload-view.hpp> | |
15 | #include <common/payload.hpp> | |
588c4b0d JG |
16 | #include <lttng/lttng.h> |
17 | #include <pthread.h> | |
a58c490f | 18 | #include <stdbool.h> |
72756a3f | 19 | #include <sys/types.h> |
c852ce4e | 20 | #include <urcu/ref.h> |
a58c490f | 21 | |
7f4d5b07 | 22 | struct lttng_rate_policy; |
6a751b95 JR |
23 | struct mi_writer; |
24 | struct mi_lttng_error_query_callbacks; | |
25 | struct lttng_trigger; | |
2d57482c | 26 | |
a58c490f JG |
27 | typedef bool (*action_validate_cb)(struct lttng_action *action); |
28 | typedef void (*action_destroy_cb)(struct lttng_action *action); | |
3647288f | 29 | typedef int (*action_serialize_cb)(struct lttng_action *action, |
c0a66c84 | 30 | struct lttng_payload *payload); |
3dd04a6a JR |
31 | typedef bool (*action_equal_cb)(const struct lttng_action *a, |
32 | const struct lttng_action *b); | |
c0a66c84 JG |
33 | typedef ssize_t (*action_create_from_payload_cb)( |
34 | struct lttng_payload_view *view, | |
869a3c2d | 35 | struct lttng_action **action); |
7f4d5b07 | 36 | typedef const struct lttng_rate_policy *(*action_get_rate_policy_cb)( |
2d57482c | 37 | const struct lttng_action *action); |
588c4b0d JG |
38 | typedef enum lttng_action_status (*action_add_error_query_results_cb)( |
39 | const struct lttng_action *action, | |
40 | struct lttng_error_query_results *results); | |
6a751b95 JR |
41 | typedef enum lttng_error_code (*action_mi_serialize_cb)( |
42 | const struct lttng_action *condition, struct mi_writer *writer); | |
a58c490f JG |
43 | |
44 | struct lttng_action { | |
c852ce4e | 45 | struct urcu_ref ref; |
a58c490f JG |
46 | enum lttng_action_type type; |
47 | action_validate_cb validate; | |
48 | action_serialize_cb serialize; | |
3dd04a6a | 49 | action_equal_cb equal; |
a58c490f | 50 | action_destroy_cb destroy; |
7f4d5b07 | 51 | action_get_rate_policy_cb get_rate_policy; |
588c4b0d | 52 | action_add_error_query_results_cb add_error_query_results; |
6a751b95 | 53 | action_mi_serialize_cb mi_serialize; |
2d57482c JR |
54 | |
55 | /* Internal use only. */ | |
56 | ||
57 | /* The number of time the actions was enqueued for execution. */ | |
58 | uint64_t execution_request_counter; | |
59 | /* | |
60 | * The number of time the action was actually executed. | |
7f4d5b07 | 61 | * Action rate policy can impact on this number. |
2d57482c JR |
62 | * */ |
63 | uint64_t execution_counter; | |
64 | /* | |
65 | * The number of time the action execution failed. | |
588c4b0d JG |
66 | * An unsigned long is used to use a type which makes atomic |
67 | * operations possible. | |
2d57482c | 68 | */ |
588c4b0d | 69 | unsigned long execution_failure_counter; |
a58c490f JG |
70 | }; |
71 | ||
72 | struct lttng_action_comm { | |
73 | /* enum lttng_action_type */ | |
74 | int8_t action_type; | |
75 | } LTTNG_PACKED; | |
76 | ||
6acb3f46 SM |
77 | void lttng_action_init(struct lttng_action *action, |
78 | enum lttng_action_type type, | |
79 | action_validate_cb validate, | |
80 | action_serialize_cb serialize, | |
3dd04a6a | 81 | action_equal_cb equal, |
2d57482c | 82 | action_destroy_cb destroy, |
588c4b0d | 83 | action_get_rate_policy_cb get_rate_policy, |
6a751b95 JR |
84 | action_add_error_query_results_cb add_error_query_results, |
85 | action_mi_serialize_cb mi); | |
6acb3f46 | 86 | |
a58c490f JG |
87 | bool lttng_action_validate(struct lttng_action *action); |
88 | ||
3647288f | 89 | int lttng_action_serialize(struct lttng_action *action, |
c0a66c84 | 90 | struct lttng_payload *buf); |
a58c490f | 91 | |
c0a66c84 | 92 | ssize_t lttng_action_create_from_payload(struct lttng_payload_view *view, |
a58c490f JG |
93 | struct lttng_action **action); |
94 | ||
3dd04a6a JR |
95 | bool lttng_action_is_equal(const struct lttng_action *a, |
96 | const struct lttng_action *b); | |
97 | ||
c852ce4e JG |
98 | void lttng_action_get(struct lttng_action *action); |
99 | ||
c852ce4e JG |
100 | void lttng_action_put(struct lttng_action *action); |
101 | ||
10615eee JR |
102 | const char* lttng_action_type_string(enum lttng_action_type action_type); |
103 | ||
2d57482c JR |
104 | void lttng_action_increase_execution_request_count(struct lttng_action *action); |
105 | ||
2d57482c JR |
106 | void lttng_action_increase_execution_count(struct lttng_action *action); |
107 | ||
2d57482c JR |
108 | void lttng_action_increase_execution_failure_count(struct lttng_action *action); |
109 | ||
2d57482c JR |
110 | bool lttng_action_should_execute(const struct lttng_action *action); |
111 | ||
588c4b0d JG |
112 | enum lttng_action_status lttng_action_add_error_query_results( |
113 | const struct lttng_action *action, | |
114 | struct lttng_error_query_results *results); | |
115 | ||
116 | /* | |
117 | * For use by the various lttng_action implementation. Implements the default | |
118 | * behavior to the generic error "execution failure counter" that all actions | |
a8940c5e | 119 | * (except list, which passes-through) provide. |
588c4b0d | 120 | */ |
588c4b0d JG |
121 | enum lttng_action_status lttng_action_generic_add_error_query_results( |
122 | const struct lttng_action *action, | |
123 | struct lttng_error_query_results *results); | |
6a751b95 JR |
124 | enum lttng_error_code lttng_action_mi_serialize(const struct lttng_trigger *trigger, |
125 | const struct lttng_action *action, | |
126 | struct mi_writer *writer, | |
127 | const struct mi_lttng_error_query_callbacks | |
128 | *error_query_callbacks, | |
129 | struct lttng_dynamic_array *action_path_indexes); | |
588c4b0d | 130 | |
a58c490f | 131 | #endif /* LTTNG_ACTION_INTERNAL_H */ |