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

#include <FocusManager.h>

Inheritance diagram for alexaClientSDK::afml::FocusManager:
Inheritance graph
[legend]
Collaboration diagram for alexaClientSDK::afml::FocusManager:
Collaboration graph
[legend]

Classes

class  ChannelConfiguration
 

Public Member Functions

 FocusManager (const std::vector< ChannelConfiguration > &channelConfigurations, std::shared_ptr< ActivityTrackerInterface > activityTrackerInterface=nullptr, const std::vector< ChannelConfiguration > &virtualChannelConfigurations=std::vector< ChannelConfiguration >(), std::shared_ptr< interruptModel::InterruptModel > interruptModel=nullptr)
 
bool acquireChannel (const std::string &channelName, std::shared_ptr< avsCommon::sdkInterfaces::ChannelObserverInterface > channelObserver, const std::string &interfaceName) override
 
bool acquireChannel (const std::string &channelName, std::shared_ptr< avsCommon::sdkInterfaces::FocusManagerInterface::Activity > channelActivity) override
 
std::future< bool > releaseChannel (const std::string &channelName, std::shared_ptr< avsCommon::sdkInterfaces::ChannelObserverInterface > channelObserver) override
 
void stopForegroundActivity () override
 
void stopAllActivities () override
 
void addObserver (const std::shared_ptr< avsCommon::sdkInterfaces::FocusManagerObserverInterface > &observer) override
 
void removeObserver (const std::shared_ptr< avsCommon::sdkInterfaces::FocusManagerObserverInterface > &observer) override
 
void modifyContentType (const std::string &channelName, const std::string &interfaceName, avsCommon::avs::ContentType contentType) override
 
- Public Member Functions inherited from alexaClientSDK::avsCommon::sdkInterfaces::FocusManagerInterface
virtual ~FocusManagerInterface ()=default
 Destructor. More...
 

Static Public Member Functions

static const std::vector< FocusManager::ChannelConfigurationgetDefaultAudioChannels ()
 
static const std::vector< FocusManager::ChannelConfigurationgetDefaultVisualChannels ()
 

Additional Inherited Members

- Static Public Attributes inherited from alexaClientSDK::avsCommon::sdkInterfaces::FocusManagerInterface
static constexpr const char * DIALOG_CHANNEL_NAME = "Dialog"
 The default Dialog Channel name. More...
 
static constexpr unsigned int DIALOG_CHANNEL_PRIORITY = 100
 The default dialog Channel priority. More...
 
static constexpr const char * COMMUNICATIONS_CHANNEL_NAME = "Communications"
 The default Communications Channel name. More...
 
static constexpr unsigned int COMMUNICATIONS_CHANNEL_PRIORITY = 150
 The default Communications Channel priority. More...
 
static constexpr const char * ALERT_CHANNEL_NAME = "Alert"
 The default Alert Channel name. More...
 
static constexpr unsigned int ALERT_CHANNEL_PRIORITY = 200
 The default Alert Channel priority. More...
 
static constexpr const char * CONTENT_CHANNEL_NAME = "Content"
 The default Content Channel name. More...
 
static constexpr unsigned int CONTENT_CHANNEL_PRIORITY = 300
 The default Content Channel priority. More...
 
static constexpr const char * VISUAL_CHANNEL_NAME = "Visual"
 The default Visual Channel name. More...
 
static constexpr unsigned int VISUAL_CHANNEL_PRIORITY = 100
 The default Visual Channel priority. More...
 

Detailed Description

The FocusManager takes requests to acquire and release Channels and updates the focuses of other Channels based on their priorities so that the invariant that there can only be one Foreground Channel is held. The following operations are provided:

acquire Channel - clients should call the acquireChannel() method, passing in the name of the Channel they wish to acquire, a pointer to the observer that they want to be notified once they get focus, and a unique interface name.

release Channel - clients should call the releaseChannel() method, passing in the name of the Channel and the observer of the Channel they wish to release.

stop foreground Channel - clients should call the stopForegroundActivity() method.

All of these methods will notify the observer of the Channel of focus changes via an asynchronous callback to the ChannelObserverInterface##onFocusChanged() method, at which point the client should make a user observable change based on the focus it receives.

Constructor & Destructor Documentation

◆ FocusManager()

alexaClientSDK::afml::FocusManager::FocusManager ( const std::vector< ChannelConfiguration > &  channelConfigurations,
std::shared_ptr< ActivityTrackerInterface activityTrackerInterface = nullptr,
const std::vector< ChannelConfiguration > &  virtualChannelConfigurations = std::vector<ChannelConfiguration>(),
std::shared_ptr< interruptModel::InterruptModel interruptModel = nullptr 
)

This constructor creates Channels based on the provided configurations.

Parameters
channelConfigurationsA vector of channelConfiguration objects that will be used to create the Channels. No two Channels should have the same name or priority. If there are multiple configurations with the same name or priority, the latter Channels with that name or priority will not be created.
activityTrackerInterfaceThe interface to notify the activity tracker a vector of channel states that has been updated.
virtualChannelConfigurationsA vector of channelConfiguration objects that will be used to create the Virtual Channels. No two Channels should have the same name or priority. If there are multiple configurations with the same name or priority, the latter Channels with that name or priority will not be created.
interruptModelInterruptModel object that provides MixingBehavior inputs to ChannelObservers upon Focus State Change.

Member Function Documentation

◆ acquireChannel() [1/2]

