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

Dispatcher based on Parsnip template, customized for pianod by adding help support. More...

#include <interpreter.h>

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

Public Types

using HelpList = std::vector< std::string >
 
- Public Types inherited from Parsnip::Dispatcher< ResponseCollector, PianodConnection & >
using ReturnType = ResponseCollector
 
using ContextType = PianodConnection &
 
using ExecutorType = std::function< ReturnType(Parser::CommandId, const Parsnip::Data &, ContextType)>
 

Public Member Functions

 PianodDispatcher (const Parsnip::ParserRef &parser, const PianodSchemaRef &schema)
 Construct a dispatcher for Pianod. More...
 
void addHandler (const Parsnip::Parser::Definitions &defs, class PianodInterpreter *interpreter)
 Add a handler to/for which commands will be dispatched. More...
 
void rewriteJsonRequest (Parsnip::Data &request) const
 Rewrite the JSON request, wrapping the actual command in any as-user, in-room, and with-source specifications. More...
 
ResponseCollector jsonRequest (const Parsnip::Data &request, PianodConnection &context) const
 Dispatch a JSON request for execution. More...
 
ResponseCollector redispatch (const Parsnip::Data &options, PianodConnection &context) const
 Dispatch a command or request embedded within another command. More...
 
const HelpList getHelp (std::vector< std::string > search)
 Request help for all interpreters which a dispatcher handles. More...
 
- Public Member Functions inherited from Parsnip::Dispatcher< ResponseCollector, PianodConnection & >
 Dispatcher (const ParserRef &parser)
 Construct a dispatcher. More...
 
void addHandler (const Parser::Definitions &defs, const ExecutorType &handler)
 Register handlers with the dispatcher. More...
 
void addHandler (const Parser::Definitions &defs, Interpreter< ResponseCollector, PianodConnection & > *interpreter)
 Register handlers with the dispatcher. More...
 
void addStatements (const Parser::Definitions &defs, ExecutorType handler)
 Add statements to the parser and register their related handler. More...
 
ReturnType operator() (Parser::CommandId command_id, const Parsnip::Data &parameters, PianodConnection & context) const
 Dispatch a command to the executor/handler function. More...
 
ReturnType operator() (Parser::StringType command, ContextType context) const
 Parse and dispatch a command to the executor/handler function. More...
 

Private Types

using base_type = Parsnip::Dispatcher< ResponseCollector, PianodConnection & >
 

Private Attributes

PianodSchemaRef schema
 
std::vector< class PianodInterpreter * > interpreters
 List of all associated interpreters. More...
 

Additional Inherited Members

- Protected Attributes inherited from Parsnip::Dispatcher< ResponseCollector, PianodConnection & >
const ParserRef parser
 

Detailed Description

Dispatcher based on Parsnip template, customized for pianod by adding help support.

Member Typedef Documentation

◆ base_type

◆ HelpList

using PianodDispatcher::HelpList = std::vector<std::string>

Constructor & Destructor Documentation

◆ PianodDispatcher()

PianodDispatcher::PianodDispatcher ( const Parsnip::ParserRef parser,
const PianodSchemaRef schema_in 
)

Construct a dispatcher for Pianod.

Parameters
parserA parser for the pianod command set.
schema_inA schema fr the pianod request set.

Member Function Documentation

◆ addHandler()

void PianodDispatcher::addHandler ( const Parsnip::Parser::Definitions defs,
class PianodInterpreter interpreter 
)

Add a handler to/for which commands will be dispatched.

Parameters
defsThe list of commands the interpreter will handle.
interpreterThe interpreter instance.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getHelp()

const std::vector< std::string > PianodDispatcher::getHelp ( std::vector< std::string >  search)

Request help for all interpreters which a dispatcher handles.

Parameters
searchSearch criteria.
Returns
A list of related help, or an empty list on no matches.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ jsonRequest()

ResponseCollector PianodDispatcher::jsonRequest ( const Parsnip::Data request,
PianodConnection context 
) const

Dispatch a JSON request for execution.

Parameters
requestThe request to dispatch.
contextThe request's context.
Returns
Data or success/failure indications.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ redispatch()

ResponseCollector PianodDispatcher::redispatch ( const Parsnip::Data options,
PianodConnection context 
) const

Dispatch a command or request embedded within another command.

I.e., ADD USER, IN ROOM, or WITH SOURCE.

Parameters
optionsThe options provided to one of the aforementioned commands.
contextThe request's context.
Returns
Data or success/failure indications.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rewriteJsonRequest()

void PianodDispatcher::rewriteJsonRequest ( Parsnip::Data request) const

Rewrite the JSON request, wrapping the actual command in any as-user, in-room, and with-source specifications.

Parameters
requestThe request, rewritten on return if required.
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ interpreters

std::vector<class PianodInterpreter *> PianodDispatcher::interpreters
private

List of all associated interpreters.

◆ schema

PianodSchemaRef PianodDispatcher::schema
private

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