AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
DoNotDisturbCapabilityAgent.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 ACSDKDONOTDISTURB_DONOTDISTURBCAPABILITYAGENT_H_
17 #define ACSDKDONOTDISTURB_DONOTDISTURBCAPABILITYAGENT_H_
18 
19 #include <atomic>
20 #include <memory>
21 #include <mutex>
22 
23 #include <rapidjson/document.h>
24 
39 #include <Settings/Setting.h>
45 
46 namespace alexaClientSDK {
47 namespace capabilityAgents {
48 namespace doNotDisturb {
49 
58  : public std::enable_shared_from_this<DoNotDisturbCapabilityAgent>
64 public:
68  ~DoNotDisturbCapabilityAgent() override = default;
69 
83  static std::shared_ptr<DoNotDisturbCapabilityAgent> createDoNotDisturbCapabilityAgent(
84  const std::shared_ptr<alexaClientSDK::avsCommon::sdkInterfaces::MessageSenderInterface>& messageSender,
85  const std::shared_ptr<alexaClientSDK::settings::storage::DeviceSettingStorageInterface>& settingsStorage,
86  const std::shared_ptr<alexaClientSDK::avsCommon::sdkInterfaces::ExceptionEncounteredSenderInterface>&
87  exceptionSender,
88  const std::shared_ptr<acsdkShutdownManagerInterfaces::ShutdownNotifierInterface>& shutdownNotifier,
92  endpointCapabilitiesRegistrar,
93  const std::shared_ptr<alexaClientSDK::avsCommon::sdkInterfaces::AVSConnectionManagerInterface>&
94  connectionManager,
95  const std::shared_ptr<alexaClientSDK::avsCommon::utils::metrics::MetricRecorderInterface>& metricRecorder);
96 
106  static std::shared_ptr<DoNotDisturbCapabilityAgent> create(
107  std::shared_ptr<alexaClientSDK::avsCommon::sdkInterfaces::ExceptionEncounteredSenderInterface>
108  exceptionEncounteredSender,
109  std::shared_ptr<alexaClientSDK::avsCommon::sdkInterfaces::MessageSenderInterface> messageSender,
110  std::shared_ptr<settings::storage::DeviceSettingStorageInterface> settingsStorage);
111 
115  void handleDirectiveImmediately(std::shared_ptr<alexaClientSDK::avsCommon::avs::AVSDirective> directive) override;
116  void preHandleDirective(
117  std::shared_ptr<alexaClientSDK::avsCommon::avs::CapabilityAgent::DirectiveInfo> info) override;
118  void handleDirective(std::shared_ptr<alexaClientSDK::avsCommon::avs::CapabilityAgent::DirectiveInfo> info) override;
119  void cancelDirective(std::shared_ptr<alexaClientSDK::avsCommon::avs::CapabilityAgent::DirectiveInfo> info) override;
121 
124  std::unordered_set<std::shared_ptr<alexaClientSDK::avsCommon::avs::CapabilityConfiguration>>
125  getCapabilityConfigurations() override;
127 
128  // @name RequiresShutdown Functions
130  void doShutdown() override;
132 
135  std::shared_future<bool> sendChangedEvent(const std::string& value) override;
136  std::shared_future<bool> sendReportEvent(const std::string& value) override;
137  std::shared_future<bool> sendStateReportEvent(const std::string& payload) override;
138  void cancel() override;
140 
143  void onConnectionStatusChanged(const Status status, const ChangedReason reason) override;
145 
151  std::shared_ptr<settings::DoNotDisturbSetting> getDoNotDisturbSetting() const;
152 
159 
160 private:
169  std::shared_ptr<alexaClientSDK::avsCommon::sdkInterfaces::ExceptionEncounteredSenderInterface>
170  exceptionEncounteredSender,
171  std::shared_ptr<alexaClientSDK::avsCommon::sdkInterfaces::MessageSenderInterface> messageSender,
172  std::shared_ptr<alexaClientSDK::avsCommon::sdkInterfaces::AVSConnectionManagerInterface> connectionManager);
173 
184  static std::shared_ptr<DoNotDisturbCapabilityAgent> create(
185  const std::shared_ptr<alexaClientSDK::avsCommon::sdkInterfaces::MessageSenderInterface>& messageSender,
186  const std::shared_ptr<alexaClientSDK::settings::storage::DeviceSettingStorageInterface>& settingsStorage,
187  const std::shared_ptr<alexaClientSDK::avsCommon::sdkInterfaces::ExceptionEncounteredSenderInterface>&
188  exceptionSender,
189  const std::shared_ptr<alexaClientSDK::avsCommon::sdkInterfaces::AVSConnectionManagerInterface>&
190  connectionManager = nullptr,
191  const std::shared_ptr<alexaClientSDK::avsCommon::utils::metrics::MetricRecorderInterface>& metricRecorder =
192  nullptr);
193 
200  bool initialize(
201  std::shared_ptr<settings::storage::DeviceSettingStorageInterface> settingsStorage,
202  const std::shared_ptr<avsCommon::utils::metrics::MetricRecorderInterface>& metricRecorder);
203 
211  std::shared_future<alexaClientSDK::avsCommon::sdkInterfaces::MessageRequestObserverInterface::Status> sendDNDEvent(
212  const std::string& eventName,
213  const std::string& value);
214 
218  void generateCapabilityConfiguration();
219 
228  bool handleSetDoNotDisturbDirective(
229  std::shared_ptr<alexaClientSDK::avsCommon::avs::CapabilityAgent::DirectiveInfo> info,
230  rapidjson::Document& document);
231 
233  std::unordered_set<std::shared_ptr<alexaClientSDK::avsCommon::avs::CapabilityConfiguration>>
234  m_capabilityConfigurations;
235 
237  std::shared_ptr<alexaClientSDK::avsCommon::sdkInterfaces::MessageSenderInterface> m_messageSender;
238 
241  std::shared_ptr<alexaClientSDK::avsCommon::sdkInterfaces::AVSConnectionManagerInterface> m_connectionManager;
242 
244  std::shared_ptr<alexaClientSDK::settings::Setting<bool>> m_dndModeSetting;
245 
250  bool m_isConnected;
251 
253  std::mutex m_connectedStateMutex;
254 
256  std::atomic_bool m_hasOfflineChanges;
257 
260 };
261 
262 } // namespace doNotDisturb
263 } // namespace capabilityAgents
264 } // namespace alexaClientSDK
265 
266 #endif // ACSDKDONOTDISTURB_DONOTDISTURBCAPABILITYAGENT_H_
std::shared_future< bool > sendChangedEvent(const std::string &value) override
Definition: CapabilityAgent.h:47
static std::shared_ptr< DoNotDisturbCapabilityAgent > createDoNotDisturbCapabilityAgent(const std::shared_ptr< alexaClientSDK::avsCommon::sdkInterfaces::MessageSenderInterface > &messageSender, const std::shared_ptr< alexaClientSDK::settings::storage::DeviceSettingStorageInterface > &settingsStorage, const std::shared_ptr< alexaClientSDK::avsCommon::sdkInterfaces::ExceptionEncounteredSenderInterface > &exceptionSender, const std::shared_ptr< acsdkShutdownManagerInterfaces::ShutdownNotifierInterface > &shutdownNotifier, const acsdkManufactory::Annotated< alexaClientSDK::avsCommon::sdkInterfaces::endpoints::DefaultEndpointAnnotation, alexaClientSDK::avsCommon::sdkInterfaces::endpoints::EndpointCapabilitiesRegistrarInterface > &endpointCapabilitiesRegistrar, const std::shared_ptr< alexaClientSDK::avsCommon::sdkInterfaces::AVSConnectionManagerInterface > &connectionManager, const std::shared_ptr< alexaClientSDK::avsCommon::utils::metrics::MetricRecorderInterface > &metricRecorder)
Definition: SettingEventMetadata.h:27
ChangedReason
Definition: ConnectionStatusObserverInterface.h:50
void handleDirective(std::shared_ptr< alexaClientSDK::avsCommon::avs::CapabilityAgent::DirectiveInfo > info) override
void onConnectionStatusChanged(const Status status, const ChangedReason reason) override
::std::string string
Definition: gtest-port.h:1097
Single-thread executor implementation.
Definition: Executor.h:45
Definition: ConnectionStatusObserverInterface.h:31
void preHandleDirective(std::shared_ptr< alexaClientSDK::avsCommon::avs::CapabilityAgent::DirectiveInfo > info) override
std::unordered_set< std::shared_ptr< alexaClientSDK::avsCommon::avs::CapabilityConfiguration > > getCapabilityConfigurations() override
static std::shared_ptr< avsCommon::utils::metrics::MetricRecorderInterface > metricRecorder
Metric recorder shared ptr.
Definition: BaseAPLCapabilityAgentTest.cpp:261
std::unordered_map< directiveRoutingRule::DirectiveRoutingRule, BlockingPolicy > DirectiveHandlerConfiguration
Definition: DirectiveHandlerConfiguration.h:32
std::shared_ptr< settings::DoNotDisturbSetting > getDoNotDisturbSetting() const
Definition: SettingEventSenderInterface.h:29
void handleDirectiveImmediately(std::shared_ptr< alexaClientSDK::avsCommon::avs::AVSDirective > directive) override
static std::shared_ptr< DoNotDisturbCapabilityAgent > create(std::shared_ptr< alexaClientSDK::avsCommon::sdkInterfaces::ExceptionEncounteredSenderInterface > exceptionEncounteredSender, std::shared_ptr< alexaClientSDK::avsCommon::sdkInterfaces::MessageSenderInterface > messageSender, std::shared_ptr< settings::storage::DeviceSettingStorageInterface > settingsStorage)
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
std::shared_future< bool > sendReportEvent(const std::string &value) override
alexaClientSDK::avsCommon::avs::DirectiveHandlerConfiguration getConfiguration() const override
Status
Definition: ConnectionStatusObserverInterface.h:36
void cancelDirective(std::shared_ptr< alexaClientSDK::avsCommon::avs::CapabilityAgent::DirectiveInfo > info) override
std::shared_future< bool > sendStateReportEvent(const std::string &payload) 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