MXS-1220: Add execution of module commands to REST API

The module command self links now point to an endpoint that executes the
module command. Depending on the type of the module command, either a GET
or a POST request must be made.
This commit is contained in:
Markus Mäkelä
2017-05-31 11:09:36 +03:00
parent 08a0883ec8
commit ba546fcd21
16 changed files with 284 additions and 99 deletions

View File

@ -65,6 +65,13 @@ typedef struct
This should always be the first argument
if the function requires an output DCB. */
/** What type of an action does the command perform? */
enum modulecmd_type
{
MODULECMD_TYPE_PASSIVE, /**< Command only displays data */
MODULECMD_TYPE_ACTIVE /**< Command can modify data */
};
/**
* Options for arguments, bits 9 through 32
*/
@ -123,6 +130,7 @@ typedef struct modulecmd
{
char *identifier; /**< Unique identifier */
char *domain; /**< Command domain */
enum modulecmd_type type; /**< Command type, either active or passive */
MODULECMDFN func; /**< The registered function */
int arg_count_min; /**< Minimum number of arguments */
int arg_count_max; /**< Maximum number of arguments */
@ -130,6 +138,9 @@ typedef struct modulecmd
struct modulecmd *next; /**< Next command */
} MODULECMD;
/** Check if the module command can modify the data/state of the module */
#define MODULECMD_MODIFIES_DATA(t) (t->type == MODULECMD_TYPE_ACTIVE)
/**
* @brief Register a new command
*
@ -143,7 +154,8 @@ typedef struct modulecmd
* @return True if the module was successfully registered, false on error
*/
bool modulecmd_register_command(const char *domain, const char *identifier,
MODULECMDFN entry_point, int argc, modulecmd_arg_type_t *argv);
enum modulecmd_type type, MODULECMDFN entry_point,
int argc, modulecmd_arg_type_t *argv);
/**
* @brief Find a registered command
@ -196,6 +208,15 @@ void modulecmd_arg_free(MODULECMD_ARG *arg);
*/
bool modulecmd_arg_is_present(const MODULECMD_ARG *arg, int idx);
/**
* @brief Check if module command requires an output DCB
*
* @param cmd Command to check
*
* @return True if module requires a DCB for printing output
*/
bool modulecmd_requires_output_dcb(const MODULECMD* cmd);
/**
* @brief Call a registered command
*