Skip to content

Commit

Permalink
Restyled by clang-format (#11433)
Browse files Browse the repository at this point in the history
Co-authored-by: Restyled.io <[email protected]>
Signed-off-by: Doru Gucea <[email protected]>
  • Loading branch information
2 people authored and doru91 committed Nov 5, 2021
1 parent c783ea7 commit a49bd3e
Showing 1 changed file with 30 additions and 20 deletions.
50 changes: 30 additions & 20 deletions src/platform/nxp/k32w/k32w0/KeyValueStoreManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
#include <platform/internal/CHIPDeviceLayerInternal.h>

#include <lib/support/CHIPMem.h>
#include <platform/nxp/k32w/k32w0/K32W0Config.h>
#include <platform/KeyValueStoreManager.h>
#include <platform/nxp/k32w/k32w0/K32W0Config.h>
#include <set>
#include <string>

Expand Down Expand Up @@ -77,8 +77,8 @@ CHIP_ERROR RestoreFromFlash()
*/

pdm_internal_id = chip::DeviceLayer::Internal::K32WConfigKey(pdm_id_kvs, key_id + kMaxNumberOfKeys);
err = chip::DeviceLayer::Internal::K32WConfig::ReadConfigValueStr(pdm_internal_id, key_string_id,
kMaxKeyValueBytes, key_string_id_size);
err = chip::DeviceLayer::Internal::K32WConfig::ReadConfigValueStr(pdm_internal_id, key_string_id, kMaxKeyValueBytes,
key_string_id_size);

if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND)
{
Expand All @@ -87,7 +87,8 @@ CHIP_ERROR RestoreFromFlash()
}
else if (err != CHIP_NO_ERROR)
{
ChipLogProgress(DeviceLayer, "KVS, Error while restoring Matter key [%s] from flash with PDM id: %i", key_string_id, pdm_internal_id);
ChipLogProgress(DeviceLayer, "KVS, Error while restoring Matter key [%s] from flash with PDM id: %i", key_string_id,
pdm_internal_id);
break;
}

