HF Interface Wrapper 0.1.0-dev
Embedded C++ hardware abstraction layer
Loading...
Searching...
No Matches
BaseNvs Class Referenceabstract

Abstract base class for non-volatile storage operations. More...

#include <BaseNvs.h>

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

Public Member Functions

virtual ~BaseNvs () noexcept=default
 Virtual destructor to ensure proper cleanup.
 
 BaseNvs (const BaseNvs &)=delete
 
BaseNvsoperator= (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.
 
virtual hf_nvs_err_t Initialize () noexcept=0
 Initialize the storage system and open the namespace.
 
virtual hf_nvs_err_t Deinitialize () noexcept=0
 Deinitialize the storage system and close the namespace.
 
virtual hf_nvs_err_t SetU32 (const char *key, hf_u32_t value) noexcept=0
 Store a 32-bit unsigned integer value.
 
virtual hf_nvs_err_t GetU32 (const char *key, hf_u32_t &value) noexcept=0
 Retrieve a 32-bit unsigned integer value.
 
virtual hf_nvs_err_t SetString (const char *key, const char *value) noexcept=0
 Store a string value.
 
virtual hf_nvs_err_t GetString (const char *key, char *buffer, size_t buffer_size, size_t *actual_size=nullptr) noexcept=0
 Retrieve a string value.
 
virtual hf_nvs_err_t SetBlob (const char *key, const void *data, size_t data_size) noexcept=0
 Store binary data (blob).
 
virtual hf_nvs_err_t GetBlob (const char *key, void *buffer, size_t buffer_size, size_t *actual_size=nullptr) noexcept=0
 Retrieve binary data (blob).
 
virtual hf_nvs_err_t EraseKey (const char *key) noexcept=0
 Remove a key from storage.
 
virtual hf_nvs_err_t Commit () noexcept=0
 Commit any pending writes to non-volatile storage.
 
virtual bool KeyExists (const char *key) noexcept=0
 Check if a key exists in storage.
 
virtual hf_nvs_err_t GetSize (const char *key, size_t &size) noexcept=0
 Get the size of a stored value.
 
const char * GetNamespace () const noexcept
 Get the namespace name.
 
virtual const char * GetDescription () const noexcept=0
 Get description of this storage implementation.
 
virtual size_t GetMaxKeyLength () const noexcept=0
 Get maximum key length supported.
 
virtual size_t GetMaxValueSize () const noexcept=0
 Get maximum value size supported.
 
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

 BaseNvs (const char *namespace_name) noexcept
 Protected constructor with namespace specification.
 
void SetInitialized (bool initialized) noexcept
 Set the initialized state.
 

Protected Attributes

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

Abstract base class for non-volatile storage operations.

This class provides a consistent interface for non-volatile storage across different hardware platforms and storage mechanisms. It supports key-value storage with various data types and namespace organization.

Key Features:

  • Namespace-based organization
  • Multiple data type support (uint32_t, string, blob)
  • Atomic operations
  • Error handling and status reporting
  • Platform-agnostic interface
  • Lazy initialization pattern
Note
Implementations should handle platform-specific details internally
This class is designed to be thread-safe when properly implemented

Constructor & Destructor Documentation

◆ ~BaseNvs()

virtual BaseNvs::~BaseNvs ( )
virtualdefaultnoexcept

Virtual destructor to ensure proper cleanup.

◆ BaseNvs() [1/2]

BaseNvs::BaseNvs ( const BaseNvs & )
delete

◆ BaseNvs() [2/2]

BaseNvs::BaseNvs ( const char * namespace_name)
inlineexplicitprotectednoexcept

Protected constructor with namespace specification.

Parameters
namespace_nameName of the storage namespace

Member Function Documentation

◆ Commit()

virtual hf_nvs_err_t BaseNvs::Commit ( )
pure virtualnoexcept

Commit any pending writes to non-volatile storage.

Returns
hf_nvs_err_t::NVS_SUCCESS if successful, error code otherwise

Implemented in EspNvs, and StmNvs.

◆ Deinitialize()

virtual hf_nvs_err_t BaseNvs::Deinitialize ( )
pure virtualnoexcept

Deinitialize the storage system and close the namespace.

Returns
hf_nvs_err_t::NVS_SUCCESS if successful, error code otherwise

Implemented in EspNvs, and StmNvs.

◆ EnsureDeinitialized()

bool BaseNvs::EnsureDeinitialized ( )
inline

Ensures that the NVS storage is deinitialized.

Returns
true if the NVS storage is deinitialized, false otherwise.

◆ EnsureInitialized()

bool BaseNvs::EnsureInitialized ( )
inline

Ensures that the NVS storage is initialized (lazy initialization).

Returns
true if the NVS storage is initialized, false otherwise.
Note
This method follows the HardFOC HAL contract pattern used by all peripherals.

◆ EraseKey()

virtual hf_nvs_err_t BaseNvs::EraseKey ( const char * key)
pure virtualnoexcept

Remove a key from storage.

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

Implemented in EspNvs, and StmNvs.

◆ GetBlob()

virtual hf_nvs_err_t BaseNvs::GetBlob ( const char * key,
void * buffer,
size_t buffer_size,
size_t * actual_size = nullptr )
pure virtualnoexcept

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

Implemented in EspNvs, and StmNvs.

◆ GetDescription()

virtual const char * BaseNvs::GetDescription ( ) const
pure virtualnoexcept

Get description of this storage implementation.

Returns
Description string

Implemented in EspNvs, and StmNvs.

◆ GetDiagnostics()

virtual hf_nvs_err_t BaseNvs::GetDiagnostics ( hf_nvs_diagnostics_t & diagnostics) const
inlinevirtualnoexcept

Get NVS diagnostic information.

Parameters
diagnosticsReference to store diagnostics data
Returns
hf_nvs_err_t::NVS_SUCCESS if successful, NVS_ERR_NOT_SUPPORTED if not implemented

Reimplemented in EspNvs.

◆ GetMaxKeyLength()

virtual size_t BaseNvs::GetMaxKeyLength ( ) const
pure virtualnoexcept

Get maximum key length supported.

Returns
Maximum key length in characters

Implemented in EspNvs, and StmNvs.

◆ GetMaxValueSize()

virtual size_t BaseNvs::GetMaxValueSize ( ) const
pure virtualnoexcept

Get maximum value size supported.

Returns
Maximum value size in bytes

Implemented in EspNvs, and StmNvs.

◆ GetNamespace()

const char * BaseNvs::GetNamespace ( ) const
inlinenoexcept

Get the namespace name.

Returns
Namespace name string

◆ GetSize()

virtual hf_nvs_err_t BaseNvs::GetSize ( const char * key,
size_t & size )
pure virtualnoexcept

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

Implemented in EspNvs, and StmNvs.

◆ GetStatistics()

virtual hf_nvs_err_t BaseNvs::GetStatistics ( hf_nvs_statistics_t & statistics) const
inlinevirtualnoexcept

Get NVS operation statistics.

Parameters
statisticsReference to store statistics data
Returns
hf_nvs_err_t::NVS_SUCCESS if successful, NVS_ERR_NOT_SUPPORTED if not implemented

Reimplemented in EspNvs.

◆ GetString()

virtual hf_nvs_err_t BaseNvs::GetString ( const char * key,
char * buffer,
size_t buffer_size,
size_t * actual_size = nullptr )
pure virtualnoexcept

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

Implemented in EspNvs, and StmNvs.

◆ GetU32()

virtual hf_nvs_err_t BaseNvs::GetU32 ( const char * key,
hf_u32_t & value )
pure virtualnoexcept

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

Implemented in EspNvs, and StmNvs.

◆ Initialize()

virtual hf_nvs_err_t BaseNvs::Initialize ( )
pure virtualnoexcept

Initialize the storage system and open the namespace.

Returns
hf_nvs_err_t::NVS_SUCCESS if successful, error code otherwise

Implemented in EspNvs, and StmNvs.

◆ IsInitialized()

bool BaseNvs::IsInitialized ( ) const
inlinenoexcept

Check if storage is initialized.

Returns
true if initialized, false otherwise

◆ KeyExists()

virtual bool BaseNvs::KeyExists ( const char * key)
pure virtualnoexcept

Check if a key exists in storage.

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

Implemented in EspNvs, and StmNvs.

◆ operator=()

BaseNvs & BaseNvs::operator= ( const BaseNvs & )
delete

◆ ResetDiagnostics()

virtual hf_nvs_err_t BaseNvs::ResetDiagnostics ( )
inlinevirtualnoexcept

Reset NVS diagnostic information.

Returns
hf_nvs_err_t::NVS_SUCCESS if successful, error code otherwise
Note
Override this method to provide platform-specific diagnostics reset

◆ ResetStatistics()

virtual hf_nvs_err_t BaseNvs::ResetStatistics ( )
inlinevirtualnoexcept

Reset NVS operation statistics.

Returns
hf_nvs_err_t::NVS_SUCCESS if successful, error code otherwise
Note
Override this method to provide platform-specific statistics reset

◆ SetBlob()

virtual hf_nvs_err_t BaseNvs::SetBlob ( const char * key,
const void * data,
size_t data_size )
pure virtualnoexcept

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

Implemented in EspNvs, and StmNvs.

◆ SetInitialized()

void BaseNvs::SetInitialized ( bool initialized)
inlineprotectednoexcept

Set the initialized state.

Parameters
initializedNew initialization state

◆ SetString()

virtual hf_nvs_err_t BaseNvs::SetString ( const char * key,
const char * value )
pure virtualnoexcept

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

Implemented in EspNvs, and StmNvs.

◆ SetU32()

virtual hf_nvs_err_t BaseNvs::SetU32 ( const char * key,
hf_u32_t value )
pure virtualnoexcept

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

Implemented in EspNvs, and StmNvs.

Member Data Documentation

◆ diagnostics_

hf_nvs_diagnostics_t BaseNvs::diagnostics_
protected

NVS diagnostic information.

◆ initialized_

bool BaseNvs::initialized_
protected

Initialization status.

◆ namespace_name_

const char* BaseNvs::namespace_name_
protected

Namespace name.

◆ statistics_

hf_nvs_statistics_t BaseNvs::statistics_
protected

NVS operation statistics.


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