pianod2
multisource multiuser scriptable networked music player
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | Friends | List of all members
ResponseCollector Class Reference

A response collector/aggregator. More...

#include <response.h>

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

Public Member Functions

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

Protected Member Functions

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

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

Private Member Functions

Parsnip::Data serialize (const User *user) const
 Assemble a response collection into either a data response or a reply (i.e., successes/failures). More...
 
void transmitJSON (PianodConnection &) const
 Format and transmit a response collection to JSON client. More...
 
void transmitLine (PianodConnection &) const
 Transmit a data response OR command reply to a specific node, followed by any client-specific add-on information. More...
 

Private Attributes

bool close_after_response = false
 If true, the connection is closed after response is sent. More...
 

Friends

class PianodConnectionoperator<< (class PianodConnection &there, const ResponseCollector &response)
 

Detailed Description

A response collector/aggregator.

This class implements a "funnel" pattern. Whatever is coming back from user commands—success indications, error messages, status updates, and data—is passed back through this structure, then serialized into a message and sent. Note: This class is used to return data, but the child DataResponse class is used to construct data responses.

Constructor & Destructor Documentation

◆ ResponseCollector() [1/8]

ResponseCollector::ResponseCollector ( )
default

◆ ResponseCollector() [2/8]

ResponseCollector::ResponseCollector ( ResponseCollector &&  from)
default

◆ ResponseCollector() [3/8]

ResponseCollector::ResponseCollector ( Response &&  initial)

Initialize a response collection, and add the initial response to the appropriate collection if applicable.

Here is the call graph for this function:

◆ ResponseCollector() [4/8]

ResponseCollector::ResponseCollector ( const RESPONSE_CODE  response)
inline

◆ ResponseCollector() [5/8]

ResponseCollector::ResponseCollector ( MusicThingie item)

Implicitly wrap a music item into a data response.

◆ ResponseCollector() [6/8]

ResponseCollector::ResponseCollector ( const ThingieList things)

Implicitly wrap a list of music items into a data response.

Here is the call graph for this function:

◆ ResponseCollector() [7/8]

ResponseCollector::ResponseCollector ( const SongList songs)

Implicitly wrap a list of songs into a data response.

Here is the call graph for this function:

◆ ResponseCollector() [8/8]

ResponseCollector::ResponseCollector ( ResponseGroup &&  group)

Implicitly wrap a response group into a data response.

Member Function Documentation

◆ allFailure()

bool ResponseCollector::allFailure ( ) const
inline

ResponseCollector contains failures but no successes.

Here is the caller graph for this function:

◆ allSuccess()

bool ResponseCollector::allSuccess ( ) const
inline

ResponseCollector contains successes but no failures.

Here is the caller graph for this function:

◆ anyFailure()

bool ResponseCollector::anyFailure ( ) const
inline

ResponseCollector contains at least one failure, regardless of successes.

◆ anySuccess()

bool ResponseCollector::anySuccess ( ) const
inline

ResponseCollector contains at least one success, regardless of failures.

Here is the caller graph for this function:

◆ close()

void ResponseCollector::close ( void  )
inline

Causes the connection to be closed after the response is sent.

Here is the caller graph for this function:

◆ data() [1/4]

void ResponseCollector::data ( const PlaylistList playlists)
protected

Add a list of playlists for transmission as response data.

◆ data() [2/4]

void ResponseCollector::data ( const SongList songs)
protected

Add a list of songs for transmission as response data.

◆ data() [3/4]

void ResponseCollector::data ( const ThingieList item_list)
protected

Add a list of music items for transmission as response data.

◆ data() [4/4]

void ResponseCollector::data ( ResponseGroup &&  group)
protected

Add a record for transmission as response data.

Here is the caller graph for this function:

◆ dataResponse()

bool ResponseCollector::dataResponse ( ) const
inline

ResponseCollector is transporting data for transmission.

Here is the caller graph for this function:

◆ isNoResponse()

bool ResponseCollector::isNoResponse ( ) const
inline

ResponseCollector should not send a reply to a command.

Here is the caller graph for this function:

◆ noop()

bool ResponseCollector::noop ( ) const
inline

ResponseCollector contains neither successes nor failures.

Here is the caller graph for this function:

◆ operator=()

ResponseCollector& ResponseCollector::operator= ( ResponseCollector &&  from)
default

◆ partial()

bool ResponseCollector::partial ( ) const
inline

ResponseCollector contains a mix of successes and failures.

Here is the caller graph for this function:

◆ serialize()

Parsnip::Data ResponseCollector::serialize ( const User user) const
private

Assemble a response collection into either a data response or a reply (i.e., successes/failures).

Returns
The JSON-formatted data response or reply.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setNoResponse()

void ResponseCollector::setNoResponse ( )
inline
Here is the call graph for this function:

◆ transmit()

void ResponseCollector::transmit ( PianodConnection destination,
const bool  json 
)

Transmit a reply.

Send requested data or reply to the requesting node using their desired protocol. Broadcast events as follows, using the appropriate protocol for each node:

  • broadcast_events go system-wide, all connections, all services
  • room_events go to all connections on the current service
  • user_events go to all connections by the same user on any services.
    Parameters
    destinationThe client to which to send the reponse.
    jsonIf true, use JSON for data or reply; otherwise use line protocol.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ transmitJSON()

void ResponseCollector::transmitJSON ( PianodConnection destination) const
private

Format and transmit a response collection to JSON client.

Parameters
destinationThe client to which to send the reply.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ transmitLine()

void ResponseCollector::transmitLine ( PianodConnection destination) const
private

Transmit a data response OR command reply to a specific node, followed by any client-specific add-on information.

Parameters
destinationThe node to which to send the response or data.
Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ operator<<

class PianodConnection& operator<< ( class PianodConnection there,
const ResponseCollector response 
)
friend

Member Data Documentation

◆ broadcast_events

ResponseGroup ResponseCollector::broadcast_events
protected

Broadcast to all users, all rooms.

◆ close_after_response

bool ResponseCollector::close_after_response = false
private

If true, the connection is closed after response is sent.

◆ data_groups

std::vector<ResponseGroup> ResponseCollector::data_groups
protected

Complete data records destined for the client.

◆ data_reply

ResponseGroup ResponseCollector::data_reply
protected

Discrete data responses destined for the client.

◆ diagnostics

ResponseGroup ResponseCollector::diagnostics
protected

Details of errors encountered.

◆ information

ResponseGroup ResponseCollector::information

Session notices going back to user.

◆ reason

RESPONSE_CODE ResponseCollector::reason { S_NOOP }
protected

The final response that will be sent.

◆ room_events

ResponseGroup ResponseCollector::room_events
protected

Broadcast to all same-room sessions.

◆ successes

ResponseGroup ResponseCollector::successes
protected

Success messages.

◆ user_events

ResponseGroup ResponseCollector::user_events
protected

Broadcast to other same-user sessions.


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