CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
cdc::core::NvsScope Class Reference

RAII wrapper for an NVS handle. More...

#include <Raii.h>

Public Member Functions

 NvsScope () noexcept=default
 Construct an empty, closed scope. Status reports ESP_FAIL until opened.
 NvsScope (const char *ns, nvs_open_mode_t mode) noexcept
 Open ns in mode. Errors are silent; use bool conversion or status() to check.
 ~NvsScope () noexcept
 NvsScope (const NvsScope &)=delete
NvsScopeoperator= (const NvsScope &)=delete
 NvsScope (NvsScope &&other) noexcept
NvsScopeoperator= (NvsScope &&other) noexcept
 operator bool () const noexcept
 True if the namespace was opened successfully.
 operator nvs_handle_t () const noexcept
 Raw handle for the underlying nvs_* functions.
esp_err_t status () const noexcept
 esp_err_t result of the original nvs_open call.
esp_err_t commit () noexcept
 Commit pending writes. Caller checks the return value if needed.
void close () noexcept
 Manually close before destruction. Idempotent.

Detailed Description

RAII wrapper for an NVS handle.

Opens the given namespace in the constructor and closes it in the destructor. Non-copyable. Use bool conversion to check whether the open succeeded.

Example
NvsScope nvs("myns", NVS_READWRITE);
if (!nvs) return false;
nvs_set_str(nvs, "key", "value");
nvs.commit();
NvsScope() noexcept=default
Construct an empty, closed scope. Status reports ESP_FAIL until opened.

Definition at line 106 of file Raii.h.

Constructor & Destructor Documentation

◆ NvsScope() [1/4]

cdc::core::NvsScope::NvsScope ( )
defaultnoexcept

Construct an empty, closed scope. Status reports ESP_FAIL until opened.

Referenced by NvsScope(), NvsScope(), NvsScope(), operator=(), and operator=().

◆ NvsScope() [2/4]

cdc::core::NvsScope::NvsScope ( const char * ns,
nvs_open_mode_t mode )
inlinenoexcept

Open ns in mode. Errors are silent; use bool conversion or status() to check.

Definition at line 112 of file Raii.h.

References NvsScope().

◆ ~NvsScope()

cdc::core::NvsScope::~NvsScope ( )
inlinenoexcept

Definition at line 118 of file Raii.h.

◆ NvsScope() [3/4]

cdc::core::NvsScope::NvsScope ( const NvsScope & )
delete

References NvsScope().

◆ NvsScope() [4/4]

cdc::core::NvsScope::NvsScope ( NvsScope && other)
inlinenoexcept

Definition at line 126 of file Raii.h.

References NvsScope().

Member Function Documentation

◆ close()

void cdc::core::NvsScope::close ( )
inlinenoexcept

Manually close before destruction. Idempotent.

Definition at line 159 of file Raii.h.

◆ commit()

esp_err_t cdc::core::NvsScope::commit ( )
inlinenoexcept

Commit pending writes. Caller checks the return value if needed.

Definition at line 153 of file Raii.h.

Referenced by cdc::mod_gpg::GpgRecvStore::deleteKey().

◆ operator bool()

cdc::core::NvsScope::operator bool ( ) const
inlineexplicitnoexcept

True if the namespace was opened successfully.

Definition at line 144 of file Raii.h.

◆ operator nvs_handle_t()

cdc::core::NvsScope::operator nvs_handle_t ( ) const
inlinenoexcept

Raw handle for the underlying nvs_* functions.

Definition at line 147 of file Raii.h.

◆ operator=() [1/2]

NvsScope & cdc::core::NvsScope::operator= ( const NvsScope & )
delete

References NvsScope().

◆ operator=() [2/2]

NvsScope & cdc::core::NvsScope::operator= ( NvsScope && other)
inlinenoexcept

Definition at line 131 of file Raii.h.

References NvsScope().

◆ status()

esp_err_t cdc::core::NvsScope::status ( ) const
inlinenoexcept

esp_err_t result of the original nvs_open call.

Definition at line 150 of file Raii.h.


The documentation for this class was generated from the following file:
  • components/cdc_core/include/cdc_core/Raii.h