AlexaClientSDK  1.25.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
Classes | Static Public Member Functions | List of all members
alexaClientSDK::capabilityAgents::speakerManager::SpeakerManager Class Reference

#include <SpeakerManager.h>

Inheritance diagram for alexaClientSDK::capabilityAgents::speakerManager::SpeakerManager:
Inheritance graph
[legend]
Collaboration diagram for alexaClientSDK::capabilityAgents::speakerManager::SpeakerManager:
Collaboration graph
[legend]

Public Member Functions

CapabilityAgent Functions
avsCommon::avs::DirectiveHandlerConfiguration getConfiguration () const override
 
void handleDirectiveImmediately (std::shared_ptr< avsCommon::avs::AVSDirective > directive) override
 
void preHandleDirective (std::shared_ptr< avsCommon::avs::CapabilityAgent::DirectiveInfo > info) override
 
void handleDirective (std::shared_ptr< avsCommon::avs::CapabilityAgent::DirectiveInfo > info) override
 
void cancelDirective (std::shared_ptr< avsCommon::avs::CapabilityAgent::DirectiveInfo > info) override
 
void doShutdown () override
 
std::future< bool > setVolume (avsCommon::sdkInterfaces::ChannelVolumeInterface::Type type, int8_t volume, const NotificationProperties &properties) override
 
std::future< bool > adjustVolume (avsCommon::sdkInterfaces::ChannelVolumeInterface::Type type, int8_t delta, const NotificationProperties &properties) override
 
std::future< bool > setMute (avsCommon::sdkInterfaces::ChannelVolumeInterface::Type type, bool mute, const NotificationProperties &properties) override
 
std::future< bool > setVolume (avsCommon::sdkInterfaces::ChannelVolumeInterface::Type type, int8_t volume, bool forceNoNotifications=false, avsCommon::sdkInterfaces::SpeakerManagerObserverInterface::Source source=avsCommon::sdkInterfaces::SpeakerManagerObserverInterface::Source::LOCAL_API) override
 
std::future< bool > adjustVolume (avsCommon::sdkInterfaces::ChannelVolumeInterface::Type type, int8_t delta, bool forceNoNotifications=false, avsCommon::sdkInterfaces::SpeakerManagerObserverInterface::Source source=avsCommon::sdkInterfaces::SpeakerManagerObserverInterface::Source::LOCAL_API) override
 
std::future< bool > setMute (avsCommon::sdkInterfaces::ChannelVolumeInterface::Type type, bool mute, bool forceNoNotifications=false, avsCommon::sdkInterfaces::SpeakerManagerObserverInterface::Source source=avsCommon::sdkInterfaces::SpeakerManagerObserverInterface::Source::LOCAL_API) override
 
std::future< bool > getSpeakerSettings (avsCommon::sdkInterfaces::ChannelVolumeInterface::Type type, avsCommon::sdkInterfaces::SpeakerInterface::SpeakerSettings *settings) override
 
void addSpeakerManagerObserver (std::shared_ptr< avsCommon::sdkInterfaces::SpeakerManagerObserverInterface > observer) override
 
void removeSpeakerManagerObserver (std::shared_ptr< avsCommon::sdkInterfaces::SpeakerManagerObserverInterface > observer) override
 
void addChannelVolumeInterface (std::shared_ptr< avsCommon::sdkInterfaces::ChannelVolumeInterface > channelVolumeInterface) override
 
CapabilityConfigurationInterface Functions
std::unordered_set< std::shared_ptr< avsCommon::avs::CapabilityConfiguration > > getCapabilityConfigurations () override
 
- Public Member Functions inherited from alexaClientSDK::avsCommon::avs::CapabilityAgent
virtual ~CapabilityAgent ()=default
 
void preHandleDirective (std::shared_ptr< AVSDirective > directive, std::unique_ptr< sdkInterfaces::DirectiveHandlerResultInterface > result) override final
 
bool handleDirective (const std::string &messageId) override final
 
void cancelDirective (const std::string &messageId) override final
 
void onDeregistered () override
 
