AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
AlertScheduler.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_ALERTSCHEDULER_H_
17 #define ALEXA_CLIENT_SDK_ACSDKALERTS_INCLUDE_ACSDKALERTS_ALERTSCHEDULER_H_
18 
20 
26 
27 #include <list>
28 #include <set>
29 #include <string>
30 
31 namespace alexaClientSDK {
32 namespace acsdkAlerts {
33 
39 public:
45  std::vector<Alert::ContextInfo> scheduledAlerts;
47  std::vector<Alert::ContextInfo> activeAlerts;
48  };
49 
60  std::shared_ptr<storage::AlertStorageInterface> alertStorage,
61  std::shared_ptr<renderer::RendererInterface> alertRenderer,
62  std::chrono::seconds alertPastDueTimeLimitSeconds,
63  std::shared_ptr<avsCommon::utils::metrics::MetricRecorderInterface> metricRecorder = nullptr);
64 
67  void onAlertStateChange(const AlertInfo& alertInfo) override;
69 
81  bool initialize(
82  const std::shared_ptr<acsdkAlertsInterfaces::AlertObserverInterface>& observer,
83  const std::shared_ptr<settings::DeviceSettingsManager>& settingsManager,
84  bool startAlertSchedulingOnInitialization = true);
85 
92  bool scheduleAlert(std::shared_ptr<Alert> alert);
93 
102  const std::string& alertToken,
103  const std::string& scheduledTime,
104  const std::string& eventTime);
105 
113  bool getOfflineStoppedAlerts(rapidjson::Value* alertContainer, rapidjson::Document::AllocatorType& allocator);
114 
124  std::shared_ptr<settings::DeviceSettingsManager> settingsManager,
125  bool shouldScheduleAlerts);
126 
135  bool snoozeAlert(const std::string& alertToken, const std::string& updatedTime_ISO_8601);
136 
143  bool deleteAlert(const std::string& alertToken);
144 
152  bool deleteAlerts(const std::list<std::string>& tokenList);
153 
160  void deleteOfflineStoppedAlert(const std::string& token, int id);
161 
168  bool isAlertActive(std::shared_ptr<Alert> alert);
169 
175  std::shared_ptr<Alert> getActiveAlert();
176 
184 
191 
198 
202  void onLocalStop();
203 
210 
214  void shutdown();
215 
221  std::list<std::shared_ptr<Alert>> getAllAlerts();
222 
223 private:
229  void executeOnAlertStateChange(const AlertInfo& alertInfo);
230 
241  bool updateAlert(
242  const std::shared_ptr<Alert>& alert,
243  const std::string& newScheduledTime,
244  const Alert::AssetConfiguration& newAssetConfiguration);
245 
251  void notifyObserver(const acsdkAlertsInterfaces::AlertObserverInterface::AlertInfo& alertInfo);
252 
258  void executeNotifyObserver(const acsdkAlertsInterfaces::AlertObserverInterface::AlertInfo& alertInfo);
259 
263  void setTimerForNextAlertLocked();
264 
268  void setTimerForNextAlert();
269 
273  void activateNextAlertLocked();
274 
280  void onAlertReady(const acsdkAlertsInterfaces::AlertObserverInterface::AlertInfo& alertInfo);
281 
288  bool isAlertActiveLocked(std::shared_ptr<Alert> alert) const;
289 
296  std::shared_ptr<Alert> getAlertLocked(const std::string& token) const;
297 
303  std::shared_ptr<Alert> getActiveAlertLocked() const;
304 
310  void deactivateActiveAlertHelperLocked(Alert::StopReason reason);
311 
318  void eraseAlert(std::shared_ptr<Alert> alert);
319 
322 
327  std::shared_ptr<acsdkAlertsInterfaces::AlertObserverInterface> m_observer;
328 
330  std::shared_ptr<settings::DeviceSettingsManager> m_settingsManager;
331 
333  std::mutex m_mutex;
334 
336  std::shared_ptr<storage::AlertStorageInterface> m_alertStorage;
338  std::shared_ptr<renderer::RendererInterface> m_alertRenderer;
339 
341  std::chrono::seconds m_alertPastDueTimeLimit;
343  avsCommon::avs::FocusState m_focusState;
345  avsCommon::avs::MixingBehavior m_mixingBehavior;
347  std::shared_ptr<Alert> m_activeAlert;
349  std::set<std::shared_ptr<Alert>, acsdkAlerts::TimeComparator> m_scheduledAlerts;
350 
352  avsCommon::utils::timing::Timer m_scheduledAlertTimer;
353 
355  bool m_shouldScheduleAlerts;
356 
358  std::shared_ptr<avsCommon::utils::metrics::MetricRecorderInterface> m_metricRecorder;
359 
367 };
368 
369 } // namespace acsdkAlerts
370 } // namespace alexaClientSDK
371 
372 #endif // ALEXA_CLIENT_SDK_ACSDKALERTS_INCLUDE_ACSDKALERTS_ALERTSCHEDULER_H_
bool deleteAlerts(const std::list< std::string > &tokenList)
MixingBehavior
Definition: MixingBehavior.h:25
bool snoozeAlert(const std::string &alertToken, const std::string &updatedTime_ISO_8601)
bool deleteAlert(const std::string &alertToken)
avsCommon::avs::FocusState getFocusState()
std::shared_ptr< Alert > getActiveAlert()
StopReason
Definition: Alert.h:84
::std::string string
Definition: gtest-port.h:1097
bool getOfflineStoppedAlerts(rapidjson::Value *alertContainer, rapidjson::Document::AllocatorType &allocator)
void deleteOfflineStoppedAlert(const std::string &token, int id)
Single-thread executor implementation.
Definition: Executor.h:45
void onAlertStateChange(const AlertInfo &alertInfo) override
void clearData(Alert::StopReason reason=Alert::StopReason::SHUTDOWN)
bool initialize(const std::shared_ptr< acsdkAlertsInterfaces::AlertObserverInterface > &observer, const std::shared_ptr< settings::DeviceSettingsManager > &settingsManager, bool startAlertSchedulingOnInitialization=true)
bool reloadAlertsFromDatabase(std::shared_ptr< settings::DeviceSettingsManager > settingsManager, bool shouldScheduleAlerts)
FocusState
Definition: FocusState.h:29
bool scheduleAlert(std::shared_ptr< Alert > alert)
static std::shared_ptr< avsCommon::utils::metrics::MetricRecorderInterface > metricRecorder
Metric recorder shared ptr.
Definition: BaseAPLCapabilityAgentTest.cpp:261
bool Value(const T &value, M matcher)
Definition: gmock-matchers.h:4347
std::vector< Alert::ContextInfo > scheduledAlerts
All alerts that are scheduled.
Definition: AlertScheduler.h:45
Timer to schedule task for delayed and periodic execution.
Definition: Timer.h:39
AlertScheduler::AlertsContextInfo getContextInfo()
bool saveOfflineStoppedAlert(const std::string &alertToken, const std::string &scheduledTime, const std::string &eventTime)
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
std::vector< Alert::ContextInfo > activeAlerts
All active alerts.
Definition: AlertScheduler.h:47
void updateFocus(avsCommon::avs::FocusState focusState, avsCommon::avs::MixingBehavior behavior)
bool isAlertActive(std::shared_ptr< Alert > alert)
The alert is being stopped due to an SDK shutdown operation.
AlertScheduler(std::shared_ptr< storage::AlertStorageInterface > alertStorage, std::shared_ptr< renderer::RendererInterface > alertRenderer, std::chrono::seconds alertPastDueTimeLimitSeconds, std::shared_ptr< avsCommon::utils::metrics::MetricRecorderInterface > metricRecorder=nullptr)
std::list< std::shared_ptr< Alert > > getAllAlerts()
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