Skip to content

Commit

Permalink
Update cluster code
Browse files Browse the repository at this point in the history
  • Loading branch information
erjiaqing committed Mar 28, 2022
1 parent c8132d7 commit 2f87a94
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 110 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ CHIP_ERROR OTAProviderExample::SendQueryImageResponse(chip::app::CommandHandler
response.metadataForRequestor.Emplace(chip::ByteSpan());
}

VerifyOrReturnError(commandObj->AddResponse(commandPath, response) == CHIP_NO_ERROR, EMBER_ZCL_STATUS_FAILURE);
commandObj->AddResponse(commandPath, response);
return CHIP_NO_ERROR;
}

Expand Down Expand Up @@ -389,7 +389,7 @@ EmberAfStatus OTAProviderExample::HandleApplyUpdateRequest(chip::app::CommandHan
// Reset back to success case for subsequent uses
mUpdateAction = OTAApplyUpdateAction::kProceed;

VerifyOrReturnError(commandObj->AddResponse(commandPath, response) == CHIP_NO_ERROR, EMBER_ZCL_STATUS_FAILURE);
commandObj->AddResponse(commandPath, response);

return EMBER_ZCL_STATUS_SUCCESS;
}
Expand Down
9 changes: 3 additions & 6 deletions src/app/CommandResponseHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,9 @@ class CommandResponseHelper

CHIP_ERROR Success(const CommandData & aResponse)
{
CHIP_ERROR err = mCommandHandler->AddResponse(mCommandPath, aResponse);
if (err == CHIP_NO_ERROR)
{
mSentResponse = true;
}
return err;
mCommandHandler->AddResponse(mCommandPath, aResponse);
mSentResponse = true;
return CHIP_NO_ERROR;
};

CHIP_ERROR Success(ClusterStatus aClusterStatus)
Expand Down
21 changes: 10 additions & 11 deletions src/app/clusters/door-lock-server/door-lock-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2169,11 +2169,10 @@ DlStatus DoorLockServer::clearSchedules(chip::EndpointId endpointId, uint16_t us
return DlStatus::kSuccess;
}

CHIP_ERROR DoorLockServer::sendGetWeekDayScheduleResponse(chip::app::CommandHandler * commandObj,
const chip::app::ConcreteCommandPath & commandPath, uint8_t weekdayIndex,
uint16_t userIndex, DlStatus status, DlDaysMaskMap daysMask,
uint8_t startHour, uint8_t startMinute, uint8_t endHour,
uint8_t endMinute)
void DoorLockServer::sendGetWeekDayScheduleResponse(chip::app::CommandHandler * commandObj,
const chip::app::ConcreteCommandPath & commandPath, uint8_t weekdayIndex,
uint16_t userIndex, DlStatus status, DlDaysMaskMap daysMask, uint8_t startHour,
uint8_t startMinute, uint8_t endHour, uint8_t endMinute)
{
VerifyOrDie(nullptr != commandObj);

Expand All @@ -2190,7 +2189,7 @@ CHIP_ERROR DoorLockServer::sendGetWeekDayScheduleResponse(chip::app::CommandHand
response.endMinute = Optional<uint8_t>(endMinute);
}

return commandObj->AddResponse(commandPath, response);
commandObj->AddResponse(commandPath, response);
}

bool DoorLockServer::yearDayIndexValid(chip::EndpointId endpointId, uint8_t yearDayIndex)
Expand Down Expand Up @@ -2242,10 +2241,10 @@ DlStatus DoorLockServer::clearYearDaySchedules(chip::EndpointId endpointId, uint
return DlStatus::kSuccess;
}