void onFocusChanged (FocusState newFocus, MixingBehavior behavior) override
 
- Public Member Functions inherited from alexaClientSDK::avsCommon::sdkInterfaces::DirectiveHandlerInterface
virtual ~DirectiveHandlerInterface ()=default
 
virtual void handleDirectiveImmediately (std::shared_ptr< avsCommon::avs::AVSDirective > directive)=0
 
virtual void preHandleDirective (std::shared_ptr< avsCommon::avs::AVSDirective > directive, std::unique_ptr< DirectiveHandlerResultInterface > result)=0
 
- Public Member Functions inherited from alexaClientSDK::avsCommon::sdkInterfaces::ChannelObserverInterface
virtual ~ChannelObserverInterface ()=default
 
- Public Member Functions inherited from alexaClientSDK::avsCommon::sdkInterfaces::StateProviderInterface
virtual ~StateProviderInterface ()=default
 
virtual void provideState (const avs::NamespaceAndName &stateProviderName, const ContextRequestToken stateRequestToken)
 
virtual void provideState (const avs::CapabilityTag &stateProviderName, const ContextRequestToken stateRequestToken)
 
virtual bool canStateBeRetrieved ()
 
virtual bool hasReportableStateProperties ()
 
- Public Member Functions inherited from alexaClientSDK::avsCommon::sdkInterfaces::ContextRequesterInterface
virtual ~ContextRequesterInterface ()=default
 
virtual void onContextAvailable (const std::string &jsonContext)
 
virtual void onContextAvailable (const endpoints::EndpointIdentifier &endpointId, const avs::AVSContext &endpointContext, ContextRequestToken requestToken)
 
virtual void onContextFailure (const ContextRequestError error)
 
virtual void onContextFailure (const ContextRequestError error, ContextRequestToken token)
 
- Public Member Functions inherited from alexaClientSDK::avsCommon::sdkInterfaces::CapabilityConfigurationInterface
virtual ~CapabilityConfigurationInterface ()=default
 
- Public Member Functions inherited from alexaClientSDK::avsCommon::sdkInterfaces::SpeakerManagerInterface
virtual void addSpeakerManagerObserver (std::shared_ptr< SpeakerManagerObserverInterface > observer)=0
 
virtual void removeSpeakerManagerObserver (std::shared_ptr< SpeakerManagerObserverInterface > observer)=0
 
virtual void addChannelVolumeInterface (std::shared_ptr< ChannelVolumeInterface > channelVolumeInterface)=0
 
virtual ~SpeakerManagerInterface ()=default
 
- Public Member Functions inherited from alexaClientSDK::avsCommon::utils::RequiresShutdown
 RequiresShutdown (const std::string &name)
 
virtual ~RequiresShutdown ()
 Destructor. More...
 
const std::string & name () const
 
void shutdown ()
 
bool isShutdown () const
 

Static Public Member Functions

static std::shared_ptr< SpeakerManagerInterfacecreateSpeakerManagerCapabilityAgent (const std::shared_ptr< avsCommon::sdkInterfaces::ContextManagerInterface > &contextManager, const std::shared_ptr< avsCommon::sdkInterfaces::MessageSenderInterface > &messageSender, const std::shared_ptr< avsCommon::sdkInterfaces::ExceptionEncounteredSenderInterface > &exceptionEncounteredSender, const std::shared_ptr< acsdkShutdownManagerInterfaces::ShutdownNotifierInterface > &shutdownNotifier, const acsdkManufactory::Annotated< avsCommon::sdkInterfaces::endpoints::DefaultEndpointAnnotation, avsCommon::sdkInterfaces::endpoints::EndpointCapabilitiesRegistrarInterface > &endpointCapabilitiesRegistrar, const std::shared_ptr< avsCommon::utils::metrics::MetricRecorderInterface > &metricRecorder)
 
