RDK Documentation (Open Sourced RDK Components)
device::HostPersistence Class Reference
Collaboration diagram for device::HostPersistence:
Collaboration graph

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 HostPersistencegetInstance (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
 

yes

Definition at line 38 of file hostPersistence.hpp.

Constructor & Destructor Documentation

◆ HostPersistence()

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.

Member Function Documentation

◆ loadFromFile()

void device::HostPersistence::loadFromFile ( const std::string &  file,
std::map< std::string, std::string > &  map 
)
private

Provides a simple utility method for loading the key and defvalue from the backup file.

Parameters
filenameproperty file name
std::map<std::string, std::string> map properties map
Returns
Integer#getInteger(String) 0 for Success and -1 for Failure

Definition at line 324 of file hostPersistence.cpp.

◆ writeToFile()

void device::HostPersistence::writeToFile ( const std::string &  file)
private

Provides a simple utility method for dumping all the data that are in hash to tmp file.

Returns
Integer#getInteger(String) 0 for Success and -1 for Failure

Definition at line 357 of file hostPersistence.cpp.

◆ getInstance()

HostPersistence & device::HostPersistence::getInstance ( void  )
static

Provides a Host Persistenc Instance.

Definition at line 122 of file hostPersistence.cpp.

◆ load()

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.

◆ getProperty()

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.

Parameters
keyproperty key
defValuedefault value
Returns
Integer#getInteger(String) for the given key, defValue

Definition at line 206 of file hostPersistence.cpp.

◆ getDefaultProperty()

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.

Parameters
keyproperty key
Returns
Integer#getInteger(String) for the given key, defValue

Definition at line 239 of file hostPersistence.cpp.

◆ persistHostProperty()

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.

Parameters
keyproperty key
defValuedefault value
Returns
Integer#getInteger(String) for the given key, defValue

Definition at line 273 of file hostPersistence.cpp.


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