A command a remote client can send, paired with the handler that carries it out.
More...
#include <RemoteCommand.h>
|
| typedef std::function< void(const char *receivedMessage)> | CommandHandler |
| | The signature every command handler must have: it receives the full message and returns nothing. More...
|
| |
|
| | RemoteCommand (const std::string &name, CommandHandler handler) |
| | Builds a remote command from its name and the handler that carries it out. More...
|
| |
| const std::string & | GetName () const |
| | Gets this command's name. More...
|
| |
| CommandHandler | GetHandler () const |
| | Gets the handler function that runs when this command matches a message. More...
|
| |
| bool | Matches (const char *receivedMessage) const |
| | Checks whether a received message is addressed to this command by testing if the message contains the command's name. More...
|
| |
| void | Execute (const char *receivedMessage) const |
| | Runs this command's handler on the given message. More...
|
| |
A command a remote client can send, paired with the handler that carries it out.
The handler is given the full message so it can read any parameters. Register one in the receiver's command list to wire it up.
- Author
- Eddie O'Hagan
- Date
- 8/13/2026
◆ CommandHandler
The signature every command handler must have: it receives the full message and returns nothing.
◆ RemoteCommand()
| RumPi::RemoteCommand::RemoteCommand |
( |
const std::string & |
name, |
|
|
CommandHandler |
handler |
|
) |
| |
Builds a remote command from its name and the handler that carries it out.
- Author
- Eddie O'Hagan
- Date
- 8/13/2026
RemoteCommand(const std::string &name, CommandHandler handler)
Builds a remote command from its name and the handler that carries it out.
Definition: RemoteCommand.cpp:19
static void HandleMoveForward(const char *receivedMessage)
Command handler for the "MoveForward" message from a remote client (placeholder - drives the robot fo...
Definition: RumPi.cpp:613
- Parameters
-
| [in] | name | The command's name; a received message that contains this string is routed to it. |
| [in] | handler | The function to run when the command matches (it receives the full message). |
◆ Execute()
| void RumPi::RemoteCommand::Execute |
( |
const char * |
receivedMessage | ) |
const |
Runs this command's handler on the given message.
Does nothing if no handler was supplied.
- Author
- Eddie O'Hagan
- Date
- 8/13/2026
moveForward.Execute("MoveForward:100");
- Parameters
-
| [in] | receivedMessage | The full message to hand to the command's handler. |
◆ GetHandler()
Gets the handler function that runs when this command matches a message.
- Author
- Eddie O'Hagan
- Date
- 8/13/2026
if (handler != nullptr)
{
handler("MoveForward");
}
std::function< void(const char *receivedMessage)> CommandHandler
The signature every command handler must have: it receives the full message and returns nothing.
Definition: RemoteCommand.h:18
- Returns
- The command's handler (may be empty if none was supplied).
◆ GetName()
| const std::string & RumPi::RemoteCommand::GetName |
( |
| ) |
const |
Gets this command's name.
- Author
- Eddie O'Hagan
- Date
- 8/13/2026
printf("Command: %s\n", moveForward.GetName().c_str());
Output: Command: MoveForward
- Returns
- The command's name.
◆ Matches()
| bool RumPi::RemoteCommand::Matches |
( |
const char * |
receivedMessage | ) |
const |
Checks whether a received message is addressed to this command by testing if the message contains the command's name.
- Author
- Eddie O'Hagan
- Date
- 8/13/2026
if (moveForward.Matches("MoveForward:100") == true)
{
moveForward.Execute("MoveForward:100");
}
- Parameters
-
| [in] | receivedMessage | The full message received from the client. May be null. |
- Returns
- true if the message contains this command's name; false otherwise (or if receivedMessage is null).
◆ myHandler
The function invoked when this command matches a message.
◆ myName
| std::string RumPi::RemoteCommand::myName |
|
private |
This command's name; a received message that contains it is routed to this command.
The documentation for this class was generated from the following files: