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
ServiceManager Class Reference

Contains and manages all the services/rooms. More...

#include <servicemanager.h>

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

Public Member Functions

virtual const Parsnip::Parser::DefinitionsgetParserDefinitions () override
 Retrieve the parser definitions handled by the interpreter. More...
 
 ServiceManager ()
 
virtual ~ServiceManager ()
 
float periodic (void)
 Perform periodic duties, and determine when next ones are due. More...
 
void shutdown (bool immediate)
 Request all services (rooms) close so pianod can shutdown. More...
 
bool flush (void)
 Persist data before shutdown. More...
 
void event (WaitEvent::Type type, const void *detail=nullptr, RESPONSE_CODE message=S_OK)
 Distribute an event to connections waiting on it. More...
 
void event (WaitEvent::Type type, RESPONSE_CODE message=S_OK)
 
void broadcastUserActions (bool v)
 Enable or disable announcing user actions to all connections. More...
 
bool broadcastingActions (void)
 Check whether user actions are announced to all connections. More...
 
void broadcast (const ResponseGroup &messages)
 Send a message to every user on all services/rooms. More...
 
void broadcast (const ResponseGroup &messages, User *target)
 Send a message to one user on all services/rooms. More...
 
void broadcastEffectivePrivileges ()
 Broadcast privileges to all users. More...
 
void broadcastEffectivePrivileges (User *target)
 Broadcast privileges to a user. More...
 
PianodServicecreateRoom (const std::string &name, const AudioSettings &audio, FB_SERVICE_OPTIONS &options)
 Add a room name/service pair to our list. More...
 
void removeRoom (PianodService *service)
 Remove a room. More...
 
bool userIsOnline (const User *user)
 Determine if a user is authenticated an connected in any room. More...
 
- Public Member Functions inherited from PianodInterpreter
virtual void registerInterpreter (PianodDispatcher &dispatcher)
 Register the interpreter with a dispatcher. More...
 
const HelpList getHelp (const std::vector< std::string > &search, std::set< std::string > *option_parsers)
 Search the interpreter's definitions for any definitions matching search criteria. More...
 

Static Public Member Functions

static const Parsnip::Parser::Definitionsparser_definitions ()
 
static const PianodSchema::CommandIdsjson_request_names (PianodSchema &schema)
 Retrieve names for our JSON requests, and make schema revisions. More...
 
- Static Public Member Functions inherited from PianodInterpreter
static bool optionIs (const Parsnip::Data &options, const char *name, const char *expected)
 Check if a string value exists and is case-blind equal to a particular value. More...
 
template<typename ValueType , typename LookupType >
static ValueType optionalValue (const Parsnip::Data &options, const char *name, const LookupType &lookup, const ValueType default_value)
 Retrieve the ID of a string value. More...
 

Public Attributes

bool broadcast_user_actions = false
 

Private Member Functions

virtual bool authorizedCommand (Parsnip::Parser::CommandId command, PianodConnection &conn) override
 Check whether a command is authorized. More...
 
virtual ResponseCollector handleCommand (Parsnip::Parser::CommandId command, const Parsnip::Data &options, PianodConnection &conn) override
 Command handler. More...
 
void sendSourceReadyEvents (const Media::Source *const source, RESPONSE_CODE result)
 Send events to those waiting on source ready, either a specific source, any source, or all sources. More...
 
void sourceReady (const Media::Source *const src)
 Prepare for a new source by alerting auto engines of it. More...
 
void sourceOffline (const Media::Source *const src)
 Handle a source going offline by removing it from use. More...
 
void sourceRemoved (const Media::Source *const src)
 Handle a source being deleted. More...
 

Private Attributes

const Parsnip::ParserRef master_parser
 A single parser shared by all rooms. More...
 
const PianodSchemaRef master_schema
 A single schema shared by all rooms. More...
 
PianodServicemaster_service = nullptr
 The initial room/service. More...
 
bool shutdown_pending = false
 Set when shutdown initiated. More...
 
time_t startup_time = time (nullptr)
 Time the service manager was instantiated. More...
 

Additional Inherited Members

- Public Types inherited from PianodInterpreter
using HelpList = PianodDispatcher::HelpList
 
- Protected Types inherited from PianodInterpreter
using StringVector = std::vector< std::string >
 
- Static Protected Attributes inherited from PianodInterpreter
static const Parsnip::Data EmptyDictionary {Parsnip::Data::Dictionary}
 An empty dictionary, often used as a default with Parsnip::Data::getOr. More...
 
static const StringVector EmptyStringVector
 An empty string vector, often used as a default with Parsnip::Data::getOr. More...
 

Detailed Description

Contains and manages all the services/rooms.

Constructor & Destructor Documentation

◆ ServiceManager()

ServiceManager::ServiceManager ( )
Here is the call graph for this function:

◆ ~ServiceManager()

ServiceManager::~ServiceManager ( )
virtual

Member Function Documentation

◆ authorizedCommand()

bool ServiceManager::authorizedCommand ( Parsnip::Parser::CommandId  command_id,
PianodConnection context 
)
overrideprivatevirtual

Check whether a command is authorized.

Parameters
command_idThe command requesting execution.
contextConnection details, including authentication state and privileges.
Returns
True if allowed, false otherwise.

Implements PianodInterpreter.

Here is the call graph for this function:

◆ broadcast() [1/2]

void ServiceManager::broadcast ( const ResponseGroup messages)

Send a message to every user on all services/rooms.

Parameters
messagesThe message(s) to broadcast.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ broadcast() [2/2]

void ServiceManager::broadcast ( const ResponseGroup messages,
User target 
)

