RumPi 1.0
A self-assembling C++ sensor & actuator library for the Raspberry Pi 5
RumPi::RemoteCommand Class Reference

A command a remote client can send, paired with the handler that carries it out. More...

#include <RemoteCommand.h>

Public Types

typedef std::function< void(const char *receivedMessage)> CommandHandler
 The signature every command handler must have: it receives the full message and returns nothing. More...
 

Public Member Functions

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

Private Attributes

std::string myName
 This command's name; a received message that contains it is routed to this command. More...
 
CommandHandler myHandler
 The function invoked when this command matches a message. More...
 

Detailed Description

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

Member Typedef Documentation

◆ CommandHandler

typedef std::function<void(const char* receivedMessage)> RumPi::RemoteCommand::CommandHandler

The signature every command handler must have: it receives the full message and returns nothing.

Constructor & Destructor Documentation

◆ 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 moveForward("MoveForward", HandleMoveForward);
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]nameThe command's name; a received message that contains this string is routed to it.
[in]handlerThe function to run when the command matches (it receives the full message).

Member Function Documentation

◆ 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
RemoteCommand moveForward("MoveForward", HandleMoveForward);
moveForward.Execute("MoveForward:100");
Parameters
[in]receivedMessageThe full message to hand to the command's handler.

◆ GetHandler()

RemoteCommand::CommandHandler RumPi::RemoteCommand::GetHandler ( ) const

Gets the handler function that runs when this command matches a message.

Author
Eddie O'Hagan
Date
8/13/2026
RemoteCommand moveForward("MoveForward", HandleMoveForward);
RemoteCommand::CommandHandler handler = moveForward.GetHandler();
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
RemoteCommand moveForward("MoveForward", HandleMoveForward);
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
RemoteCommand moveForward("MoveForward", HandleMoveForward);
if (moveForward.Matches("MoveForward:100") == true)
{
moveForward.Execute("MoveForward:100");
}
Parameters
[in]receivedMessageThe 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).

Member Data Documentation

◆ myHandler

CommandHandler RumPi::RemoteCommand::myHandler
private

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: