@@ -54,6 +54,25 @@ namespace ScenesManagement {
54
54
55
55
namespace {
56
56
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
+
57
76
// / @brief Generate and add a response to a command handler context if err parameter is not CHIP_NO_ERROR
58
77
// / @tparam ResponseType Type of response, depends on the command
59
78
// / @param ctx Command Handler context where to add reponse
@@ -65,24 +84,7 @@ CHIP_ERROR AddResponseOnError(CommandHandlerInterface::HandlerContext & ctx, Res
65
84
{
66
85
if (CHIP_NO_ERROR != err)
67
86
{
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));
86
88
ctx.mCommandHandler .AddResponse (ctx.mRequestPath , resp);
87
89
}
88
90
return err;
@@ -97,24 +99,28 @@ CHIP_ERROR AddResponseOnError(CommandHandlerInterface::HandlerContext & ctx, Res
97
99
template <typename ResponseType>
98
100
CHIP_ERROR AddResponseOnError (CommandHandlerInterface::HandlerContext & ctx, ResponseType & resp, Status status)
99
101
{
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.
100
104
return AddResponseOnError (ctx, resp, StatusIB (status).ToChipError ());
101
105
}
102
106
103
- template <typename ResponseType>
104
- CHIP_ERROR UpdateLastConfiguredBy (HandlerContext & ctx, ResponseType resp)
107
+ Status SetLastConfiguredBy (HandlerContext & ctx)
105
108
{
106
- Access::SubjectDescriptor descriptor = ctx.mCommandHandler .GetSubjectDescriptor ();
107
- Status status = Status::Success;
109
+ const Access::SubjectDescriptor descriptor = ctx.mCommandHandler .GetSubjectDescriptor ();
108
110
109
111
if (AuthMode::kCase == descriptor.authMode )
110
112
{
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 );
116
114
}
117
115
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
+
118
124
// LastConfiguredBy is optional, so we don't want to fail the command if it fails to update
119
125
VerifyOrReturnValue (!(Status::Success == status || Status::UnsupportedAttribute == status), CHIP_NO_ERROR);
120
126
return AddResponseOnError (ctx, resp, status);
0 commit comments