Skip to content

Commit 6d33cae

Browse files
committed
Replaced the use of ->Decode with DataModel::Decode.
1 parent 76cfea2 commit 6d33cae

File tree

5 files changed

+25
-27
lines changed

5 files changed

+25
-27
lines changed

src/app/clusters/basic-information/basic-information-cluster-objects.h

+12-7
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ namespace Clusters {
1010
namespace BasicInformation {
1111

1212
const uint32_t kMaxDeviceLocationNameLength = 128;
13-
using DeviceLocatioType = Attributes::DeviceLocation::TypeInfo::Type;
13+
using DeviceLocationType = Attributes::DeviceLocation::TypeInfo::Type;
1414

1515

16-
struct MutableDeviceLocation : public DeviceLocatioType
16+
struct MutableDeviceLocation : public DeviceLocationType
1717
{
1818
MutableDeviceLocation() {
1919
MutableDeviceLocation(CharSpan(mLocationNameBuffer, 0), DataModel::NullNullable, DataModel::NullNullable);
@@ -24,6 +24,12 @@ struct MutableDeviceLocation : public DeviceLocatioType
2424
}
2525

2626
MutableDeviceLocation & operator = (const MutableDeviceLocation & other) {
27+
if (other.IsNull())
28+
{
29+
this->SetNull();
30+
return *this;
31+
}
32+
2733
Set(other->locationName, other->floorNumber, other->areaType);
2834
return *this;
2935
}
@@ -32,8 +38,7 @@ struct MutableDeviceLocation : public DeviceLocatioType
3238
*this = other;
3339
}
3440

35-
// todo is this needed?
36-
MutableDeviceLocation & operator = (const DeviceLocatioType & other) {
41+
MutableDeviceLocation & operator = (const DeviceLocationType & other) {
3742
if (other.IsNull())
3843
{
3944
this->SetNull();
@@ -45,7 +50,9 @@ struct MutableDeviceLocation : public DeviceLocatioType
4550
}
4651

4752
/**
48-
* @brief Set the location name, floor number, and area type tag. The location name is truncated to kMaxDeviceLocationNameLength. The location name is deep copied.
53+
* @brief Set the location name, floor number, and area type tag.
54+
* The location name is truncated to kMaxDeviceLocationNameLength.
55+
* The location name is deep copied.
4956
*/
5057
void Set(CharSpan aLocationName, DataModel::Nullable<int16_t> aFloorNumber, DataModel::Nullable<AreaTypeTag> aAreaTypeTag) {
5158

@@ -64,8 +71,6 @@ struct MutableDeviceLocation : public DeviceLocatioType
6471
this->Value().areaType = aAreaTypeTag;
6572
}
6673

67-
// todo add setters and getters for all the attributes
68-
6974
private:
7075
char mLocationNameBuffer[kMaxDeviceLocationNameLength] = { 0 };
7176
};

src/app/clusters/basic-information/basic-information.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ CHIP_ERROR BasicAttrAccess::ReadDeviceLocation(AttributeValueEncoder & aEncoder)
433433

434434
CHIP_ERROR BasicAttrAccess::WriteDeviceLocation(AttributeValueDecoder & aDecoder)
435435
{
436-
DeviceLocatioType deviceLocation;
436+
DeviceLocationType deviceLocation;
437437

438438
ReturnErrorOnFailure(aDecoder.Decode(deviceLocation));
439439

src/include/platform/ConfigurationManager.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
#include <platform/PersistedStorage.h>
4141
#include <platform/internal/CHIPDeviceLayerInternal.h>
4242

43-
using DeviceLocatioType = chip::app::Clusters::BasicInformation::Attributes::DeviceLocation::TypeInfo::Type;
43+
using DeviceLocationType = chip::app::Clusters::BasicInformation::Attributes::DeviceLocation::TypeInfo::Type;
4444
using MutableDeviceLocation = chip::app::Clusters::BasicInformation::MutableDeviceLocation;
4545

4646
namespace chip {
@@ -138,7 +138,7 @@ class ConfigurationManager
138138
virtual CHIP_ERROR GetFailSafeArmed(bool & val) = 0;
139139
virtual CHIP_ERROR SetFailSafeArmed(bool val) = 0;
140140
virtual CHIP_ERROR GetDeviceLocation(MutableDeviceLocation & location) = 0;
141-
virtual CHIP_ERROR SetDeviceLocation(DeviceLocatioType location) = 0;
141+
virtual CHIP_ERROR SetDeviceLocation(DeviceLocationType location) = 0;
142142

143143
virtual CHIP_ERROR GetBLEDeviceIdentificationInfo(Ble::ChipBLEDeviceIdentificationInfo & deviceIdInfo) = 0;
144144

src/include/platform/internal/GenericConfigurationManagerImpl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class GenericConfigurationManagerImpl : public ConfigurationManager
8787
* Expects that location is initialised with a locationName CharSpan pointing to a buffer of size kMaxDeviceLocationNameLength.
8888
*/
8989
CHIP_ERROR GetDeviceLocation(MutableDeviceLocation & location) override;
90-
CHIP_ERROR SetDeviceLocation(DeviceLocatioType location) override;
90+
CHIP_ERROR SetDeviceLocation(DeviceLocationType location) override;
9191
CHIP_ERROR GetBLEDeviceIdentificationInfo(Ble::ChipBLEDeviceIdentificationInfo & deviceIdInfo) override;
9292
bool IsCommissionableDeviceTypeEnabled() override;
9393
CHIP_ERROR GetDeviceTypeId(uint32_t & deviceType) override;

src/include/platform/internal/GenericConfigurationManagerImpl.ipp

+9-16
Original file line numberDiff line numberDiff line change
@@ -589,9 +589,10 @@ CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::SetFailSafeArmed(bool v
589589
template <class ConfigClass>
590590
CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::GetDeviceLocation(MutableDeviceLocation & location)
591591
{
592-
uint8_t locationData[app::Clusters::BasicInformation::kMaxDeviceLocationNameLength + sizeof(DeviceLocatioType)];
592+
uint8_t locationData[app::Clusters::BasicInformation::kMaxDeviceLocationNameLength + sizeof(DeviceLocationType)];
593593
MutableByteSpan locationSpan(locationData);
594594

595+
// If the location key is not found, assume a null location.
595596
size_t outLen = 0;
596597
auto err = ReadConfigValueBin(ConfigClass::kConfigKey_DeviceLocation, locationSpan.data(), locationSpan.size(), outLen);
597598
if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND)
@@ -604,34 +605,26 @@ CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::GetDeviceLocation(Mutab
604605
TLV::TLVReader tlvReader;
605606
tlvReader.Init(locationSpan);
606607

607-
char locationNameBuffer[1] = { 0 };
608-
DeviceLocatioType loc({
609-
.locationName = CharSpan(locationNameBuffer, 0),
610-
});
608+
DeviceLocationType loc;
611609

612610
ReturnErrorOnFailure(tlvReader.Next(TLV::AnonymousTag()));
613-
ReturnErrorOnFailure(loc->Decode(tlvReader));
614-
615-
// This would not be needed if the Decode methed proprly decodes a null value.
616-
if (loc.Value().locationName.empty() && loc.Value().floorNumber.IsNull() && loc.Value().areaType.IsNull())
617-
{
618-
loc.SetNull();
619-
}
611+
ReturnErrorOnFailure(app::DataModel::Decode(tlvReader, loc));
620612

621613
location = loc;
622-
614+
623615
return CHIP_NO_ERROR;
624616
}
617+
625618
template <class ConfigClass>
626-
CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::SetDeviceLocation(DeviceLocatioType location)
619+
CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::SetDeviceLocation(DeviceLocationType location)
627620
{
628-
uint8_t locationData[app::Clusters::BasicInformation::kMaxDeviceLocationNameLength + sizeof(DeviceLocatioType)];
621+
uint8_t locationData[app::Clusters::BasicInformation::kMaxDeviceLocationNameLength + sizeof(DeviceLocationType)];
629622
MutableByteSpan locationSpan(locationData);
630623

631624
TLV::TLVWriter tlvWriter;
632625
tlvWriter.Init(locationSpan);
633626

634-
ReturnErrorOnFailure(location->Encode(tlvWriter, TLV::AnonymousTag()));
627+
ReturnErrorOnFailure(app::DataModel::Encode(tlvWriter, TLV::AnonymousTag(), location));
635628

636629
ReturnErrorOnFailure(WriteConfigValueBin(ConfigClass::kConfigKey_DeviceLocation,
637630
static_cast<const uint8_t *>(locationSpan.data()), tlvWriter.GetLengthWritten()));

0 commit comments

Comments
 (0)