AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
AlertsCapabilityAgent.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_ACSDKALERTS_INCLUDE_ACSDKALERTS_ALERTSCAPABILITYAGENT_H_
17 #define ALEXA_CLIENT_SDK_ACSDKALERTS_INCLUDE_ACSDKALERTS_ALERTSCAPABILITYAGENT_H_
18 
19 #include <chrono>
20 #include <set>
21 #include <string>
22 #include <unordered_set>
23 
51 #include <Settings/Setting.h>
53 
54 #include "acsdkAlerts/Alert.h"
56 
57 namespace alexaClientSDK {
58 namespace acsdkAlerts {
59 
60 static const std::chrono::minutes ALERT_PAST_DUE_CUTOFF_MINUTES = std::chrono::minutes(30);
61 
76  , public std::enable_shared_from_this<AlertsCapabilityAgent> {
77 public:
102  static std::shared_ptr<AlertsCapabilityAgentInterface> createAlertsCapabilityAgent(
103  const std::shared_ptr<acsdkAlerts::renderer::Renderer>& alertRenderer,
104  const std::shared_ptr<acsdkShutdownManagerInterfaces::ShutdownNotifierInterface>& shutdownNotifier,
105  const std::shared_ptr<avsCommon::sdkInterfaces::AVSConnectionManagerInterface>& connectionManager,
106  const std::shared_ptr<avsCommon::sdkInterfaces::ContextManagerInterface>& contextManager,
107  const std::shared_ptr<avsCommon::sdkInterfaces::ExceptionEncounteredSenderInterface>&
108  exceptionEncounteredSender,
112  const std::shared_ptr<avsCommon::sdkInterfaces::MessageSenderInterface>& messageSender,
113  const std::shared_ptr<avsCommon::sdkInterfaces::SpeakerManagerInterface>& speakerManager,
114  const std::shared_ptr<avsCommon::sdkInterfaces::audio::AudioFactoryInterface>& audioFactory,
118  const std::shared_ptr<avsCommon::utils::metrics::MetricRecorderInterface>& metricRecorder,
119  const std::shared_ptr<acsdkSystemClockMonitorInterfaces::SystemClockNotifierInterface>& systemClockMonitor,
120  const std::shared_ptr<certifiedSender::CertifiedSender>& certifiedSender,
121  const std::shared_ptr<registrationManager::CustomerDataManagerInterface>& dataManager,
122  const std::shared_ptr<settings::DeviceSettingsManager>& settingsManager,
123  const std::shared_ptr<storage::AlertStorageInterface>& alertStorage,
124  bool startAlertSchedulingOnInitialization = true);
125 
149  static std::shared_ptr<AlertsCapabilityAgent> create(
150  std::shared_ptr<avsCommon::sdkInterfaces::MessageSenderInterface> messageSender,
151  std::shared_ptr<avsCommon::sdkInterfaces::AVSConnectionManagerInterface> connectionManager,
152  std::shared_ptr<certifiedSender::CertifiedSender> certifiedMessageSender,
153  std::shared_ptr<avsCommon::sdkInterfaces::FocusManagerInterface> focusManager,
154  std::shared_ptr<avsCommon::sdkInterfaces::SpeakerManagerInterface> speakerManager,
155  std::shared_ptr<avsCommon::sdkInterfaces::ContextManagerInterface> contextManager,
156  std::shared_ptr<avsCommon::sdkInterfaces::ExceptionEncounteredSenderInterface> exceptionEncounteredSender,
157  std::shared_ptr<storage::AlertStorageInterface> alertStorage,
158  std::shared_ptr<avsCommon::sdkInterfaces::audio::AlertsAudioFactoryInterface> alertsAudioFactory,
159  std::shared_ptr<renderer::RendererInterface> alertRenderer,
160  std::shared_ptr<registrationManager::CustomerDataManagerInterface> dataManager,
161  std::shared_ptr<settings::AlarmVolumeRampSetting> alarmVolumeRampSetting,
162  std::shared_ptr<settings::DeviceSettingsManager> settingsManager,
163  std::shared_ptr<avsCommon::utils::metrics::MetricRecorderInterface> metricRecorder = nullptr,
164  bool startAlertSchedulingOnInitialization = true,
165  std::shared_ptr<acsdkSystemClockMonitorInterfaces::SystemClockNotifierInterface> systemClockMonitor = nullptr);
166 
170 
171  void handleDirectiveImmediately(std::shared_ptr<avsCommon::avs::AVSDirective> directive) override;
172 
173  void preHandleDirective(std::shared_ptr<DirectiveInfo> info) override;
174 
175  void handleDirective(std::shared_ptr<DirectiveInfo> info) override;
176 
177  void cancelDirective(std::shared_ptr<DirectiveInfo> info) override;
178 
179  void onDeregistered() override;
180 
181  void onConnectionStatusChanged(const Status status, const ChangedReason reason) override;
182 
185 
188  void onAlertStateChange(const AlertInfo& alertInfo) override;
190 
193  void onFocusChanged(const std::string& channelName, avsCommon::avs::FocusState newFocus) override;
195 
198  std::unordered_set<std::shared_ptr<avsCommon::avs::CapabilityConfiguration>> getCapabilityConfigurations() override;
200 
204  const Source& source,
208 
211  void onSystemClockSynchronized() override;
213 
216 
219  void clearData() override;
221 
224  void addObserver(std::shared_ptr<acsdkAlertsInterfaces::AlertObserverInterface> observer) override;
225  void removeObserver(std::shared_ptr<acsdkAlertsInterfaces::AlertObserverInterface> observer) override;
226  void removeAllAlerts() override;
227  void onLocalStop() override;
229 
236 
242  int getAlertVolume();
243 
244 private:
265  std::shared_ptr<avsCommon::sdkInterfaces::MessageSenderInterface> messageSender,
266  std::shared_ptr<certifiedSender::CertifiedSender> certifiedMessageSender,
267  std::shared_ptr<avsCommon::sdkInterfaces::FocusManagerInterface> focusManager,
268  std::shared_ptr<avsCommon::sdkInterfaces::SpeakerManagerInterface> speakerManager,
269  std::shared_ptr<avsCommon::sdkInterfaces::ContextManagerInterface> contextManager,
270  std::shared_ptr<avsCommon::sdkInterfaces::ExceptionEncounteredSenderInterface> exceptionEncounteredSender,
271  std::shared_ptr<storage::AlertStorageInterface> alertStorage,
272  std::shared_ptr<avsCommon::sdkInterfaces::audio::AlertsAudioFactoryInterface> alertsAudioFactory,
273  std::shared_ptr<renderer::RendererInterface> alertRenderer,
274  std::shared_ptr<registrationManager::CustomerDataManagerInterface> dataManager,
275  std::shared_ptr<settings::AlarmVolumeRampSetting> alarmVolumeRampSetting,
276  std::shared_ptr<settings::DeviceSettingsManager> settingsManager,
277  std::shared_ptr<avsCommon::utils::metrics::MetricRecorderInterface> metricRecorder,
278  std::shared_ptr<acsdkSystemClockMonitorInterfaces::SystemClockNotifierInterface> systemClockMonitor);
279 
280  void doShutdown() override;
281 
289  bool initialize(bool startAlertSchedulingOnInitialization = true);
290 
298  bool initializeAlerts(bool startAlertSchedulingOnInitialization = true);
299 
310 
317  void executeHandleDirectiveImmediately(std::shared_ptr<DirectiveInfo> info);
318 
325  void executeOnConnectionStatusChanged(const Status status, const ChangedReason reason);
326 
331  void executeOnSpeakerSettingsChanged(
334 
340  void executeOnAlertStateChange(const acsdkAlertsInterfaces::AlertObserverInterface::AlertInfo& alertInfo);
341 
347  void executeAddObserver(std::shared_ptr<acsdkAlertsInterfaces::AlertObserverInterface> observer);
348 
354  void executeRemoveObserver(std::shared_ptr<acsdkAlertsInterfaces::AlertObserverInterface> observer);
355 
361  void executeNotifyObservers(const acsdkAlertsInterfaces::AlertObserverInterface::AlertInfo& alertInfo);
362 
366  void executeRemoveAllAlerts();
367 
371  void executeOnLocalStop();
372 
382  bool handleSetAlert(
383  const std::shared_ptr<avsCommon::avs::AVSDirective>& directive,
384  const rapidjson::Document& payload,
385  std::string* alertToken);
386 
396  bool handleDeleteAlert(
397  const std::shared_ptr<avsCommon::avs::AVSDirective>& directive,
398  const rapidjson::Document& payload,
399  std::string* alertToken);
400 
408  bool handleDeleteAlerts(
409  const std::shared_ptr<avsCommon::avs::AVSDirective>& directive,
410  const rapidjson::Document& payload);
411 
419  bool handleSetVolume(
420  const std::shared_ptr<avsCommon::avs::AVSDirective>& directive,
421  const rapidjson::Document& payload);
422 
430  bool handleAdjustVolume(
431  const std::shared_ptr<avsCommon::avs::AVSDirective>& directive,
432  const rapidjson::Document& payload);
433 
441  bool handleSetAlarmVolumeRamp(
442  const std::shared_ptr<avsCommon::avs::AVSDirective>& directive,
443  const rapidjson::Document& payload);
444 
456  void sendEvent(
457  const std::string& eventName,
458  const std::string& alertToken,
459  bool isCertified = false,
460  const std::string& scheduledTime = std::string(),
461  const std::string& eventTime = std::string());
462 
472  void sendBulkEvent(const std::string& eventName, const std::list<std::string>& tokenList, bool isCertified = false);
473 
480  void updateAVSWithLocalVolumeChanges(int8_t volume, bool forceUpdate);
481 
488  void sendProcessingDirectiveException(
489  const std::shared_ptr<avsCommon::avs::AVSDirective>& directive,
490  const std::string& errorMessage);
491 
495  void acquireChannel();
496 
500  void releaseChannel();
501 
505  void updateContextManager();
506 
512  std::string getContextString();
513 
520  bool getAlertVolumeSettings(avsCommon::sdkInterfaces::SpeakerInterface::SpeakerSettings* speakerSettings);
521 
528  bool getSpeakerVolumeSettings(avsCommon::sdkInterfaces::SpeakerInterface::SpeakerSettings* speakerSettings);
529 
536  void setNextAlertVolume(int64_t volume);
537 
544  void submitAlertStartedMetricWithMetadata(const std::string& alertToken, const std::string& alertType);
545 
553  void submitAlertCanceledMetricWithMetadata(
554  const std::string& alertToken,
555  const std::string& alertType,
556  const std::string& scheduledTime);
557 
564 
567  std::shared_ptr<avsCommon::utils::metrics::MetricRecorderInterface> m_metricRecorder;
569  std::shared_ptr<avsCommon::sdkInterfaces::MessageSenderInterface> m_messageSender;
571  std::shared_ptr<certifiedSender::CertifiedSender> m_certifiedSender;
573  std::shared_ptr<avsCommon::sdkInterfaces::FocusManagerInterface> m_focusManager;
575  std::shared_ptr<avsCommon::sdkInterfaces::SpeakerManagerInterface> m_speakerManager;
577  std::shared_ptr<avsCommon::sdkInterfaces::ContextManagerInterface> m_contextManager;
578 
580  std::unordered_set<std::shared_ptr<acsdkAlertsInterfaces::AlertObserverInterface>> m_observers;
581 
583  bool m_isConnected;
584 
586  AlertScheduler m_alertScheduler;
587 
589 
591  std::shared_ptr<avsCommon::sdkInterfaces::audio::AlertsAudioFactoryInterface> m_alertsAudioFactory;
592 
594  std::unordered_set<std::shared_ptr<avsCommon::avs::CapabilityConfiguration>> m_capabilityConfigurations;
595 
598 
600  bool m_contentChannelIsActive;
601 
603  bool m_commsChannelIsActive;
604 
606  bool m_alertIsSounding;
607 
609  std::clock_t m_startSystemClock;
610 
618 
622  std::shared_ptr<settings::AlarmVolumeRampSetting> m_alarmVolumeRampSetting;
623 
625  std::shared_ptr<settings::DeviceSettingsManager> m_settingsManager;
626 
628  std::shared_ptr<acsdkSystemClockMonitorInterfaces::SystemClockNotifierInterface> m_systemClockMonitor;
629 };
630 
631 } // namespace acsdkAlerts
632 } // namespace alexaClientSDK
633 
634 #endif // ALEXA_CLIENT_SDK_ACSDKALERTS_INCLUDE_ACSDKALERTS_ALERTSCAPABILITYAGENT_H_
static std::shared_ptr< AlertsCapabilityAgentInterface > createAlertsCapabilityAgent(const std::shared_ptr< acsdkAlerts::renderer::Renderer > &alertRenderer, const std::shared_ptr< acsdkShutdownManagerInterfaces::ShutdownNotifierInterface > &shutdownNotifier, const std::shared_ptr< avsCommon::sdkInterfaces::AVSConnectionManagerInterface > &connectionManager, const std::shared_ptr< avsCommon::sdkInterfaces::ContextManagerInterface > &contextManager, const std::shared_ptr< avsCommon::sdkInterfaces::ExceptionEncounteredSenderInterface > &exceptionEncounteredSender, const acsdkManufactory::Annotated< avsCommon::sdkInterfaces::AudioFocusAnnotation, avsCommon::sdkInterfaces::FocusManagerInterface > &audioFocusManager, const std::shared_ptr< avsCommon::sdkInterfaces::MessageSenderInterface > &messageSender, const std::shared_ptr< avsCommon::sdkInterfaces::SpeakerManagerInterface > &speakerManager, const std::shared_ptr< avsCommon::sdkInterfaces::audio::AudioFactoryInterface > &audioFactory, const acsdkManufactory::Annotated< avsCommon::sdkInterfaces::endpoints::DefaultEndpointAnnotation, avsCommon::sdkInterfaces::endpoints::EndpointCapabilitiesRegistrarInterface > &endpointCapabilitiesRegistrar, const std::shared_ptr< avsCommon::utils::metrics::MetricRecorderInterface > &metricRecorder, const std::shared_ptr< acsdkSystemClockMonitorInterfaces::SystemClockNotifierInterface > &systemClockMonitor, const std::shared_ptr< certifiedSender::CertifiedSender > &certifiedSender, const std::shared_ptr< registrationManager::CustomerDataManagerInterface > &dataManager, const std::shared_ptr< settings::DeviceSettingsManager > &settingsManager, const std::shared_ptr< storage::AlertStorageInterface > &alertStorage, bool startAlertSchedulingOnInitialization=true)
Definition: CapabilityAgent.h:47
avsCommon::avs::DirectiveHandlerConfiguration getConfiguration() const override
MixingBehavior
Definition: MixingBehavior.h:25
void cancelDirective(std::shared_ptr< DirectiveInfo > info) override
void onAlertStateChange(const AlertInfo &alertInfo) override
Definition: SettingEventMetadata.h:27
void onFocusChanged(avsCommon::avs::FocusState focusState, avsCommon::avs::MixingBehavior behavior) override
ChangedReason
Definition: ConnectionStatusObserverInterface.h:50
An interface that clients can extend to register to observe focus changes.
Definition: FocusManagerObserverInterface.h:26
::std::string string
Definition: gtest-port.h:1097
void addObserver(std::shared_ptr< acsdkAlertsInterfaces::AlertObserverInterface > observer) override
Single-thread executor implementation.
Definition: Executor.h:45
Definition: ConnectionStatusObserverInterface.h:31
void onSpeakerSettingsChanged(const Source &source, const avsCommon::sdkInterfaces::ChannelVolumeInterface::Type &type, const avsCommon::sdkInterfaces::SpeakerInterface::SpeakerSettings &settings) override
std::unordered_set< std::shared_ptr< avsCommon::avs::CapabilityConfiguration > > getCapabilityConfigurations() override
FocusState
Definition: FocusState.h:29
static settings::SettingEventMetadata getAlarmVolumeRampMetadata()
static std::shared_ptr< avsCommon::utils::metrics::MetricRecorderInterface > metricRecorder
Metric recorder shared ptr.
Definition: BaseAPLCapabilityAgentTest.cpp:261
Definition: AlertsCapabilityAgent.h:65
std::unordered_map< directiveRoutingRule::DirectiveRoutingRule, BlockingPolicy > DirectiveHandlerConfiguration
Definition: DirectiveHandlerConfiguration.h:32
static std::shared_ptr< AlertsCapabilityAgent > create(std::shared_ptr< avsCommon::sdkInterfaces::MessageSenderInterface > messageSender, std::shared_ptr< avsCommon::sdkInterfaces::AVSConnectionManagerInterface > connectionManager, std::shared_ptr< certifiedSender::CertifiedSender > certifiedMessageSender, std::shared_ptr< avsCommon::sdkInterfaces::FocusManagerInterface > focusManager, std::shared_ptr< avsCommon::sdkInterfaces::SpeakerManagerInterface > speakerManager, std::shared_ptr< avsCommon::sdkInterfaces::ContextManagerInterface > contextManager, std::shared_ptr< avsCommon::sdkInterfaces::ExceptionEncounteredSenderInterface > exceptionEncounteredSender, std::shared_ptr< storage::AlertStorageInterface > alertStorage, std::shared_ptr< avsCommon::sdkInterfaces::audio::AlertsAudioFactoryInterface > alertsAudioFactory, std::shared_ptr< renderer::RendererInterface > alertRenderer, std::shared_ptr< registrationManager::CustomerDataManagerInterface > dataManager, std::shared_ptr< settings::AlarmVolumeRampSetting > alarmVolumeRampSetting, std::shared_ptr< settings::DeviceSettingsManager > settingsManager, std::shared_ptr< avsCommon::utils::metrics::MetricRecorderInterface > metricRecorder=nullptr, bool startAlertSchedulingOnInitialization=true, std::shared_ptr< acsdkSystemClockMonitorInterfaces::SystemClockNotifierInterface > systemClockMonitor=nullptr)
void handleDirective(std::shared_ptr< DirectiveInfo > info) override
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
Definition: AlertsCapabilityAgentInterface.h:27
void removeObserver(std::shared_ptr< acsdkAlertsInterfaces::AlertObserverInterface > observer) override
void onConnectionStatusChanged(const Status status, const ChangedReason reason) override
void preHandleDirective(std::shared_ptr< DirectiveInfo > info) override
type
Definition: upload.py:443
Source
Indicates whether the source of the call is from an AVS Directive or through a Local API call...
Definition: SpeakerManagerObserverInterface.h:35
static const std::chrono::minutes ALERT_PAST_DUE_CUTOFF_MINUTES
Definition: AlertsCapabilityAgent.h:60
Status
Definition: ConnectionStatusObserverInterface.h:36
void handleDirectiveImmediately(std::shared_ptr< avsCommon::avs::AVSDirective > directive) override
Definition: AlertScheduler.h:38

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