34#ifndef _CONSOLE_CONSOLE_HXX_
35#define _CONSOLE_CONSOLE_HXX_
42#if OPENMRN_FEATURE_BSD_SOCKETS
43#define CONSOLE_NETWORKING
315#if defined (CONSOLE_NETWORKING)
333 return listen_and_call(&selectHelper, fdListen,
STATE(
accept));
489#if defined (CONSOLE_NETWORKING)
int accept(int socket, struct sockaddr *address, socklen_t *address_len)
Accept a new connection on a socket.
int listen(int socket, int backlog)
Mark a connection-mode socket, specified by the socket argument, as accepting connections.
#define STATE(_fn)
Turns a function name into an argument to be supplied to functions expecting a state.
State flow base class that handles interactive commands.
~CommandFlow()
Destructor.
Command * command
Keep track of Command instance for destruction time.
virtual StateFlowBase::Action entry()=0
Entry point to command flow.
const char ** argv
list of arguments on command line
int argc
number of arguments on command line
StateFlowBase::Action wait_for_line_and_call(StateFlowBase::Callback c)
Wait for a complete line of input.
Session * session
Session flow to notify when command is complete.
CommandStatus callback(Session *session, int fd, FILE *fp, int argc, const char *argv[])
Start flow with the incoming data parameters.
int fd
file descriptor for input data
FILE * fp
FILE* reference for output data.
StateFlowBase::Action record_status_and_exit(CommandStatus status)
Record the CommandStatus and exit the CommandFlow.
CommandStatus status
Resulting status of running command.
StateFlowBase::Action read_line()
Read a line of input.
Console session metadata.
StateFlowBase::Action entry()
Entry point to the state machine.
StateFlowBase::Action exit_interactive()
Wait for completion of an interactive command in order to cleanup based on result.
Command * command
Command instance that we are currently acting on.
size_t pos
current line position
void prompt(FILE *fp)
Print the standard prompt.
size_t line_size
current max line size
CommandStatus callback(int argc, const char *argv[])
Process a potential callback for a given command.
StateFlowBase::StateFlowSelectHelper selectHelper
metadata for waiting on the listen socket to become active
int fdOut
output file descriptor of the session
const char * args[MAX_ARGS]
parsed argument list
char * line
current line content
FILE * fp
file pointer of session
int fdIn
input file descriptor of the session
StateFlowBase::Action process_read()
Process the incoming command line input.
bool callback_result_process(CommandStatus status, const char *name)
Process the result of the command callback.
This class provides a console available from stdin/stdout as well as via telnet.
friend class Listen
Give Listen class access to Console private members.
void add_command(const char *name, Callback callback, void *context=NULL)
Add a new command to the console.
static const int FD_STDOUT
Default STDOUT file descriptor.
CommandStatus
Enumeration of recognized command callback results.
@ COMMAND_NOT_FOUND
Command not found.
@ COMMAND_ERROR
Command had some kind of error.
@ COMMAND_NEXT
Command waiting for input.
@ COMMAND_CLOSE
Command wants to close the session.
@ COMMAND_OK
Command executed successfully.
static CommandStatus help_command(FILE *fp, int argc, const char *argv[], void *context)
Print out the help menu by calling the in context helper function.
Command help
the "help" command instance
CommandStatus(* Callback)(FILE *, int, const char *argv[], void *)
Console command callback.
static CommandStatus quit_command(FILE *fp, int argc, const char *argv[], void *context)
Quit out of the current login session by calling the in context helper function.
static const int FD_STDIN
Default STDIN file descriptor.
Command helpMark
the help "?" command instance
void add_session(int fd_in, int fd_out)
Add a console session.
static const size_t MAX_ARGS
Maximum number of supported arguments including the command itself.
void open_session(int fd_in, int fd_out)
Open and initialize a new session.
This class implements an execution of tasks pulled off an input queue.
Collection of related state machines that pend on incoming messages.
ExecutorBase * executor()
Return type for a state flow callback.
Base class for state machines.
Action read_single(StateFlowSelectHelper *helper, int fd, void *buf, size_t size, Callback c, unsigned priority=Selectable::MAX_PRIO)
Attempts to read at most size_t bytes, and blocks the caller until at least one byte is read.
Service * service()
Return a pointer to the service I am bound to.
void notify() override
Wakeup call arrived.
Action exit()
Terminate current StateFlow activity.
void start_flow(Callback c)
Resets the flow to the specified state and starts it.
Action wait_and_call(Callback c)
Wait for resource to become available before proceeding to next state.
Action(StateFlowBase::* Callback)()
State Flow callback prototype.
#define HASSERT(x)
Checks that the value of expression x is true, else terminates the current process.
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Removes default copy-constructor and assignment added by C++.
Console command metadata.
Command * next
next Command in list
CommandFlow * flow
state flow for interactive commands
void * context
context pointer to pass into callback
Command(const char *name, Callback callback, void *context=NULL, Command *next=NULL)
Construct a new command.
Callback callback
callback function for command
bool interactive
true if command is interactive
const char * name
command name
Command(const char *name, CommandFlow *flow, Command *next=NULL)
Construct a new command.
Use this class to read from an fd using select() in a state flow.