AlexaClientSDK
1.26.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
|
#include <StorageManager.h>
Classes | |
struct | ReservationToken |
Public Member Functions | |
~StorageManager ()=default | |
void | purgeUnreferenced () |
std::shared_ptr< Resource > | registerAndAcquireResource (std::unique_ptr< StorageManager::ReservationToken > reservationToken, const std::string &id, const std::string &sourcePath) |
std::shared_ptr< Resource > | acquireResource (const std::string &id) |
size_t | releaseResource (const std::shared_ptr< Resource > &resource) |
std::unique_ptr< ReservationToken > | reserveSpace (size_t requestedAmount) |
size_t | availableBudget () |
size_t | getBudget () |
void | setBudget (size_t valueMB) |
Static Public Member Functions | |
static std::shared_ptr< StorageManager > | create (const std::string &workingDirectory, const std::shared_ptr< AssetManager > &assetManager) |
Static Public Attributes | |
static constexpr auto | MAX_BUDGET_MB = 500 |
Protected Member Functions | |
StorageManager (const std::string &workingDirectory, const std::shared_ptr< AssetManager > &assetManager, size_t budget) | |
bool | init () |
void | requestGarbageCollection (size_t requestedAmount) |
bool | requestSpace (size_t requestedAmount) |
void | freeReservedSpace (size_t size) |
This class manages a certain budget that Asset Manager should not go over. If at any point the amount of space used by Asset Manager goes over the budget, this class will trigger a call to the Asset Manager to free up space by deleting unused artifacts.
|
default |
|
explicitprotected |
shared_ptr< Resource > alexaClientSDK::acsdkAssets::manager::StorageManager::acquireResource | ( | const std::string & | id | ) |
Given an id, attempt to acquire a resource which will increment its reference count and returns the resource accordingly. If no resource is found with this id, then return a nullptr.
id | REQUIRED, a unique identifier for the requested resource. |
size_t alexaClientSDK::acsdkAssets::manager::StorageManager::availableBudget | ( | ) |
|
static |
Create a Storage Manager that is responsible for maintaining a budget for the artifacts to remain under.
workingDirectory | REQUIRED, place to store budget configuration. |
assetManager | REQUIRED, used to request low priority artifacts cleanup to meet the budget. |
|
protected |
Free up reserved space, to be used by reservation tokens
size_t alexaClientSDK::acsdkAssets::manager::StorageManager::getBudget | ( | ) |
|
protected |
Goes through the working directory and initializes all the available resources.
void alexaClientSDK::acsdkAssets::manager::StorageManager::purgeUnreferenced | ( | ) |
Post initialization step that goes through the map of resources and erases any that are unreferenced.
shared_ptr< Resource > alexaClientSDK::acsdkAssets::manager::StorageManager::registerAndAcquireResource | ( | std::unique_ptr< StorageManager::ReservationToken > | reservationToken, |
const std::string & | id, | ||
const std::string & | sourcePath | ||
) |
Registers a resource given a path to its content. If the operation succeeds, then it will be acquired as well. If another resource is found with the same id, then this will delete the provided path and use the existing resource. If there is no other resource with this id, then this will move the source path to the resources directory.
reservationToken | REQUIRED, a unique token that was used to reserve space ahead of download |
id | REQUIRED, a unique identifier for this resource, preferably the sha2 checksum. |
sourcePath | REQUIRED, the path on disk where this resource is found. |
size_t alexaClientSDK::acsdkAssets::manager::StorageManager::releaseResource | ( | const std::shared_ptr< Resource > & | resource | ) |
Given a resource, attempt to find it in the list and decrement its reference count. If the reference count is 0, then erase the resource from the system and return the size of how much memory was freed. If there are others referencing this resource, then return 0 and keep the resource on disk.
resource | REQUIRED, a valid resource that is registered by storage manager. |
|
protected |
Asks the Asset Manager to free up a certain amount of space in a background task.
requestedAmount | amount in bytes to be cleared. |
|
protected |
Forwards request to Asset Manager to free up space according to the given amount.
requestedAmount | amount in bytes to clear. |
unique_ptr< StorageManager::ReservationToken > alexaClientSDK::acsdkAssets::manager::StorageManager::reserveSpace | ( | size_t | requestedAmount | ) |
Reserve the requested amount of space and return a token that will be used to track the reserved space and is needed for registering a new resource. If the token is destroyed, the space is automatically freed.
requestedAmount | space to reserve |
void alexaClientSDK::acsdkAssets::manager::StorageManager::setBudget | ( | size_t | valueMB | ) |
Set a new budget value.
value | the new budget in MB. |
|
staticconstexpr |
AlexaClientSDK 1.26.0 - Copyright 2016-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0