AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
Public Types | Public Member Functions | Static Public Member Functions | List of all members
alexaClientSDK::acsdkAlerts::storage::SQLiteAlertStorage Class Reference

#include <SQLiteAlertStorage.h>

Inheritance diagram for alexaClientSDK::acsdkAlerts::storage::SQLiteAlertStorage:
Inheritance graph
[legend]
Collaboration diagram for alexaClientSDK::acsdkAlerts::storage::SQLiteAlertStorage:
Collaboration graph
[legend]

Public Types

enum  StatLevel { StatLevel::ONE_LINE, StatLevel::ALERTS_SUMMARY, StatLevel::EVERYTHING }
 

Public Member Functions

 ~SQLiteAlertStorage ()
 
bool createDatabase () override
 
bool open () override
 
void close () override
 
bool store (std::shared_ptr< Alert > alert) override
 
bool storeOfflineAlert (const std::string &token, const std::string &scheduledTime, const std::string &eventTime) override
 
bool load (std::vector< std::shared_ptr< Alert >> *alertContainer, std::shared_ptr< settings::DeviceSettingsManager > settingsManager) override
 
bool loadOfflineAlerts (rapidjson::Value *alertContainer, rapidjson::Document::AllocatorType &allocator) override
 
bool modify (std::shared_ptr< Alert > alert) override
 
bool erase (std::shared_ptr< Alert > alert) override
 
bool eraseOffline (const std::string &token, int id) override
 
bool bulkErase (const std::list< std::shared_ptr< Alert >> &alertList) override
 
bool clearDatabase () override
 
void printStats (StatLevel level=StatLevel::ONE_LINE)
 
- Public Member Functions inherited from alexaClientSDK::acsdkAlerts::storage::AlertStorageInterface
virtual ~AlertStorageInterface ()=default
 

Static Public Member Functions

static std::shared_ptr< AlertStorageInterfacecreateAlertStorageInterface (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)
 
static std::unique_ptr< SQLiteAlertStoragecreate (const avsCommon::utils::configuration::ConfigurationNode &configurationRoot, const std::shared_ptr< avsCommon::sdkInterfaces::audio::AlertsAudioFactoryInterface > &alertsAudioFactory, std::shared_ptr< avsCommon::utils::metrics::MetricRecorderInterface > metricRecorder=nullptr)
 

Detailed Description

An implementation that allows us to store alerts using SQLite. This class is not thread safe.

TODO: ACSDK-390 Investigate adding an abstraction layer between this class and the AlertStorageInterface, where the middle layer is expressed purely in SQL.

Member Enumeration Documentation

◆ StatLevel

An enum class to help debug database contents. This type is used in the printStats function below.

Enumerator
ONE_LINE 

Print only a single line, providing a count of rows from each table.

ALERTS_SUMMARY 

Print all details of the Alerts table, summarizing the other tables.

EVERYTHING 

Print all details of all records.

Constructor & Destructor Documentation

◆ ~SQLiteAlertStorage()

alexaClientSDK::acsdkAlerts::storage::SQLiteAlertStorage::~SQLiteAlertStorage ( )

On destruction, close the underlying database.

Member Function Documentation

◆ bulkErase()

bool alexaClientSDK::acsdkAlerts::storage::SQLiteAlertStorage::bulkErase ( const std::list< std::shared_ptr< Alert >> &  alertList)
overridevirtual

Erases multiple alerts from the database. This function must be atomic, no alert is to be deleted if there was an error deleting one.

Note
It is not an error if an alert in the parameter list is not present in the database. This accommodates the race condition between an local alert deletion and a request from AVS.
Parameters
alertListThe list of alerts to be erased.
Returns
Whether all alerts were successfully erased.

Implements alexaClientSDK::acsdkAlerts::storage::AlertStorageInterface.

◆ clearDatabase()

bool alexaClientSDK::acsdkAlerts::storage::SQLiteAlertStorage::clearDatabase ( )
overridevirtual

A utility function to clear the database of all records. Note that the database will still exist, as will the tables. Only the rows will be erased.

Returns
Whether the database was successfully cleared.

Implements alexaClientSDK::acsdkAlerts::storage::AlertStorageInterface.

◆ close()

void alexaClientSDK::acsdkAlerts::storage::SQLiteAlertStorage::close ( )
overridevirtual

Close the currently open database, if one is open.

Implements alexaClientSDK::acsdkAlerts::storage::AlertStorageInterface.

◆ create()

static std::unique_ptr<SQLiteAlertStorage> alexaClientSDK::acsdkAlerts::storage::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 
)
static

Factory method for creating a storage object for Alerts based on an SQLite database.

Deprecated:
Parameters
configurationRootThe global config object.
alertsAudioFactoryA factory that can produce default alert sounds.
metricRecorderThe MetricRecorderInterface used to record metrics.
Returns
Pointer to the SQLiteAlertStorage object, nullptr if there's an error creating it.

◆ createAlertStorageInterface()

