Skip to content

Commit

Permalink
[chip-tool] Add an optional suppressResponse argument to chip-tool co…
Browse files Browse the repository at this point in the history
…mmand line for cluster commands and write commands (#15792)
  • Loading branch information
vivien-apple authored and pull[bot] committed Jul 21, 2023
1 parent 4a3c5ff commit 1307928
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 11 deletions.
7 changes: 6 additions & 1 deletion examples/chip-tool/commands/clusters/ClusterCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class ClusterCommand : public ModelCommand, public chip::app::CommandSender::Cal
AddArgument("command-id", 0, UINT32_MAX, &mCommandId);
AddArgument("payload", &mPayload);
AddArgument("timedInteractionTimeoutMs", 0, UINT16_MAX, &mTimedInteractionTimeoutMs);
AddArgument("suppressResponse", 0, 1, &mSuppressResponse);
ModelCommand::AddArguments();
}

Expand All @@ -41,13 +42,15 @@ class ClusterCommand : public ModelCommand, public chip::app::CommandSender::Cal
AddArgument("command-id", 0, UINT32_MAX, &mCommandId);
AddArgument("payload", &mPayload);
AddArgument("timedInteractionTimeoutMs", 0, UINT16_MAX, &mTimedInteractionTimeoutMs);
AddArgument("suppressResponse", 0, 1, &mSuppressResponse);
ModelCommand::AddArguments();
}

ClusterCommand(const char * commandName, CredentialIssuerCommands * credsIssuerConfig) :
ModelCommand(commandName, credsIssuerConfig)
{
AddArgument("timedInteractionTimeoutMs", 0, UINT16_MAX, &mTimedInteractionTimeoutMs);
AddArgument("suppressResponse", 0, 1, &mSuppressResponse);
}

~ClusterCommand() {}
Expand Down Expand Up @@ -107,7 +110,8 @@ class ClusterCommand : public ModelCommand, public chip::app::CommandSender::Cal
mCommandSender =
std::make_unique<chip::app::CommandSender>(this, device->GetExchangeManager(), mTimedInteractionTimeoutMs.HasValue());
VerifyOrReturnError(mCommandSender != nullptr, CHIP_ERROR_NO_MEMORY);
ReturnErrorOnFailure(mCommandSender->AddRequestDataNoTimedCheck(commandPath, value, mTimedInteractionTimeoutMs));
ReturnErrorOnFailure(mCommandSender->AddRequestDataNoTimedCheck(commandPath, value, mTimedInteractionTimeoutMs,
mSuppressResponse.ValueOr(false)));
ReturnErrorOnFailure(mCommandSender->SendCommandRequest(device->GetSecureSession().Value()));
return CHIP_NO_ERROR;
}
Expand Down Expand Up @@ -137,6 +141,7 @@ class ClusterCommand : public ModelCommand, public chip::app::CommandSender::Cal
chip::ClusterId mClusterId;
chip::CommandId mCommandId;
chip::Optional<uint16_t> mTimedInteractionTimeoutMs;
chip::Optional<bool> mSuppressResponse;

CHIP_ERROR mError = CHIP_NO_ERROR;
CustomArgument mPayload;
Expand Down
7 changes: 6 additions & 1 deletion examples/chip-tool/commands/clusters/WriteAttributeCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class WriteAttribute : public ModelCommand, public chip::app::WriteClient::Callb
AddArgument("attribute-value", &mAttributeValue);
AddArgument("timedInteractionTimeoutMs", 0, UINT16_MAX, &mTimedInteractionTimeoutMs);
AddArgument("data-version", 0, UINT32_MAX, &mDataVersion);
AddArgument("suppressResponse", 0, 1, &mSuppressResponse);
ModelCommand::AddArguments();
}

Expand All @@ -43,6 +44,7 @@ class WriteAttribute : public ModelCommand, public chip::app::WriteClient::Callb
AddArgument("attribute-value", &mAttributeValue);
AddArgument("timedInteractionTimeoutMs", 0, UINT16_MAX, &mTimedInteractionTimeoutMs);
AddArgument("data-version", 0, UINT32_MAX, &mDataVersion);
AddArgument("suppressResponse", 0, 1, &mSuppressResponse);
ModelCommand::AddArguments();
}

Expand All @@ -51,6 +53,7 @@ class WriteAttribute : public ModelCommand, public chip::app::WriteClient::Callb
{
AddArgument("timedInteractionTimeoutMs", 0, UINT16_MAX, &mTimedInteractionTimeoutMs);
AddArgument("data-version", 0, UINT32_MAX, &mDataVersion);
AddArgument("suppressResponse", 0, 1, &mSuppressResponse);
}

~WriteAttribute() {}
Expand Down Expand Up @@ -103,7 +106,8 @@ class WriteAttribute : public ModelCommand, public chip::app::WriteClient::Callb
attributePathParams.mClusterId = clusterId;
attributePathParams.mAttributeId = attributeId;

mWriteClient = std::make_unique<chip::app::WriteClient>(device->GetExchangeManager(), this, mTimedInteractionTimeoutMs);
mWriteClient = std::make_unique<chip::app::WriteClient>(device->GetExchangeManager(), this, mTimedInteractionTimeoutMs,
mSuppressResponse.ValueOr(false));

ReturnErrorOnFailure(mWriteClient->EncodeAttribute(attributePathParams, value, mDataVersion));

