diff --git a/examples/chip-tool/commands/common/RemoteDataModelLogger.cpp b/examples/chip-tool/commands/common/RemoteDataModelLogger.cpp index 294673512882b3..3c6342752a0a61 100644 --- a/examples/chip-tool/commands/common/RemoteDataModelLogger.cpp +++ b/examples/chip-tool/commands/common/RemoteDataModelLogger.cpp @@ -160,8 +160,7 @@ CHIP_ERROR LogErrorAsJSON(const CHIP_ERROR & error) VerifyOrReturnError(gDelegate != nullptr, CHIP_NO_ERROR); Json::Value value; - chip::app::StatusIB status; - status.InitFromChipError(error); + chip::app::StatusIB status(error); return LogError(value, status); } diff --git a/examples/fabric-admin/commands/common/RemoteDataModelLogger.cpp b/examples/fabric-admin/commands/common/RemoteDataModelLogger.cpp index 6334d42506d53f..0e51a1503ea3e1 100644 --- a/examples/fabric-admin/commands/common/RemoteDataModelLogger.cpp +++ b/examples/fabric-admin/commands/common/RemoteDataModelLogger.cpp @@ -160,8 +160,7 @@ CHIP_ERROR LogErrorAsJSON(const CHIP_ERROR & error) VerifyOrReturnError(gDelegate != nullptr, CHIP_NO_ERROR); Json::Value value; - chip::app::StatusIB status; - status.InitFromChipError(error); + chip::app::StatusIB status(error); return LogError(value, status); } diff --git a/src/app/CommandSender.h b/src/app/CommandSender.h index 489c6aa9cd2965..ba98c7178a5c83 100644 --- a/src/app/CommandSender.h +++ b/src/app/CommandSender.h @@ -100,8 +100,8 @@ class CommandSender final : public Messaging::ExchangeDelegate * - CHIP_ERROR_TIMEOUT: A response was not received within the expected response timeout. * - CHIP_ERROR_*TLV*: A malformed, non-compliant response was received from the server. * - CHIP_ERROR encapsulating a StatusIB: If we got a non-path-specific - * status response from the server. In that case, - * StatusIB::InitFromChipError can be used to extract the status. + * status response from the server. In that case, constructing + * a StatusIB from the error can be used to extract the status. * - CHIP_ERROR*: All other cases. */ CHIP_ERROR error; diff --git a/src/app/CommandSenderLegacyCallback.h b/src/app/CommandSenderLegacyCallback.h index f6c63c1fd96292..2645dcbdee58df 100644 --- a/src/app/CommandSenderLegacyCallback.h +++ b/src/app/CommandSenderLegacyCallback.h @@ -65,8 +65,8 @@ class CommandSenderLegacyCallback * - CHIP_ERROR_TIMEOUT: A response was not received within the expected response timeout. * - CHIP_ERROR_*TLV*: A malformed, non-compliant response was received from the server. * - CHIP_ERROR encapsulating a StatusIB: If we got a non-path-specific or path-specific - * status response from the server. In that case, - * StatusIB::InitFromChipError can be used to extract the status. + * status response from the server. In that case, constructing a + * StatusIB from the error can be used to extract the status. * - Note: a CommandSender using `CommandSender::Callback` only supports sending * a single InvokeRequest. As a result, only one path-specific error is expected * to ever be sent to the OnError callback. diff --git a/src/app/MessageDef/StatusIB.cpp b/src/app/MessageDef/StatusIB.cpp index 55fec8b92661de..d612f549aeeae1 100644 --- a/src/app/MessageDef/StatusIB.cpp +++ b/src/app/MessageDef/StatusIB.cpp @@ -149,7 +149,7 @@ CHIP_ERROR StatusIB::ToChipError() const return ChipError(ChipError::SdkPart::kIMGlobalStatus, to_underlying(mStatus)); } -void StatusIB::InitFromChipError(CHIP_ERROR aError) +StatusIB::StatusIB(CHIP_ERROR aError) { if (aError.IsPart(ChipError::SdkPart::kIMClusterStatus)) { @@ -204,8 +204,7 @@ bool FormatStatusIBError(char * buf, uint16_t bufSize, CHIP_ERROR err) constexpr size_t formattedSize = max(sizeof(generalFormat) + statusNameMaxLength, sizeof(clusterFormat)); char formattedString[formattedSize]; - StatusIB status; - status.InitFromChipError(err); + StatusIB status(err); if (status.mClusterStatus.HasValue()) { snprintf(formattedString, formattedSize, clusterFormat, status.mClusterStatus.Value()); diff --git a/src/app/MessageDef/StatusIB.h b/src/app/MessageDef/StatusIB.h index 08137045ffcd7b..291a68c7fd295d 100644 --- a/src/app/MessageDef/StatusIB.h +++ b/src/app/MessageDef/StatusIB.h @@ -60,7 +60,7 @@ struct StatusIB } } - explicit StatusIB(CHIP_ERROR error) { InitFromChipError(error); } + explicit StatusIB(CHIP_ERROR error); enum class Tag : uint8_t { @@ -105,13 +105,6 @@ struct StatusIB */ CHIP_ERROR ToChipError() const; - /** - * Extract a CHIP_ERROR into this StatusIB. If IsIMStatus() is false for - * the error, this might do a best-effort attempt to come up with a - * corresponding StatusIB, defaulting to a generic Status::Failure. - */ - void InitFromChipError(CHIP_ERROR aError); - /** * Test whether this status is a success. */ diff --git a/src/app/ReadClient.h b/src/app/ReadClient.h index 9bfb628b47e252..57852499c6ccbf 100644 --- a/src/app/ReadClient.h +++ b/src/app/ReadClient.h @@ -195,8 +195,8 @@ class ReadClient : public Messaging::ExchangeDelegate * - CHIP_ERROR_TIMEOUT: A response was not received within the expected response timeout. * - CHIP_ERROR_*TLV*: A malformed, non-compliant response was received from the server. * - CHIP_ERROR encapsulating a StatusIB: If we got a non-path-specific - * status response from the server. In that case, - * StatusIB::InitFromChipError can be used to extract the status. + * status response from the server. In that case, constructing + * a StatusIB from the error can be used to extract the status. * - CHIP_ERROR*: All other cases. * * This object MUST continue to exist after this call is completed. The application shall wait until it diff --git a/src/app/TimedRequest.h b/src/app/TimedRequest.h index edfe1d78cf8b6a..729c1266b4d401 100644 --- a/src/app/TimedRequest.h +++ b/src/app/TimedRequest.h @@ -38,8 +38,8 @@ class TimedRequest // but came in after we sent a timed request). // // If the response is a failure StatusResponse, its status will be - // encapsulated in the CHIP_ERROR this returns. In that case, - // StatusIB::InitFromChipError can be used to extract the status. + // encapsulated in the CHIP_ERROR this returns. In that case, constructing + // a StatusIB from the error can be used to extract the status. static CHIP_ERROR HandleResponse(const PayloadHeader & aPayloadHeader, System::PacketBufferHandle && aPayload); }; diff --git a/src/app/WriteClient.h b/src/app/WriteClient.h index b4d803981be3d8..b056d238bf7e6e 100644 --- a/src/app/WriteClient.h +++ b/src/app/WriteClient.h @@ -88,8 +88,8 @@ class WriteClient : public Messaging::ExchangeDelegate * - CHIP_ERROR_TIMEOUT: A response was not received within the expected response timeout. * - CHIP_ERROR_*TLV*: A malformed, non-compliant response was received from the server. * - CHIP_ERROR encapsulating a StatusIB: If we got a non-path-specific - * status response from the server. In that case, - * StatusIB::InitFromChipError can be used to extract the status. + * status response from the server. In that case, constructing + * a StatusIB from the error can be used to extract the status. * - CHIP_ERROR*: All other cases. * * The WriteClient object MUST continue to exist after this call is completed. The application shall wait until it diff --git a/src/app/tests/TestStatusIB.cpp b/src/app/tests/TestStatusIB.cpp index 22806168a9e6da..9234a4f2350210 100644 --- a/src/app/tests/TestStatusIB.cpp +++ b/src/app/tests/TestStatusIB.cpp @@ -46,8 +46,7 @@ class TestStatusIB : public ::testing::Test #define VERIFY_ROUNDTRIP(err, status) \ do \ { \ - StatusIB newStatus; \ - newStatus.InitFromChipError(err); \ + StatusIB newStatus(err); \ EXPECT_EQ(newStatus.mStatus, status.mStatus); \ EXPECT_EQ(newStatus.mClusterStatus, status.mClusterStatus); \ } while (0); @@ -86,16 +85,14 @@ TEST_F(TestStatusIB, TestStatusIBToFromChipError) err = status.ToChipError(); EXPECT_NE(err, CHIP_NO_ERROR); { - StatusIB newStatus; - newStatus.InitFromChipError(err); + StatusIB newStatus(err); EXPECT_EQ(newStatus.mStatus, Status::Failure); EXPECT_EQ(newStatus.mClusterStatus, status.mClusterStatus); } err = CHIP_ERROR_NO_MEMORY; { - StatusIB newStatus; - newStatus.InitFromChipError(err); + StatusIB newStatus(err); EXPECT_EQ(newStatus.mStatus, Status::Failure); EXPECT_FALSE(newStatus.mClusterStatus.HasValue()); } diff --git a/src/controller/TypedReadCallback.h b/src/controller/TypedReadCallback.h index 000b5d51d522ce..f65b4f2168bff7 100644 --- a/src/controller/TypedReadCallback.h +++ b/src/controller/TypedReadCallback.h @@ -43,8 +43,8 @@ namespace Controller { * encapsulate a StatusIB). This could be a path-specific error or it * could be a general error for the entire request; the distinction is not * that important, because we only have one path involved. If the - * CHIP_ERROR encapsulates a StatusIB, StatusIB::InitFromChipError can be - * used to extract the status. + * CHIP_ERROR encapsulates a StatusIB, constructing a StatusIB from it will + * extract the status. */ template class TypedReadAttributeCallback final : public app::ReadClient::Callback