Internal Interface Wrap
API reference
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Private Attributes | List of all members
HostNvs Class Reference

Hash-map NVS namespace for host builds and deterministic tests. More...

#include <HostNvs.h>

Inheritance diagram for HostNvs:
[legend]
Collaboration diagram for HostNvs:
[legend]

Public Member Functions

 HostNvs (const char *name)
 
 ~HostNvs () override=default
 
- Public Member Functions inherited from BaseNvs
virtual ~BaseNvs () noexcept=default
 Virtual destructor to ensure proper cleanup.
 
 BaseNvs (const BaseNvs &)=delete
 
BaseNvs & operator= (const BaseNvs &)=delete
 
bool EnsureInitialized ()
 Ensures that the NVS storage is initialized (lazy initialization).
 
bool EnsureDeinitialized ()
 Ensures that the NVS storage is deinitialized.
 
bool IsInitialized () const noexcept
 Check if storage is initialized.
 
const char * GetNamespace () const noexcept
 Get the namespace name.
 
virtual hf_nvs_err_t ResetStatistics () noexcept
 Reset NVS operation statistics.
 
virtual hf_nvs_err_t ResetDiagnostics () noexcept
 Reset NVS diagnostic information.
 
virtual hf_nvs_err_t GetStatistics (hf_nvs_statistics_t &statistics) const noexcept
 Get NVS operation statistics.
 
virtual hf_nvs_err_t GetDiagnostics (hf_nvs_diagnostics_t &diagnostics) const noexcept
 Get NVS diagnostic information.
 

Protected Member Functions

hf_nvs_err_t Initialize () noexcept override
 Initialize the storage system and open the namespace.
 
hf_nvs_err_t Deinitialize () noexcept override
 Deinitialize the storage system and close the namespace.
 
hf_nvs_err_t SetU32 (const char *key, hf_u32_t value) noexcept override
 Store a 32-bit unsigned integer value.
 
hf_nvs_err_t GetU32 (const char *key, hf_u32_t &value) noexcept override
 Retrieve a 32-bit unsigned integer value.
 
hf_nvs_err_t SetString (const char *key, const char *value) noexcept override
 Store a string value.
 
hf_nvs_err_t GetString (const char *key, char *buffer, size_t buffer_size, size_t *actual_size) noexcept override
 Retrieve a string value.
 
hf_nvs_err_t SetBlob (const char *key, const void *data, size_t data_size) noexcept override
 Store binary data (blob).
 
hf_nvs_err_t GetBlob (const char *key, void *buffer, size_t buffer_size, size_t *actual_size) noexcept override
 Retrieve binary data (blob).
 
hf_nvs_err_t EraseKey (const char *key) noexcept override
 Remove a key from storage.
 
hf_nvs_err_t Commit () noexcept override
 Commit any pending writes to non-volatile storage.
 
bool KeyExists (const char *key) noexcept override
 Check if a key exists in storage.
 
hf_nvs_err_t GetSize (const char *key, size_t &size) noexcept override
 Get the size of a stored value.
 
const char * GetDescription () const noexcept override
 Get description of this storage implementation.
 
size_t GetMaxKeyLength () const noexcept override
 Get maximum key length supported.
 
size_t GetMaxValueSize () const noexcept override
 Get maximum value size supported.
 
- Protected Member Functions inherited from BaseNvs
 BaseNvs (const char *namespace_name) noexcept
 Protected constructor with namespace specification.
 
void SetInitialized (bool initialized) noexcept
 Set the initialized state.
 

Private Attributes

const char * name_
 
std::unordered_map< std::string, std::vector< uint8_t > > blobs_
 
std::unordered_map< std::string, hf_u32_t > u32s_
 
std::unordered_map< std::string, std::string > strings_
 

Additional Inherited Members

- Protected Attributes inherited from BaseNvs
const char * namespace_name_
 Namespace name.
 
bool initialized_
 Initialization status.
 
hf_nvs_statistics_t statistics_
 NVS operation statistics.
 
hf_nvs_diagnostics_t diagnostics_
 NVS diagnostic information.
 

Detailed Description

Hash-map NVS namespace for host builds and deterministic tests.

Constructor & Destructor Documentation

◆ HostNvs()

HostNvs::HostNvs ( const char *  name)
explicit

◆ ~HostNvs()

HostNvs::~HostNvs ( )
overridedefault

Member Function Documentation

◆ Commit()

hf_nvs_err_t HostNvs::Commit ( )
overrideprotectedvirtualnoexcept

Commit any pending writes to non-volatile storage.

Returns
hf_nvs_err_t::NVS_SUCCESS if successful, error code otherwise

Implements BaseNvs.

◆ Deinitialize()

hf_nvs_err_t HostNvs::Deinitialize ( )
overrideprotectedvirtualnoexcept

Deinitialize the storage system and close the namespace.

Returns
hf_nvs_err_t::NVS_SUCCESS if successful, error code otherwise

Implements BaseNvs.

◆ EraseKey()

