Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
Console::CommandFlow Class Referenceabstract

State flow base class that handles interactive commands. More...

#include <Console.hxx>

Inheritance diagram for Console::CommandFlow:
StateFlowBase Executable Notifiable QMember Destructable

Protected Member Functions

 CommandFlow (Console *console, const char *name)
 Constructor.
 
 ~CommandFlow ()
 Destructor.
 
virtual StateFlowBase::Action entry ()=0
 Entry point to command flow.
 
StateFlowBase::Action read_line ()
 Read a line of input.
 
StateFlowBase::Action wait_for_line_and_call (StateFlowBase::Callback c)
 Wait for a complete line of input.
 
StateFlowBase::Action record_status_and_exit (CommandStatus status)
 Record the CommandStatus and exit the CommandFlow.
 
- Protected Member Functions inherited from StateFlowBase
 StateFlowBase (Service *service)
 Constructor.
 
 ~StateFlowBase ()
 Destructor.
 
void reset_flow (Callback c)
 Resets the flow to the specified state.
 
bool is_state (Callback c)
 
bool is_terminated ()
 
void start_flow (Callback c)
 Resets the flow to the specified state and starts it.
 
Action again ()
 Call the current state again via call_immediately.
 
Action exit ()
 Terminate current StateFlow activity.
 
Action delete_this ()
 Terminates the flow and deletes *this.
 
Action set_terminated ()
 Sets the flow to terminated state.
 
Action call_immediately (Callback c)
 Imediately call the next state upon return.
 
Action wait ()
 Wait for an asynchronous call.
 
Action wait_and_call (Callback c)
 Wait for resource to become available before proceeding to next state.
 
template<class T >
Action allocate_and_call (FlowInterface< Buffer< T > > *target_flow, Callback c, Pool *pool=nullptr)
 Allocates a buffer from a pool and proceed to the next state when allocation is successful.
 
Action allocate_and_call (Callback c, QAsync *queue)
 Allocates an entry from an asynchronous queue, and transitions to a state once the allocation is complete.
 
template<class T >
Buffer< T > * full_allocation_result (FlowInterface< Buffer< T > > *target_flow)
 Takes the result of the asynchronous allocation without resetting the object.
 
template<class T >
T * full_allocation_result (TypedQAsync< T > *queue)
 Takes the result of the asynchronous allocation without resetting the object.
 
template<class T >
void cast_allocation_result (T **member)
 Takes the result of the asynchronous allocation without resetting the object.
 
template<class T >
Buffer< T > * get_allocation_result (FlowInterface< Buffer< T > > *target_flow)
 Takes the result of the asynchronous allocation.
 
Action yield_and_call (Callback c)
 Place the current flow to the back of the executor, and transition to a new state after we get the CPU again.
 
Action yield ()
 Place the current flow to the back of the executor, and re-try the current state after we get the CPU again.
 
Action sleep_and_call (::Timer *timer, long long timeout_nsec, Callback c)
 Suspends execution of this control flow for a specified time.
 
template<class T , typename... Args>
Action invoke_subflow_and_wait (FlowInterface< Buffer< T > > *target_flow, Callback c, Args &&... args)
 Calls a helper flow to perform some actions.
 
Action read_repeated (StateFlowSelectHelper *helper, int fd, void *buf, size_t size, Callback c, unsigned priority=Selectable::MAX_PRIO)
 Blocks until size bytes are read and then invokes the next state.
 
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.
 
Action read_nonblocking (StateFlowSelectHelper *helper, int fd, void *buf, size_t size, Callback c, unsigned priority=Selectable::MAX_PRIO)
 Attempts to read at most size bytes, and then invokes the next state, even if only zero bytes are available right now.
 
Action read_repeated_with_timeout (StateFlowTimedSelectHelper *helper, long long timeout_nsec, int fd, void *buf, size_t size, Callback c, unsigned priority=Selectable::MAX_PRIO)
 Blocks until size bytes are read, or a timeout expires.
 
Action internal_try_read ()
 Implementation state that gets repeatedly called upon every wakeup and tries to make progress on reading.
 
Action write_repeated (StateFlowSelectHelper *helper, int fd, const void *buf, size_t size, Callback c, unsigned priority=Selectable::MAX_PRIO)
 Writes some data into a file descriptor, repeating the operation as necessary until all bytes are written.
 
Action internal_try_write ()
 Implementation state that gets repeatedly called upon every wakeup and tries to make progress on writing.
 
- Protected Member Functions inherited from QMember
 QMember ()
 Constructor.
 
 ~QMember ()
 Destructor.
 

Protected Attributes

int argc
 number of arguments on command line
 
const char ** argv
 list of arguments on command line
 
FILE * fp
 FILE* reference for output data.
 
- Protected Attributes inherited from QMember
QMembernext
 pointer to the next member in the queue
 

Private Member Functions

CommandStatus callback (Session *session, int fd, FILE *fp, int argc, const char *argv[])
 Start flow with the incoming data parameters.
 
 DISALLOW_COPY_AND_ASSIGN (CommandFlow)
 

Private Attributes

Commandcommand
 Keep track of Command instance for destruction time.
 
