From 8bdc3c260100dcaf3aad068caf9fd237fd459a1e Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Wed, 7 Aug 2024 10:26:33 -0400 Subject: [PATCH] Remove code duplication for CHIP_ERROR to ClusterCode conversion. (#34752) * Remove code duplication for CHIP_ERROR to ClusterCode conversion. We have a complete implementation of this in ClusterStatusCode. Remove the logic in StatusIB and use the ClusterStatusCode one instead. Generally StatusIB is just a ClusterStatusCode ontainer, however due to direct TLV reads, it splits out its contents. I only updated the constructor to use common code. * Move the chip-error conversion from statusIB into the header and made it re-use code --------- Co-authored-by: Andrei Litvin --- src/app/MessageDef/StatusIB.cpp | 26 +------------------------- src/app/MessageDef/StatusIB.h | 2 +- 2 files changed, 2 insertions(+), 26 deletions(-) diff --git a/src/app/MessageDef/StatusIB.cpp b/src/app/MessageDef/StatusIB.cpp index d612f549aeeae1..63012cc64f7f1f 100644 --- a/src/app/MessageDef/StatusIB.cpp +++ b/src/app/MessageDef/StatusIB.cpp @@ -24,6 +24,7 @@ #include "StatusIB.h" #include "MessageDefHelper.h" +#include "protocols/interaction_model/StatusCode.h" #include #include @@ -149,31 +150,6 @@ CHIP_ERROR StatusIB::ToChipError() const return ChipError(ChipError::SdkPart::kIMGlobalStatus, to_underlying(mStatus)); } -StatusIB::StatusIB(CHIP_ERROR aError) -{ - if (aError.IsPart(ChipError::SdkPart::kIMClusterStatus)) - { - mStatus = Status::Failure; - mClusterStatus = MakeOptional(aError.GetSdkCode()); - return; - } - - mClusterStatus = NullOptional; - if (aError == CHIP_NO_ERROR) - { - mStatus = Status::Success; - return; - } - - if (aError.IsPart(ChipError::SdkPart::kIMGlobalStatus)) - { - mStatus = static_cast(aError.GetSdkCode()); - return; - } - - mStatus = Status::Failure; -} - namespace { bool FormatStatusIBError(char * buf, uint16_t bufSize, CHIP_ERROR err) { diff --git a/src/app/MessageDef/StatusIB.h b/src/app/MessageDef/StatusIB.h index 291a68c7fd295d..a0087f4849201d 100644 --- a/src/app/MessageDef/StatusIB.h +++ b/src/app/MessageDef/StatusIB.h @@ -60,7 +60,7 @@ struct StatusIB } } - explicit StatusIB(CHIP_ERROR error); + explicit StatusIB(CHIP_ERROR error) : StatusIB(Protocols::InteractionModel::ClusterStatusCode(error)) {} enum class Tag : uint8_t {