Skip to content

Commit 0f4228a

Browse files
Fix false-positive compiler warning in ecoinfo cluster (#38149)
* Fix false-positive compiler warning in ecoinfo cluster * Restyled by clang-format --------- Co-authored-by: Restyled.io <commits@restyled.io>
1 parent 85e9d5f commit 0f4228a

File tree

2 files changed

+38
-16
lines changed

2 files changed

+38
-16
lines changed

src/app/clusters/ecosystem-information-server/ecosystem-information-server.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,10 @@ std::unique_ptr<EcosystemDeviceStruct> EcosystemDeviceStruct::Builder::Build()
148148
VerifyOrReturnValue(locationId.size() <= kUniqueLocationIdMaxSize, nullptr, ChipLogError(Zcl, "Location id too long"));
149149
}
150150

151-
// std::make_unique does not have access to private constructor we workaround with using new
152-
std::unique_ptr<EcosystemDeviceStruct> ret{ new EcosystemDeviceStruct(
151+
PrivateToken token;
152+
std::unique_ptr<EcosystemDeviceStruct> ret = std::make_unique<EcosystemDeviceStruct>(
153153
std::move(mDeviceName), mDeviceNameLastEditEpochUs, mBridgedEndpoint, mOriginalEndpoint, std::move(mDeviceTypes),
154-
std::move(mUniqueLocationIds), mUniqueLocationIdsLastEditEpochUs, mFabricIndex) };
154+
std::move(mUniqueLocationIds), mUniqueLocationIdsLastEditEpochUs, mFabricIndex, token);
155155
mIsAlreadyBuilt = true;
156156
return ret;
157157
}
@@ -222,8 +222,9 @@ std::unique_ptr<EcosystemLocationStruct> EcosystemLocationStruct::Builder::Build
222222
ChipLogError(Zcl, "Location Name must be less than %u bytes", static_cast<uint16_t>(kLocationDescriptorNameMaxSize)));
223223

224224
// std::make_unique does not have access to private constructor we workaround with using new
225-
std::unique_ptr<EcosystemLocationStruct> ret{ new EcosystemLocationStruct(std::move(mLocationDescriptor),
226-
mLocationDescriptorLastEditEpochUs) };
225+
PrivateToken token;
226+
std::unique_ptr<EcosystemLocationStruct> ret =
227+
std::make_unique<EcosystemLocationStruct>(std::move(mLocationDescriptor), mLocationDescriptorLastEditEpochUs, token);
227228
mIsAlreadyBuilt = true;
228229
return ret;
229230
}

src/app/clusters/ecosystem-information-server/ecosystem-information-server.h

+32-11
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,17 @@ class TestOnlyParameter
5555
// of underlying types.
5656
class EcosystemDeviceStruct
5757
{
58+
private:
59+
// Originally we wanted the constructor of EcosystemDeviceStruct to be private to ensure
60+
// only Builder could construct it. This would ensure that this struct will only be
61+
// created with values that conform to the spec. Unfortunately, std::make_unique is
62+
// not able to call a private constructor. As a workaround, to ensure the constructor is
63+
// only callable internally, we created this PrivateToken as a privately accessible
64+
// parameter that needs to be passed into the constructor.
65+
class PrivateToken
66+
{
67+
};
68+
5869
public:
5970
class Builder
6071
{
@@ -84,15 +95,10 @@ class EcosystemDeviceStruct
8495
bool mIsAlreadyBuilt = false;
8596
};
8697

87-
CHIP_ERROR Encode(const AttributeValueEncoder::ListEncodeHelper & aEncoder);
88-
89-
private:
90-
// Constructor is intentionally private. This is to ensure that it is only constructed with
91-
// values that conform to the spec.
9298
explicit EcosystemDeviceStruct(std::string && aDeviceName, uint64_t aDeviceNameLastEditEpochUs, EndpointId aBridgedEndpoint,
9399
EndpointId aOriginalEndpoint, std::vector<Structs::DeviceTypeStruct::Type> && aDeviceTypes,
94100
std::vector<std::string> && aUniqueLocationIds, uint64_t aUniqueLocationIdsLastEditEpochUs,
95-
FabricIndex aFabricIndex) :
101+
FabricIndex aFabricIndex, PrivateToken _) :
96102
mDeviceName(std::move(aDeviceName)),
97103
mDeviceNameLastEditEpochUs(aDeviceNameLastEditEpochUs), mBridgedEndpoint(aBridgedEndpoint),
98104
mOriginalEndpoint(aOriginalEndpoint), mDeviceTypes(std::move(aDeviceTypes)),
@@ -101,6 +107,9 @@ class EcosystemDeviceStruct
101107

102108
{}
103109

110+
CHIP_ERROR Encode(const AttributeValueEncoder::ListEncodeHelper & aEncoder);
111+
112+
private:
104113
const std::string mDeviceName;
105114
uint64_t mDeviceNameLastEditEpochUs;
106115
EndpointId mBridgedEndpoint;
@@ -122,6 +131,17 @@ struct LocationDescriptorStruct
122131
// of underlying types.
123132
class EcosystemLocationStruct
124133
{
134+
private:
135+
// Originally we wanted the constructor of EcosystemLocationStruct to be private to ensure
136+
// only Builder could construct it. This would ensure that this struct will only be
137+
// created with values that conform to the spec. Unfortunately, std::make_unique is
138+
// not able to call a private constructor. As a workaround, to ensure the constructor is
139+
// only callable internally, we created this PrivateToken as a privately accessible
140+
// parameter that needs to be passed into the constructor.
141+
class PrivateToken
142+
{
143+
};
144+
125145
public:
126146
class Builder
127147
{
@@ -143,15 +163,16 @@ class EcosystemLocationStruct
143163
bool mIsAlreadyBuilt = false;
144164
};
145165

166+
explicit EcosystemLocationStruct(LocationDescriptorStruct && aLocationDescriptor, uint64_t aLocationDescriptorLastEditEpochUs,
167+
PrivateToken _) :
168+
mLocationDescriptor(aLocationDescriptor),
169+
mLocationDescriptorLastEditEpochUs(aLocationDescriptorLastEditEpochUs)
170+
{}
171+
146172
CHIP_ERROR Encode(const AttributeValueEncoder::ListEncodeHelper & aEncoder, const std::string & aUniqueLocationId,
147173
const FabricIndex & aFabricIndex);
148174

149175
private:
150-
// Constructor is intentionally private. This is to ensure that it is only constructed with
151-
// values that conform to the spec.
152-
explicit EcosystemLocationStruct(LocationDescriptorStruct && aLocationDescriptor, uint64_t aLocationDescriptorLastEditEpochUs) :
153-
mLocationDescriptor(aLocationDescriptor), mLocationDescriptorLastEditEpochUs(aLocationDescriptorLastEditEpochUs)
154-
{}
155176
// EcosystemLocationStruct is used as a value in a key-value map.
156177
// Because UniqueLocationId and FabricIndex are mandatory when an entry exist,
157178
// and needs to be unique, we use it as a key to the key-value pair and is why it is

0 commit comments

Comments
 (0)