AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
Public Types | Static Public Member Functions | List of all members
alexaClientSDK::settings::Setting< ValueT > Class Template Reference

#include <Setting.h>

Inheritance diagram for alexaClientSDK::settings::Setting< ValueT >:
Inheritance graph
[legend]
Collaboration diagram for alexaClientSDK::settings::Setting< ValueT >:
Collaboration graph
[legend]

Public Types

using ValueType = ValueT
 Define an alias for setting value type. More...
 
- Public Types inherited from alexaClientSDK::settings::SettingInterface< ValueT >
using ValueType = ValueT
 Define the setting value type. More...
 
using ObserverType = SettingObserverInterface< SettingInterface< ValueType > >
 Define the observer type for this setting. More...
 

Public Member Functions

SettingInterface methods.
SetSettingResult setLocalChange (const ValueType &value) override
 
bool setAvsChange (const ValueType &value) override
 
bool clearData (const ValueType &value) override
 
- Public Member Functions inherited from alexaClientSDK::settings::SettingInterface< ValueT >
virtual ~SettingInterface ()=default
 
ValueType get () const
 
ValueType getDefault () const
 
bool addObserver (std::shared_ptr< ObserverType > observer)
 
void removeObserver (std::shared_ptr< ObserverType > &observer)
 

Static Public Member Functions

static std::shared_ptr< Setting< ValueT > > create (const ValueType &defaultValue, std::unique_ptr< SettingProtocolInterface > settingProtocol, std::function< bool(const ValueType &)> applyValueFn=std::function< bool(const ValueType &)>())
 

Additional Inherited Members

- Protected Types inherited from alexaClientSDK::settings::SettingInterface< ValueT >
using GuardedValue = avsCommon::utils::GuardedValue< ValueType >
 Alias for GuardedValue with the templated value ValueType. More...
 
using LogEntry = avsCommon::utils::logger::LogEntry
 Alias to make log entries less verbose. More...
 
- Protected Member Functions inherited from alexaClientSDK::settings::SettingInterface< ValueT >
 SettingInterface (const ValueType &value)
 
void notifyObservers (SettingNotifications notification)
 
- Protected Attributes inherited from alexaClientSDK::settings::SettingInterface< ValueT >
std::mutex m_observerMutex
 Mutex used to guard observers. More...
 
std::unordered_set< std::shared_ptr< ObserverType > > m_observers
 Set of all observers of this setting. More...
 
std::conditional< std::is_scalar< ValueType >::value, std::atomic< ValueType >, GuardedValue >::type m_value
 The setting value. (is_trivially_copyable is not supported on gcc4.8) More...
 
const ValueType m_defaultValue
 The default setting value. More...
 

Detailed Description

template<typename ValueT>
class alexaClientSDK::settings::Setting< ValueT >

The setting class implements the setting interface for the given value.

This class provide methods to set value through local request (set method) and through AVS request (setAvsChange). This setting should also be able to persist the current value as well as revert to previous value if a transaction fails.

The setting can be configured to use multiple avs synchronization protocols. See SettingProtocolInterface.

Template Parameters
ValueTThe type of the value used to represent a given setting.

Member Typedef Documentation

◆ ValueType

template<typename ValueT >
using alexaClientSDK::settings::Setting< ValueT >::ValueType = ValueT

Define an alias for setting value type.

Member Function Documentation

◆ clearData()

template<typename ValueT >
bool alexaClientSDK::settings::Setting< ValueT >::clearData ( const ValueType value)
overridevirtual

Clear the data this Setting.

Parameters
valueThe default value for this setting.
Returns
true if it data is cleared; otherwise.

Implements alexaClientSDK::settings::SettingInterface< ValueT >.

◆ create()

template<typename ValueT >
std::shared_ptr< Setting< ValueT > > alexaClientSDK::settings::Setting< ValueT >::create ( const ValueType defaultValue,
std::unique_ptr< SettingProtocolInterface settingProtocol,
std::function< bool(const ValueType &)>  applyValueFn = std::function<bool(const ValueType&)>() 
)
static

Create a Setting object.

Parameters
defaultValueThe default value to be used if no value was found in the storage.
settingProtocolThe avs protocol used to persist and synchronize values with avs.
applyValueFnFunction responsible for validating and applying a new setting value to the device.
Note
The applyValueFn should succeed if there is no value change.
Returns
A pointer to the new object if it succeeds; nullptr otherwise.

◆ setAvsChange()

template<typename ValueT >
bool alexaClientSDK::settings::Setting< ValueT >::setAvsChange ( const ValueType value)
overridevirtual

Request to set the managed setting to the given value. This should be used when the request came from AVS.

Parameters
valueThe target value.
Returns
true if it succeeds to enqueue the request; otherwise.

Implements alexaClientSDK::settings::SettingInterface< ValueT >.

◆ setLocalChange()

template<typename ValueT >
SetSettingResult alexaClientSDK::settings::Setting< ValueT >::setLocalChange ( const ValueType value)
overridevirtual

Request to set the managed setting to the given value. Note that this is an asynchronous operation.

Parameters
valueThe target value.
Returns
The result of the enqueue operation.

Implements alexaClientSDK::settings::SettingInterface< ValueT >.


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

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