| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | #ifndef NETDATA_RRDFUNCTIONS_H |
| 3 | #define NETDATA_RRDFUNCTIONS_H 1 |
| 4 | |
| 5 | // ---------------------------------------------------------------------------- |
| 6 | |
| 7 | #include "libnetdata/libnetdata.h" |
| 8 | |
| 9 | #define RRDFUNCTIONS_PRIORITY_DEFAULT 100 |
| 10 | #define RRDFUNCTIONS_VERSION_DEFAULT 0 |
| 11 | #define RRDFUNCTIONS_TAG_HIDDEN "hidden" |
| 12 | |
| 13 | #define RRDFUNCTIONS_TIMEOUT_EXTENSION_UT (1 * USEC_PER_SEC) |
| 14 | |
| 15 | typedef void (*rrd_function_result_callback_t)(BUFFER *wb, int code, void *result_cb_data); |
| 16 | typedef bool (*rrd_function_is_cancelled_cb_t)(void *is_cancelled_cb_data); |
| 17 | typedef void (*rrd_function_cancel_cb_t)(void *data); |
| 18 | typedef void (*rrd_function_register_canceller_cb_t)(void *register_cancel_cb_data, rrd_function_cancel_cb_t cancel_cb, void *cancel_cb_data); |
| 19 | typedef void (*rrd_function_progress_cb_t)(nd_uuid_t *transaction, void *data, size_t done, size_t all); |
| 20 | typedef void (*rrd_function_progresser_cb_t)(const char *transaction, void *data); |
| 21 | typedef void (*rrd_function_register_progresser_cb_t)(void *register_progresser_cb_data, rrd_function_progresser_cb_t progresser_cb, void *progresser_cb_data); |
| 22 | |
| 23 | struct rrd_function_execute { |
| 24 | nd_uuid_t *transaction; |
| 25 | const char *function; |
| 26 | BUFFER *payload; |
| 27 | const char *source; |
| 28 | |
| 29 | HTTP_ACCESS user_access; |
| 30 | |
| 31 | usec_t *stop_monotonic_ut; |
| 32 | |
| 33 | struct { |
| 34 | BUFFER *wb; // the response should be written here |
| 35 | rrd_function_result_callback_t cb; |
| 36 | void *data; |
| 37 | } result; |
| 38 | |
| 39 | struct { |
| 40 | rrd_function_progress_cb_t cb; |
| 41 | void *data; |
| 42 | } progress; |
| 43 | |
| 44 | struct { |
| 45 | rrd_function_is_cancelled_cb_t cb; |
| 46 | void *data; |
| 47 | } is_cancelled; |
| 48 | |
| 49 | struct { |
| 50 | rrd_function_register_canceller_cb_t cb; |
| 51 | void *data; |
| 52 | } register_canceller; |
| 53 | |
| 54 | struct { |
| 55 | rrd_function_register_progresser_cb_t cb; |
| 56 | void *data; |
| 57 | } register_progresser; |
| 58 | }; |
| 59 | |
| 60 | typedef int (*rrd_function_execute_cb_t)(struct rrd_function_execute *rfe, void *data); |
| 61 | |
| 62 | |
| 63 | // ---------------------------------------------------------------------------- |
| 64 | |
| 65 | #include "rrd.h" |
| 66 | |
| 67 | void rrd_functions_host_init(RRDHOST *host); |
| 68 | void rrd_functions_host_destroy(RRDHOST *host); |
| 69 | |
| 70 | // add a function, to be run from the collector |
| 71 | void rrd_function_add(RRDHOST *host, RRDSET *st, const char *name, int timeout, int priority, uint32_t version, const char *help, const char *tags, |
| 72 | HTTP_ACCESS access, bool sync, rrd_function_execute_cb_t execute_cb, |
| 73 | void *execute_cb_data); |
| 74 | |
| 75 | void rrd_function_del(RRDHOST *host, RRDSET *st, const char *name); |
| 76 | |
| 77 | // call a function, to be run from anywhere |
| 78 | int rrd_function_run(RRDHOST *host, BUFFER *result_wb, int timeout_s, |
| 79 | HTTP_ACCESS user_access, const char *cmd, |
| 80 | bool wait, const char *transaction, |
| 81 | rrd_function_result_callback_t result_cb, void *result_cb_data, |
| 82 | rrd_function_progress_cb_t progress_cb, void *progress_cb_data, |
| 83 | rrd_function_is_cancelled_cb_t is_cancelled_cb, void *is_cancelled_cb_data, |
| 84 | BUFFER *payload, const char *source, bool allow_restricted); |
| 85 | |
| 86 | bool rrd_function_available(RRDHOST *host, const char *function); |
| 87 | |
| 88 | bool rrd_function_has_this_original_result_callback(nd_uuid_t *transaction, rrd_function_result_callback_t cb); |
| 89 | |
| 90 | #include "rrdfunctions-inline.h" |
| 91 | #include "rrdfunctions-inflight.h" |
| 92 | #include "rrdfunctions-exporters.h" |
| 93 | |
| 94 | #endif // NETDATA_RRDFUNCTIONS_H |