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

Connection to a pianod client, along with context and state of that connection. More...

#include <connection.h>

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

Public Member Functions

virtual ~PianodConnection () override
 
bool transmitJSON () const
 
void close_after_events ()
 Close after events are handled, or now if not waiting on one. More...
 
bool authenticated (void) const
 Determine if the connection is authenticated, i.e., has a user. More...
 
ResponseGroup updateConnection ()
 
std::string username (void) const
 
Media::Source *const source () const
 Get the connection's selected source. More...
 
ResponseGroup source (Media::Source *const source, bool announce=true)
 Set the selected source. More...
 
bool haveRank (Rank rank) const
 
Rank effectiveRank (void) const
 Get connected user's rank. More...
 
bool havePrivilege (Privilege priv) const
 Determine if the user has a privilege. More...
 
void waitForEventWithOptions (WaitEvent::Type type, const Parsnip::Data &options, const void *detail)
 Interpret options and begin waiting for an event on a connection. More...
 
void waitForEvent (WaitEvent::Type type, const void *detail)
 Begin waiting for an event on a connection. More...
 
void event (WaitEvent::Type type, const void *detail, RESPONSE_CODE reply)
 Process an event for a connection. More...
 
void checkTimeouts ()
 Check if a pending event has timed out. More...
 
ResponseGroup sendSelectedSource () const
 Report the selected source to the connection. More...
 
ResponseGroup sendEffectivePrivileges () const
 Transmit the user's effective privileges. More...
 
void announceToRoom (ResponseGroup &&announcement) const
 Send some messages to all users in a room. More...
 
void announceToAll (ResponseGroup &&announcement) const
 Broadcast some messages to all connected sessions, all rooms. More...
 
PianodServiceservice (void) const
 
- Public Member Functions inherited from Football::Connection
ServiceBaseservice (void) const
 Get a connection's parent service. More...
 
virtual ~Connection () override
 
virtual ssize_t conditional_print (bool(*callback)(FB_CONNECTION *), const std::string &message) override
 Send a message to some output queues depending on the callback function return value. More...
 
bool transfer (ServiceBase *service, bool invokeNewConnectionHandler=false)
 Transfer a connection to another service. More...
 
void close (void)
 Initiate connection closure. More...
 
void acceptInput (bool mode)
 Control acceptance of input. More...
 
- Public Member Functions inherited from Football::Thingie
virtual ~Thingie ()
 
ssize_t print (const std::string &message)
 Add a string to the output queues. More...
 
ssize_t conditional_broadcast (bool(*callback)(FB_CONNECTION *), const std::string &message)
 Send a message to some output queues depending on the callback function return value. More...
 
ssize_t printf (const char *format,...)
 Add messages to output queues. More...
 
ssize_t vprintf (const char *format, va_list parameters)
 
ssize_t bprintf (const char *format,...)
 
ssize_t bvprintf (const char *format, va_list parameters)
 
ssize_t cbprintf (bool(*callback)(FB_CONNECTION *), const char *format,...)
 
ssize_t cbvprintf (bool(*callback)(FB_CONNECTION *), const char *format, va_list parameters)
 
virtual std::streamsize xsputn (const char_type *data, std::streamsize count) override
 
virtual int_type overflow (int_type c) override
 

Static Public Member Functions

static bool json_connections_only (FB_CONNECTION *)
 Callback function used to identify JSON connections. More...
 
static bool line_connections_only (FB_CONNECTION *)
 Callback function used to identify line protocol connections. More...
 

Public Attributes

Useruser = nullptr
 

Private Member Functions

virtual void newConnection (const FB_EVENT *event) override
 Invoked when a new connection has arrived/greeted. More...
 
virtual void connectionClose (const FB_EVENT *event) override
 Invoked when a connection is closing. More...
 
virtual void inputReceived (const FB_EVENT *event) override
 Invoked when a completed message is received. More...
 

Private Attributes

Media::Source_source = nullptr
 The current source. More...
 
WaitEvent pending
 An event this connection is waited for. More...
 
bool use_json = false
 Set to true if protocol is JSON. More...
 

Additional Inherited Members

- Static Protected Member Functions inherited from Football::Connection
static ConnectiontryGetFromOld (FB_CONNECTION *connection)
 

Detailed Description

Connection to a pianod client, along with context and state of that connection.

Constructor & Destructor Documentation

◆ ~PianodConnection()

PianodConnection::~PianodConnection ( )
overridevirtual

Member Function Documentation

◆ announceToAll()

void PianodConnection::announceToAll ( ResponseGroup &&  announcements) const

Broadcast some messages to all connected sessions, all rooms.

If announcing user actions is disabled, any such messages are deleted.

Parameters
announcementsThe announcements to send.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ announceToRoom()

void PianodConnection::announceToRoom ( ResponseGroup &&  announcements) const

Send some messages to all users in a room.

If announcing user actions is disabled, any such messages are deleted.

Parameters
announcementsThe announcements to send.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ authenticated()

bool PianodConnection::authenticated ( void  ) const
inline