hf_nvs_err_t HostNvs::EraseKey ( const char *  key)
overrideprotectedvirtualnoexcept

Remove a key from storage.

Parameters
keyStorage key to remove
Returns
hf_nvs_err_t::NVS_SUCCESS if successful, error code otherwise

Implements BaseNvs.

◆ GetBlob()

hf_nvs_err_t HostNvs::GetBlob ( const char *  key,
void *  buffer,
size_t  buffer_size,
size_t *  actual_size 
)
overrideprotectedvirtualnoexcept

Retrieve binary data (blob).

Parameters
keyStorage key (null-terminated string)
bufferBuffer to store the retrieved data
buffer_sizeSize of the buffer in bytes
actual_sizeActual size of the data (optional)
Returns
hf_nvs_err_t::NVS_SUCCESS if successful, error code otherwise

Implements BaseNvs.

◆ GetDescription()

const char * HostNvs::GetDescription ( ) const
overrideprotectedvirtualnoexcept

Get description of this storage implementation.

Returns
Description string

Implements BaseNvs.

◆ GetMaxKeyLength()

size_t HostNvs::GetMaxKeyLength ( ) const
overrideprotectedvirtualnoexcept

Get maximum key length supported.

Returns
Maximum key length in characters

Implements BaseNvs.

◆ GetMaxValueSize()

size_t HostNvs::GetMaxValueSize ( ) const
overrideprotectedvirtualnoexcept

Get maximum value size supported.

Returns
Maximum value size in bytes

Implements BaseNvs.

◆ GetSize()

hf_nvs_err_t HostNvs::GetSize ( const char *  key,
size_t &  size 
)
overrideprotectedvirtualnoexcept

Get the size of a stored value.

Parameters
keyStorage key
sizeReference to store the size
Returns
hf_nvs_err_t::NVS_SUCCESS if successful, error code otherwise

Implements BaseNvs.

◆ GetString()

hf_nvs_err_t HostNvs::GetString ( const char *  key,
char *  buffer,
size_t  buffer_size,
size_t *  actual_size 
)
overrideprotectedvirtualnoexcept

Retrieve a string value.

Parameters
keyStorage key (null-terminated string)
bufferBuffer to store the retrieved string
buffer_sizeSize of the buffer in bytes
actual_sizeActual size of the string (optional)
Returns
hf_nvs_err_t::NVS_SUCCESS if successful, error code otherwise

Implements BaseNvs.

◆ GetU32()

hf_nvs_err_t HostNvs::GetU32 ( const char *  key,
hf_u32_t &  value 
)
overrideprotectedvirtualnoexcept

Retrieve a 32-bit unsigned integer value.

Parameters
keyStorage key (null-terminated string)
valueReference to store the retrieved value
Returns
hf_nvs_err_t::NVS_SUCCESS if successful, error code otherwise

Implements BaseNvs.

◆ Initialize()

hf_nvs_err_t HostNvs::Initialize ( )
overrideprotectedvirtualnoexcept

Initialize the storage system and open the namespace.

Returns
hf_nvs_err_t::NVS_SUCCESS if successful, error code otherwise

Implements BaseNvs.

◆ KeyExists()

bool HostNvs::KeyExists ( const char *  key)
overrideprotectedvirtualnoexcept

Check if a key exists in storage.

Parameters
keyStorage key to check
Returns
true if key exists, false otherwise

Implements BaseNvs.

◆ SetBlob()

hf_nvs_err_t HostNvs::SetBlob ( const char *  key,
const void *  data,
size_t  data_size 
)
overrideprotectedvirtualnoexcept

Store binary data (blob).

Parameters
keyStorage key (null-terminated string)
dataPointer to data to store
data_sizeSize of data in bytes
Returns
hf_nvs_err_t::NVS_SUCCESS if successful, error code otherwise

Implements BaseNvs.

◆ SetString()

hf_nvs_err_t HostNvs::SetString ( const char *  key,
const char *  value 
)
overrideprotectedvirtualnoexcept

Store a string value.

Parameters
keyStorage key (null-terminated string)
valueString value to store
Returns
hf_nvs_err_t::NVS_SUCCESS if successful, error code otherwise

Implements BaseNvs.

◆ SetU32()

hf_nvs_err_t HostNvs::SetU32 ( const char *  key,
hf_u32_t  value 
)
overrideprotectedvirtualnoexcept

Store a 32-bit unsigned integer value.

Parameters
keyStorage key (null-terminated string)
valueValue to store
Returns
hf_nvs_err_t::NVS_SUCCESS if successful, error code otherwise

Implements BaseNvs.

Member Data Documentation

◆ blobs_

std::unordered_map<std::string, std::vector<uint8_t> > HostNvs::blobs_
private

◆ name_

const char* HostNvs::name_
private

◆ strings_

std::unordered_map<std::string, std::string> HostNvs::strings_
private

◆ u32s_

std::unordered_map<std::string, hf_u32_t> HostNvs::u32s_
private

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