AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
SQLiteAlertStorage.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_STORAGE_SQLITEALERTSTORAGE_H_
17 #define ALEXA_CLIENT_SDK_ACSDKALERTS_INCLUDE_ACSDKALERTS_STORAGE_SQLITEALERTSTORAGE_H_
18 
19 #include <set>
20 
27 
29 
30 namespace alexaClientSDK {
31 namespace acsdkAlerts {
32 namespace storage {
33 
41 public:
50  static std::shared_ptr<AlertStorageInterface> createAlertStorageInterface(
51  const std::shared_ptr<avsCommon::utils::configuration::ConfigurationNode>& configurationRoot,
52  const std::shared_ptr<avsCommon::sdkInterfaces::audio::AudioFactoryInterface>& audioFactory,
53  std::shared_ptr<avsCommon::utils::metrics::MetricRecorderInterface> metricRecorder = nullptr);
54 
64  static std::unique_ptr<SQLiteAlertStorage> create(
66  const std::shared_ptr<avsCommon::sdkInterfaces::audio::AlertsAudioFactoryInterface>& alertsAudioFactory,
67  std::shared_ptr<avsCommon::utils::metrics::MetricRecorderInterface> metricRecorder = nullptr);
68 
73 
74  bool createDatabase() override;
75 
76  bool open() override;
77 
78  void close() override;
79 
80  bool store(std::shared_ptr<Alert> alert) override;
81 
82  bool storeOfflineAlert(const std::string& token, const std::string& scheduledTime, const std::string& eventTime)
83  override;
84 
85  bool load(
86  std::vector<std::shared_ptr<Alert>>* alertContainer,
87  std::shared_ptr<settings::DeviceSettingsManager> settingsManager) override;
88 
89  bool loadOfflineAlerts(rapidjson::Value* alertContainer, rapidjson::Document::AllocatorType& allocator) override;
90 
91  bool modify(std::shared_ptr<Alert> alert) override;
92 
93  bool erase(std::shared_ptr<Alert> alert) override;
94 
95  bool eraseOffline(const std::string& token, int id) override;
96 
97  bool bulkErase(const std::list<std::shared_ptr<Alert>>& alertList) override;
98 
99  bool clearDatabase() override;
100 
104  enum class StatLevel {
106  ONE_LINE,
110  EVERYTHING
111  };
112 
118 
119 private:
128  const std::string& dbFilePath,
129  const std::shared_ptr<avsCommon::sdkInterfaces::audio::AlertsAudioFactoryInterface>& alertsAudioFactory,
130  std::shared_ptr<avsCommon::utils::metrics::MetricRecorderInterface> metricRecorder);
131 
141  bool loadHelper(
142  int dbVersion,
143  std::vector<std::shared_ptr<Alert>>* alertContainer,
144  std::shared_ptr<settings::DeviceSettingsManager> settingsManager);
145 
156  bool storeOfflineAlertHelper(
157  const int dbVersion,
158  const std::string& token,
159  const std::string& scheduledTime,
160  const std::string& eventTime);
161 
171  bool loadOfflineAlertsHelper(
172  const int dbVersion,
173  rapidjson::Value* alertContainer,
174  rapidjson::Document::AllocatorType& allocator);
175 
184  bool eraseOfflineHelper(const int dbVersion, const std::string& token);
185 
193  bool alertExists(const int dbVersion, const std::string& token);
194 
200  bool isOfflineTableV1Legacy();
201 
209  bool offlineAlertExists(const int dbVersion, const std::string& token);
210 
217  bool migrateOfflineAlertsDbFromV1ToV2();
218 
225  bool migrateAlertsDbFromV2ToV3();
226 
234  bool modifyAlert(const int dbVersion, std::shared_ptr<Alert> alert);
235 
245  template <typename Task, typename... Args>
246  bool retryDataMigration(Task task, Args&&... args);
247 
249  std::shared_ptr<avsCommon::sdkInterfaces::audio::AlertsAudioFactoryInterface> m_alertsAudioFactory;
250 
253 
255  std::shared_ptr<avsCommon::utils::metrics::MetricRecorderInterface> m_metricRecorder;
256 
258  avsCommon::utils::RetryTimer m_retryTimer;
259 
261  avsCommon::utils::WaitEvent m_waitRetryEvent;
262 };
263 
264 } // namespace storage
265 } // namespace acsdkAlerts
266 } // namespace alexaClientSDK
267 
268 #endif // ALEXA_CLIENT_SDK_ACSDKALERTS_INCLUDE_ACSDKALERTS_STORAGE_SQLITEALERTSTORAGE_H_
def args
Definition: android_test.py:111
::std::string string
Definition: gtest-port.h:1097
internal::ArgsMatcher< InnerMatcher > Args(const InnerMatcher &matcher)
Definition: gmock-generated-matchers.h:481
bool erase(std::shared_ptr< Alert > alert) override
static std::shared_ptr< avsCommon::utils::metrics::MetricRecorderInterface > metricRecorder
Metric recorder shared ptr.
Definition: BaseAPLCapabilityAgentTest.cpp:261
bool storeOfflineAlert(const std::string &token, const std::string &scheduledTime, const std::string &eventTime) override
static std::unique_ptr< SQLiteAlertStorage > create(const avsCommon::utils::configuration::ConfigurationNode &configurationRoot, const std::shared_ptr< avsCommon::sdkInterfaces::audio::AlertsAudioFactoryInterface > &alertsAudioFactory, std::shared_ptr< avsCommon::utils::metrics::MetricRecorderInterface > metricRecorder=nullptr)
bool Value(const T &value, M matcher)
Definition: gmock-matchers.h:4347
bool modify(std::shared_ptr< Alert > alert) override
void printStats(StatLevel level=StatLevel::ONE_LINE)
bool loadOfflineAlerts(rapidjson::Value *alertContainer, rapidjson::Document::AllocatorType &allocator) override
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
bool bulkErase(const std::list< std::shared_ptr< Alert >> &alertList) override
bool load(std::vector< std::shared_ptr< Alert >> *alertContainer, std::shared_ptr< settings::DeviceSettingsManager > settingsManager) override
Print only a single line, providing a count of rows from each table.
Print all details of the Alerts table, summarizing the other tables.
StatLevel
Definition: SQLiteAlertStorage.h:104
static std::shared_ptr< AlertStorageInterface > createAlertStorageInterface(const std::shared_ptr< avsCommon::utils::configuration::ConfigurationNode > &configurationRoot, const std::shared_ptr< avsCommon::sdkInterfaces::audio::AudioFactoryInterface > &audioFactory, std::shared_ptr< avsCommon::utils::metrics::MetricRecorderInterface > metricRecorder=nullptr)
bool eraseOffline(const std::string &token, int id) override
bool store(std::shared_ptr< Alert > alert) 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