RumPi 1.0
A self-assembling C++ sensor & actuator library for the Raspberry Pi 5
RemoteCommand.h
Go to the documentation of this file.
1#pragma once
2#include <string>
3#include <functional>
4
5namespace RumPi
6{
15 {
16 public:
18 typedef std::function<void(const char* receivedMessage)> CommandHandler;
19
20 private:
22 std::string myName;
23
26
27 public:
41 RemoteCommand(const std::string& name, CommandHandler handler);
42
57 const std::string& GetName() const;
58
77
97 bool Matches(const char* receivedMessage) const;
98
112 void Execute(const char* receivedMessage) const;
113 };
114} // namespace RumPi
A command a remote client can send, paired with the handler that carries it out.
Definition: RemoteCommand.h:15
const std::string & GetName() const
Gets this command's name.
Definition: RemoteCommand.cpp:39
bool Matches(const char *receivedMessage) const
Checks whether a received message is addressed to this command by testing if the message contains the...
Definition: RemoteCommand.cpp:85
std::string myName
This command's name; a received message that contains it is routed to this command.
Definition: RemoteCommand.h:22
CommandHandler GetHandler() const
Gets the handler function that runs when this command matches a message.
Definition: RemoteCommand.cpp:61
void Execute(const char *receivedMessage) const
Runs this command's handler on the given message.
Definition: RemoteCommand.cpp:104
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
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
CommandHandler myHandler
The function invoked when this command matches a message.
Definition: RemoteCommand.h:25
RumPi is the library's top-level facade.
Definition: AlertManager.h:6