summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorlijia <[email protected]>2024-10-18 16:47:51 +0800
committerlijia <[email protected]>2024-11-07 18:30:58 +0800
commite734af76d81b07090c618b1c4af3b2fdd6b592f3 (patch)
treec9b894fb0eaa9c56bd5f04bfab5628a97592091d /include
parent99a68d5c9efe500ab339165a2af515a0a7355ada (diff)
rebase onto develop-2.0
Diffstat (limited to 'include')
-rw-r--r--include/stellar/monitor.h54
1 files changed, 54 insertions, 0 deletions
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