Skip to content

Commit 26c816a

Browse files
Remove StatusIB::InitFromChipError. (project-chip#34712)
The constructor is a better fit for being able to convert CHIP_ERROR to ClusterStatusCode and then to StatusIB.
1 parent 138b5b8 commit 26c816a

File tree

11 files changed

+20
-33
lines changed

11 files changed

+20
-33
lines changed

examples/chip-tool/commands/common/RemoteDataModelLogger.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,7 @@ CHIP_ERROR LogErrorAsJSON(const CHIP_ERROR & error)
160160
VerifyOrReturnError(gDelegate != nullptr, CHIP_NO_ERROR);
161161

162162
Json::Value value;
163-
chip::app::StatusIB status;
164-
status.InitFromChipError(error);
163+
chip::app::StatusIB status(error);
165164
return LogError(value, status);
166165
}
167166

examples/fabric-admin/commands/common/RemoteDataModelLogger.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,7 @@ CHIP_ERROR LogErrorAsJSON(const CHIP_ERROR & error)
160160
VerifyOrReturnError(gDelegate != nullptr, CHIP_NO_ERROR);
161161

162162
Json::Value value;
163-
chip::app::StatusIB status;
164-
status.InitFromChipError(error);
163+
chip::app::StatusIB status(error);
165164
return LogError(value, status);
166165
}
167166

src/app/CommandSender.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ class CommandSender final : public Messaging::ExchangeDelegate
100100
* - CHIP_ERROR_TIMEOUT: A response was not received within the expected response timeout.
101101
* - CHIP_ERROR_*TLV*: A malformed, non-compliant response was received from the server.
102102
* - CHIP_ERROR encapsulating a StatusIB: If we got a non-path-specific
103-
* status response from the server. In that case,
104-
* StatusIB::InitFromChipError can be used to extract the status.
103+
* status response from the server. In that case, constructing
104+
* a StatusIB from the error can be used to extract the status.
105105
* - CHIP_ERROR*: All other cases.
106106
*/
107107
CHIP_ERROR error;

src/app/CommandSenderLegacyCallback.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ class CommandSenderLegacyCallback
6565
* - CHIP_ERROR_TIMEOUT: A response was not received within the expected response timeout.
6666
* - CHIP_ERROR_*TLV*: A malformed, non-compliant response was received from the server.
6767
* - CHIP_ERROR encapsulating a StatusIB: If we got a non-path-specific or path-specific
68-
* status response from the server. In that case,
69-
* StatusIB::InitFromChipError can be used to extract the status.
68+
* status response from the server. In that case, constructing a
69+
* StatusIB from the error can be used to extract the status.
7070
* - Note: a CommandSender using `CommandSender::Callback` only supports sending
7171
* a single InvokeRequest. As a result, only one path-specific error is expected
7272
* to ever be sent to the OnError callback.

src/app/MessageDef/StatusIB.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ CHIP_ERROR StatusIB::ToChipError() const
149149
return ChipError(ChipError::SdkPart::kIMGlobalStatus, to_underlying(mStatus));
150150
}
151151

