@@ -45,6 +45,16 @@ Delegate * GetDelegate(EndpointId aEndpoint)
45
45
return (aEndpoint >= kActionsDelegateTableSize ? nullptr : gDelegateTable [aEndpoint]);
46
46
}
47
47
48
+ CHIP_ERROR IsValid (Delegate * delegate)
49
+ {
50
+ if (delegate == nullptr )
51
+ {
52
+ ChipLogError (Zcl, " Actions delegate is null!!!" );
53
+ return CHIP_ERROR_INCORRECT_STATE;
54
+ }
55
+ return CHIP_NO_ERROR;
56
+ }
57
+
48
58
} // namespace
49
59
50
60
ActionsServer ActionsServer::sInstance ;
@@ -117,11 +127,7 @@ CHIP_ERROR ActionsServer::ReadActionListAttribute(const ConcreteReadAttributePat
117
127
const AttributeValueEncoder::ListEncodeHelper & aEncoder)
118
128
{
119
129
Delegate * delegate = GetDelegate (aPath.mEndpointId );
120
- if (delegate == nullptr )
121
- {
122
- ChipLogError (Zcl, " Actions delegate is null!!!" );
123
- return CHIP_ERROR_INCORRECT_STATE;
124
- }
130
+ VerifyOrReturnError (IsValid (delegate) == CHIP_NO_ERROR, CHIP_ERROR_INCORRECT_STATE);
125
131
126
132
for (uint16_t i = 0 ; i < kMaxActionListLength ; i++)
127
133
{
@@ -142,11 +148,8 @@ CHIP_ERROR ActionsServer::ReadEndpointListAttribute(const ConcreteReadAttributeP
142
148
const AttributeValueEncoder::ListEncodeHelper & aEncoder)
143
149
{
144
150
Delegate * delegate = GetDelegate (aPath.mEndpointId );
145
- if (delegate == nullptr )
146
- {
147
- ChipLogError (Zcl, " Actions delegate is null!!!" );
148
- return CHIP_ERROR_INCORRECT_STATE;
149
- }
151
+ VerifyOrReturnError (IsValid (delegate) == CHIP_NO_ERROR, CHIP_ERROR_INCORRECT_STATE);
152
+
150
153
for (uint16_t i = 0 ; i < kMaxEndpointListLength ; i++)
151
154
{
152
155
EndpointListStorage epList;
@@ -165,11 +168,7 @@ CHIP_ERROR ActionsServer::ReadEndpointListAttribute(const ConcreteReadAttributeP
165
168
bool ActionsServer::HaveActionWithId (EndpointId aEndpointId, uint16_t aActionId)
166
169
{
167
170
Delegate * delegate = GetDelegate (aEndpointId);
168
- if (delegate == nullptr )
169
- {
170
- ChipLogError (Zcl, " Actions delegate is null!!!" );
171
- return false ;
172
- }
171
+ VerifyOrReturnValue (IsValid (delegate) == CHIP_NO_ERROR, false );
173
172
return delegate->HaveActionWithId (aActionId);
174
173
}
175
174
@@ -405,11 +404,7 @@ void ActionsServer::InvokeCommand(HandlerContext & handlerContext)
405
404
CHIP_ERROR ActionsServer::ModifyActionList (EndpointId aEndpoint, const ActionStructStorage & aAction)
406
405
{
407
406
Delegate * delegate = GetDelegate (aEndpoint);
408
- if (delegate == nullptr )
409
- {
410
- ChipLogError (Zcl, " Actions delegate is null!" );
411
- return CHIP_ERROR_INCORRECT_STATE;
412
- }
407
+ VerifyOrReturnError (IsValid (delegate) == CHIP_NO_ERROR, CHIP_ERROR_INCORRECT_STATE);
413
408
414
409
// Read through the list to find and update the existing action that matches the passed-in action's ID.
415
410
for (uint16_t i = 0 ; i < kMaxActionListLength ; i++)
@@ -437,11 +432,7 @@ CHIP_ERROR ActionsServer::ModifyActionList(EndpointId aEndpoint, const ActionStr
437
432
CHIP_ERROR ActionsServer::ModifyEndpointList (EndpointId aEndpoint, const EndpointListStorage & aEpList)
438
433
{
439
434
Delegate * delegate = GetDelegate (aEndpoint);
440
- if (delegate == nullptr )
441
- {
442
- ChipLogError (Zcl, " Actions delegate is null!" );
443
- return CHIP_ERROR_INCORRECT_STATE;
444
- }
435
+ VerifyOrReturnError (IsValid (delegate) == CHIP_NO_ERROR, CHIP_ERROR_INCORRECT_STATE);
445
436
446
437
// Read through the list to find and update the existing action that matches the passed-in endpoint-list's ID
447
438
for (uint16_t i = 0 ; i < kMaxEndpointListLength ; i++)
0 commit comments