A response. More...
#include <response.hpp>
Public Types | |
enum | Code : std::uint8_t { Code::OHAI, Code::IAMA, Code::FLOAD, Code::EJECT, Code::POS, Code::END, Code::PLAY, Code::STOP, Code::ACK } |
Enumeration of all possible response codes. More... | |
Public Member Functions | |
Response (const std::string &tag, Response::Code code) | |
Constructs a Response with no arguments. More... | |
Response & | AddArg (const std::string &arg) |
Adds an argument to this Response. More... | |
std::string | Pack () const |
Packs the Response, converting it to a BAPS3 protocol message. More... | |
Static Public Member Functions | |
static Response | Success (const std::string &tag) |
Shortcut for constructing a final response to a successful request. More... | |
static Response | Invalid (const std::string &tag, const std::string &msg) |
Shortcut for constructing a final response to a invalid request. More... | |
static Response | Failure (const std::string &tag, const std::string &msg) |
Shortcut for constructing a final response to a failed request. More... | |
Static Public Attributes | |
static const std::string | NOREQUEST = "!" |
The tag for unsolicited messages (not from responses). | |
static constexpr std::uint8_t | CODE_COUNT = 9 |
The number of codes, which should agree with Response::Code. | |
Static Private Member Functions | |
static std::string | EscapeArg (const std::string &arg) |
Escapes a single response argument. More... | |
Private Attributes | |
std::string | string |
The current packed form of the response. More... | |
Static Private Attributes | |
static const std::array< std::string, CODE_COUNT > | STRINGS |
A map from Response::Code codes to their string equivalents. More... | |
A response.
Definition at line 23 of file response.hpp.
|
strong |
Enumeration of all possible response codes.
Definition at line 35 of file response.hpp.
Response::Response | ( | const std::string & | tag, |
Response::Code | code | ||
) |
Constructs a Response with no arguments.
tag | The tag of the response. |
code | The Response::Code representing the response command. |
Definition at line 32 of file response.cpp.
References EscapeArg(), and STRINGS.
Referenced by Failure(), Invalid(), and Success().
Response & Response::AddArg | ( | const std::string & | arg | ) |
Adds an argument to this Response.
arg | The argument to add. The argument must not be escaped. |
Definition at line 38 of file response.cpp.
References EscapeArg().
|
staticprivate |
Escapes a single response argument.
arg | The argument to escape. |
Definition at line 68 of file response.cpp.
Referenced by AddArg(), and Response().
|
static |
Shortcut for constructing a final response to a failed request.
tag | The tag of the original request. |
msg | The failure message. |
Definition at line 62 of file response.cpp.
References ACK, and Response().
Referenced by Player::Dump(), Player::Eject(), Player::End(), Player::Load(), Player::Pos(), Player::Quit(), and Player::SetPlaying().
|
static |
Shortcut for constructing a final response to a invalid request.
tag | The tag of the original request. |
msg | The failure message. |
Definition at line 56 of file response.cpp.
References ACK, and Response().
Referenced by Player::Load(), Player::Pos(), Connection::RunCommand(), and Player::SetPlaying().
std::string Response::Pack | ( | ) | const |
Packs the Response, converting it to a BAPS3 protocol message.
Pack()ing does not alter the Response, which may be Pack()ed again.
Definition at line 44 of file response.cpp.
References string.
Referenced by IoCore::Broadcast(), Connection::Respond(), and IoCore::Unicast().
|
static |
Shortcut for constructing a final response to a successful request.
tag | The tag of the original request. |
Definition at line 49 of file response.cpp.
References ACK, and Response().
Referenced by IoCore::Accept(), Player::Dump(), Player::Eject(), Player::End(), Player::Load(), Player::Pos(), Player::Quit(), and Player::SetPlaying().
|
private |
The current packed form of the response.
Definition at line 111 of file response.hpp.
Referenced by Pack().
|
staticprivate |
A map from Response::Code codes to their string equivalents.
Definition at line 100 of file response.hpp.
Referenced by Response().