Expand Down Expand Up @@ -141,6 +145,7 @@ class WriteAttribute : public ModelCommand, public chip::app::WriteClient::Callb
CHIP_ERROR mError = CHIP_NO_ERROR;
chip::Optional<uint16_t> mTimedInteractionTimeoutMs;
chip::Optional<chip::DataVersion> mDataVersion = chip::NullOptional;
chip::Optional<bool> mSuppressResponse;
CustomArgument mAttributeValue;
std::unique_ptr<chip::app::WriteClient> mWriteClient;
};
3 changes: 2 additions & 1 deletion src/app/CommandSender.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,9 @@ class CommandSender final : public Messaging::ExchangeDelegate
*/
template <typename CommandDataT>
CHIP_ERROR AddRequestDataNoTimedCheck(const CommandPathParams & aCommandPath, const CommandDataT & aData,
const Optional<uint16_t> & aTimedInvokeTimeoutMs)
const Optional<uint16_t> & aTimedInvokeTimeoutMs, bool aSuppressResponse = false)
{
mSuppressResponse = aSuppressResponse;
return AddRequestDataInternal(aCommandPath, aData, aTimedInvokeTimeoutMs);
}
#endif // CONFIG_IM_BUILD_FOR_UNIT_TEST
Expand Down
1 change: 1 addition & 0 deletions src/app/WriteClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ CHIP_ERROR WriteClient::StartNewMessage()
ReturnErrorOnFailure(mMessageWriter.ReserveBuffer(reservedSize));

ReturnErrorOnFailure(mWriteRequestBuilder.Init(&mMessageWriter));
mWriteRequestBuilder.SuppressResponse(mSuppressResponse);
mWriteRequestBuilder.TimedRequest(mTimedWriteTimeoutMs.HasValue());
ReturnErrorOnFailure(mWriteRequestBuilder.GetError());
mWriteRequestBuilder.CreateWriteRequests();
Expand Down
8 changes: 5 additions & 3 deletions src/app/WriteClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,12 @@ class WriteClient : public Messaging::ExchangeDelegate
* @param[in] apExchangeMgr A pointer to the ExchangeManager object.
* @param[in] apCallback Callback set by application.
* @param[in] aTimedWriteTimeoutMs If provided, do a timed write using this timeout.
* @param[in] aSuppressResponse If provided, set SuppressResponse field to the provided value
*/
WriteClient(Messaging::ExchangeManager * apExchangeMgr, Callback * apCallback,
const Optional<uint16_t> & aTimedWriteTimeoutMs) :
WriteClient(Messaging::ExchangeManager * apExchangeMgr, Callback * apCallback, const Optional<uint16_t> & aTimedWriteTimeoutMs,
bool aSuppressResponse = false) :
mpExchangeMgr(apExchangeMgr),
mpCallback(apCallback), mTimedWriteTimeoutMs(aTimedWriteTimeoutMs)
mpCallback(apCallback), mTimedWriteTimeoutMs(aTimedWriteTimeoutMs), mSuppressResponse(aSuppressResponse)
{}

#if CONFIG_IM_BUILD_FOR_UNIT_TEST
Expand Down Expand Up @@ -391,6 +392,7 @@ class WriteClient : public Messaging::ExchangeDelegate
// If mTimedWriteTimeoutMs has a value, we are expected to do a timed
// write.
Optional<uint16_t> mTimedWriteTimeoutMs;
bool mSuppressResponse = false;

// A list of buffers, one buffer for each chunk.
System::PacketBufferHandle mChunks;
Expand Down
4 changes: 2 additions & 2 deletions src/app/WriteHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ CHIP_ERROR WriteHandler::Init()

void WriteHandler::Close()
{
mSuppressResponse = false;
VerifyOrReturn(mState != State::Uninitialized);

if (mpExchangeCtx != nullptr)
Expand Down Expand Up @@ -394,7 +395,6 @@ Status WriteHandler::ProcessWriteRequest(System::PacketBufferHandle && aPayload,
WriteRequestMessage::Parser writeRequestParser;
AttributeDataIBs::Parser AttributeDataIBsParser;
TLV::TLVReader AttributeDataIBsReader;
bool needSuppressResponse = false;
// Default to InvalidAction for our status; that's what we want if any of
// the parsing of our overall structure or paths fails. Once we have a
// successfully parsed path, the only way we will get a failure return is if
Expand All @@ -413,7 +413,7 @@ Status WriteHandler::ProcessWriteRequest(System::PacketBufferHandle && aPayload,
err = writeRequestParser.CheckSchemaValidity();
SuccessOrExit(err);
#endif
err = writeRequestParser.GetSuppressResponse(&needSuppressResponse);
err = writeRequestParser.GetSuppressResponse(&mSuppressResponse);
if (err == CHIP_END_OF_TLV)
{
err = CHIP_NO_ERROR;
Expand Down
7 changes: 4 additions & 3 deletions src/app/WriteHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,10 @@ class WriteHandler : public Messaging::ExchangeDelegate
private:
Messaging::ExchangeContext * mpExchangeCtx = nullptr;
WriteResponseMessage::Builder mWriteResponseBuilder;
State mState = State::Uninitialized;
bool mIsTimedRequest = false;
bool mHasMoreChunks = false;
State mState = State::Uninitialized;
bool mIsTimedRequest = false;
bool mSuppressResponse = false;
bool mHasMoreChunks = false;
Optional<ConcreteAttributePath> mProcessingAttributePath;
Optional<AttributeAccessToken> mACLCheckCache = NullOptional;
};
Expand Down

0 comments on commit 1307928

Please sign in to comment.