static std::shared_ptr< SpeakerManagercreate (const std::vector< std::shared_ptr< avsCommon::sdkInterfaces::ChannelVolumeInterface >> &volumeInterfaces, std::shared_ptr< avsCommon::sdkInterfaces::ContextManagerInterface > contextManager, std::shared_ptr< avsCommon::sdkInterfaces::MessageSenderInterface > messageSender, std::shared_ptr< avsCommon::sdkInterfaces::ExceptionEncounteredSenderInterface > exceptionEncounteredSender, std::shared_ptr< avsCommon::utils::metrics::MetricRecorderInterface > metricRecorder=nullptr)
 

Additional Inherited Members

- Protected Member Functions inherited from alexaClientSDK::avsCommon::avs::CapabilityAgent
 CapabilityAgent (const std::string &nameSpace, std::shared_ptr< sdkInterfaces::ExceptionEncounteredSenderInterface > exceptionEncounteredSender)
 
virtual std::shared_ptr< DirectiveInfocreateDirectiveInfo (std::shared_ptr< AVSDirective > directive, std::unique_ptr< sdkInterfaces::DirectiveHandlerResultInterface > result)
 
virtual void preHandleDirective (std::shared_ptr< DirectiveInfo > info)=0
 
virtual void handleDirective (std::shared_ptr< DirectiveInfo > info)=0
 
virtual void cancelDirective (std::shared_ptr< DirectiveInfo > info)=0
 
void removeDirective (const std::string &messageId)
 
void sendExceptionEncounteredAndReportFailed (std::shared_ptr< DirectiveInfo > info, const std::string &message, avsCommon::avs::ExceptionErrorType type=avsCommon::avs::ExceptionErrorType::INTERNAL_ERROR)
 
const std::pair< std::string, std::string > buildJsonEventString (const std::string &eventName, const std::string &dialogRequestIdString="", const std::string &payload="{}", const std::string &context="") const
 
- Protected Attributes inherited from alexaClientSDK::avsCommon::avs::CapabilityAgent
const std::string m_namespace
 The namespace of the capability agent. More...
 
std::shared_ptr< sdkInterfaces::ExceptionEncounteredSenderInterfacem_exceptionEncounteredSender
 Object to use to send exceptionEncountered messages. More...
 

Detailed Description

This class implements a CapabilityAgent that handles the AVS Speaker API.

The SpeakerManager can handle multiple ChannelVolumeInterface objects and dedupe them with the same getId() value. The ChannelVolumeInterface are grouped by their respective ChannelVolumeInterface::Type, and the volume and mute state will be consistent across each type. For example, to change the volume of all ChannelVolumeInterface objects of a specific type:

// Use local setVolume API.
std::future<bool> result = speakerManager->setVolume(type, AVS_SET_VOLUME_MAX);
// Optionally, wait for the operation to complete.
if (result.valid()) {
result.wait();
}

Clients may extend the ChannelVolumeInterface::Type enum if multiple independent volume controls are needed.

Member Function Documentation

◆ addChannelVolumeInterface()

void alexaClientSDK::capabilityAgents::speakerManager::SpeakerManager::addChannelVolumeInterface ( std::shared_ptr< avsCommon::sdkInterfaces::ChannelVolumeInterface channelVolumeInterface)
override

◆ addSpeakerManagerObserver()

void alexaClientSDK::capabilityAgents::speakerManager::SpeakerManager::addSpeakerManagerObserver ( std::shared_ptr< avsCommon::sdkInterfaces::SpeakerManagerObserverInterface observer)
override

◆ adjustVolume() [1/2]

std::future< bool > alexaClientSDK::capabilityAgents::speakerManager::SpeakerManager::adjustVolume ( avsCommon::sdkInterfaces::ChannelVolumeInterface::Type  type,
int8_t  delta,
const NotificationProperties properties 
)
overridevirtual

Adjusts the volume for ChannelVolumeInterfaces of a certain Type with a volume delta.

Parameters
typeThe type of ChannelVolumeInterface to modify.
deltaThe delta to modify volume by. Values must be between [-100,100].
propertiesNotification properties that specify how the volume change will be notified.
Returns
A future to be set with the operation's result. The future must be checked for validity before attempting to obtain the shared state. An invalid future indicates an internal error, and the caller should not assume the operation was successful.