static std::shared_ptr<AlertStorageInterface> alexaClientSDK::acsdkAlerts::storage::SQLiteAlertStorage::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 
)
static

Factory method for creating a storage object for Alerts based on an SQLite database.

Parameters
configurationRootThe global config object.
audioFactoryA factory that can produce default alert sounds.
metricRecorderThe MetricRecorderInterface used to record metrics.
Returns
Pointer to the SQLiteAlertStorage object, nullptr if there's an error creating it.

◆ createDatabase()

bool alexaClientSDK::acsdkAlerts::storage::SQLiteAlertStorage::createDatabase ( )
overridevirtual

Creates a new database. If a database is already being handled by this object or there is another internal error, then this function returns false.

Returns
true If the database is created ok, or false if a database is already being handled by this object or there is a problem creating the database.

Implements alexaClientSDK::acsdkAlerts::storage::AlertStorageInterface.

◆ erase()

bool alexaClientSDK::acsdkAlerts::storage::SQLiteAlertStorage::erase ( std::shared_ptr< Alert alert)
overridevirtual

Erases a single alert from the database.

Parameters
alertThe Alert to be erased.
Returns
Whether the Alert was successfully erased.

Implements alexaClientSDK::acsdkAlerts::storage::AlertStorageInterface.

◆ eraseOffline()

bool alexaClientSDK::acsdkAlerts::storage::SQLiteAlertStorage::eraseOffline ( const std::string &  token,
int  id 
)
overridevirtual

Erases a single alert from the offline database.

Parameters
tokenThe alertToken of the alert to be erased.
idThe id of the alert to be erased
Returns
Whether the alert was successfully erased.

Implements alexaClientSDK::acsdkAlerts::storage::AlertStorageInterface.

◆ load()

bool alexaClientSDK::acsdkAlerts::storage::SQLiteAlertStorage::load ( std::vector< std::shared_ptr< Alert >> *  alertContainer,
std::shared_ptr< settings::DeviceSettingsManager settingsManager 
)
overridevirtual

Loads all alerts in the database.

Parameters
[out]alertContainerThe container where alerts should be stored.
settingsManagerA settingsManager object that manages alarm volume ramp setting.
Returns
Whether the Alerts were successfully loaded.

Implements alexaClientSDK::acsdkAlerts::storage::AlertStorageInterface.

◆ loadOfflineAlerts()

bool alexaClientSDK::acsdkAlerts::storage::SQLiteAlertStorage::loadOfflineAlerts ( rapidjson::Value *  alertContainer,
rapidjson::Document::AllocatorType &  allocator 
)
overridevirtual

Loads all alerts in the offline database.

Parameters
[out]alertContainerThe container where alerts should be stored.
allocatorThe rapidjson allocator, required for the results of this function to be mergable with other rapidjson::Value objects.

Implements alexaClientSDK::acsdkAlerts::storage::AlertStorageInterface.

◆ modify()

bool alexaClientSDK::acsdkAlerts::storage::SQLiteAlertStorage::modify ( std::shared_ptr< Alert alert)
overridevirtual

Updates a database record of the Alert parameter. The fields which are updated by this operation are the state and scheduled times of the alert. All other fields of an alert do not change over time, and so will not be captured in the database when calling this function.

Parameters
alertThe Alert to be modified.
Returns
Whether the Alert was successfully modified.

Implements alexaClientSDK::acsdkAlerts::storage::AlertStorageInterface.

◆ open()

bool alexaClientSDK::acsdkAlerts::storage::SQLiteAlertStorage::open ( )
overridevirtual

Open an existing database. If this object is already managing an open database, or there is a problem opening the database, this function returns false.

Returns
true If the database is opened ok, false if this object is already managing an open database, or if there is another internal reason the database could not be opened.

Implements alexaClientSDK::acsdkAlerts::storage::AlertStorageInterface.

◆ printStats()

void alexaClientSDK::acsdkAlerts::storage::SQLiteAlertStorage::printStats ( StatLevel  level = StatLevel::ONE_LINE)

A utility function to print the contents of the database to the SDK logger output. This function is provided for debug use only.

◆ store()

bool alexaClientSDK::acsdkAlerts::storage::SQLiteAlertStorage::store ( std::shared_ptr< Alert alert)
overridevirtual

Stores a single Alert in the database.

Parameters
TheAlert to store.
Returns
Whether the Alert was successfully stored.

Implements alexaClientSDK::acsdkAlerts::storage::AlertStorageInterface.

◆ storeOfflineAlert()

bool alexaClientSDK::acsdkAlerts::storage::SQLiteAlertStorage::storeOfflineAlert ( const std::string &  token,
const std::string &  scheduledTime,
const std::string &  eventTime 
)
overridevirtual

Stores a single Alert in the offline alerts database.

Parameters
tokenThe alertToken of the alert to be erased.
scheduledTimeThe scheduled time of the alert
eventTimethe time the alert stopped
Returns
Whether the Alert was successfully stored.

Implements alexaClientSDK::acsdkAlerts::storage::AlertStorageInterface.


The documentation for this class was generated from the following file:

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