RDK Documentation (Open Sourced RDK Components)
|
Public Member Functions | |
HostPersistence () | |
HostPersistence (const std::string &storeFolder) | |
void | load () |
std::string | getProperty (const std::string &key) |
std::string | getProperty (const std::string &key, const std::string &defValue) |
std::string | getDefaultProperty (const std::string &key) |
void | persistHostProperty (const std::string &key, const std::string &value) |
Static Public Member Functions | |
static HostPersistence & | getInstance (void) |
Private Member Functions | |
void | loadFromFile (const std::string &file, std::map< std::string, std::string > &map) |
void | writeToFile (const std::string &file) |
Private Attributes | |
std::map< std::string, std::string > | _properties |
std::map< std::string, std::string > | _defaultProperties |
std::string | filePath |
std::string | defaultFilePath |
Definition at line 38 of file hostPersistence.hpp.
device::HostPersistence::HostPersistence | ( | ) |
HostPersistence
is an simple class that provides for robust serialization of (key,value) values stored in a Hashmap.
The local file system is used as the database, with different sets of persistent objects may occupy individual files in the file system.
In order to provide for more robust updates, we never overwrite a file directly. Instead we write to a secondary file, then delete the original, and finally rename the secondary file. When reading files in we look for the secondary file first. If no secondary file is found or it is corrupt, we fall back to the original filename.
For this implementation, where the key is a string constant and value is either a string constant or a primitive data type, we use a HashMap to store the properties.
@TODO: If necessary, we will later add capability to configure the file path where the persistent data is to be stored.
Definition at line 81 of file hostPersistence.cpp.
|
private |
Provides a simple utility method for loading the key and defvalue from the backup file.
filename | property file name |
std::map | <std::string, std::string> map properties map |
Definition at line 324 of file hostPersistence.cpp.
|
private |
Provides a simple utility method for dumping all the data that are in hash to tmp file.
Definition at line 357 of file hostPersistence.cpp.
|
static |
Provides a Host Persistenc Instance.
Definition at line 122 of file hostPersistence.cpp.
void device::HostPersistence::load | ( | ) |
Provides a simple utility method for load host persisted values. from file system. Exception is thrown if the persisted file is not readable, and property map is loaded with default values.
Definition at line 133 of file hostPersistence.cpp.
std::string device::HostPersistence::getProperty | ( | const std::string & | key, |
const std::string & | defValue | ||
) |
Provides a simple utility method for accessing host persisted values Default value is returned if the asked property is not available.
key | property key |
defValue | default value |
Definition at line 206 of file hostPersistence.cpp.
std::string device::HostPersistence::getDefaultProperty | ( | const std::string & | key | ) |
Provides a simple utility method for accessing host persisted values. Exception is thrown if the asked property is not available.
key | property key |
Definition at line 239 of file hostPersistence.cpp.
void device::HostPersistence::persistHostProperty | ( | const std::string & | key, |
const std::string & | value | ||
) |
Provides a simple utility method for persist host values to a file. Default value is returned if the asked property is not available.
key | property key |
defValue | default value |
Definition at line 273 of file hostPersistence.cpp.