Implements alexaClientSDK::avsCommon::sdkInterfaces::SpeakerManagerInterface.

◆ adjustVolume() [2/2]

std::future< bool > alexaClientSDK::capabilityAgents::speakerManager::SpeakerManager::adjustVolume ( avsCommon::sdkInterfaces::ChannelVolumeInterface::Type  type,
int8_t  delta,
bool  forceNoNotifications = false,
avsCommon::sdkInterfaces::SpeakerManagerObserverInterface::Source  source = avsCommon::sdkInterfaces::SpeakerManagerObserverInterface::Source::LOCAL_API 
)
overridevirtual
Deprecated:

Adjusts the volume for ChannelVolumeInterfaces of a certain Type with a volume delta.

Parameters
typeThe type of ChannelVolumeInterface to modify.
deltaThe delta to modify volume by. Values must be between [-100,100].
forceNoNotificationsSetting this to true will ensure no event is sent and no observer is notified. Setting this to false does not guarantee that a notification will be sent.
sourceWhether the call is a result from an AVS directive or local interaction.
Returns
A future to be set with the operation's result. The future must be checked for validity before attempting to obtain the shared state. An invalid future indicates an internal error, and the caller should not assume the operation was successful.

Implements alexaClientSDK::avsCommon::sdkInterfaces::SpeakerManagerInterface.

◆ cancelDirective()

void alexaClientSDK::capabilityAgents::speakerManager::SpeakerManager::cancelDirective ( std::shared_ptr< avsCommon::avs::CapabilityAgent::DirectiveInfo info)
override

◆ create()

std::shared_ptr< SpeakerManager > alexaClientSDK::capabilityAgents::speakerManager::SpeakerManager::create ( const std::vector< std::shared_ptr< avsCommon::sdkInterfaces::ChannelVolumeInterface >> &  volumeInterfaces,
std::shared_ptr< avsCommon::sdkInterfaces::ContextManagerInterface contextManager,
std::shared_ptr< avsCommon::sdkInterfaces::MessageSenderInterface messageSender,
std::shared_ptr< avsCommon::sdkInterfaces::ExceptionEncounteredSenderInterface exceptionEncounteredSender,
std::shared_ptr< avsCommon::utils::metrics::MetricRecorderInterface metricRecorder = nullptr 
)
static

Create an instance of SpeakerManager, and register the ChannelVolumeInterfaces that will be controlled by it. ChannelVolumeInterfaces will be grouped by ChannelVolumeInterface::Type.

Parameters
volumeInterfacesThe ChannelVolumeInterfaces to register.
contextManagerA ContextManagerInterface to manage the context.
messageSenderA MessageSenderInterface to send messages to AVS.
exceptionEncounteredSenderAn ExceptionEncounteredSenderInterface to send directive processing exceptions to AVS.
metricRecorderThe metric recorder.

◆ createSpeakerManagerCapabilityAgent()

std::shared_ptr< SpeakerManagerInterface > alexaClientSDK::capabilityAgents::speakerManager::SpeakerManager::createSpeakerManagerCapabilityAgent ( const std::shared_ptr< avsCommon::sdkInterfaces::ContextManagerInterface > &  contextManager,
const std::shared_ptr< avsCommon::sdkInterfaces::MessageSenderInterface > &  messageSender,
const std::shared_ptr< avsCommon::sdkInterfaces::ExceptionEncounteredSenderInterface > &  exceptionEncounteredSender,
const std::shared_ptr< acsdkShutdownManagerInterfaces::ShutdownNotifierInterface > &  shutdownNotifier,
const acsdkManufactory::Annotated< avsCommon::sdkInterfaces::endpoints::DefaultEndpointAnnotation, avsCommon::sdkInterfaces::endpoints::EndpointCapabilitiesRegistrarInterface > &  endpointCapabilitiesRegistrar,
const std::shared_ptr< avsCommon::utils::metrics::MetricRecorderInterface > &  metricRecorder 
)
static

