Firmware  0.0.0
Loading...
Searching...
No Matches
mem::nvs::Base Class Reference

NVS base. More...

#include <base.hpp>

Inheritance diagram for mem::nvs::Base:
Collaboration diagram for mem::nvs::Base:

Classes

struct  Iterator
 Wrapper around C-style NVS iterators More...
 
struct  Sentinel
 Sentinel type for Iterator. More...
 

Public Member Functions

auto begin () const
 
auto cbegin () const
 
auto end () const
 
auto cend () const
 
esp_err_t erase (std::string const &key)
 Erase key-value pair with given key name.
 
esp_err_t eraseAll ()
 Erase all key-value pairs in a namespace.
 

Protected Member Functions

 Base (char const *namespace_name, nvs_open_mode_t open_mode)
 Ctor.
 
 ~Base ()
 Dtor.
 
std::string getBlob (std::string const &key) const
 Get blob value for given key.
 
esp_err_t setBlob (std::string const &key, std::string_view str)
 Set blob value for given key.
 
uint8_t getU8 (std::string const &key) const
 Get uint8_t value for given key.
 
esp_err_t setU8 (std::string const &key, uint8_t value)
 Set uint8_t value for given key.
 
uint8_t getU16 (std::string const &key) const
 Get uint16_t value for given key.
 
esp_err_t setU16 (std::string const &key, uint16_t value)
 Set uint16_t value for given key.
 

Private Attributes

char const * _namespace_name {}
 Store namespace name (mainly for iterator)
 
nvs_handle_t _handle {}
 Opaque pointer type representing non-volatile storage handle.
 
bool _commit_pending {}
 Flag to indicate commit pending.
 

Detailed Description

nvs::Base is a convenience wrapper over the NVS C-API and forms the basis of all NVS classes. The RAII idiom ensures that the desired namespace is opened in the constructor and that any write operations are committed in the destructor and the namespace is closed again.

A nested iterator type (nvs::Base::Iterator) ensures that the keys of the namespace can be iterated over.

Constructor & Destructor Documentation

◆ Base()

mem::nvs::Base::Base ( char const * namespace_name,
nvs_open_mode_t open_mode )
protected

Open non-volatile storage with a given namespace from the default NVS partition.

Parameters
namespace_nameNamespace to open
open_modeMode of opening the non-volatile storage

◆ ~Base()

mem::nvs::Base::~Base ( )
protected

Write any pending changes to non-volatile storage, then close the storage handle and free any allocated resources.

Member Function Documentation

◆ begin()

auto mem::nvs::Base::begin ( ) const
inline

◆ cbegin()

auto mem::nvs::Base::cbegin ( ) const
inline

◆ cend()

auto mem::nvs::Base::cend ( ) const
inline

◆ end()

auto mem::nvs::Base::end ( ) const
inline

◆ erase()

esp_err_t mem::nvs::Base::erase ( std::string const & key)
Parameters
keyKey name
Return values
ESP_OKErase operation was successful
ESP_FAILInternal error
ESP_ERR_NVS_NOT_FOUNDRequested key doesn't exist

◆ eraseAll()

esp_err_t mem::nvs::Base::eraseAll ( )
Return values
ESP_OKErase operation was successful
ESP_FAILInternal error

◆ getBlob()

std::string mem::nvs::Base::getBlob ( std::string const & key) const
protected
Parameters
keyKey name
Returns
Blob value as std::string

◆ getU16()

uint8_t mem::nvs::Base::getU16 ( std::string const & key) const
protected
Parameters
keyKey name
Returns
uint16_t value

◆ getU8()

uint8_t mem::nvs::Base::getU8 ( std::string const & key) const
protected
Parameters
keyKey name
Returns
uint8_t value

◆ setBlob()

esp_err_t mem::nvs::Base::setBlob ( std::string const & key,
std::string_view str )
protected
Parameters
keyKey name
strBlob value
Return values
ESP_OKValue was set successfully
ESP_FAILInternal error
ESP_ERR_NVS_INVALID_NAMEKey name doesn't satisfy constraints
ESP_ERR_NVS_NOT_ENOUGH_SPACENot enough space
ESP_ERR_NVS_REMOVE_FAILEDValue wasn't updated because flash write operation has failed
ESP_ERR_NVS_VALUE_TOO_LONGString value is too long

◆ setU16()

esp_err_t mem::nvs::Base::setU16 ( std::string const & key,
uint16_t value )
protected
Parameters
keyKey name
valueuint16_t value
Return values
ESP_OKValue was set successfully
ESP_FAILInternal error
ESP_ERR_NVS_INVALID_NAMEKey name doesn't satisfy constraints
ESP_ERR_NVS_NOT_ENOUGH_SPACENot enough space
ESP_ERR_NVS_REMOVE_FAILEDValue wasn't updated because flash write operation has failed

◆ setU8()

esp_err_t mem::nvs::Base::setU8 ( std::string const & key,
uint8_t value )
protected
Parameters
keyKey name
valueuint8_t value
Return values
ESP_OKValue was set successfully
ESP_FAILInternal error
ESP_ERR_NVS_INVALID_NAMEKey name doesn't satisfy constraints
ESP_ERR_NVS_NOT_ENOUGH_SPACENot enough space
ESP_ERR_NVS_REMOVE_FAILEDValue wasn't updated because flash write operation has failed

Member Data Documentation

◆ _commit_pending

bool mem::nvs::Base::_commit_pending {}
private

◆ _handle

nvs_handle_t mem::nvs::Base::_handle {}
private

◆ _namespace_name

char const* mem::nvs::Base::_namespace_name {}
private

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