int fd
 file descriptor for input data
 
Sessionsession
 Session flow to notify when command is complete.
 
CommandStatus status
 Resulting status of running command.
 

Friends

class Console
 Give Console class access to CommandFlow private members.
 
class Session
 Give Session class access to Commandflow private members.
 

Additional Inherited Members

- Public Member Functions inherited from StateFlowBase
void run () override
 Callback from the executor.
 
void notify () override
 Wakeup call arrived.
 
Serviceservice ()
 Return a pointer to the service I am bound to.
 
- Public Member Functions inherited from Executable
void test_deletion ()
 
- Public Member Functions inherited from QMember
void init ()
 Initiailize a QMember, in place of a public placement construction.
 
- Static Public Member Functions inherited from StateFlowBase
template<class T , typename... Args>
static void invoke_subflow_and_ignore_result (FlowInterface< Buffer< T > > *target_flow, Args &&... args)
 Calls a helper flow to perform some actions.
 
- Protected Types inherited from StateFlowBase
typedef Action(StateFlowBase::* Callback) ()
 State Flow callback prototype.
 

Detailed Description

State flow base class that handles interactive commands.

This may also be used for non-interactive commands that want to use the StateFlow paradigm for responding.

Example:

class ExampleCommandFlow : public Console::CommandFlow
{
public:
ExampleCommandFlow()
: CommandFlow(&console, "test")
{
}
~ExampleCommandFlow()
{
}
private:
{
fprintf(fp, "param: ");
return wait_for_line_and_call(STATE(input));
}
{
if (argc == 1 && strcmp(argv[0])
{
// do stuff
return record_status_and_exit(Console::COMMAND_OK);
}
return record_status_and_exit(Console::COMMAND_ERROR);
}
};
#define STATE(_fn)
Turns a function name into an argument to be supplied to functions expecting a state.
Definition StateFlow.hxx:61
State flow base class that handles interactive commands.
Definition Console.hxx:176
@ COMMAND_ERROR
Command had some kind of error.
Definition Console.hxx:83
@ COMMAND_OK
Command executed successfully.
Definition Console.hxx:81
Return type for a state flow callback.

Definition at line 175 of file Console.hxx.

Constructor & Destructor Documentation

◆ CommandFlow()

Console::CommandFlow::CommandFlow ( Console console,
const char *  name 
)
protected

Constructor.

Parameters
consoleConsole instance that this belongs to
namecommand name

add the command to the end of the list

Definition at line 148 of file Console.cxx.

◆ ~CommandFlow()

Console::CommandFlow::~CommandFlow ( )
protected

Destructor.

Definition at line 167 of file Console.cxx.

Member Function Documentation

◆ callback()

CommandStatus Console::CommandFlow::callback ( Session session,
int  fd,
FILE *  fp,
int  argc,
const char *  argv[] 
)
inlineprivate

Start flow with the incoming data parameters.

Definition at line 232 of file Console.hxx.

◆ entry()

virtual StateFlowBase::Action Console::CommandFlow::entry ( )
protectedpure virtual

Entry point to command flow.

Returns
defined by derived class

◆ read_line()

StateFlowBase::Action Console::CommandFlow::read_line ( )
protected

Read a line of input.

Returns
next state wait_for_line()

◆ record_status_and_exit()

StateFlowBase::Action Console::CommandFlow::record_status_and_exit ( CommandStatus  status)
inlineprotected

Record the CommandStatus and exit the CommandFlow.

Parameters
statusexit status of the command
Returns
exit action

Definition at line 223 of file Console.hxx.

◆ wait_for_line_and_call()

StateFlowBase::Action Console::CommandFlow::wait_for_line_and_call ( StateFlowBase::Callback  c)
inlineprotected

Wait for a complete line of input.

Parameters
cstate to call when the line is acquired.
Returns
next action

Definition at line 211 of file Console.hxx.

Friends And Related Symbol Documentation

◆ Console

friend class Console
friend

Give Console class access to CommandFlow private members.

Definition at line 257 of file Console.hxx.

◆ Session

friend class Session
friend

Give Session class access to Commandflow private members.

Definition at line 260 of file Console.hxx.

Member Data Documentation

◆ argc

int Console::CommandFlow::argc
protected

number of arguments on command line

Definition at line 199 of file Console.hxx.

◆ argv

const char** Console::CommandFlow::argv
protected

list of arguments on command line

Definition at line 202 of file Console.hxx.

◆ command

Command* Console::CommandFlow::command
private

Keep track of Command instance for destruction time.

Definition at line 245 of file Console.hxx.

◆ fd

int Console::CommandFlow::fd
private

file descriptor for input data

Definition at line 248 of file Console.hxx.

◆ fp

FILE* Console::CommandFlow::fp
protected

FILE* reference for output data.

Definition at line 205 of file Console.hxx.

◆ session

Session* Console::CommandFlow::session
private

Session flow to notify when command is complete.

Definition at line 251 of file Console.hxx.

◆ status

CommandStatus Console::CommandFlow::status
private

Resulting status of running command.

Definition at line 254 of file Console.hxx.


The documentation for this class was generated from the following files: