pianod2
multisource multiuser scriptable networked music player
Public Types | Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | List of all members
CommandReply Class Reference

This class is derived from ResponseCollector and adds success/failure adder functions and a few variables to support this. More...

#include <response.h>

Inheritance diagram for CommandReply:
Inheritance graph
[legend]
Collaboration diagram for CommandReply:
Collaboration graph
[legend]

Public Types

enum class  Aggregation { PESSIMISTIC , OPTIMISTIC }
 

Public Member Functions

void fail (Response &&failure)
 Add a failure response to the collection. More...
 
template<typename ParamOne , typename ParamTwo , typename... Additional>
void fail (ParamOne &&first, ParamTwo &&second, Additional &&...more)
 Add a failure to the failures list, after constructing it. More...
 
void succeed (Response &&success)
 Add a success response to the collection. More...
 
void succeed ()
 Add a simple success to the list. More...
 
template<typename ParamOne , typename ParamTwo , typename... Additional>
void succeed (ParamOne &&first, ParamTwo &&second, Additional &&...more)
 Add a succeess to the successes list, after constructing it. More...
 
void operator() (Response &&r)
 Add a success or failure response to the collection. More...
 
template<typename ParamOne , typename... Parameters>
void operator() (ParamOne &&first, Parameters &&...more)
 Construct a response and add it to the successes, failures or data list based on its type. More...
 
 CommandReply (Aggregation kind=Aggregation::OPTIMISTIC)
 Construct a response collector for status collection. More...
 
 CommandReply (Response &&initial)
 
 CommandReply (const std::exception_ptr except, const char *triggering_command=nullptr)
 Contruct a maningful failure response from an exception. More...
 
- Public Member Functions inherited from ResponseCollector
void setNoResponse ()
 
bool allSuccess () const
 ResponseCollector contains successes but no failures. More...
 
bool allFailure () const
 ResponseCollector contains failures but no successes. More...
 
bool anySuccess () const
 ResponseCollector contains at least one success, regardless of failures. More...
 
bool anyFailure () const
 ResponseCollector contains at least one failure, regardless of successes. More...
 
bool partial () const
 ResponseCollector contains a mix of successes and failures. More...
 
bool noop () const
 ResponseCollector contains neither successes nor failures. More...
 
bool dataResponse () const
 ResponseCollector is transporting data for transmission. More...
 
bool isNoResponse () const
 ResponseCollector should not send a reply to a command. More...
 
void close ()
 Causes the connection to be closed after the response is sent. More...
 
void transmit (PianodConnection &, const bool json)
 Transmit a reply. More...
 
 ResponseCollector ()=default
 
 ResponseCollector (ResponseCollector &&from)=default
 
ResponseCollectoroperator= (ResponseCollector &&from)=default
 
 ResponseCollector (Response &&initial)
 Initialize a response collection, and add the initial response to the appropriate collection if applicable. More...
 
 ResponseCollector (const RESPONSE_CODE response)
 
 ResponseCollector (MusicThingie *item)
 Implicitly wrap a music item into a data response. More...
 
 ResponseCollector (const ThingieList &things)
 Implicitly wrap a list of music items into a data response. More...
 
 ResponseCollector (const SongList &songs)
 Implicitly wrap a list of songs into a data response. More...
 
 ResponseCollector (ResponseGroup &&group)
 Implicitly wrap a response group into a data response. More...
 

Public Attributes

ResponseGroup information
 Session notices going back to user. More...
 
ResponseGroup user_events
 Broadcast to other same-user sessions. More...
 
ResponseGroup room_events
 Broadcast to all same-room sessions. More...
 
ResponseGroup broadcast_events
 Broadcast to all users, all rooms. More...
 
- Public Attributes inherited from ResponseCollector
ResponseGroup information
 Session notices going back to user. More...
 

Private Member Functions

void mergeReason (RESPONSE_CODE why)
 Update the collection's final status. More...
 

Private Attributes

RESPONSE_CODE mixed_reason { E_PARTIAL }
 The final response if there are both successes and failures. More...
 

Additional Inherited Members

- Protected Member Functions inherited from ResponseCollector
void data (ResponseGroup &&group)
 Add a record for transmission as response data. More...
 
void data (const ThingieList &item_list)
 Add a list of music items for transmission as response data. More...
 
void data (const SongList &songs)
 Add a list of songs for transmission as response data. More...
 
void data (const PlaylistList &playlists)
 Add a list of playlists for transmission as response data. More...
 
- Protected Attributes inherited from ResponseCollector
RESPONSE_CODE reason { S_NOOP }
 The final response that will be sent. More...
 
ResponseGroup successes
 Success messages. More...
 
ResponseGroup diagnostics
 Details of errors encountered. More...
 
std::vector< ResponseGroupdata_groups
 Complete data records destined for the client. More...
 
ResponseGroup data_reply
 Discrete data responses destined for the client. More...
 
ResponseGroup user_events
 Broadcast to other same-user sessions. More...
 
ResponseGroup room_events
 Broadcast to all same-room sessions. More...
 
ResponseGroup broadcast_events
 Broadcast to all users, all rooms. More...
 

Detailed Description

This class is derived from ResponseCollector and adds success/failure adder functions and a few variables to support this.

The name makes its purpose clearer, the interface avoids data mixing with successes/failures, which is invalid. The cost is needing std::move() whereever we return as a ResponseCollector; when this is done, we are indeed slicing the object.

Member Enumeration Documentation

◆ Aggregation

Enumerator
PESSIMISTIC 
OPTIMISTIC 

Constructor & Destructor Documentation

◆ CommandReply() [1/3]

CommandReply::CommandReply ( Aggregation  kind = Aggregation::OPTIMISTIC)

Construct a response collector for status collection.

Parameters
kindIf the evemt of mixed successes/failures, an Aggregation::OPTIMISTIC collector will report success, a Aggregation::PESSIMISTIC will return failure for the final/overall status.

◆ CommandReply() [2/3]

CommandReply::CommandReply ( Response &&  initial)
inline

◆ CommandReply() [3/3]

CommandReply::CommandReply ( const std::exception_ptr  except,
const char *  triggering_command = nullptr 
)

Contruct a maningful failure response from an exception.

Parameters
exceptAn exception of any type.
triggering_commandThe command causing the exception (for logging; may be omitted.)
Here is the call graph for this function:

Member Function Documentation

◆ fail() [1/2]

template<typename ParamOne , typename ParamTwo , typename... Additional>
void CommandReply::fail ( ParamOne &&  first,
ParamTwo &&  second,
Additional &&...  more 
)
inline

Add a failure to the failures list, after constructing it.

Here is the call graph for this function:

◆ fail() [2/2]

void CommandReply::fail ( Response &&  failure)

Add a failure response to the collection.

Parameters
failureThe failure to add.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mergeReason()

void CommandReply::mergeReason ( RESPONSE_CODE  why)
private

Update the collection's final status.

Parameters
whyThe new response code being accommodated; must be a success or command error code.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator()() [1/2]

template<typename ParamOne , typename... Parameters>
void CommandReply::operator() ( ParamOne &&  first,
Parameters &&...  more 
)
inline

Construct a response and add it to the successes, failures or data list based on its type.

Here is the call graph for this function:

◆ operator()() [2/2]

void CommandReply::operator() ( Response &&  status)

Add a success or failure response to the collection.

Parameters
statusThe response to add.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ succeed() [1/3]

void CommandReply::succeed ( )
inline

Add a simple success to the list.

Here is the caller graph for this function:

◆ succeed() [2/3]

template<typename ParamOne , typename ParamTwo , typename... Additional>
void CommandReply::succeed ( ParamOne &&  first,
ParamTwo &&  second,
Additional &&...  more 
)
inline

Add a succeess to the successes list, after constructing it.

Here is the call graph for this function:

◆ succeed() [3/3]

void CommandReply::succeed ( Response &&  success)

Add a success response to the collection.

Parameters
successThe success to add.
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ broadcast_events

ResponseGroup ResponseCollector::broadcast_events

Broadcast to all users, all rooms.

◆ information

ResponseGroup ResponseCollector::information

Session notices going back to user.

◆ mixed_reason

RESPONSE_CODE CommandReply::mixed_reason { E_PARTIAL }
private

The final response if there are both successes and failures.

◆ room_events

ResponseGroup ResponseCollector::room_events

Broadcast to all same-room sessions.

◆ user_events

ResponseGroup ResponseCollector::user_events

Broadcast to other same-user sessions.


The documentation for this class was generated from the following files: