AceRoutine  0.1
A low-memory, fast-switching, cooperative multitasking library using stackless coroutines on Arduino platforms.
Public Member Functions | Static Public Member Functions | List of all members
ace_routine::cli::CommandDispatcherC Class Reference

A CommandDispatcher that takes DispatchRecordC records using C-strings. More...

#include <CommandDispatcher.h>

Inheritance diagram for ace_routine::cli::CommandDispatcherC:
Inheritance graph
[legend]
Collaboration diagram for ace_routine::cli::CommandDispatcherC:
Collaboration graph
[legend]

Public Member Functions

 CommandDispatcherC (StreamReader &streamReader, Print &printer, const DispatchRecordC *dispatchTable, uint8_t numCommands, const char **argv, uint8_t argvSize)
 Constructor. More...
 
- Public Member Functions inherited from ace_routine::cli::CommandDispatcher
 CommandDispatcher (StreamReader &streamReader, Print &printer, uint8_t numCommands, const char **argv, uint8_t argvSize)
 Constructor. More...
 
- Public Member Functions inherited from ace_routine::Coroutine
Coroutine ** getNext ()
 Return the next pointer as a pointer to the pointer, similar to getRoot(). More...
 
const FCStringgetName () const
 Human-readable name of the coroutine. More...
 
virtual unsigned long millis () const
 Returns the current millisecond clock. More...
 
void suspend ()
 Suspend the coroutine at the next scheduler iteration. More...
 
void resume ()
 Add a Suspended coroutine into the head of the scheduler linked list, and change the state to Yielding. More...
 
bool isDelayExpired ()
 Check if delay time is over. More...
 
bool isSuspended () const
 The coroutine was suspended with a call to suspend(). More...
 
bool isYielding () const
 The coroutine returned using COROUTINE_YIELD(). More...
 
bool isAwaiting () const
 The coroutine returned using COROUTINE_AWAIT(). More...
 
bool isDelaying () const
 The coroutine returned using COROUTINE_DELAY(). More...
 
bool isRunning () const
 The coroutine is currently running. More...
 
bool isEnding () const
 The coroutine returned using COROUTINE_END(). More...
 
bool isTerminated () const
 The coroutine was terminated by the scheduler with a call to setTerminated(). More...
 
bool isDone () const
 The coroutine is either Ending or Terminated. More...
 

Static Public Member Functions

static const DispatchRecordCfindCommand (const DispatchRecordC *dispatchTable, uint8_t numCommands, const char *cmd)
 Find the CommandHandler of the given command name. More...
 
- Static Public Member Functions inherited from ace_routine::cli::CommandDispatcher
static uint8_t tokenize (char *line, const char **argv, uint8_t argvSize)
 Tokenize the line, and fill argv with each token until argvSize is reached. More...
 
- Static Public Member Functions inherited from ace_routine::Coroutine
static Coroutine ** getRoot ()
 Get the pointer to the root pointer. More...
 

Additional Inherited Members

- Protected Types inherited from ace_routine::Coroutine
typedef uint8_t Status
 The execution status of the coroutine, corresponding to the COROUTINE_YIELD(), COROUTINE_DELAY(), COROUTINE_AWAIT() and COROUTINE_END() macros. More...
 
- Protected Member Functions inherited from ace_routine::cli::CommandDispatcher
 CommandDispatcher (const CommandDispatcher &)=delete
 
CommandDispatcheroperator= (const CommandDispatcher &)=delete
 
void printLineError (const char *line, uint8_t statusCode)
 Print the error caused by the given line. More...
 
void helpCommandHandler (Print &printer, int argc, const char **argv)
 Handle the 'help' command. More...
 
void runCommand (char *line)
 Tokenize the given line and run the command handler. More...
 
virtual int run () override
 The body of the coroutine. More...
 
- Protected Member Functions inherited from ace_routine::Coroutine
 Coroutine ()
 Constructor. More...
 