Expand All @@ -98,11 +99,13 @@ CHIP_ERROR RestoreFromFlash()
if (!g_kvs_map.insert(std::make_pair(std::string(key_string_id), key_id)).second)
{
/* key collision is not expected when restoring from flash */
ChipLogProgress(DeviceLayer, "KVS, Unexpected collision while restoring Matter key [%s] from flash with PDM id: %i", key_string_id, pdm_internal_id);
ChipLogProgress(DeviceLayer, "KVS, Unexpected collision while restoring Matter key [%s] from flash with PDM id: %i",
key_string_id, pdm_internal_id);
}
else
{
ChipLogProgress(DeviceLayer, "KVS, restored Matter key [%s] from flash with PDM id: %i", key_string_id, pdm_internal_id);
ChipLogProgress(DeviceLayer, "KVS, restored Matter key [%s] from flash with PDM id: %i", key_string_id,
pdm_internal_id);
}
}
}
Expand All @@ -118,18 +121,19 @@ CHIP_ERROR KeyValueStoreManagerImpl::_Get(const char * key, void * value, size_t
CHIP_ERROR err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND;
uint8_t pdm_id_kvs = chip::DeviceLayer::Internal::K32WConfig::kPDMId_KVS;
std::unordered_map<std::string, uint8_t>::const_iterator it;
size_t read_bytes = 0;
uint8_t key_id = 0;
size_t read_bytes = 0;
uint8_t key_id = 0;
uint16_t pdm_internal_id = 0;

VerifyOrExit((key != NULL) && (value != NULL) && (RestoreFromFlash() == CHIP_NO_ERROR), err = CHIP_ERROR_INVALID_ARGUMENT);

if ((it = g_kvs_map.find(key)) != g_kvs_map.end())
{
key_id = it->second;
key_id = it->second;
pdm_internal_id = chip::DeviceLayer::Internal::K32WConfigKey(pdm_id_kvs, key_id);

err = chip::DeviceLayer::Internal::K32WConfig::ReadConfigValueBin(pdm_internal_id, (uint8_t *) value, value_size, read_bytes);
err =
chip::DeviceLayer::Internal::K32WConfig::ReadConfigValueBin(pdm_internal_id, (uint8_t *) value, value_size, read_bytes);
*read_bytes_size = read_bytes;

ChipLogProgress(DeviceLayer, "KVS, get Matter key [%s] with PDM id: %i", key, pdm_internal_id);
Expand Down Expand Up @@ -175,7 +179,7 @@ CHIP_ERROR KeyValueStoreManagerImpl::_Put(const char * key, const void * value,
if (put_key)
{
pdm_internal_id = chip::DeviceLayer::Internal::K32WConfigKey(pdm_id_kvs, key_id);
ChipLogProgress(DeviceLayer, "KVS, save in flash Matter key [%s] with PDM id: %i", key, pdm_internal_id);
ChipLogProgress(DeviceLayer, "KVS, save in flash the value of the Matter key [%s] with PDM id: %i", key, pdm_internal_id);

g_kvs_map.insert(std::make_pair(std::string(key), key_id));
err = chip::DeviceLayer::Internal::K32WConfig::WriteConfigValueBin(pdm_internal_id, (uint8_t *) value, value_size);
Expand All @@ -184,18 +188,20 @@ CHIP_ERROR KeyValueStoreManagerImpl::_Put(const char * key, const void * value,
if (err == CHIP_NO_ERROR)
{
pdm_internal_id = chip::DeviceLayer::Internal::K32WConfigKey(pdm_id_kvs, key_id + kMaxNumberOfKeys);
ChipLogProgress(DeviceLayer, "KVS, save in flash the value of the Matter key [%s] with PDM id: %i", key, pdm_internal_id);
ChipLogProgress(DeviceLayer, "KVS, save in flash the Matter key [%s] with PDM id: %i", key,
pdm_internal_id);

err = chip::DeviceLayer::Internal::K32WConfig::WriteConfigValueStr(pdm_internal_id, key, strlen(key));

if (err != CHIP_NO_ERROR)
{
ChipLogProgress(DeviceLayer, "KVS, Error while saving in flash the value of the Matter key [%s] with PDM id: %i", key, pdm_internal_id);
ChipLogProgress(DeviceLayer, "KVS, Error while saving in flash the Matter key [%s] with PDM id: %i",
key, pdm_internal_id);
}
}
else
{
ChipLogProgress(DeviceLayer, "KVS, Error while saving in flash Matter key [%s] with PDM id: %i", key, pdm_internal_id);
ChipLogProgress(DeviceLayer, "KVS, Error while saving in flash the value of the Matter key [%s] with PDM id: %i", key, pdm_internal_id);
}
}

Expand All @@ -207,15 +213,15 @@ CHIP_ERROR KeyValueStoreManagerImpl::_Delete(const char * key)
{
CHIP_ERROR err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND;
std::unordered_map<std::string, uint8_t>::const_iterator it;
uint8_t pdm_id_kvs = chip::DeviceLayer::Internal::K32WConfig::kPDMId_KVS;
uint8_t key_id = 0;
uint8_t pdm_id_kvs = chip::DeviceLayer::Internal::K32WConfig::kPDMId_KVS;
uint8_t key_id = 0;
uint16_t pdm_internal_id = 0;

VerifyOrExit((key != NULL) && (RestoreFromFlash() == CHIP_NO_ERROR), err = CHIP_ERROR_INVALID_ARGUMENT);

if ((it = g_kvs_map.find(key)) != g_kvs_map.end())
{
key_id = it->second;
key_id = it->second;
pdm_internal_id = chip::DeviceLayer::Internal::K32WConfigKey(pdm_id_kvs, key_id);

g_key_ids_set.erase(key_id);
Expand All @@ -228,18 +234,22 @@ CHIP_ERROR KeyValueStoreManagerImpl::_Delete(const char * key)
if (err == CHIP_NO_ERROR)
{
pdm_internal_id = chip::DeviceLayer::Internal::K32WConfigKey(pdm_id_kvs, key_id + kMaxNumberOfKeys);
ChipLogProgress(DeviceLayer, "KVS, delete from flash the value of the Matter key [%s] with PDM id: %i", key, pdm_internal_id);
ChipLogProgress(DeviceLayer, "KVS, delete from flash the value of the Matter key [%s] with PDM id: %i", key,
pdm_internal_id);

err = chip::DeviceLayer::Internal::K32WConfig::ClearConfigValue(pdm_internal_id);

if (err != CHIP_NO_ERROR)
{
ChipLogProgress(DeviceLayer, "KVS, Error while deleting from flash the value of the Matter key [%s] with PDM id: %i", key, pdm_internal_id);
ChipLogProgress(DeviceLayer,
"KVS, Error while deleting from flash the value of the Matter key [%s] with PDM id: %i", key,
pdm_internal_id);
}
}
else
{
ChipLogProgress(DeviceLayer, "KVS, Error while deleting from flash the Matter key [%s] with PDM id: %i", key, pdm_internal_id);
ChipLogProgress(DeviceLayer, "KVS, Error while deleting from flash the Matter key [%s] with PDM id: %i", key,
pdm_internal_id);
}
}

Expand Down

0 comments on commit a49bd3e

Please sign in to comment.