From e734af76d81b07090c618b1c4af3b2fdd6b592f3 Mon Sep 17 00:00:00 2001 From: lijia Date: Fri, 18 Oct 2024 16:47:51 +0800 Subject: rebase onto develop-2.0 --- include/stellar/monitor.h | 54 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 include/stellar/monitor.h (limited to 'include') diff --git a/include/stellar/monitor.h b/include/stellar/monitor.h new file mode 100644 index 0000000..9e50949 --- /dev/null +++ b/include/stellar/monitor.h @@ -0,0 +1,54 @@ +#pragma once +#ifdef __cplusplus +extern "C" +{ +#endif +#include "stellar/module.h" +#define MONITOR_MODULE_NAME "monitor" + struct stellar_monitor; + /* use stellar_module_manager_get_module() to get monitor_module */ + struct stellar_monitor *monitor_module_to_monitor(struct module *monitor_module); + +#define error_format_server_close "ERR Server closed the connection" +#define error_format_connection_error "ERR could not connect to '%s:%u' : Connection refused" +#define error_format_unknown_command "ERR unknown command '%s'" +#define error_format_unknown_arg "ERR unrecognized args '%s'" +#define error_format_wrong_number_of_args "ERR wrong number of arguments for '%s' command" +#define error_format_arg_not_valid_integer "ERR arg '%s' is not an integer or out of range" + + struct monitor_reply; + struct monitor_reply *monitor_reply_nil(void); + struct monitor_reply *monitor_reply_new_string(const char *format, ...); + struct monitor_reply *monitor_reply_new_integer(long long integer); + struct monitor_reply *monitor_reply_new_double(double dval); + struct monitor_reply *monitor_reply_new_error(const char *format, ...); /* for common errors, "error_format_xxx" should be used */ + struct monitor_reply *monitor_reply_new_status(const char *format, ...); + + /* Like Linux bash, argv[0] is always the command name itself */ + typedef struct monitor_reply *(monitor_cmd_cb)(struct stellar_monitor *monitor, int argc, char *argv[], void *arg); + + /* + * All command characters are case-insensitive. + * The set of flags 'flags' specify the behavior of the command, and should be + * passed as a C string composed of space separated words, The set of flags are: + * + * "write" : The command may modify the data set (it may also read from it). + * "readonly": The command returns data from keys but never writes. + * + * return value: + * 0: success + * -1: failed + * 1: already exist, has been registered + */ + int monitor_register_cmd(struct stellar_monitor *monitor, const char *cmd, monitor_cmd_cb *cb, const char *flags, + const char *hint, const char *description, void *arg); + +/* + All modules should support "-h/--help/help" args to output usage information. + "show modulea help" + "show moduleb -h" + "show modulec --help" +*/ +#ifdef __cplusplus +} +#endif -- cgit v1.2.3