CHIP_ERROR DoorLockServer::sendGetYearDayScheduleResponse(chip::app::CommandHandler * commandObj,
const chip::app::ConcreteCommandPath & commandPath, uint8_t yearDayIndex,
uint16_t userIndex, DlStatus status, uint32_t localStartTime,
uint32_t localEndTime)
void DoorLockServer::sendGetYearDayScheduleResponse(chip::app::CommandHandler * commandObj,
const chip::app::ConcreteCommandPath & commandPath, uint8_t yearDayIndex,
uint16_t userIndex, DlStatus status, uint32_t localStartTime,
uint32_t localEndTime)
{
VerifyOrDie(nullptr != commandObj);

Expand All @@ -2259,7 +2258,7 @@ CHIP_ERROR DoorLockServer::sendGetYearDayScheduleResponse(chip::app::CommandHand
response.localEndTime = Optional<uint32_t>(localEndTime);
}

return commandObj->AddResponse(commandPath, response);
commandObj->AddResponse(commandPath, response);
}

EmberAfStatus DoorLockServer::clearCredential(chip::EndpointId endpointId, chip::FabricIndex modifier, chip::NodeId sourceNodeId,
Expand Down
16 changes: 7 additions & 9 deletions src/app/clusters/door-lock-server/door-lock-server.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,21 +238,19 @@ class DoorLockServer
DlStatus clearWeekDaySchedules(chip::EndpointId endpointId, uint16_t userIndex);
DlStatus clearSchedules(chip::EndpointId endpointId, uint16_t userIndex);

CHIP_ERROR sendGetWeekDayScheduleResponse(chip::app::CommandHandler * commandObj,
const chip::app::ConcreteCommandPath & commandPath, uint8_t weekdayIndex,
uint16_t userIndex, DlStatus status, DlDaysMaskMap daysMask = DlDaysMaskMap(0),
uint8_t startHour = 0, uint8_t startMinute = 0, uint8_t endHour = 0,
uint8_t endMinute = 0);
void sendGetWeekDayScheduleResponse(chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath,
uint8_t weekdayIndex, uint16_t userIndex, DlStatus status,
DlDaysMaskMap daysMask = DlDaysMaskMap(0), uint8_t startHour = 0, uint8_t startMinute = 0,
uint8_t endHour = 0, uint8_t endMinute = 0);

bool yearDayIndexValid(chip::EndpointId endpointId, uint8_t yearDayIndex);

DlStatus clearYearDaySchedule(chip::EndpointId endpointId, uint16_t userIndex, uint8_t weekDayIndex);
DlStatus clearYearDaySchedules(chip::EndpointId endpointId, uint16_t userIndex);

CHIP_ERROR sendGetYearDayScheduleResponse(chip::app::CommandHandler * commandObj,
const chip::app::ConcreteCommandPath & commandPath, uint8_t yearDayIndex,
uint16_t userIndex, DlStatus status, uint32_t localStartTime = 0,
uint32_t localEndTime = 0);
void sendGetYearDayScheduleResponse(chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath,
uint8_t yearDayIndex, uint16_t userIndex, DlStatus status, uint32_t localStartTime = 0,
uint32_t localEndTime = 0);

bool sendRemoteLockUserChange(chip::EndpointId endpointId, DlLockDataType dataType, DlDataOperationType operation,
chip::NodeId nodeId, chip::FabricIndex fabricIndex, uint16_t userIndex = 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,12 @@ bool emberAfGeneralCommissioningClusterArmFailSafeCallback(app::CommandHandler *
CheckSuccess(failSafeContext.ArmFailSafe(accessingFabricIndex, System::Clock::Seconds16(commandData.expiryLengthSeconds)),
Failure);
response.errorCode = CommissioningError::kOk;
CheckSuccess(commandObj->AddResponse(commandPath, response), Failure);
commandObj->AddResponse(commandPath, response);
}
else
{
response.errorCode = CommissioningError::kBusyWithOtherAdmin;
CheckSuccess(commandObj->AddResponse(commandPath, response), Failure);
commandObj->AddResponse(commandPath, response);
}

return true;
Expand All @@ -178,7 +178,7 @@ bool emberAfGeneralCommissioningClusterCommissioningCompleteCallback(

Commands::CommissioningCompleteResponse::Type response;
response.errorCode = CommissioningError::kOk;
CheckSuccess(commandObj->AddResponse(commandPath, response), Failure);
commandObj->AddResponse(commandPath, response);

return true;
}
Expand All @@ -195,7 +195,7 @@ bool emberAfGeneralCommissioningClusterSetRegulatoryConfigCallback(app::CommandH

Commands::SetRegulatoryConfigResponse::Type response;
response.errorCode = CommissioningError::kOk;
CheckSuccess(commandObj->AddResponse(commandPath, response), Failure);
commandObj->AddResponse(commandPath, response);

return true;
}
Expand Down
13 changes: 2 additions & 11 deletions src/app/clusters/group-key-mgmt-server/group-key-mgmt-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,12 +438,7 @@ bool emberAfGroupKeyManagementClusterKeySetReadCallback(
}
response.groupKeySet.epochKey2.SetNull();

CHIP_ERROR err = commandObj->AddResponse(commandPath, response);
if (CHIP_NO_ERROR != err)
{
ChipLogDetail(Zcl, "GroupKeyManagementCluster: KeySetRead failed: %s", ErrorStr(err));
emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_FAILURE);
}
commandObj->AddResponse(commandPath, response);
return true;
}

