55 using List = std::vector<std::string>;
147 return (*there << response);
174 push_back (std::move (r));
177 template <
typename... Parameters>
179 push_back (
Response (std::forward<Parameters> (params)...));
310 template <
typename ParamOne,
typename ParamTwo,
typename... Additional>
311 inline void fail (ParamOne &&first, ParamTwo &&second, Additional &&...more) {
313 std::forward<ParamTwo> (second),
314 std::forward<Additional> (more)...));
323 template <
typename ParamOne,
typename ParamTwo,
typename... Additional>
324 inline void succeed (ParamOne &&first, ParamTwo &&second, Additional &&...more) {
326 std::forward<ParamTwo> (second),
327 std::forward<Additional> (more)...));
332 template <
typename ParamOne,
typename... Parameters>
333 inline void operator() (ParamOne &&first, Parameters &&...more) {
334 operator() (
Response (std::forward<ParamOne> (first), std::forward<Parameters> (more)...));
339 CommandReply (
const std::exception_ptr except,
const char *triggering_command =
nullptr);
355 template <
typename ParamOne,
typename ParamTwo,
typename... Additional>
356 inline void data (ParamOne &&first, ParamTwo &&second, Additional &&...more) {
358 std::forward<ParamTwo> (second),
359 std::forward<Additional> (more)...));
363 template <
typename T>
Exception for command execution problems.
Definition: fundamentals.h:293
This class is derived from ResponseCollector and adds success/failure adder functions and a few varia...
Definition: response.h:294
void mergeReason(RESPONSE_CODE why)
Update the collection's final status.
Definition: response.cpp:466
void succeed(ParamOne &&first, ParamTwo &&second, Additional &&...more)
Add a succeess to the successes list, after constructing it.
Definition: response.h:324
RESPONSE_CODE mixed_reason
The final response if there are both successes and failures.
Definition: response.h:299
CommandReply(Aggregation kind=Aggregation::OPTIMISTIC)
Construct a response collector for status collection.
Definition: response.cpp:509
Aggregation
Definition: response.h:296
CommandReply(Response &&initial)
Definition: response.h:338
void fail(ParamOne &&first, ParamTwo &&second, Additional &&...more)
Add a failure to the failures list, after constructing it.
Definition: response.h:311
void fail(Response &&failure)
Add a failure response to the collection.
Definition: response.cpp:481
void succeed()
Add a simple success to the list.
Definition: response.h:319
void operator()(Response &&r)
Add a success or failure response to the collection.
Definition: response.cpp:497
This class is derived from ResponseCollector, and adds no member variables but adds data adder functi...
Definition: response.h:347
void data(ParamOne &&first, ParamTwo &&second, Additional &&...more)
Add data to the data response list, after constructing it.
Definition: response.h:356
void data(const Retainer< T > &from)
Add a music item to the data response list.
Definition: response.h:364
DataResponse()
Construct a new DataResponse (i.e., a ResponseCollector that's been earmarked for returning data.
Definition: response.h:372
void data(ResponseGroup &&group)
Add a record for transmission as response data.
Definition: response.cpp:421
Base class for songs, albums, artists, playlists, genres, etc.
Definition: musictypes.h:77
Generic data type.
Definition: parsnip.h:81
Connection to a pianod client, along with context and state of that connection.
Definition: connection.h:54
User * user
Definition: connection.h:76
Pianod service, a customized FootballService for Pianod connections.
Definition: connection.h:115
Base class for songs, these are also MusicThingies, artists and albums.
Definition: musictypes.h:339
A container for lists of playlists.
Definition: retainedlist.h:324
A response collector/aggregator.
Definition: response.h:197
ResponseGroup room_events
Broadcast to all same-room sessions.
Definition: response.h:223
bool allSuccess() const
ResponseCollector contains successes but no failures.
Definition: response.h:234
RESPONSE_CODE reason
The final response that will be sent.
Definition: response.h:208
ResponseGroup broadcast_events
Broadcast to all users, all rooms.
Definition: response.h:224
bool dataResponse() const
ResponseCollector is transporting data for transmission.
Definition: response.h:263
bool allFailure() const
ResponseCollector contains failures but no successes.
Definition: response.h:239
ResponseGroup successes
Success messages.
Definition: response.h:210
friend class PianodConnection & operator<<(class PianodConnection &there, const ResponseCollector &response)
ResponseCollector()=default
ResponseGroup diagnostics
Details of errors encountered.
Definition: response.h:211
bool anyFailure() const
ResponseCollector contains at least one failure, regardless of successes.
Definition: response.h:249
bool close_after_response
If true, the connection is closed after response is sent.
Definition: response.h:201
ResponseCollector(ResponseCollector &&from)=default
ResponseCollector(const RESPONSE_CODE response)
Definition: response.h:282
Parsnip::Data serialize(const User *user) const
Assemble a response collection into either a data response or a reply (i.e., successes/failures).
Definition: responsejson.cpp:359
bool isNoResponse() const
ResponseCollector should not send a reply to a command.
Definition: response.h:267
bool noop() const
ResponseCollector contains neither successes nor failures.
Definition: response.h:259
void transmitJSON(PianodConnection &) const
Format and transmit a response collection to JSON client.
Definition: responsejson.cpp:399
ResponseGroup data_reply
Discrete data responses destined for the client.
Definition: response.h:214
ResponseGroup user_events
Broadcast to other same-user sessions.
Definition: response.h:222
bool partial() const
ResponseCollector contains a mix of successes and failures.
Definition: response.h:254
void close()
Causes the connection to be closed after the response is sent.
Definition: response.h:271
void transmit(PianodConnection &, const bool json)
Transmit a reply.
Definition: response.cpp:443
void data(ResponseGroup &&group)
Add a record for transmission as response data.
Definition: response.cpp:421
std::vector< ResponseGroup > data_groups
Complete data records destined for the client.
Definition: response.h:213
void setNoResponse()
Definition: response.h:228
void transmitLine(PianodConnection &) const
Transmit a data response OR command reply to a specific node, followed by any client-specific add-on ...
Definition: responseline.cpp:144
ResponseCollector & operator=(ResponseCollector &&from)=default
bool anySuccess() const
ResponseCollector contains at least one success, regardless of failures.
Definition: response.h:244
ResponseGroup information
Session notices going back to user.
Definition: response.h:226
Container for multiple Responses.
Definition: response.h:155
void transmitJSON(class PianodService &) const
Transmit a group of responses JSON connection on a service.
Definition: responsejson.cpp:332
Parsnip::Data serializeEvents(bool, const User *) const
Re-sort messages to be broadcast into categories:
Definition: responsejson.cpp:251
Parsnip::Data serializeData(const User *) const
Format a record's worth of reponses for JSON protocol.
Definition: responsejson.cpp:213
ResponseGroup & operator=(ResponseGroup &&)=default
void transmitLine(class PianodService &) const
Broadcast a group of responses to an entire service.
Definition: responseline.cpp:124
ResponseGroup(Response &&r)
Construct from a single response.
Definition: response.h:173
Parsnip::Data serializeHomogenousData(const User *) const
Format a homogenous list of responses as a series JSON records.
Definition: responsejson.cpp:233
void transmit(class PianodService &) const
Transmit a group of response messages to all nodes on a service, using the appropriate protocol for e...
Definition: response.cpp:333
void operator()(Parameters &&...params)
Add a new response to the list, after constructing it.
Definition: response.h:178
Parsnip::Data serializeReply() const
Format successes or diagnostics for JSON transmission.
Definition: responsejson.cpp:202
ResponseGroup(ResponseGroup &&)=default
Type combining RESPONSE_CODE with a value or explanation:
Definition: response.h:49
static constexpr int TransmitAsDiagnostic
Transform command errors to diagnostic codes.
Definition: response.h:57
std::vector< std::string > List
Definition: response.h:55
Parsnip::Data serialize() const
Format a response for JSON protocol.
Definition: responsejson.cpp:131
Retainer< MusicThingie * > related
Music item to send, or in regards to.
Definition: response.h:72
static Parsnip::Data NoJsonData
Definition: response.h:59
std::shared_ptr< Parsnip::Data > json_data
Parsnip data to be used for JSON replies.
Definition: response.h:70
bool isSuccess() const
Definition: response.h:82
bool isDataField() const
Definition: response.h:79
List list
Definition: response.h:69
Type
Definition: response.h:62
Response & operator=(const Response &)=default
void bindUser(const class User *u) const
Associate a user triggering the response (for user actions & yells).
Definition: response.h:95
void transmitLine(Football::Thingie &there, int offset=TransmitUnaltered) const
Transmit a response using line protocol.
Definition: responseline.cpp:37
Response(Response &&)=default
double double_value
Definition: response.h:67
bool isStatusChange() const
Definition: response.h:76
static constexpr int TransmitUnaltered
Transmit data as stored.
Definition: response.h:56
const class User * user
User triggering the response.
Definition: response.h:73
RESPONSE_CODE message
Message code, initialized to "empty" value.
Definition: response.h:63
bool isUserAction() const
Definition: response.h:91
bool isServerFailure() const
Definition: response.h:88
std::string value
Definition: response.h:65
int double_precision
Definition: response.h:68
long long_value
Definition: response.h:66
Type type
Type of additional data stored herein.
Definition: response.h:64
bool isCommandError() const
Definition: response.h:85
Response(const Response &)=default
std::string regarding
ID or name of item response is in regards to.
Definition: response.h:71
A container for holding songs.
Definition: retainedlist.h:328
Base class for storing lists of thingies, which need to be reference counted accurately.
Definition: retainedlist.h:20
Data about each user.
Definition: user.h:53
Essential data structures and support.
bool isServerFailure(RESPONSE_CODE code)
Definition: fundamentals.h:283
bool isDataField(RESPONSE_CODE code)
Definition: fundamentals.h:271
bool isSuccess(RESPONSE_CODE code)
Definition: fundamentals.h:275
enum server_status_t RESPONSE_CODE
bool isUserAction(RESPONSE_CODE code)
Definition: fundamentals.h:287
@ I_ATTACHED_THING
Transmit the attached thing instead of a response message.
Definition: fundamentals.h:159
@ S_DATA
Definition: fundamentals.h:167
@ S_NOOP
Nothing to do; default success.
Definition: fundamentals.h:173
@ NO_REPLY
Do not transmit any reply.
Definition: fundamentals.h:78
@ S_OK
Definition: fundamentals.h:164
@ E_PARTIAL
Partial failure, but a portion succeeded.
Definition: fundamentals.h:206
bool isCommandError(RESPONSE_CODE code)
Definition: fundamentals.h:279
bool isStatusChange(RESPONSE_CODE code)
Definition: fundamentals.h:267
Playlist / Artist / Album / Song data types.
const char * PlayDuration
Definition: responsejson.cpp:48
static const char * Data
Definition: responsejson.cpp:42
const char * PlayRemaining
Definition: responsejson.cpp:50
const char * PlayPoint
Definition: responsejson.cpp:49
Definition: response.h:35
Definition: musiccache.cpp:18
Serialization and parsing library.
Definition: mediaunit.h:26
std::string format_duration(time_t duration, int minute_places=1)
Format a duration as minutes and seconds.
Definition: response.cpp:47
Football::Thingie & operator<<(Football::Thingie &there, const Response &response)
Use << as output operator for Response.
Definition: response.h:132
const char * ResponseText(RESPONSE_CODE code)
Retrieve the text for a success, failure, event or data message.
Definition: response.cpp:56
void sendUpdatedRatings(PianodConnection &conn, const PianodSong *song, CommandReply *reply)
Send updated ratings.
Definition: response.cpp:527
const char * JSONFieldName(RESPONSE_CODE code)
Retrieve the JSON text for a response.
Definition: responsejson.cpp:58
Smart pointers for music thingie types.