Create an instance of SpeakerManagerInterface. ChannelVolumeInterfaces can be registered via addChannelVolumeInterface.

Parameters
contextManagerA ContextManagerInterface to manage the context.
messageSenderA MessageSenderInterface to send messages to AVS.
exceptionEncounteredSenderAn ExceptionEncounteredSenderInterface to send directive processing exceptions to AVS.
shutdownNotifierA ShutdownNotifierInterface to notify the SpeakerManager when it's time to shut down.
endpointCapabilitiesRegistrarThe EndpointCapabilitiesRegistrarInterface for the default endpoint (annotated with DefaultEndpointAnnotation), so that the SpeakerManager can register itself as a capability with the default endpoint.
metricRecorderThe metric recorder.

◆ doShutdown()

void alexaClientSDK::capabilityAgents::speakerManager::SpeakerManager::doShutdown ( )
overridevirtual

Prepares/enables this object to be deleted. This should be the last function called on this object prior to deleting (or resetting) its shared_ptr.

Warning
  • Attempting to call functions on this object after calling shutdown() can result in undefined behavior.
  • Neglecting to call shutdown() on this object can result in resource leaks or other undefined behavior.

Implements alexaClientSDK::avsCommon::utils::RequiresShutdown.

◆ getCapabilityConfigurations()

std::unordered_set< std::shared_ptr< avsCommon::avs::CapabilityConfiguration > > alexaClientSDK::capabilityAgents::speakerManager::SpeakerManager::getCapabilityConfigurations ( )
overridevirtual

Returns the configurations of the capability interfaces being implemented.

Returns
A set of CapabilityConfigurations

Implements alexaClientSDK::avsCommon::sdkInterfaces::CapabilityConfigurationInterface.

◆ getConfiguration()

DirectiveHandlerConfiguration alexaClientSDK::capabilityAgents::speakerManager::SpeakerManager::getConfiguration ( ) const
overridevirtual

Returns the configuration of the directive handler.

The configuration consists of multiple directive routing rules and their respective blocking policy. The directives will be matched from the most specific rule (with all fields defined) to the least specific rule (which only matches the directive endpointId).

Returns
The avs::DirectiveHandlerConfiguration of the handler.

Implements alexaClientSDK::avsCommon::sdkInterfaces::DirectiveHandlerInterface.

◆ getSpeakerSettings()

std::future< bool > alexaClientSDK::capabilityAgents::speakerManager::SpeakerManager::getSpeakerSettings ( avsCommon::sdkInterfaces::ChannelVolumeInterface::Type  type,
avsCommon::sdkInterfaces::SpeakerInterface::SpeakerSettings settings 
)
overridevirtual

Gets the speaker settings.

Parameters
typeThe type of ChannelVolumeInterface to retrieve settings for.
[out]settingsThe settings if the operation was successful.
Returns
A future to be set with the operation's result. The future must be checked for validity before attempting to obtain the shared state. An invalid future indicates an internal error, and the caller should not assume the operation was successful.

Implements alexaClientSDK::avsCommon::sdkInterfaces::SpeakerManagerInterface.

◆ handleDirective()

void alexaClientSDK::capabilityAgents::speakerManager::SpeakerManager::handleDirective ( std::shared_ptr< avsCommon::avs::CapabilityAgent::DirectiveInfo info)
override

◆ handleDirectiveImmediately()

void alexaClientSDK::capabilityAgents::speakerManager::SpeakerManager::handleDirectiveImmediately ( std::shared_ptr< avsCommon::avs::AVSDirective directive)
override

◆ preHandleDirective()

void alexaClientSDK::capabilityAgents::speakerManager::SpeakerManager::preHandleDirective ( std::shared_ptr< avsCommon::avs::CapabilityAgent::DirectiveInfo info)
override

◆ removeSpeakerManagerObserver()

void alexaClientSDK::capabilityAgents::speakerManager::SpeakerManager::removeSpeakerManagerObserver ( std::shared_ptr< avsCommon::sdkInterfaces::SpeakerManagerObserverInterface observer)
override

◆ setMute() [1/2]

