Data Structures | |
struct | Command_t |
Structure used to define a command. More... | |
struct | CommandVariable_t |
Structure used to define a variable that can be retrieved/set item. More... | |
struct | CommandContext_t |
Structure used to define the context a command is running in. More... | |
Defines | |
#define | COMMAND_OK 0x0000 |
Command completed OK. | |
#define | COMMAND_ERROR_TOO_MANY_CONNS 0x0001 |
Too many connections, connection refused. | |
#define | COMMAND_ERROR_UNKNOWN_COMMAND 0x0002 |
Command is not known. | |
#define | COMMAND_ERROR_WRONG_ARGS 0x0003 |
Wrong number of arguments supplied for command. | |
#define | COMMAND_ERROR_AUTHENTICATION 0x0004 |
Connection has not authenticated successfully. | |
#define | COMMAND_ERROR_GENERIC 0xffff |
Unknown error code, the error message string should explain the problem. | |
#define | MAX_ERR_MSG 256 |
Maximum length of the error message string. | |
#define | CommandError(_errcode, _msgformat...) |
Macro for making error reporting simpler and consistent. | |
#define | CommandCheckAuthenticated() |
Macro to make checking a user has authenticated before executing a command easier and consistent. | |
Typedefs | |
typedef void(* | CommandVariableGet_t )(char *name) |
Function pointer to call when retrieve a variable. | |
typedef void(* | CommandVariableSet_t )(char *name, int argc, char **argv) |
Function pointer to call when setting a variable. | |
Functions | |
int | CommandInit (void) |
Initialise the command processor. | |
void | CommandDeInit (void) |
Deinitialise the command processor. | |
void | CommandRegisterCommands (Command_t *commands) |
Register an array of commands to be used by the command processor. | |
void | CommandUnRegisterCommands (Command_t *commands) |
Unregister an array of commands previously registered by a call to CommandRegisterCommands. | |
void | CommandLoop (void) |
Start interactive command loop. | |
int | CommandProcessFile (char *file) |
Load and process the command in file. | |
bool | CommandExecuteConsole (char *line) |
Execute a command in the console command context. | |
bool | CommandExecute (CommandContext_t *context, char *command) |
Execute the command line supplied. | |
int | CommandPrintf (const char *fmt,...) |
Printf style output function that should be in command functions to send data to the user. | |
char * | CommandGets (char *buffer, int len) |
fgets style function to retrieve data from the control connection. | |
CommandContext_t * | CommandContextGet (void) |
Retrieve the command context specific to the current thread. | |
void | CommandRegisterVariable (CommandVariable_t *handler) |
Register an info handler that will be invoked by the get/set command. | |
void | CommandUnRegisterVariable (CommandVariable_t *handler) |
UnRegister a variable handler that will be invoked by the get/set command. |
#define COMMAND_ERROR_AUTHENTICATION 0x0004 |
Connection has not authenticated successfully.
#define COMMAND_ERROR_GENERIC 0xffff |
Unknown error code, the error message string should explain the problem.
#define COMMAND_ERROR_TOO_MANY_CONNS 0x0001 |
Too many connections, connection refused.
#define COMMAND_ERROR_UNKNOWN_COMMAND 0x0002 |
Command is not known.
#define COMMAND_ERROR_WRONG_ARGS 0x0003 |
Wrong number of arguments supplied for command.
#define COMMAND_OK 0x0000 |
Command completed OK.
#define CommandCheckAuthenticated | ( | ) |
Value:
do{\ CommandContext_t *context = CommandContextGet();\ if (!context->authenticated)\ {\ CommandError(COMMAND_ERROR_AUTHENTICATION, "Not authenticated!");\ return;\ }\ }while(0)
#define CommandError | ( | _errcode, | |||
_msgformat... | ) |
Value:
do{\ CommandContext_t *context = CommandContextGet();\ context->errorNumber = _errcode;\ snprintf(context->errorMessage, MAX_ERR_MSG,_msgformat);\ }while(0)
CommandContext_t* CommandContextGet | ( | void | ) |
Retrieve the command context specific to the current thread.
bool CommandExecute | ( | CommandContext_t * | context, | |
char * | command | |||
) |
Execute the command line supplied.
context | The context the command is being executed. | |
command | The command line to execute. |
bool CommandExecuteConsole | ( | char * | line | ) |
Execute a command in the console command context.
line | The command line to execute. |
char* CommandGets | ( | char * | buffer, | |
int | len | |||
) |
fgets style function to retrieve data from the control connection.
buffer | The buffer to store the data in. | |
len | Length of the buffer. |
int CommandInit | ( | void | ) |
Initialise the command processor.
void CommandLoop | ( | void | ) |
Start interactive command loop.
This function returns when the user exits the command loop, or the ExitProgram variable is TRUE.
int CommandPrintf | ( | const char * | fmt, | |
... | ||||
) |
Printf style output function that should be in command functions to send data to the user.
fmt | Printf format. |
int CommandProcessFile | ( | char * | file | ) |
Load and process the command in file.
file | Name of the file to process. |
void CommandRegisterCommands | ( | Command_t * | commands | ) |
Register an array of commands to be used by the command processor.
commands | The command=NULL terminated array of commands to add, |
void CommandRegisterVariable | ( | CommandVariable_t * | handler | ) |
Register an info handler that will be invoked by the get/set command.
handler | The details of the info handler. |
void CommandUnRegisterCommands | ( | Command_t * | commands | ) |
Unregister an array of commands previously registered by a call to CommandRegisterCommands.
commands | The array of commands to remove. |
void CommandUnRegisterVariable | ( | CommandVariable_t * | handler | ) |
UnRegister a variable handler that will be invoked by the get/set command.
handler | The details of the variable handler. |