Added support for NVS iterators

Closes https://github.com/espressif/esp-idf/issues/129
This commit is contained in:
MartinValik
2018-11-05 09:03:04 +01:00
parent bde1c30c5b
commit 5268960235
9 changed files with 545 additions and 47 deletions

View File

@@ -688,4 +688,66 @@ extern "C" esp_err_t nvs_flash_read_security_cfg(const esp_partition_t* partitio
return ESP_OK;
}
#endif
static nvs_iterator_t create_iterator(nvs::Storage *storage, nvs_type_t type)
{
nvs_iterator_t it = (nvs_iterator_t)calloc(1, sizeof(nvs_opaque_iterator_t));
if (it == NULL) {
return NULL;
}
it->storage = storage;
it->type = type;
return it;
}
extern "C" nvs_iterator_t nvs_entry_find(const char *part_name, const char *namespace_name, nvs_type_t type)
{
Lock lock;
nvs::Storage *pStorage;
pStorage = lookup_storage_from_name(part_name);
if (pStorage == NULL) {
return NULL;
}
nvs_iterator_t it = create_iterator(pStorage, type);
if (it == NULL) {
return NULL;
}
bool entryFound = pStorage->findEntry(it, namespace_name);
if (!entryFound) {
free(it);
return NULL;
}
return it;
}
extern "C" nvs_iterator_t nvs_entry_next(nvs_iterator_t it)
{
Lock lock;
assert(it);
bool entryFound = it->storage->nextEntry(it);
if (!entryFound) {
free(it);
return NULL;
}
return it;
}
extern "C" void nvs_entry_info(nvs_iterator_t it, nvs_entry_info_t *out_info)
{
*out_info = it->entry_info;
}
extern "C" void nvs_release_iterator(nvs_iterator_t it)
{
free(it);
}