Command Processing


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_tCommandContextGet (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 Documentation

#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)
Macro to make checking a user has authenticated before executing a command easier and consistent.

#define CommandError ( _errcode,
_msgformat...   ) 

Value:

do{\
        CommandContext_t *context = CommandContextGet();\
        context->errorNumber = _errcode;\
        snprintf(context->errorMessage, MAX_ERR_MSG,_msgformat);\
    }while(0)
Macro for making error reporting simpler and consistent.


Function Documentation

CommandContext_t* CommandContextGet ( void   ) 

Retrieve the command context specific to the current thread.

Returns:
A CommandContext_t instance or NULL if a command is not executing.

bool CommandExecute ( CommandContext_t context,
char *  command 
)

Execute the command line supplied.

Parameters:
context The context the command is being executed.
command The command line to execute.
Returns:
true if the command was found, false otherwise.

bool CommandExecuteConsole ( char *  line  ) 

Execute a command in the console command context.

Parameters:
line The command line to execute.
Returns:
TRUE if the command was found, FALSE otherwise.

char* CommandGets ( char *  buffer,
int  len 
)

fgets style function to retrieve data from the control connection.

Parameters:
buffer The buffer to store the data in.
len Length of the buffer.
Returns:
On success returns buffer, otherwise returns NULL.

int CommandInit ( void   ) 

Initialise the command processor.

Returns:
0 on success, non 0 on error.

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.

Parameters:
fmt Printf format.
Returns:
Number of bytes printed.

int CommandProcessFile ( char *  file  ) 

Load and process the command in file.

Parameters:
file Name of the file to process.
Returns:
0 on success, non 0 on error.

void CommandRegisterCommands ( Command_t commands  ) 

Register an array of commands to be used by the command processor.

Parameters:
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.

Parameters:
handler The details of the info handler.

void CommandUnRegisterCommands ( Command_t commands  ) 

Unregister an array of commands previously registered by a call to CommandRegisterCommands.

Parameters:
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.

Parameters:
handler The details of the variable handler.


Generated on Thu Jun 26 12:58:31 2008 for DVBStreamer by  doxygen 1.5.5