MXS-929: Add errors to the modulecmd system
The modules can now return human-readable error messages to the caller of the function. The internals of the modulecmd system also use this to return errors to the users. The error messages can be retrieved with a common error function which should make it easy to use in various clients.
This commit is contained in:
@ -110,7 +110,8 @@ typedef struct modulecmd
|
||||
char *identifier; /**< Unique identifier */
|
||||
char *domain; /**< Command domain */
|
||||
MODULECMDFN func; /**< The registered function */
|
||||
int arg_count; /**< Number of arguments */
|
||||
int arg_count_min; /**< Minimum number of arguments */
|
||||
int arg_count_max; /**< Maximum number of arguments */
|
||||
modulecmd_arg_type_t *arg_types; /**< Argument types */
|
||||
struct modulecmd *next; /**< Next command */
|
||||
} MODULECMD;
|
||||
@ -168,4 +169,22 @@ void modulecmd_arg_free(MODULECMD_ARG *arg);
|
||||
*/
|
||||
bool modulecmd_call_command(const MODULECMD *cmd, const MODULECMD_ARG *args);
|
||||
|
||||
/**
|
||||
* @brief Set the current error message
|
||||
*
|
||||
* Modules that register commands should use this function to report errors.
|
||||
* This will overwrite the existing error message.
|
||||
*
|
||||
* @param format Format string
|
||||
* @param ... Format string arguments
|
||||
*/
|
||||
void modulecmd_set_error(const char *format, ...);
|
||||
|
||||
/**
|
||||
* @brief Get the latest error generated by the modulecmd system
|
||||
*
|
||||
* @return Human-readable error message
|
||||
*/
|
||||
const char* modulecmd_get_error();
|
||||
|
||||
MXS_END_DECLS
|
||||
|
Reference in New Issue
Block a user