Skip to content

Commit

Permalink
Remove code duplication for CHIP_ERROR to ClusterCode conversion. (#3…
Browse files Browse the repository at this point in the history
…4752)

* 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 <[email protected]>
  • Loading branch information
andy31415 and andreilitvin authored Aug 7, 2024
1 parent cea7fd8 commit 8bdc3c2
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 26 deletions.
26 changes: 1 addition & 25 deletions src/app/MessageDef/StatusIB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "StatusIB.h"

#include "MessageDefHelper.h"
#include "protocols/interaction_model/StatusCode.h"

#include <inttypes.h>
#include <stdarg.h>
Expand Down Expand Up @@ -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<Status>(aError.GetSdkCode());
return;
}

mStatus = Status::Failure;
}

namespace {
bool FormatStatusIBError(char * buf, uint16_t bufSize, CHIP_ERROR err)
{
Expand Down
2 changes: 1 addition & 1 deletion 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);
explicit StatusIB(CHIP_ERROR error) : StatusIB(Protocols::InteractionModel::ClusterStatusCode(error)) {}

enum class Tag : uint8_t
{
Expand Down

0 comments on commit 8bdc3c2

Please sign in to comment.