Skip to content

Commit

Permalink
Remove StatusIB::InitFromChipError. (#34712)
Browse files Browse the repository at this point in the history
The constructor is a better fit for being able to convert CHIP_ERROR to
ClusterStatusCode and then to StatusIB.
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Dec 23, 2024
1 parent f58da33 commit 3760875
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 33 deletions.
3 changes: 1 addition & 2 deletions examples/chip-tool/commands/common/RemoteDataModelLogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
4 changes: 2 additions & 2 deletions src/app/CommandSender.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/app/CommandSenderLegacyCallback.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 2 additions & 3 deletions src/app/MessageDef/StatusIB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down Expand Up @@ -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());
Expand Down
9 changes: 1 addition & 8 deletions src/app/MessageDef/StatusIB.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ struct StatusIB
}
}

explicit StatusIB(CHIP_ERROR error) { InitFromChipError(error); }
explicit StatusIB(CHIP_ERROR error);

enum class Tag : uint8_t
{
Expand Down Expand Up @@ -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.
*/
Expand Down
4 changes: 2 additions & 2 deletions src/app/ReadClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/app/TimedRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down
4 changes: 2 additions & 2 deletions src/app/WriteClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 3 additions & 6 deletions src/app/tests/TestStatusIB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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());
}
Expand Down
4 changes: 2 additions & 2 deletions src/controller/TypedReadCallback.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename DecodableAttributeType>
class TypedReadAttributeCallback final : public app::ReadClient::Callback
Expand Down

0 comments on commit 3760875

Please sign in to comment.