| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | #ifndef NETDATA_COMMANDS_H |
| 4 | #define NETDATA_COMMANDS_H 1 |
| 5 | |
| 6 | #define MAX_COMMAND_LENGTH (8192) |
| 7 | #define MAX_EXIT_STATUS_LENGTH 23 /* Can't ever be bigger than "X-18446744073709551616" */ |
| 8 | |
| 9 | typedef enum cmd { |
| 10 | CMD_HELP = 0, |
| 11 | CMD_RELOAD_HEALTH, |
| 12 | CMD_REOPEN_LOGS, |
| 13 | CMD_EXIT, |
| 14 | CMD_FATAL, |
| 15 | CMD_RELOAD_CLAIMING_STATE, |
| 16 | CMD_RELOAD_LABELS, |
| 17 | CMD_READ_CONFIG, |
| 18 | CMD_WRITE_CONFIG, |
| 19 | CMD_PING, |
| 20 | CMD_ACLK_STATE, |
| 21 | CMD_VERSION, |
| 22 | CMD_DUMPCONFIG, |
| 23 | CMD_REMOVE_NODE, |
| 24 | CMD_MARK_NODE, |
| 25 | CMD_UPDATE_NODE_INFO, |
| 26 | CMD_TOTAL_COMMANDS |
| 27 | } cmd_t; |
| 28 | |
| 29 | typedef enum cmd_status { |
| 30 | CMD_STATUS_SUCCESS = 0, |
| 31 | CMD_STATUS_FAILURE, |
| 32 | CMD_STATUS_BUSY |
| 33 | } cmd_status_t; |
| 34 | |
| 35 | #define CMD_PREFIX_INFO 'O' /* Following string should go to cli stdout */ |
| 36 | #define CMD_PREFIX_ERROR 'E' /* Following string should go to cli stderr */ |
| 37 | #define CMD_PREFIX_EXIT_CODE 'X' /* Following string is cli integer exit code */ |
| 38 | |
| 39 | typedef enum cmd_type { |
| 40 | /* |
| 41 | * No other command is allowed to run at the same time (except for CMD_TYPE_HIGH_PRIORITY). |
| 42 | */ |
| 43 | CMD_TYPE_EXCLUSIVE = 0, |
| 44 | /* |
| 45 | * Other commands are allowed to run concurrently (except for CMD_TYPE_EXCLUSIVE) but calls to this command are |
| 46 | * serialized. |
| 47 | */ |
| 48 | CMD_TYPE_ORTHOGONAL, |
| 49 | /* |
| 50 | * Other commands are allowed to run concurrently (except for CMD_TYPE_EXCLUSIVE) as are calls to this command. |
| 51 | */ |
| 52 | CMD_TYPE_CONCURRENT, |
| 53 | /* |
| 54 | * Those commands are always allowed to run. |
| 55 | */ |
| 56 | CMD_TYPE_HIGH_PRIORITY |
| 57 | } cmd_type_t; |
| 58 | |
| 59 | /** |
| 60 | * Executes a command and returns the status. |
| 61 | * |
| 62 | * @param args a string that may contain additional parameters to be parsed |
| 63 | * @param message allocate and return a message if need be (up to MAX_COMMAND_LENGTH bytes) |
| 64 | * @return CMD_FAILURE or CMD_SUCCESS |
| 65 | */ |
| 66 | typedef cmd_status_t (command_action_t) (char *args, char **message); |
| 67 | |
| 68 | typedef enum cmd_init_status { |
| 69 | CMD_INIT_STATUS_OFF, |
| 70 | CMD_INIT_STATUS_INIT, |
| 71 | CMD_INIT_STATUS_FULL, |
| 72 | } cmd_init_status_t; |
| 73 | |
| 74 | typedef struct command_info { |
| 75 | char *cmd_str; // the command string |
| 76 | char *params; |
| 77 | char *help; |
| 78 | command_action_t *func; // the function that executes the command |
| 79 | cmd_type_t type; // Concurrency control information for the command |
| 80 | cmd_init_status_t init_status; // command availability during start |
| 81 | } command_info_t; |
| 82 | |
| 83 | typedef void (command_lock_t) (unsigned index); |
| 84 | |
| 85 | cmd_status_t execute_command(cmd_t idx, char *args, char **message); |
| 86 | void commands_init(void); |
| 87 | void commands_exit(void); |
| 88 | |
| 89 | #endif //NETDATA_COMMANDS_H |