Expand Down Expand Up @@ -530,11 +525,7 @@ bool emberAfGroupKeyManagementClusterKeySetReadAllIndicesCallback(
return true;
}

CHIP_ERROR err = commandObj->AddResponse(commandPath, KeySetReadAllIndicesResponse(keysIt));
if (CHIP_NO_ERROR != err)
{
ChipLogDetail(Zcl, "GroupKeyManagementCluster: KeySetReadAllIndices failed: %s", ErrorStr(err));
}
commandObj->AddResponse(commandPath, KeySetReadAllIndicesResponse(keysIt));
keysIt->Release();
return true;
}
27 changes: 4 additions & 23 deletions src/app/clusters/groups-server/groups-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ bool emberAfGroupsClusterAddGroupCallback(app::CommandHandler * commandObj, cons
{
auto fabricIndex = commandObj->GetAccessingFabricIndex();
Groups::Commands::AddGroupResponse::Type response;
CHIP_ERROR err = CHIP_NO_ERROR;

// For all networks, Add Group commands are only responded to when
// they are addressed to a single device.
Expand All @@ -148,12 +147,7 @@ bool emberAfGroupsClusterAddGroupCallback(app::CommandHandler * commandObj, cons

response.groupId = commandData.groupId;
response.status = GroupAdd(fabricIndex, commandPath.mEndpointId, commandData.groupId, commandData.groupName);
err = commandObj->AddResponse(commandPath, response);
if (CHIP_NO_ERROR != err)
{
ChipLogDetail(Zcl, "GroupsCluster: AddGroup failed: %s", err.AsString());
emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_FAILURE);
}
commandObj->AddResponse(commandPath, response);
return true;
}

Expand Down Expand Up @@ -185,12 +179,7 @@ bool emberAfGroupsClusterViewGroupCallback(app::CommandHandler * commandObj, con
exit:
response.groupId = groupId;
response.status = status;
err = commandObj->AddResponse(commandPath, response);
if (CHIP_NO_ERROR != err)
{
ChipLogDetail(Zcl, "GroupsCluster: ViewGroup failed: %s", err.AsString());
emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_FAILURE);
}
commandObj->AddResponse(commandPath, response);
return true;
}

