mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
components/nvs: fix formatting
This commit is contained in:
parent
076141aab9
commit
e87d80d478
@ -20,12 +20,12 @@
|
||||
class HandleEntry : public intrusive_list_node<HandleEntry>
|
||||
{
|
||||
public:
|
||||
HandleEntry(){}
|
||||
HandleEntry() {}
|
||||
|
||||
HandleEntry(nvs_handle handle, bool readOnly, uint8_t nsIndex) :
|
||||
mHandle(handle),
|
||||
mReadOnly(readOnly),
|
||||
mNsIndex(nsIndex)
|
||||
mHandle(handle),
|
||||
mReadOnly(readOnly),
|
||||
mNsIndex(nsIndex)
|
||||
{
|
||||
}
|
||||
|
||||
@ -263,12 +263,10 @@ static esp_err_t nvs_get_str_or_blob(nvs_handle handle, nvs::ItemType type, cons
|
||||
|
||||
if (length == nullptr) {
|
||||
return ESP_ERR_NVS_INVALID_LENGTH;
|
||||
}
|
||||
else if (out_value == nullptr) {
|
||||
} else if (out_value == nullptr) {
|
||||
*length = dataSize;
|
||||
return ESP_OK;
|
||||
}
|
||||
else if (*length < dataSize) {
|
||||
} else if (*length < dataSize) {
|
||||
*length = dataSize;
|
||||
return ESP_ERR_NVS_INVALID_LENGTH;
|
||||
}
|
||||
|
@ -53,8 +53,7 @@ void HashList::insert(const Item& item, size_t index)
|
||||
|
||||
void HashList::erase(size_t index)
|
||||
{
|
||||
for (auto it = std::begin(mBlockList); it != std::end(mBlockList);)
|
||||
{
|
||||
for (auto it = std::begin(mBlockList); it != std::end(mBlockList);) {
|
||||
bool haveEntries = false;
|
||||
for (size_t i = 0; i < it->mCount; ++i) {
|
||||
if (it->mNodes[i].mIndex == index) {
|
||||
@ -70,8 +69,7 @@ void HashList::erase(size_t index)
|
||||
++it;
|
||||
mBlockList.erase(tmp);
|
||||
delete static_cast<HashListBlock*>(tmp);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
++it;
|
||||
}
|
||||
}
|
||||
@ -81,13 +79,12 @@ void HashList::erase(size_t index)
|
||||
size_t HashList::find(size_t start, const Item& item)
|
||||
{
|
||||
const uint32_t hash_24 = item.calculateCrc32WithoutValue() & 0xffffff;
|
||||
for (auto it = std::begin(mBlockList); it != std::end(mBlockList); ++it)
|
||||
{
|
||||
for (auto it = std::begin(mBlockList); it != std::end(mBlockList); ++it) {
|
||||
for (size_t index = 0; index < it->mCount; ++index) {
|
||||
HashListNode& e = it->mNodes[index];
|
||||
if (e.mIndex >= start &&
|
||||
e.mHash == hash_24 &&
|
||||
e.mIndex != 0xff) {
|
||||
e.mHash == hash_24 &&
|
||||
e.mIndex != 0xff) {
|
||||
return e.mIndex;
|
||||
}
|
||||
}
|
||||
|
@ -34,12 +34,12 @@ protected:
|
||||
|
||||
struct HashListNode {
|
||||
HashListNode() :
|
||||
mIndex(0xff), mHash(0)
|
||||
mIndex(0xff), mHash(0)
|
||||
{
|
||||
}
|
||||
|
||||
HashListNode(uint32_t hash, size_t index) :
|
||||
mIndex((uint32_t) index), mHash(hash)
|
||||
mIndex((uint32_t) index), mHash(hash)
|
||||
{
|
||||
}
|
||||
|
||||
@ -47,8 +47,7 @@ protected:
|
||||
uint32_t mHash : 24;
|
||||
};
|
||||
|
||||
struct HashListBlock : public intrusive_list_node<HashList::HashListBlock>
|
||||
{
|
||||
struct HashListBlock : public intrusive_list_node<HashList::HashListBlock> {
|
||||
HashListBlock();
|
||||
|
||||
static const size_t BYTE_SIZE = 128;
|
||||
|
@ -59,11 +59,9 @@ esp_err_t Page::load(uint32_t sectorNumber)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (header.mCrc32 != header.calculateCrc32()) {
|
||||
} else if (header.mCrc32 != header.calculateCrc32()) {
|
||||
header.mState = PageState::CORRUPT;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
mState = header.mState;
|
||||
mSeqNumber = header.mSeqNumber;
|
||||
}
|
||||
@ -208,6 +206,7 @@ esp_err_t Page::writeItem(uint8_t nsIndex, ItemType datatype, const char* key, c
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
@ -327,8 +326,7 @@ esp_err_t Page::eraseEntryAndSpan(size_t index)
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
auto rc = alterEntryState(index, EntryState::ERASED);
|
||||
if (rc != ESP_OK) {
|
||||
return rc;
|
||||
@ -538,8 +536,7 @@ esp_err_t Page::mLoadEntryTable()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (mState == PageState::FULL || mState == PageState::FREEING) {
|
||||
} else if (mState == PageState::FULL || mState == PageState::FREEING) {
|
||||
// We have already filled mHashList for page in active state.
|
||||
// Do the same for the case when page is in full or freeing state.
|
||||
Item item;
|
||||
@ -675,8 +672,7 @@ esp_err_t Page::findItem(uint8_t nsIndex, ItemType datatype, const char* key, si
|
||||
size_t cachedIndex = mHashList.find(start, Item(nsIndex, datatype, 0, key));
|
||||
if (cachedIndex < ENTRY_COUNT) {
|
||||
start = cachedIndex;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return ESP_ERR_NVS_NOT_FOUND;
|
||||
}
|
||||
}
|
||||
@ -793,18 +789,15 @@ void Page::debugDump() const
|
||||
EntryState state = mEntryTable.get(i);
|
||||
if (state == EntryState::EMPTY) {
|
||||
printf("E\n");
|
||||
}
|
||||
else if (state == EntryState::ERASED) {
|
||||
} else if (state == EntryState::ERASED) {
|
||||
printf("X\n");
|
||||
}
|
||||
else if (state == EntryState::WRITTEN) {
|
||||
} else if (state == EntryState::WRITTEN) {
|
||||
Item item;
|
||||
readEntry(i, item);
|
||||
if (skip == 0) {
|
||||
printf("W ns=%2u type=%2u span=%3u key=\"%s\"\n", item.nsIndex, static_cast<unsigned>(item.datatype), item.span, item.key);
|
||||
skip = item.span - 1;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
printf("D\n");
|
||||
skip--;
|
||||
}
|
||||
|
@ -167,9 +167,11 @@ public:
|
||||
|
||||
protected:
|
||||
|
||||
class Header {
|
||||
class Header
|
||||
{
|
||||
public:
|
||||
Header() {
|
||||
Header()
|
||||
{
|
||||
std::fill_n(mReserved, sizeof(mReserved)/sizeof(mReserved[0]), UINT32_MAX);
|
||||
}
|
||||
|
||||
|
@ -47,8 +47,7 @@ esp_err_t PageManager::load(uint32_t baseSector, uint32_t sectorCount)
|
||||
if (mPageList.empty()) {
|
||||
mSeqNumber = 0;
|
||||
return activatePage();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
uint32_t lastSeqNo;
|
||||
assert(mPageList.back().getSeqNumber(lastSeqNo) == ESP_OK);
|
||||
mSeqNumber = lastSeqNo + 1;
|
||||
@ -78,7 +77,7 @@ esp_err_t PageManager::load(uint32_t baseSector, uint32_t sectorCount)
|
||||
for (auto it = begin(); it!= end(); ++it) {
|
||||
if (it->state() == Page::PageState::FREEING) {
|
||||
Page* newPage = &mPageList.back();
|
||||
if(newPage->state() != Page::PageState::ACTIVE) {
|
||||
if (newPage->state() != Page::PageState::ACTIVE) {
|
||||
auto err = activatePage();
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
|
@ -51,7 +51,7 @@ esp_err_t Storage::init(uint32_t baseSector, uint32_t sectorCount)
|
||||
Page& p = *it;
|
||||
size_t itemIndex = 0;
|
||||
Item item;
|
||||
while(p.findItem(Page::NS_INDEX, ItemType::U8, nullptr, itemIndex, item) == ESP_OK) {
|
||||
while (p.findItem(Page::NS_INDEX, ItemType::U8, nullptr, itemIndex, item) == ESP_OK) {
|
||||
NamespaceEntry* entry = new NamespaceEntry;
|
||||
item.getKey(entry->mName, sizeof(entry->mName) - 1);
|
||||
item.getValue(entry->mIndex);
|
||||
@ -103,14 +103,13 @@ esp_err_t Storage::writeItem(uint8_t nsIndex, ItemType datatype, const char* key
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
else if (err != ESP_OK) {
|
||||
} else if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
if (findPage) {
|
||||
if (findPage->state() == Page::PageState::UNINITIALIZED ||
|
||||
findPage->state() == Page::PageState::INVALID) {
|
||||
findPage->state() == Page::PageState::INVALID) {
|
||||
auto err = findItem(nsIndex, datatype, key, findPage, item);
|
||||
assert(err == ESP_OK);
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ public:
|
||||
static const size_t MAX_KEY_LENGTH = sizeof(key) - 1;
|
||||
|
||||
Item(uint8_t nsIndex, ItemType datatype, uint8_t span, const char* key_)
|
||||
: nsIndex(nsIndex), datatype(datatype), span(span), reserved(0xff)
|
||||
: nsIndex(nsIndex), datatype(datatype), span(span), reserved(0xff)
|
||||
{
|
||||
std::fill_n(reinterpret_cast<uint32_t*>(key), sizeof(key) / 4, 0xffffffff);
|
||||
std::fill_n(reinterpret_cast<uint32_t*>(data), sizeof(data) / 4, 0xffffffff);
|
||||
|
Loading…
x
Reference in New Issue
Block a user