Skip to content

Commit 79a3224

Browse files
Scenes-cluster: move non-template things into non-template functions to save flash (project-chip#36288)
* Move non-template things into non-template functions * Add back comment referencing bug * Add a comment regarding status ... I did not update the logic but it does seem wrong --------- Co-authored-by: Andrei Litvin <andreilitvin@google.com>
1 parent e57dedf commit 79a3224

File tree

1 file changed

+33
-27
lines changed

1 file changed

+33
-27
lines changed

src/app/clusters/scenes-server/scenes-server.cpp

+33-27
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,25 @@ namespace ScenesManagement {
5454

5555
namespace {
5656

57+
Protocols::InteractionModel::Status ResponseStatus(CHIP_ERROR err)
58+
{
59+
// TODO : Properly fix mapping between error types (issue https://github.com/project-chip/connectedhomeip/issues/26885)
60+
if (CHIP_ERROR_NOT_FOUND == err)
61+
{
62+
return Protocols::InteractionModel::Status::NotFound;
63+
}
64+
if (CHIP_ERROR_NO_MEMORY == err)
65+
{
66+
return Protocols::InteractionModel::Status::ResourceExhausted;
67+
}
68+
if (CHIP_IM_GLOBAL_STATUS(UnsupportedAttribute) == err)
69+
{
70+
// TODO: Confirm if we need to add UnsupportedAttribute status as a return for Scene Commands
71+
return Protocols::InteractionModel::Status::InvalidCommand;
72+
}
73+
return StatusIB(err).mStatus;
74+
}
75+
5776
/// @brief Generate and add a response to a command handler context if err parameter is not CHIP_NO_ERROR
5877
/// @tparam ResponseType Type of response, depends on the command
5978
/// @param ctx Command Handler context where to add reponse
@@ -65,24 +84,7 @@ CHIP_ERROR AddResponseOnError(CommandHandlerInterface::HandlerContext & ctx, Res
6584
{
6685
if (CHIP_NO_ERROR != err)
6786
{
68-
// TODO : Properly fix mapping between error types (issue https://github.com/project-chip/connectedhomeip/issues/26885)
69-
if (CHIP_ERROR_NOT_FOUND == err)
70-
{
71-
resp.status = to_underlying(Protocols::InteractionModel::Status::NotFound);
72-
}
73-
else if (CHIP_ERROR_NO_MEMORY == err)
74-
{
75-
resp.status = to_underlying(Protocols::InteractionModel::Status::ResourceExhausted);
76-
}
77-
else if (CHIP_IM_GLOBAL_STATUS(UnsupportedAttribute) == err)
78-
{
79-
// TODO: Confirm if we need to add UnsupportedAttribute status as a return for Scene Commands
80-
resp.status = to_underlying(Protocols::InteractionModel::Status::InvalidCommand);
81-
}
82-
else
83-
{
84-
resp.status = to_underlying(StatusIB(err).mStatus);
85-
}
87+
resp.status = to_underlying(ResponseStatus(err));
8688
ctx.mCommandHandler.AddResponse(ctx.mRequestPath, resp);
8789
}
8890
return err;
@@ -97,24 +99,28 @@ CHIP_ERROR AddResponseOnError(CommandHandlerInterface::HandlerContext & ctx, Res
9799
template <typename ResponseType>
98100
CHIP_ERROR AddResponseOnError(CommandHandlerInterface::HandlerContext & ctx, ResponseType & resp, Status status)
99101
{
102+
// TODO: this seems odd: we convert `status` to a CHIP_ERROR and then back to status. This seems
103+
// potentially lossy and not ideal.
100104
return AddResponseOnError(ctx, resp, StatusIB(status).ToChipError());
101105
}
102106

103-
template <typename ResponseType>
104-
CHIP_ERROR UpdateLastConfiguredBy(HandlerContext & ctx, ResponseType resp)
107+
Status SetLastConfiguredBy(HandlerContext & ctx)
105108
{
106-
Access::SubjectDescriptor descriptor = ctx.mCommandHandler.GetSubjectDescriptor();
107-
Status status = Status::Success;
109+
const Access::SubjectDescriptor descriptor = ctx.mCommandHandler.GetSubjectDescriptor();
108110

109111
if (AuthMode::kCase == descriptor.authMode)
110112
{
111-
status = Attributes::LastConfiguredBy::Set(ctx.mRequestPath.mEndpointId, descriptor.subject);
112-
}
113-
else
114-
{
115-
status = Attributes::LastConfiguredBy::SetNull(ctx.mRequestPath.mEndpointId);
113+
return Attributes::LastConfiguredBy::Set(ctx.mRequestPath.mEndpointId, descriptor.subject);
116114
}
117115

116+
return Attributes::LastConfiguredBy::SetNull(ctx.mRequestPath.mEndpointId);
117+
}
118+
119+
template <typename ResponseType>
120+
CHIP_ERROR UpdateLastConfiguredBy(HandlerContext & ctx, ResponseType resp)
121+
{
122+
Status status = SetLastConfiguredBy(ctx);
123+
118124
// LastConfiguredBy is optional, so we don't want to fail the command if it fails to update
119125
VerifyOrReturnValue(!(Status::Success == status || Status::UnsupportedAttribute == status), CHIP_NO_ERROR);
120126
return AddResponseOnError(ctx, resp, status);

0 commit comments

Comments
 (0)