std::future< bool > alexaClientSDK::capabilityAgents::speakerManager::SpeakerManager::setMute ( avsCommon::sdkInterfaces::ChannelVolumeInterface::Type  type,
bool  mute,
const NotificationProperties properties 
)
overridevirtual

Sets the mute for ChannelVolumeInterfaces of a certain Type.

Parameters
typeThe type of ChannelVolumeInterface to modify.
muteA boolean indicating mute. true = mute, false = unmute.
propertiesNotification properties that specify how the mute change will be notified.
Returns
A future to be set with the operation's result. The future must be checked for validity before attempting to obtain the shared state. An invalid future indicates an internal error, and the caller should not assume the operation was successful.

Implements alexaClientSDK::avsCommon::sdkInterfaces::SpeakerManagerInterface.

◆ setMute() [2/2]

std::future< bool > alexaClientSDK::capabilityAgents::speakerManager::SpeakerManager::setMute ( avsCommon::sdkInterfaces::ChannelVolumeInterface::Type  type,
bool  mute,
bool  forceNoNotifications = false,
avsCommon::sdkInterfaces::SpeakerManagerObserverInterface::Source  source = avsCommon::sdkInterfaces::SpeakerManagerObserverInterface::Source::LOCAL_API 
)
overridevirtual
Deprecated:

Sets the mute for ChannelVolumeInterfaces of a certain Type.

Parameters
typeThe type of ChannelVolumeInterface to modify.
muteA boolean indicating mute. true = mute, false = unmute.
forceNoNotificationsSetting this to true will ensure no event is sent and no observer is notified. Setting this to false does not guarantee that a notification will be sent.
sourceWhether the call is a result from an AVS directive or local interaction.
Returns
A future to be set with the operation's result. The future must be checked for validity before attempting to obtain the shared state. An invalid future indicates an internal error, and the caller should not assume the operation was successful.

Implements alexaClientSDK::avsCommon::sdkInterfaces::SpeakerManagerInterface.

◆ setVolume() [1/2]

std::future< bool > alexaClientSDK::capabilityAgents::speakerManager::SpeakerManager::setVolume ( avsCommon::sdkInterfaces::ChannelVolumeInterface::Type  type,
int8_t  volume,
const NotificationProperties properties 
)
overridevirtual

Set the volume for ChannelVolumeInterfaces of a certain Type.

Parameters
typeThe type of ChannelVolumeInterface to modify.
volumeThe volume to set. Values must be between [0,100].
propertiesNotification properties that specify how the volume change will be notified.
Returns
A future to be set with the operation's result. The future must be checked for validity before attempting to obtain the shared state. An invalid future indicates an internal error, and the caller should not assume the operation was successful.

Implements alexaClientSDK::avsCommon::sdkInterfaces::SpeakerManagerInterface.

◆ setVolume() [2/2]

std::future< bool > alexaClientSDK::capabilityAgents::speakerManager::SpeakerManager::setVolume ( avsCommon::sdkInterfaces::ChannelVolumeInterface::Type  type,
int8_t  volume,
bool  forceNoNotifications = false,
avsCommon::sdkInterfaces::SpeakerManagerObserverInterface::Source  source = avsCommon::sdkInterfaces::SpeakerManagerObserverInterface::Source::LOCAL_API 
)
overridevirtual
Deprecated:

Set the volume for ChannelVolumeInterfaces of a certain Type.

Parameters
typeThe type of ChannelVolumeInterface to modify.
volumeThe volume to set. Values must be between [0,100].
forceNoNotificationsSetting this to true will ensure no event is sent and no observer is notified. Setting this to false does not guarantee that a notification will be sent.
sourceWhether the call is a result from an AVS directive or local interaction.
Returns
A future to be set with the operation's result. The future must be checked for validity before attempting to obtain the shared state. An invalid future indicates an internal error, and the caller should not assume the operation was successful.

Implements alexaClientSDK::avsCommon::sdkInterfaces::SpeakerManagerInterface.


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

AlexaClientSDK 1.25.0 - Copyright 2016-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0