Send a message to one user on all services/rooms.

Parameters
messagesThe messages to broadcast.
targetThe user to send the message to. If nullptr, broadcasts to visitors.
Here is the call graph for this function:

◆ broadcastEffectivePrivileges() [1/2]

void ServiceManager::broadcastEffectivePrivileges ( )

Broadcast privileges to all users.

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

◆ broadcastEffectivePrivileges() [2/2]

void ServiceManager::broadcastEffectivePrivileges ( User target)

Broadcast privileges to a user.

Parameters
targetThe target user, or NULL to target visitors.
Here is the call graph for this function:

◆ broadcastingActions()

bool ServiceManager::broadcastingActions ( void  )
inline

Check whether user actions are announced to all connections.

Returns
True if enabled, false if not.
Here is the caller graph for this function:

◆ broadcastUserActions()

void ServiceManager::broadcastUserActions ( bool  v)
inline

Enable or disable announcing user actions to all connections.

Parameters
vTrue to enable, false to disable.
Here is the caller graph for this function:

◆ createRoom()

PianodService * ServiceManager::createRoom ( const std::string &  name,
const AudioSettings audio,
FB_SERVICE_OPTIONS options 
)

Add a room name/service pair to our list.

Parameters
nameThe name of the room, so users can select it.
audioAudio settings (presumably a certain audio out) for the room.
optionsFootball options for the room's service. Each room gets a separate service.
Here is the caller graph for this function:

◆ event() [1/2]

void ServiceManager::event ( WaitEvent::Type  type,
const void *  detail = nullptr,
RESPONSE_CODE  reply = S_OK 
)

Distribute an event to connections waiting on it.

Parameters
typeThe type of event.
detailPointer representing a specific event instance.
replyStatus code to report to connections waiting for the event.
Here is the caller graph for this function:

◆ event() [2/2]

void ServiceManager::event ( WaitEvent::Type  type,
RESPONSE_CODE  message = S_OK 
)
inline
See also
event (3 parameter version).
Here is the call graph for this function:

◆ flush()

bool ServiceManager::flush ( void  )

Persist data before shutdown.

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

◆ getParserDefinitions()

const Parsnip::Parser::Definitions & ServiceManager::getParserDefinitions ( )
overridevirtual

Retrieve the parser definitions handled by the interpreter.

Returns
Parser definitions.

Implements PianodInterpreter.

Here is the call graph for this function:

◆ handleCommand()

ResponseCollector ServiceManager::handleCommand ( Parsnip::Parser::CommandId  command_id,
const Parsnip::Data parameters,
PianodConnection context 
)
overrideprivatevirtual

Command handler.

Parameters
command_idCommand to execute.
parametersCommand parameters.
contextConnection details, including authentication state and privileges.
Returns
Data or success/failure indications.
Exceptions
CommandErroror other exception if an error occurs.

Implements PianodInterpreter.

Here is the call graph for this function:

◆ json_request_names()

const PianodSchema::CommandIds & ServiceManager::json_request_names ( PianodSchema schema)
static

Retrieve names for our JSON requests, and make schema revisions.

Parameters
schemaThe schemaset containing our requests.
Returns
Request name to command ID mappings.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ parser_definitions()

const Parsnip::Parser::Definitions & ServiceManager::parser_definitions ( void  )
static
Here is the caller graph for this function:

◆ periodic()

float ServiceManager::periodic ( void  )

Perform periodic duties, and determine when next ones are due.

All sources, the audio engines (rooms) and users are invoked, allowing them to perform periodic duties (freeing resources, persisting data, background tasks).

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

◆ removeRoom()

void ServiceManager::removeRoom ( PianodService service)

Remove a room.

Triggers a flush when the last room is removed. This is a callback function, invoked when Football calls the serviceShutdown() method.

Parameters
serviceThe room to remove.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendSourceReadyEvents()

void ServiceManager::sendSourceReadyEvents ( const Media::Source *const  source,
RESPONSE_CODE  result 
)
private

Send events to those waiting on source ready, either a specific source, any source, or all sources.

Parameters
sourceThe source that is transitioning from pending to ready or dead.
resultThe status of the source's transition.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ shutdown()

void ServiceManager::shutdown ( bool  immediate)

Request all services (rooms) close so pianod can shutdown.

Parameters
immediateIf true, aborts playback in all rooms.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sourceOffline()

void ServiceManager::sourceOffline ( const Media::Source *const  source)
private

Handle a source going offline by removing it from use.

Unlike invalidating sources, however, historical and queue references remain.

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

◆ sourceReady()

void ServiceManager::sourceReady ( const Media::Source *const  src)
private

Prepare for a new source by alerting auto engines of it.

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

◆ sourceRemoved()

void ServiceManager::sourceRemoved ( const Media::Source *const  src)
private

Handle a source being deleted.

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

◆ userIsOnline()

bool ServiceManager::userIsOnline ( const User user)

Determine if a user is authenticated an connected in any room.

Parameters
userThe user to look for.
Returns
True if the user is online, false otherwise.
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ broadcast_user_actions

bool ServiceManager::broadcast_user_actions = false

◆ master_parser

const Parsnip::ParserRef ServiceManager::master_parser
private

A single parser shared by all rooms.

◆ master_schema

const PianodSchemaRef ServiceManager::master_schema
private

A single schema shared by all rooms.

◆ master_service

PianodService* ServiceManager::master_service = nullptr
private

The initial room/service.

◆ shutdown_pending

bool ServiceManager::shutdown_pending = false
private

Set when shutdown initiated.

◆ startup_time

time_t ServiceManager::startup_time = time (nullptr)
private

Time the service manager was instantiated.


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