pianod2
multisource multiuser scriptable networked music player
Public Types | Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Static Protected Attributes | Private Member Functions | Private Attributes | List of all members
PianodInterpreter Class Referenceabstract

Interpreter class based on Parsnip template, customized base for pianod interpreters with the addition of help support. More...

#include <interpreter.h>

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

Public Types

using HelpList = PianodDispatcher::HelpList
 

Public Member Functions

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

Protected Types

using StringVector = std::vector< std::string >
 

Protected Member Functions

virtual bool authorizedCommand (Parsnip::Parser::CommandId command_id, PianodConnection &context)=0
 Check whether a command is authorized. More...
 
virtual ResponseCollector handleCommand (Parsnip::Parser::CommandId command_id, const Parsnip::Data &parameters, PianodConnection &context)=0
 Command handler. More...
 
virtual const Parsnip::Parser::DefinitionsgetParserDefinitions ()=0
 Retrieve the parser definitions handled by the interpreter. More...
 

Static Protected Attributes

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

Private Member Functions

virtual ResponseCollector interpret (Parsnip::Parser::CommandId command_id, const Parsnip::Data &parameters, PianodConnection &context) override final
 Authorize and execute a command. More...
 

Private Attributes

friend PianodDispatcher
 

Detailed Description

Interpreter class based on Parsnip template, customized base for pianod interpreters with the addition of help support.

Member Typedef Documentation

◆ HelpList

◆ StringVector

using PianodInterpreter::StringVector = std::vector <std::string>
protected

Member Function Documentation

◆ authorizedCommand()

virtual bool PianodInterpreter::authorizedCommand ( Parsnip::Parser::CommandId  command_id,
PianodConnection context 
)
protectedpure virtual

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.

Implemented in UserManager, ToneGeneratorCommands, PandoraCommands, FilesystemCommands, Tuner::Tuner, ServiceManager, Media::Manager, and AudioEngine.

Here is the caller graph for this function:

◆ getHelp()

const std::vector< std::string > PianodInterpreter::getHelp ( const std::vector< std::string > &  search,
std::set< std::string > *  option_parsers 
)

Search the interpreter's definitions for any definitions matching search criteria.

Parameters
searchThe search criteria. If empty, returns all.
option_parsersAny option parsers used by matching statements are added to this set.
Returns
Matching definitions, ready for presentation as help.
Here is the call graph for this function:

◆ getParserDefinitions()

virtual const Parsnip::Parser::Definitions& PianodInterpreter::getParserDefinitions ( )
protectedpure virtual

Retrieve the parser definitions handled by the interpreter.

Returns
Parser definitions.

Implemented in UserManager, Tuner::Tuner, ServiceManager, ToneGeneratorCommands, PandoraCommands, Media::Manager, FilesystemCommands, and AudioEngine.

Here is the caller graph for this function:

◆ handleCommand()

virtual ResponseCollector PianodInterpreter::handleCommand ( Parsnip::Parser::CommandId  command_id,
const Parsnip::Data parameters,
PianodConnection context 
)
protectedpure virtual

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.

Implemented in UserManager, ToneGeneratorCommands, PandoraCommands, FilesystemCommands, Tuner::Tuner, ServiceManager, Media::Manager, and AudioEngine.

Here is the caller graph for this function:

◆ interpret()

ResponseCollector PianodInterpreter::interpret ( Parsnip::Parser::CommandId  command_id,
const Parsnip::Data parameters,
PianodConnection context 
)
finaloverrideprivatevirtual

Authorize and execute a command.

Parameters
command_idThe command to execute.
parametersOptions for the command.
contextThe connection and context executing the command.
Returns
Data or success/failure indications.
Exceptions
CommandErroror any other exception.

Implements Parsnip::Interpreter< ResponseCollector, PianodConnection & >.

Here is the call graph for this function:

◆ optionalValue()

template<typename ValueType , typename LookupType >
static ValueType PianodInterpreter::optionalValue ( const Parsnip::Data options,
const char *  name,
const LookupType &  lookup,
const ValueType  default_value 
)
inlinestatic

Retrieve the ID of a string value.

Parameters
optionsWhere to look for the value.
nameThe name of the value.
lookupThe lookup table for the value.
default_valueThe default value, if not specified.
Returns
The ID value from the lookup table, or default.
Exceptions
Ifthe value is not in the table.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ optionIs()

bool PianodInterpreter::optionIs ( const Parsnip::Data options,
const char *  name,
const char *  expected 
)
static

Check if a string value exists and is case-blind equal to a particular value.

Parameters
optionsThe options dictionary to look in.
nameThe name of the value to check
expectedThe expected value.
Returns
True if the options value exists and has the expected value.
Exceptions
Ifthe value has the wrong type.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ registerInterpreter()

void PianodInterpreter::registerInterpreter ( PianodDispatcher dispatcher)
virtual

Register the interpreter with a dispatcher.

Parameters
dispatcherThe dispatcher with which to register.

Reimplemented in AudioEngine.

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

Member Data Documentation

◆ EmptyDictionary

const Parsnip::Data PianodInterpreter::EmptyDictionary {Parsnip::Data::Dictionary}
staticprotected

An empty dictionary, often used as a default with Parsnip::Data::getOr.

◆ EmptyStringVector

const PianodInterpreter::StringVector PianodInterpreter::EmptyStringVector
staticprotected

An empty string vector, often used as a default with Parsnip::Data::getOr.

◆ PianodDispatcher

friend PianodInterpreter::PianodDispatcher
private

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