bool alexaClientSDK::afml::FocusManager::acquireChannel ( const std::string &  channelName,
std::shared_ptr< avsCommon::sdkInterfaces::ChannelObserverInterface channelObserver,
const std::string &  interfaceName 
)
overridevirtual

This method will acquire the channel and grant the appropriate focus to it and other channels if needed. The caller will be notified via an ChannelObserverInterface##onFocusChanged() call to the channelObserver when it can start the activity.

Parameters
channelNameThe name of the Channel to acquire.
channelObserverThe observer that will be acquiring the Channel and be notified of focus changes.
interfaceNameThe name of the AVS interface occupying the Channel. This should be unique and represents the name of the AVS interface using the Channel. The name of the AVS interface is used by the ActivityTracker to send Context to AVS.
Returns
Returns true if the Channel can be acquired and false otherwise.

Implements alexaClientSDK::avsCommon::sdkInterfaces::FocusManagerInterface.

◆ acquireChannel() [2/2]

bool alexaClientSDK::afml::FocusManager::acquireChannel ( const std::string &  channelName,
std::shared_ptr< avsCommon::sdkInterfaces::FocusManagerInterface::Activity channelActivity 
)
overridevirtual

This method will acquire the channel and grant the appropriate focus to it and other channels if needed. The caller will be notified via an ChannelObserverInterface##onFocusChanged() call to the channelObserver when it can start the activity.

Parameters
channelNameThe name of the Channel to acquire.
channelActivityActivity object associated with the Channel.
Returns
Returns true if the Channel can be acquired and false otherwise.

Implements alexaClientSDK::avsCommon::sdkInterfaces::FocusManagerInterface.

◆ addObserver()

void alexaClientSDK::afml::FocusManager::addObserver ( const std::shared_ptr< avsCommon::sdkInterfaces::FocusManagerObserverInterface > &  observer)
overridevirtual

Add an observer to the focus manager.

Parameters
observerThe observer to add.

Implements alexaClientSDK::avsCommon::sdkInterfaces::FocusManagerInterface.

◆ getDefaultAudioChannels()

const std::vector< FocusManager::ChannelConfiguration > alexaClientSDK::afml::FocusManager::getDefaultAudioChannels ( )
static

Retrieves the default ChannelConfiguration for AVS audio channels.

Returns
the default ChannelConfiguration for AVS audio channels.

◆ getDefaultVisualChannels()

const std::vector< FocusManager::ChannelConfiguration > alexaClientSDK::afml::FocusManager::getDefaultVisualChannels ( )
static

Retrieves the default ChannelConfiguration for AVS visual channels.

Returns
the default ChannelConfiguration for AVS visual channels.

◆ modifyContentType()

void alexaClientSDK::afml::FocusManager::modifyContentType ( const std::string &  channelName,
const std::string &  interfaceName,
avsCommon::avs::ContentType  contentType 
)
overridevirtual

This function allows ChannelObservers to modify the ContentType rendering on their associated Activity This will cause the focus manager to reconsult the interruptModel in order to determine the new MixingBehavior for all backgrounded channels.

Parameters
channelNamethe channel associated with the ChannelObserver
interfaceNamethe interface name associated with the ChannelObserver
contentTypethe new content type

Implements alexaClientSDK::avsCommon::sdkInterfaces::FocusManagerInterface.

◆ releaseChannel()

std::future< bool > alexaClientSDK::afml::FocusManager::releaseChannel ( const std::string &  channelName,
std::shared_ptr< avsCommon::sdkInterfaces::ChannelObserverInterface channelObserver 
)
overridevirtual

This method will release the Channel and notify the observer of the Channel, if the observer is the same as the observer passed in the acquireChannel call, to stop via ChannelObserverInterface##onFocusChanged(). If the Channel to release is the current foreground focused Channel, it will also notify the next highest priority Channel via an ChannelObserverInterface##onFocusChanged() callback that it has gained foreground focus.

Parameters
channelNameThe name of the Channel to release.
channelObserverThe observer to be released from the Channel.
Returns
std::future<bool> which will contain true if the Channel can be released and false otherwise.

Implements alexaClientSDK::avsCommon::sdkInterfaces::FocusManagerInterface.

◆ removeObserver()

void alexaClientSDK::afml::FocusManager::removeObserver ( const std::shared_ptr< avsCommon::sdkInterfaces::FocusManagerObserverInterface > &  observer)
overridevirtual

Remove an observer from the focus manager.

Parameters
observerThe observer to remove.

Implements alexaClientSDK::avsCommon::sdkInterfaces::FocusManagerInterface.

◆ stopAllActivities()

void alexaClientSDK::afml::FocusManager::stopAllActivities ( )
overridevirtual

This method will request to stop all active channels. This will be performed asynchronously, and so, if at the time performing the stop, the channel is owned by another interface, this channel won't get stopped.

Implements alexaClientSDK::avsCommon::sdkInterfaces::FocusManagerInterface.

◆ stopForegroundActivity()

void alexaClientSDK::afml::FocusManager::stopForegroundActivity ( )
overridevirtual

This method will request that the currently foregrounded Channel activity be stopped, if there is one. This will be performed asynchronously, and so, if at the time of processing, the activity has stopped for any reason, then no stop will be performed. If something was stopped, the next highest priority active Channel will be brought to the foreground.

Implements alexaClientSDK::avsCommon::sdkInterfaces::FocusManagerInterface.


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