AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
LocaleWakeWordsSetting.h
Go to the documentation of this file.
1 /*
2  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License").
5  * You may not use this file except in compliance with the License.
6  * A copy of the License is located at
7  *
8  * http://aws.amazon.com/apache2.0/
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 #ifndef ALEXA_CLIENT_SDK_SETTINGS_INCLUDE_SETTINGS_TYPES_LOCALEWAKEWORDSSETTING_H_
16 #define ALEXA_CLIENT_SDK_SETTINGS_INCLUDE_SETTINGS_TYPES_LOCALEWAKEWORDSSETTING_H_
17 
18 #include <memory>
19 #include <mutex>
20 
24 
30 #include "Settings/SettingStatus.h"
32 
33 namespace alexaClientSDK {
34 namespace settings {
35 namespace types {
36 
41  : public LocalesSetting
42  , public WakeWordsSetting
44 public:
46  using RequestId = unsigned int;
47 
49  enum class RequestType : uint8_t {
51  LOCAL,
53  AVS,
55  NONE
56  };
57 
67  static std::shared_ptr<LocaleWakeWordsSetting> create(
68  std::shared_ptr<SettingEventSenderInterface> localeEventSender,
69  std::shared_ptr<SettingEventSenderInterface> wakeWordsEventSender,
70  std::shared_ptr<storage::DeviceSettingStorageInterface> settingStorage,
71  std::shared_ptr<avsCommon::sdkInterfaces::LocaleAssetsManagerInterface> assetsManager);
72 
75  SetSettingResult setLocalChange(const DeviceLocales& locale) override;
76  bool setAvsChange(const DeviceLocales& locale) override;
77  bool clearData(const DeviceLocales& locale) override;
79 
82  SetSettingResult setLocalChange(const WakeWords& wakeWords) override;
83  bool setAvsChange(const WakeWords& WakeWords) override;
84  bool clearData(const WakeWords& WakeWords) override;
86 
89  void onConnectionStatusChanged(const Status status, const ChangedReason reason) override;
91 
96 
97 private:
101  struct RequestParameters {
103  const RequestId id;
104 
106  const RequestType localeRequestType;
107 
109  const DeviceLocales locales;
110 
112  const RequestType wakeWordsRequestType;
113 
115  const WakeWords wakeWords;
116 
120  RequestParameters(
121  const RequestType localeRequestType,
122  const DeviceLocales& locales,
123  const RequestType wakeWordsRequestType,
124  const WakeWords& wakeWords);
125  };
126 
135  std::shared_ptr<SettingEventSenderInterface> localeEventSender,
136  std::shared_ptr<SettingEventSenderInterface> wakeWordsEventSender,
137  std::shared_ptr<storage::DeviceSettingStorageInterface> settingStorage,
138  std::shared_ptr<avsCommon::sdkInterfaces::LocaleAssetsManagerInterface> assetsManager);
139 
147  SetSettingResult setLocales(const DeviceLocales& locale, RequestType requestType);
148 
156  SetSettingResult setWakeWords(const WakeWords& wakeWords, RequestType requestType);
157 
163  void synchronize(const RequestParameters& request);
164 
170  void synchronizeWakeWords(const RequestParameters& request);
171 
177  void synchronizeLocale(const RequestParameters& request);
178 
184  void handleFailure(const RequestParameters& request);
185 
192  bool storeValues(const RequestParameters& request);
193 
200  void executeChangeValue(const RequestParameters& request);
201 
206  void notifyObserversOfCancellationLocked(const RequestParameters& request);
207  void notifyObserversOfFailure(const RequestParameters& request);
208  void notifyObserversOfSuccess(const RequestParameters& request);
209  void notifyObserversOfChangeInProgress(const RequestParameters& request);
211 
219  inline bool isLatestRequestLocked(const RequestParameters& request) const;
220 
225  void restoreInitialValue();
226 
232  void clearPendingRequest(const RequestParameters& request);
233 
242  std::pair<bool, WakeWords> supportedWakeWords(const DeviceLocales& locale, const WakeWords& wakeWords);
243 
245  std::shared_ptr<SettingEventSenderInterface> m_localeEventSender;
246 
248  std::shared_ptr<SettingEventSenderInterface> m_wakeWordsEventSender;
249 
251  std::shared_ptr<storage::DeviceSettingStorageInterface> m_storage;
252 
254  std::mutex m_mutex;
255 
257  std::unique_ptr<RequestParameters> m_pendingRequest;
258 
260  SettingStatus m_localeStatus;
261 
263  SettingStatus m_wakeWordsStatus;
264 
266  std::shared_ptr<avsCommon::sdkInterfaces::LocaleAssetsManagerInterface> m_assetsManager;
267 
270 };
271 
272 } // namespace types
273 } // namespace settings
274 } // namespace alexaClientSDK
275 
276 #endif // ALEXA_CLIENT_SDK_SETTINGS_INCLUDE_SETTINGS_TYPES_LOCALEWAKEWORDSSETTING_H_
ChangedReason
Definition: ConnectionStatusObserverInterface.h:50
static std::shared_ptr< LocaleWakeWordsSetting > create(std::shared_ptr< SettingEventSenderInterface > localeEventSender, std::shared_ptr< SettingEventSenderInterface > wakeWordsEventSender, std::shared_ptr< storage::DeviceSettingStorageInterface > settingStorage, std::shared_ptr< avsCommon::sdkInterfaces::LocaleAssetsManagerInterface > assetsManager)
Definition: LocaleWakeWordsSetting.h:40
std::set< WakeWord > WakeWords
Alias for a set of wake words type.
Definition: DeviceSettingsManager.h:43
Definition: SettingInterface.h:45
Single-thread executor implementation.
Definition: Executor.h:45
Definition: ConnectionStatusObserverInterface.h:31
SettingStatus
Definition: SettingStatus.h:25
SetSettingResult setLocalChange(const DeviceLocales &locale) override
RequestType
Type of request.
Definition: LocaleWakeWordsSetting.h:49
void onConnectionStatusChanged(const Status status, const ChangedReason reason) override
SetSettingResult
Definition: SetSettingResult.h:23
unsigned int RequestId
Alias for request id.
Definition: LocaleWakeWordsSetting.h:46
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
bool setAvsChange(const DeviceLocales &locale) override
bool clearData(const DeviceLocales &locale) override
std::vector< Locale > DeviceLocales
Alias for locales enabled in the device.
Definition: DeviceSettingsManager.h:37
Status
Definition: ConnectionStatusObserverInterface.h:36

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