Skip to content

Commit

Permalink
Update for the review questions
Browse files Browse the repository at this point in the history
  • Loading branch information
pankore committed Oct 28, 2021
1 parent 034d646 commit 098d454
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 33 deletions.
9 changes: 2 additions & 7 deletions src/platform/Ameba/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ void BLEManagerImpl::HandleTXCharCCCDWrite(int conn_id, int indicationsEnabled,
// If indications are not already enabled for the connection...
if (!IsSubscribed(conn_id))
{
// Record that indications have been enabled for this connection. If this fails because
// Record that indications have been enabled for this connection.
err = SetSubscribed(conn_id);
VerifyOrExit(err != CHIP_ERROR_NO_MEMORY, err = CHIP_NO_ERROR);
SuccessOrExit(err);
Expand Down Expand Up @@ -411,10 +411,7 @@ CHIP_ERROR BLEManagerImpl::_SetDeviceName(const char * deviceName)

if (deviceName != NULL && deviceName[0] != 0)
{
if (strlen(deviceName) >= kMaxDeviceNameLength)
{
return CHIP_ERROR_INVALID_ARGUMENT;
}
VerifyOrExit(strlen(deviceName) >= kMaxDeviceNameLength, err = CHIP_ERROR_INVALID_ARGUMENT);
strcpy(mDeviceName, deviceName);
mFlags.Set(Flags::kDeviceNameSet);
ChipLogProgress(DeviceLayer, "Setting device name to : \"%s\"", deviceName);
Expand Down Expand Up @@ -556,7 +553,6 @@ bool BLEManagerImpl::SendIndication(BLE_CONNECTION_OBJECT conId, const ChipBleUU
PacketBufferHandle data)
{
CHIP_ERROR err = CHIP_NO_ERROR;
// struct os_mbuf * om;

VerifyOrExit(IsSubscribed(conId), err = CHIP_ERROR_INVALID_ARGUMENT);
server_send_data(conId, bt_matter_adapter_service_id, BT_MATTER_ADAPTER_SERVICE_CHAR_NOTIFY_CCCD_INDEX - 1, data->Start(),
Expand Down Expand Up @@ -658,7 +654,6 @@ CHIP_ERROR BLEManagerImpl::StartAdvertising(void)
mFlags.Clear(Flags::kRestartAdvertising);

if (err == CHIP_NO_ERROR)
/* schedule NFC emulation stop */
{
ChipDeviceEvent advChange;
advChange.Type = DeviceEventType::kCHIPoBLEAdvertisingChange;
Expand Down
32 changes: 6 additions & 26 deletions src/platform/Ameba/KeyValueStoreManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,21 @@ CHIP_ERROR KeyValueStoreManagerImpl::_Get(const char * key, void * value, size_t
{
CHIP_ERROR err = CHIP_NO_ERROR;
int32_t ret = -1;
char * _key = (char *) malloc(strlen(key) + 1);

if (!value)
{
return (err = CHIP_ERROR_INVALID_ARGUMENT);
}
if (_key == NULL)
{
return (err = CHIP_ERROR_NO_MEMORY);
}

if (offset_bytes > 0)
{
// Offset and partial reads are not supported in nvs, for now just return NOT_IMPLEMENTED. Support can be added in the
// future if this is needed.
return (err = CHIP_ERROR_NOT_IMPLEMENTED);
}

strcpy(_key, key);
ret = getPref_bin_new(_key, _key, (uint8_t *) value, value_size, read_bytes_size);
ret = getPref_bin_new(key, key, (uint8_t *) value, value_size, read_bytes_size);

if (TRUE == ret)
{
err = CHIP_NO_ERROR;
Expand All @@ -68,54 +64,38 @@ CHIP_ERROR KeyValueStoreManagerImpl::_Get(const char * key, void * value, size_t
err = CHIP_ERROR_INTERNAL;
}

free(_key);
return err;
}

CHIP_ERROR KeyValueStoreManagerImpl::_Put(const char * key, const void * value, size_t value_size)
{
CHIP_ERROR err = CHIP_NO_ERROR;
int32_t ret = -1;
char * _key = (char *) malloc(strlen(key) + 1);

if (!value)
{
return (err = CHIP_ERROR_INVALID_ARGUMENT);
}
if (_key == NULL)
{
return (err = CHIP_ERROR_NO_MEMORY);
}

strcpy(_key, key);
ret = setPref_new(_key, _key, (uint8_t *) value, value_size);
ret = setPref_new(key, key, (uint8_t *) value, value_size);

if (TRUE == ret)
err = CHIP_NO_ERROR;
else
err = CHIP_ERROR_INTERNAL;

free(_key);

return err;
}

CHIP_ERROR KeyValueStoreManagerImpl::_Delete(const char * key)
{
CHIP_ERROR err = CHIP_NO_ERROR;
char * _key = (char *) malloc(strlen(key) + 1);
if (_key == NULL)
{
return (err = CHIP_ERROR_NO_MEMORY);
}

strcpy(_key, key);
// registerPref(_key);
if (TRUE == deleteKey(_key, _key))
if (TRUE == deleteKey(key, key))
err = CHIP_NO_ERROR;
else
err = CHIP_ERROR_INTERNAL;

free(_key);
return err;
}

Expand Down

0 comments on commit 098d454

Please sign in to comment.