2 * Copyright (C) 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * SPDX-License-Identifier: LGPL-2.1-only
8 #ifndef LTTNG_ACTION_INTERNAL_H
9 #define LTTNG_ACTION_INTERNAL_H
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>
17 #include <lttng/lttng.h>
21 #include <sys/types.h>
24 struct lttng_rate_policy;
26 struct mi_lttng_error_query_callbacks;
29 using action_validate_cb = bool (*)(struct lttng_action *);
30 using action_destroy_cb = void (*)(struct lttng_action *);
31 using action_serialize_cb = int (*)(struct lttng_action *, struct lttng_payload *);
32 using action_equal_cb = bool (*)(const struct lttng_action *, const struct lttng_action *);
33 using action_create_from_payload_cb = ssize_t (*)(struct lttng_payload_view *,
34 struct lttng_action **);
35 using action_get_rate_policy_cb = const struct lttng_rate_policy *(*) (const struct lttng_action *);
36 using action_add_error_query_results_cb = enum lttng_action_status (*)(
37 const struct lttng_action *, struct lttng_error_query_results *);
38 using action_mi_serialize_cb = enum lttng_error_code (*)(const struct lttng_action *,
43 enum lttng_action_type type;
44 action_validate_cb validate;
45 action_serialize_cb serialize;
46 action_equal_cb equal;
47 action_destroy_cb destroy;
48 action_get_rate_policy_cb get_rate_policy;
49 action_add_error_query_results_cb add_error_query_results;
50 action_mi_serialize_cb mi_serialize;
52 /* Internal use only. */
54 /* The number of time the actions was enqueued for execution. */
55 uint64_t execution_request_counter;
57 * The number of time the action was actually executed.
58 * Action rate policy can impact on this number.
60 uint64_t execution_counter;
62 * The number of time the action execution failed.
63 * An unsigned long is used to use a type which makes atomic
64 * operations possible.
66 unsigned long execution_failure_counter;
69 struct lttng_action_comm {
70 /* enum lttng_action_type */
74 void lttng_action_init(struct lttng_action *action,
75 enum lttng_action_type type,
76 action_validate_cb validate,
77 action_serialize_cb serialize,
78 action_equal_cb equal,
79 action_destroy_cb destroy,
80 action_get_rate_policy_cb get_rate_policy,
81 action_add_error_query_results_cb add_error_query_results,
82 action_mi_serialize_cb mi);
84 bool lttng_action_validate(struct lttng_action *action);
86 int lttng_action_serialize(struct lttng_action *action, struct lttng_payload *buf);
88 ssize_t lttng_action_create_from_payload(struct lttng_payload_view *view,
89 struct lttng_action **action);
91 bool lttng_action_is_equal(const struct lttng_action *a, const struct lttng_action *b);
93 void lttng_action_get(struct lttng_action *action);
95 void lttng_action_put(struct lttng_action *action);
97 const char *lttng_action_type_string(enum lttng_action_type action_type);
99 void lttng_action_increase_execution_request_count(struct lttng_action *action);
101 void lttng_action_increase_execution_count(struct lttng_action *action);
103 void lttng_action_increase_execution_failure_count(struct lttng_action *action);
105 bool lttng_action_should_execute(const struct lttng_action *action);
107 enum lttng_action_status
108 lttng_action_add_error_query_results(const struct lttng_action *action,
109 struct lttng_error_query_results *results);
112 * For use by the various lttng_action implementation. Implements the default
113 * behavior to the generic error "execution failure counter" that all actions
114 * (except list, which passes-through) provide.
116 enum lttng_action_status
117 lttng_action_generic_add_error_query_results(const struct lttng_action *action,
118 struct lttng_error_query_results *results);
119 enum lttng_error_code
120 lttng_action_mi_serialize(const struct lttng_trigger *trigger,
121 const struct lttng_action *action,
122 struct mi_writer *writer,
123 const struct mi_lttng_error_query_callbacks *error_query_callbacks,
124 struct lttng_dynamic_array *action_path_indexes);
126 #endif /* LTTNG_ACTION_INTERNAL_H */