Determine if the connection is authenticated, i.e., has a user.

Returns
true if the connection is authenticated.
Here is the caller graph for this function:

◆ checkTimeouts()

void PianodConnection::checkTimeouts ( )

Check if a pending event has timed out.

If so, fire it with failure. Otherwise, check then pending event for a closer next timeout time.

Here is the call graph for this function:

◆ close_after_events()

void PianodConnection::close_after_events ( )

Close after events are handled, or now if not waiting on one.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ connectionClose()

void PianodConnection::connectionClose ( const FB_EVENT event)
overrideprivatevirtual

Invoked when a connection is closing.

Corresponds to FB_EVENT_CLOSE event. This is the last notification/event for a connection before it closes.

Parameters
eventClosing connection details.

Reimplemented from Football::Connection.

Here is the call graph for this function:

◆ effectiveRank()

Rank PianodConnection::effectiveRank ( void  ) const

Get connected user's rank.

Returns
User's rank, or visitor rank if not authenticated.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ event()

void PianodConnection::event ( WaitEvent::Type  type,
const void *  detail,
RESPONSE_CODE  reply 
)

Process an event for a connection.

If waiting for the event, the status is announced and input is resumed. If not waiting, or waiting for a different event, nothing happens.

Parameters
typeThe type of event occurring.
detailA pointer representing a specific event instance.
replyThe status to report if the event applies to the connection.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ havePrivilege()

bool PianodConnection::havePrivilege ( Privilege  priv) const

Determine if the user has a privilege.

Visitors cannot be assigned privileges but they may be implied by rank.

Parameters
privThe privilege to check.
Returns
True if the user either has the privilege or it is implied by rank.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ haveRank()

bool PianodConnection::haveRank ( Rank  rank) const
Here is the call graph for this function:
Here is the caller graph for this function:

◆ inputReceived()

void PianodConnection::inputReceived ( const FB_EVENT event)
overrideprivatevirtual

Invoked when a completed message is received.

Corresponds to FB_EVENT_INPUT event.

Parameters
eventDetails of the message received.

Reimplemented from Football::Connection.

Here is the call graph for this function:

◆ json_connections_only()

bool PianodConnection::json_connections_only ( FB_CONNECTION conn)
static

Callback function used to identify JSON connections.

Parameters
connA football connection.
Returns
True if the connection is JSON.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ line_connections_only()

bool PianodConnection::line_connections_only ( FB_CONNECTION conn)
static

Callback function used to identify line protocol connections.

Parameters
connA football connection.
Returns
True if the connection is line-oriented.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ newConnection()

void PianodConnection::newConnection ( const FB_EVENT event)
overrideprivatevirtual

Invoked when a new connection has arrived/greeted.

Corresponds to FB_EVENT_CONNECT.

Parameters
eventThe new connection details, or a nullptr for transferred connections.

Reimplemented from Football::Connection.

Here is the call graph for this function:

◆ sendEffectivePrivileges()

ResponseGroup PianodConnection::sendEffectivePrivileges ( ) const

Transmit the user's effective privileges.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendSelectedSource()

ResponseGroup PianodConnection::sendSelectedSource ( ) const

Report the selected source to the connection.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ service()

PianodService& PianodConnection::service ( void  ) const
inline
Here is the call graph for this function:
Here is the caller graph for this function:

◆ source() [1/2]

Media::Source* const PianodConnection::source ( ) const
inline

Get the connection's selected source.

Returns
The selected source.
Here is the caller graph for this function:

◆ source() [2/2]

ResponseGroup PianodConnection::source ( Media::Source *const  source,
bool  announce = true 
)

Set the selected source.

Parameters
sourceThe new source.
announceTrue (or omitted) to announce the new source in protocol.
Here is the call graph for this function:

◆ transmitJSON()

bool PianodConnection::transmitJSON ( ) const
inline
Here is the caller graph for this function:

◆ updateConnection()

ResponseGroup PianodConnection::updateConnection ( )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ username()

std::string PianodConnection::username ( void  ) const
inline
Here is the call graph for this function:
Here is the caller graph for this function:

◆ waitForEvent()

void PianodConnection::waitForEvent ( WaitEvent::Type  type,
const void *  detail 
)

Begin waiting for an event on a connection.

Parameters
typeThe type of event to wait for.
detailA pointer representing a specific event instance to wait for.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ waitForEventWithOptions()

void PianodConnection::waitForEventWithOptions ( WaitEvent::Type  type,
const Parsnip::Data options,
const void *  detail 
)

Interpret options and begin waiting for an event on a connection.

Parameters
typeThe type of event to wait for.
optionsWait-related details from command line.
detailA pointer representing a specific event instance to wait for.
Returns
True on success, false if event options are invalid.
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ _source

Media::Source* PianodConnection::_source = nullptr
private

The current source.

◆ pending

WaitEvent PianodConnection::pending
private

An event this connection is waited for.

◆ use_json

bool PianodConnection::use_json = false
private

Set to true if protocol is JSON.

◆ user

User* PianodConnection::user = nullptr

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