void init (const char *name)
 Initialize the coroutine, set it to Yielding state, and add it to the linked list of coroutines. More...
 
void init (const __FlashStringHelper *name)
 Same as init(const char*) except using flash string type. More...
 
Status getStatus () const
 Return the status of the coroutine. More...
 
void setJump (void *jumpPoint)
 Pointer to label where execute will start on the next call to run(). More...
 
void * getJump () const
 Pointer to label where execute will start on the next call to run(). More...
 
void setRunning ()
 Set the kStatusRunning state. More...
 
void setYielding ()
 Set the kStatusDelaying state. More...
 
void setAwaiting ()
 Set the kStatusAwaiting state. More...
 
void setDelaying ()
 Set the kStatusDelaying state. More...
 
void setDelay (uint16_t delayMillisDuration)
 Configure the delay timer. More...
 
void setEnding ()
 Set the kStatusEnding state. More...
 
void setTerminated ()
 Set status to indicate that the Coroutine has been removed from the Scheduler queue. More...
 
- Protected Attributes inherited from ace_routine::cli::CommandDispatcher
StreamReadermStreamReader
 
Print & mPrinter
 
const uint8_t mNumCommands
 
const char **const mArgv
 
const uint8_t mArgvSize
 
- Static Protected Attributes inherited from ace_routine::cli::CommandDispatcher
static const uint8_t STATUS_SUCCESS = 0
 
static const uint8_t STATUS_BUFFER_OVERFLOW = 1
 
static const uint8_t STATUS_FLUSH_TO_EOL = 2
 
static const char DELIMS [] = " \t\n"
 
- Static Protected Attributes inherited from ace_routine::Coroutine
static const Status kStatusSuspended = 0
 Coroutine has been suspended using suspend() and the scheduler should remove it from the queue upon the next iteration. More...
 
static const Status kStatusYielding = 1
 Coroutine returned using the COROUTINE_YIELD() statement. More...
 
static const Status kStatusAwaiting = 2
 Coroutine returned using the COROUTINE_AWAIT() statement. More...
 
static const Status kStatusDelaying = 3
 Coroutine returned using the COROUTINE_DELAY() statement. More...
 
static const Status kStatusRunning = 4
 Coroutine is currenly running. More...
 
static const Status kStatusEnding = 5
 Coroutine executed the COROUTINE_END() statement. More...
 
static const Status kStatusTerminated = 6
 Coroutine has ended and no longer in the scheduler queue. More...
 

Detailed Description

A CommandDispatcher that takes DispatchRecordC records using C-strings.

Definition at line 147 of file CommandDispatcher.h.

Constructor & Destructor Documentation

◆ CommandDispatcherC()

ace_routine::cli::CommandDispatcherC::CommandDispatcherC ( StreamReader streamReader,
Print &  printer,
const DispatchRecordC dispatchTable,
uint8_t  numCommands,
const char **  argv,
uint8_t  argvSize 
)
inline

Constructor.

Parameters
streamReaderAn instance of StreamReader.
printerThe output object, normally the global Serial object.
dispatchTableAn array of DispatchRecords.
numCommandsNumber of entries in the dispatchTable.
argvArray of (const char*) that will be used to hold the word tokens of a command line string.
argvSizeThe size of the argv array. Tokens which are beyond this limit will be silently dropped.

Definition at line 161 of file CommandDispatcher.h.

Member Function Documentation

◆ findCommand()

const DispatchRecordC * ace_routine::cli::CommandDispatcherC::findCommand ( const DispatchRecordC dispatchTable,
uint8_t  numCommands,
const char *  cmd 
)
static

Find the CommandHandler of the given command name.

VisibleForTesting.

NOTE: this is currently a linear O(N) scan which is good enough for small number of commands. If we sorted the handlers, we could do a binary search for O(log(N)) and handle larger number of commands.

Definition at line 153 of file CommandDispatcher.cpp.


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