152-
void StatusIB::InitFromChipError(CHIP_ERROR aError)
152+
StatusIB::StatusIB(CHIP_ERROR aError)
153153
{
154154
if (aError.IsPart(ChipError::SdkPart::kIMClusterStatus))
155155
{
@@ -204,8 +204,7 @@ bool FormatStatusIBError(char * buf, uint16_t bufSize, CHIP_ERROR err)
204204
constexpr size_t formattedSize = max(sizeof(generalFormat) + statusNameMaxLength, sizeof(clusterFormat));
205205
char formattedString[formattedSize];
206206

207-
StatusIB status;
208-
status.InitFromChipError(err);
207+
StatusIB status(err);
209208
if (status.mClusterStatus.HasValue())
210209
{
211210
snprintf(formattedString, formattedSize, clusterFormat, status.mClusterStatus.Value());

src/app/MessageDef/StatusIB.h

+1-8
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ struct StatusIB
6060
}
6161
}
6262

63-
explicit StatusIB(CHIP_ERROR error) { InitFromChipError(error); }
63+
explicit StatusIB(CHIP_ERROR error);
6464

6565
enum class Tag : uint8_t
6666
{
@@ -105,13 +105,6 @@ struct StatusIB
105105
*/
106106
CHIP_ERROR ToChipError() const;
107107

108-
/**
109-
* Extract a CHIP_ERROR into this StatusIB. If IsIMStatus() is false for
110-
* the error, this might do a best-effort attempt to come up with a
111-
* corresponding StatusIB, defaulting to a generic Status::Failure.
112-
*/
113-
void InitFromChipError(CHIP_ERROR aError);
114-
115108
/**
116109
* Test whether this status is a success.
117110
*/

src/app/ReadClient.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@ class ReadClient : public Messaging::ExchangeDelegate
195195
* - CHIP_ERROR_TIMEOUT: A response was not received within the expected response timeout.
196196
* - CHIP_ERROR_*TLV*: A malformed, non-compliant response was received from the server.
197197
* - CHIP_ERROR encapsulating a StatusIB: If we got a non-path-specific
198-
* status response from the server. In that case,
199-
* StatusIB::InitFromChipError can be used to extract the status.
198+
* status response from the server. In that case, constructing
199+
* a StatusIB from the error can be used to extract the status.
200200
* - CHIP_ERROR*: All other cases.
201201
*
202202
* This object MUST continue to exist after this call is completed. The application shall wait until it

src/app/TimedRequest.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ class TimedRequest
3838
// but came in after we sent a timed request).
3939
//
4040
// If the response is a failure StatusResponse, its status will be
41-
// encapsulated in the CHIP_ERROR this returns. In that case,
42-
// StatusIB::InitFromChipError can be used to extract the status.
41+
// encapsulated in the CHIP_ERROR this returns. In that case, constructing
42+
// a StatusIB from the error can be used to extract the status.
4343
static CHIP_ERROR HandleResponse(const PayloadHeader & aPayloadHeader, System::PacketBufferHandle && aPayload);
4444
};
4545

src/app/WriteClient.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ class WriteClient : public Messaging::ExchangeDelegate
8888
* - CHIP_ERROR_TIMEOUT: A response was not received within the expected response timeout.
8989
* - CHIP_ERROR_*TLV*: A malformed, non-compliant response was received from the server.
9090
* - CHIP_ERROR encapsulating a StatusIB: If we got a non-path-specific
91-
* status response from the server. In that case,
92-
* StatusIB::InitFromChipError can be used to extract the status.
91+
* status response from the server. In that case, constructing
92+
* a StatusIB from the error can be used to extract the status.
9393
* - CHIP_ERROR*: All other cases.
9494
*
9595
* The WriteClient object MUST continue to exist after this call is completed. The application shall wait until it

src/app/tests/TestStatusIB.cpp

+3-6
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ class TestStatusIB : public ::testing::Test
4646
#define VERIFY_ROUNDTRIP(err, status) \
4747
do \
4848
{ \
49-
StatusIB newStatus; \
50-
newStatus.InitFromChipError(err); \
49+
StatusIB newStatus(err); \
5150
EXPECT_EQ(newStatus.mStatus, status.mStatus); \
5251
EXPECT_EQ(newStatus.mClusterStatus, status.mClusterStatus); \
5352
} while (0);
@@ -86,16 +85,14 @@ TEST_F(TestStatusIB, TestStatusIBToFromChipError)
8685
err = status.ToChipError();
8786
EXPECT_NE(err, CHIP_NO_ERROR);
8887
{
89-
StatusIB newStatus;
90-
newStatus.InitFromChipError(err);
88+
StatusIB newStatus(err);
9189
EXPECT_EQ(newStatus.mStatus, Status::Failure);
9290
EXPECT_EQ(newStatus.mClusterStatus, status.mClusterStatus);
9391
}
9492

9593
err = CHIP_ERROR_NO_MEMORY;
9694
{
97-
StatusIB newStatus;
98-
newStatus.InitFromChipError(err);
95+
StatusIB newStatus(err);
9996
EXPECT_EQ(newStatus.mStatus, Status::Failure);
10097
EXPECT_FALSE(newStatus.mClusterStatus.HasValue());
10198
}

src/controller/TypedReadCallback.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ namespace Controller {
4343
* encapsulate a StatusIB). This could be a path-specific error or it
4444
* could be a general error for the entire request; the distinction is not
4545
* that important, because we only have one path involved. If the
46-
* CHIP_ERROR encapsulates a StatusIB, StatusIB::InitFromChipError can be
47-
* used to extract the status.
46+
* CHIP_ERROR encapsulates a StatusIB, constructing a StatusIB from it will
47+
* extract the status.
4848
*/
4949
template <typename DecodableAttributeType>
5050
class TypedReadAttributeCallback final : public app::ReadClient::Callback

0 commit comments

Comments
 (0)