Expand Down Expand Up @@ -284,14 +273,12 @@ bool emberAfGroupsClusterGetGroupMembershipCallback(app::CommandHandler * comman

{
GroupDataProvider::EndpointIterator * iter = nullptr;
CHIP_ERROR err = CHIP_NO_ERROR;

iter = provider->IterateEndpoints(fabricIndex);
VerifyOrExit(nullptr != iter, status = EMBER_ZCL_STATUS_FAILURE);

err = commandObj->AddResponse(commandPath, GroupMembershipResponse(commandData, commandPath.mEndpointId, iter));
commandObj->AddResponse(commandPath, GroupMembershipResponse(commandData, commandPath.mEndpointId, iter));
iter->Release();
status = (CHIP_NO_ERROR == err) ? EMBER_ZCL_STATUS_SUCCESS : EMBER_ZCL_STATUS_FAILURE;
}

exit:
Expand All @@ -308,7 +295,6 @@ bool emberAfGroupsClusterRemoveGroupCallback(app::CommandHandler * commandObj, c
{
auto fabricIndex = commandObj->GetAccessingFabricIndex();
Groups::Commands::RemoveGroupResponse::Type response;
CHIP_ERROR err = CHIP_NO_ERROR;

// For all networks, Remove Group commands are only responded to when
// they are addressed to a single device.
Expand All @@ -324,12 +310,7 @@ bool emberAfGroupsClusterRemoveGroupCallback(app::CommandHandler * commandObj, c
response.groupId = commandData.groupId;
response.status = GroupRemove(fabricIndex, commandPath.mEndpointId, commandData.groupId);

err = commandObj->AddResponse(commandPath, response);
if (CHIP_NO_ERROR != err)
{
ChipLogDetail(Zcl, "GroupsCluster: RemoveGroup failed: %s", err.AsString());
emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_FAILURE);
}
commandObj->AddResponse(commandPath, response);
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ using namespace chip::Protocols::InteractionModel;

namespace {

CHIP_ERROR SendNOCResponse(app::CommandHandler * commandObj, const ConcreteCommandPath & path, OperationalCertStatus status,
uint8_t index, const CharSpan & debug_text);
void SendNOCResponse(app::CommandHandler * commandObj, const ConcreteCommandPath & path, OperationalCertStatus status,
uint8_t index, const CharSpan & debug_text);
OperationalCertStatus ConvertToNOCResponseStatus(CHIP_ERROR err);

constexpr uint8_t kDACCertificate = 1;
Expand Down Expand Up @@ -519,8 +519,8 @@ namespace {
// TODO: Manage ephemeral RCAC/ICAC/NOC storage to avoid a full FabricInfo being needed here.
FabricInfo gFabricBeingCommissioned;

CHIP_ERROR SendNOCResponse(app::CommandHandler * commandObj, const ConcreteCommandPath & path, OperationalCertStatus status,
uint8_t index, const CharSpan & debug_text)
void SendNOCResponse(app::CommandHandler * commandObj, const ConcreteCommandPath & path, OperationalCertStatus status,
uint8_t index, const CharSpan & debug_text)
{
Commands::NOCResponse::Type payload;
payload.statusCode = status;
Expand All @@ -535,7 +535,7 @@ CHIP_ERROR SendNOCResponse(app::CommandHandler * commandObj, const ConcreteComma
payload.debugText.Emplace(to_send);
}

return commandObj->AddResponse(path, payload);
commandObj->AddResponse(path, payload);
}

OperationalCertStatus ConvertToNOCResponseStatus(CHIP_ERROR err)
Expand Down Expand Up @@ -774,7 +774,7 @@ bool emberAfOperationalCredentialsClusterCertificateChainRequestCallback(
}

response.certificate = derBufSpan;
SuccessOrExit(err = commandObj->AddResponse(commandPath, response));
commandObj->AddResponse(commandPath, response);

exit:
if (err != CHIP_NO_ERROR)
Expand Down Expand Up @@ -834,7 +834,7 @@ bool emberAfOperationalCredentialsClusterAttestationRequestCallback(app::Command

response.attestationElements = attestationElementsSpan;
response.signature = signatureSpan;
SuccessOrExit(err = commandObj->AddResponse(commandPath, response));
commandObj->AddResponse(commandPath, response);
}

exit:
Expand Down Expand Up @@ -922,7 +922,7 @@ bool emberAfOperationalCredentialsClusterCSRRequestCallback(app::CommandHandler

response.NOCSRElements = nocsrElementsSpan;
response.attestationSignature = signatureSpan;
SuccessOrExit(err = commandObj->AddResponse(commandPath, response));
commandObj->AddResponse(commandPath, response);
}

exit:
Expand Down
40 changes: 8 additions & 32 deletions src/app/clusters/test-cluster-server/test-cluster-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -714,11 +714,7 @@ bool emberAfTestClusterClusterTestSpecificCallback(CommandHandler * apCommandObj
{
TestSpecificResponse::Type responseData;
responseData.returnValue = 7;
CHIP_ERROR err = apCommandObj->AddResponse(commandPath, responseData);
if (CHIP_NO_ERROR != err)
{
ChipLogError(Zcl, "Test Cluster: failed to send TestSpecific response: %" CHIP_ERROR_FORMAT, err.Format());
}
apCommandObj->AddResponse(commandPath, responseData);
return true;
}

Expand All @@ -738,23 +734,15 @@ bool emberAfTestClusterClusterTestAddArgumentsCallback(CommandHandler * apComman

TestAddArgumentsResponse::Type responseData;
responseData.returnValue = static_cast<uint8_t>(commandData.arg1 + commandData.arg2);
CHIP_ERROR err = apCommandObj->AddResponse(commandPath, responseData);
if (CHIP_NO_ERROR != err)
{
ChipLogError(Zcl, "Test Cluster: failed to send TestAddArguments response: %" CHIP_ERROR_FORMAT, err.Format());
}
apCommandObj->AddResponse(commandPath, responseData);
return true;
}

static bool SendBooleanResponse(CommandHandler * commandObj, const ConcreteCommandPath & commandPath, bool value)
{
Commands::BooleanResponse::Type response;
response.value = value;
CHIP_ERROR err = commandObj->AddResponse(commandPath, response);
if (err != CHIP_NO_ERROR)
{
commandObj->AddStatus(commandPath, Protocols::InteractionModel::Status::Failure);
}
commandObj->AddResponse(commandPath, response);
return true;
}

Expand Down Expand Up @@ -923,7 +911,7 @@ bool emberAfTestClusterClusterTestListInt8UReverseRequestCallback(
Commands::TestListInt8UReverseResponse::Type responseData;
if (count == 0)
{
SuccessOrExit(commandObj->AddResponse(commandPath, responseData));
commandObj->AddResponse(commandPath, responseData);
return true;
}
size_t cur = count;
Expand All @@ -937,7 +925,7 @@ bool emberAfTestClusterClusterTestListInt8UReverseRequestCallback(
VerifyOrExit(cur == 0, );
VerifyOrExit(iter.GetStatus() == CHIP_NO_ERROR, );
responseData.arg1 = DataModel::List<uint8_t>(responseBuf.Get(), count);
SuccessOrExit(commandObj->AddResponse(commandPath, responseData));
commandObj->AddResponse(commandPath, responseData);
return true;
}

Expand All @@ -953,11 +941,7 @@ bool emberAfTestClusterClusterTestEnumsRequestCallback(CommandHandler * commandO
response.arg1 = commandData.arg1;
response.arg2 = commandData.arg2;

CHIP_ERROR err = commandObj->AddResponse(commandPath, response);
if (err != CHIP_NO_ERROR)
{
emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_FAILURE);
}
commandObj->AddResponse(commandPath, response);
return true;
}

Expand All @@ -979,11 +963,7 @@ bool emberAfTestClusterClusterTestNullableOptionalRequestCallback(
response.originalValue.Emplace(commandData.arg1.Value());
}

CHIP_ERROR err = commandObj->AddResponse(commandPath, response);
if (err != CHIP_NO_ERROR)
{
emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_FAILURE);
}
commandObj->AddResponse(commandPath, response);
return true;
}

Expand All @@ -1000,11 +980,7 @@ bool emberAfTestClusterClusterSimpleStructEchoRequestCallback(CommandHandler * c
response.arg1.g = commandData.arg1.g;
response.arg1.h = commandData.arg1.h;

CHIP_ERROR err = commandObj->AddResponse(commandPath, response);
if (err != CHIP_NO_ERROR)
{
emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_FAILURE);
}
commandObj->AddResponse(commandPath, response);
return true;
}

Expand Down
Loading

0 comments on commit 2f87a94

Please sign in to comment.