AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
SharedAVSSettingProtocol.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 
16 #ifndef ALEXA_CLIENT_SDK_SETTINGS_INCLUDE_SETTINGS_SHAREDAVSSETTINGPROTOCOL_H_
17 #define ALEXA_CLIENT_SDK_SETTINGS_INCLUDE_SETTINGS_SHAREDAVSSETTINGPROTOCOL_H_
18 
19 #include <functional>
20 #include <memory>
21 #include <mutex>
22 #include <string>
23 #include <utility>
24 
28 
35 #include "Settings/SettingStatus.h"
37 
38 namespace alexaClientSDK {
39 namespace settings {
40 
46 public:
61  static std::unique_ptr<SharedAVSSettingProtocol> create(
62  const SettingEventMetadata& metadata,
63  std::shared_ptr<SettingEventSenderInterface> eventSender,
64  std::shared_ptr<storage::DeviceSettingStorageInterface> settingStorage,
65  std::shared_ptr<avsCommon::sdkInterfaces::AVSConnectionManagerInterface> connectionManager,
66  const std::shared_ptr<avsCommon::utils::metrics::MetricRecorderInterface>& metricRecorder,
67  bool isDefaultCloudAuthoritative = false);
68 
72  ApplyChangeFunction applyChange,
73  RevertChangeFunction revertChange,
74  SettingNotificationFunction notifyObservers) override;
75 
76  bool avsChange(
77  ApplyChangeFunction applyChange,
78  RevertChangeFunction revertChange,
79  SettingNotificationFunction notifyObservers) override;
80 
81  bool restoreValue(ApplyDbChangeFunction applyChange, SettingNotificationFunction notifyObservers) override;
82  bool clearData() override;
84 
89  void connectionStatusChangeCallback(bool isConnected);
90 
96 
97 private:
101  struct Request {
109  Request(ApplyChangeFunction applyFn, RevertChangeFunction revertFn, SettingNotificationFunction notifyFn);
110 
112  ApplyChangeFunction applyChange;
113 
115  RevertChangeFunction revertChange;
116 
118  SettingNotificationFunction notifyObservers;
119  };
120 
134  const std::string& settingKey,
135  std::shared_ptr<SettingEventSenderInterface> eventSender,
136  std::shared_ptr<storage::DeviceSettingStorageInterface> settingStorage,
137  std::shared_ptr<avsCommon::sdkInterfaces::AVSConnectionManagerInterface> connectionManager,
138  const std::shared_ptr<avsCommon::utils::metrics::MetricRecorderInterface>& metricRecorder,
139  bool isDefaultCloudAuthoritative);
140 
144  void executeSynchronizeOnConnected();
145 
147  const std::string m_key;
148 
150  const bool m_isDefaultCloudAuthoritative;
151 
153  std::shared_ptr<SettingEventSenderInterface> m_eventSender;
154 
156  std::shared_ptr<storage::DeviceSettingStorageInterface> m_storage;
157 
159  std::shared_ptr<avsCommon::sdkInterfaces::AVSConnectionManagerInterface> m_connectionManager;
160 
162  std::shared_ptr<SettingConnectionObserver> m_connectionObserver;
163 
165  std::unique_ptr<Request> m_pendingRequest;
166 
167  std::shared_ptr<avsCommon::utils::metrics::MetricRecorderInterface> m_metricRecorder;
168 
170  std::mutex m_requestLock;
171 
174 };
175 
176 } // namespace settings
177 } // namespace alexaClientSDK
178 
179 #endif // ALEXA_CLIENT_SDK_SETTINGS_INCLUDE_SETTINGS_SHAREDAVSSETTINGPROTOCOL_H_
std::function< std::pair< bool, std::string >()> ApplyChangeFunction
Definition: SettingProtocolInterface.h:46
static std::unique_ptr< SharedAVSSettingProtocol > create(const SettingEventMetadata &metadata, std::shared_ptr< SettingEventSenderInterface > eventSender, std::shared_ptr< storage::DeviceSettingStorageInterface > settingStorage, std::shared_ptr< avsCommon::sdkInterfaces::AVSConnectionManagerInterface > connectionManager, const std::shared_ptr< avsCommon::utils::metrics::MetricRecorderInterface > &metricRecorder, bool isDefaultCloudAuthoritative=false)
bool restoreValue(ApplyDbChangeFunction applyChange, SettingNotificationFunction notifyObservers) override
std::function< std::pair< bool, std::string >(const std::string &dbValue)> ApplyDbChangeFunction
Definition: SettingProtocolInterface.h:56
Definition: SettingEventMetadata.h:27
::std::string string
Definition: gtest-port.h:1097
bool avsChange(ApplyChangeFunction applyChange, RevertChangeFunction revertChange, SettingNotificationFunction notifyObservers) override
Single-thread executor implementation.
Definition: Executor.h:45
std::function< void(SettingNotifications notification)> SettingNotificationFunction
Definition: SettingProtocolInterface.h:63
static std::shared_ptr< avsCommon::utils::metrics::MetricRecorderInterface > metricRecorder
Metric recorder shared ptr.
Definition: BaseAPLCapabilityAgentTest.cpp:261
Definition: SharedAVSSettingProtocol.h:45
std::function< std::string()> RevertChangeFunction
Definition: SettingProtocolInterface.h:70
SetSettingResult
Definition: SetSettingResult.h:23
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
Definition: SettingProtocolInterface.h:38
SetSettingResult localChange(ApplyChangeFunction applyChange, RevertChangeFunction revertChange, SettingNotificationFunction notifyObservers) override

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