Skip to content

Commit

Permalink
Document the timedInteractionTimeoutMs argument in chip-tool. (#18703)
Browse files Browse the repository at this point in the history
Refactors some of the relevant code slightly to reduce the amount of
copy/paste.
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Jul 18, 2022
1 parent b8338dd commit 1457282
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 62 deletions.
33 changes: 17 additions & 16 deletions examples/chip-tool-darwin/commands/clusters/ClusterCommandBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ class ClusterCommand : public ModelCommand {
AddArgument("cluster-id", 0, UINT32_MAX, &mClusterId);
AddArgument("command-id", 0, UINT32_MAX, &mCommandId);
AddArgument("payload", &mPayload);
AddArgument("timedInteractionTimeoutMs", 0, UINT16_MAX, &mTimedInteractionTimeoutMs);
AddArgument("repeat-count", 1, UINT16_MAX, &mRepeatCount);
AddArgument("repeat-delay-ms", 0, UINT16_MAX, &mRepeatDelayInMs);
ModelCommand::AddArguments();
AddArguments();
}

ClusterCommand(chip::ClusterId clusterId)
Expand All @@ -44,18 +41,7 @@ class ClusterCommand : public ModelCommand {
{
AddArgument("command-id", 0, UINT32_MAX, &mCommandId);
AddArgument("payload", &mPayload);
AddArgument("timedInteractionTimeoutMs", 0, UINT16_MAX, &mTimedInteractionTimeoutMs);
AddArgument("repeat-count", 1, UINT16_MAX, &mRepeatCount);
AddArgument("repeat-delay-ms", 0, UINT16_MAX, &mRepeatDelayInMs);
ModelCommand::AddArguments();
}

ClusterCommand(const char * _Nonnull commandName)
: ModelCommand(commandName)
{
AddArgument("timedInteractionTimeoutMs", 0, UINT16_MAX, &mTimedInteractionTimeoutMs);
AddArgument("repeat-count", 1, UINT16_MAX, &mRepeatCount);
AddArgument("repeat-delay-ms", 0, UINT16_MAX, &mRepeatDelayInMs);
AddArguments();
}

~ClusterCommand() {}
Expand Down Expand Up @@ -117,6 +103,21 @@ class ClusterCommand : public ModelCommand {
}

protected:
ClusterCommand(const char * _Nonnull commandName)
: ModelCommand(commandName)
{
// Subclasses are responsible for calling AddArguments.
}

void AddArguments()
{
AddArgument("timedInteractionTimeoutMs", 0, UINT16_MAX, &mTimedInteractionTimeoutMs,
"If provided, do a timed invoke with the given timed interaction timeout.");
AddArgument("repeat-count", 1, UINT16_MAX, &mRepeatCount);
AddArgument("repeat-delay-ms", 0, UINT16_MAX, &mRepeatDelayInMs);
ModelCommand::AddArguments();
}

chip::Optional<uint16_t> mTimedInteractionTimeoutMs;
chip::Optional<uint16_t> mRepeatCount;
chip::Optional<uint16_t> mRepeatDelayInMs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ class WriteAttribute : public ModelCommand {
AddArgument("cluster-id", 0, UINT32_MAX, &mClusterId);
AddArgument("attribute-id", 0, UINT32_MAX, &mAttributeId);
AddArgument("attribute-value", &mAttributeValue);
AddArgument("timedInteractionTimeoutMs", 0, UINT16_MAX, &mTimedInteractionTimeoutMs);
ModelCommand::AddArguments();
AddArguments();
}

WriteAttribute(chip::ClusterId clusterId)
Expand All @@ -40,15 +39,7 @@ class WriteAttribute : public ModelCommand {
{
AddArgument("attribute-id", 0, UINT32_MAX, &mAttributeId);
AddArgument("attribute-value", &mAttributeValue);
AddArgument("timedInteractionTimeoutMs", 0, UINT16_MAX, &mTimedInteractionTimeoutMs);
ModelCommand::AddArguments();
}

WriteAttribute(const char * _Nonnull attributeName)
: ModelCommand("write")
{
AddArgument("data-version", 0, UINT32_MAX, &mDataVersion);
AddArgument("timedInteractionTimeoutMs", 0, UINT16_MAX, &mTimedInteractionTimeoutMs);
AddArguments();
}

~WriteAttribute() {}
Expand Down Expand Up @@ -103,6 +94,20 @@ class WriteAttribute : public ModelCommand {
}

protected:
WriteAttribute(const char * _Nonnull attributeName)
: ModelCommand("write")
{
AddArgument("data-version", 0, UINT32_MAX, &mDataVersion);
// Subclasses are responsible for calling AddArguments.
}

void AddArguments()
{
AddArgument("timedInteractionTimeoutMs", 0, UINT16_MAX, &mTimedInteractionTimeoutMs,
"If provided, do a timed write with the given timed interaction timeout.");
ModelCommand::AddArguments();
}

chip::Optional<uint16_t> mTimedInteractionTimeoutMs;
chip::Optional<uint32_t> mDataVersion;

Expand Down
38 changes: 19 additions & 19 deletions examples/chip-tool/commands/clusters/ClusterCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,15 @@ class ClusterCommand : public InteractionModelCommands, public ModelCommand, pub
AddArgument("cluster-id", 0, UINT32_MAX, &mClusterId);
AddArgument("command-id", 0, UINT32_MAX, &mCommandId);
AddArgument("payload", &mPayload);
AddArgument("timedInteractionTimeoutMs", 0, UINT16_MAX, &mTimedInteractionTimeoutMs);
AddArgument("suppressResponse", 0, 1, &mSuppressResponse);
AddArgument("repeat-count", 1, UINT16_MAX, &mRepeatCount);
AddArgument("repeat-delay-ms", 0, UINT16_MAX, &mRepeatDelayInMs);
ModelCommand::AddArguments();
AddArguments();
}

ClusterCommand(chip::ClusterId clusterId, CredentialIssuerCommands * credsIssuerConfig) :
InteractionModelCommands(this), ModelCommand("command-by-id", credsIssuerConfig), mClusterId(clusterId)
{
AddArgument("command-id", 0, UINT32_MAX, &mCommandId);
AddArgument("payload", &mPayload);
AddArgument("timedInteractionTimeoutMs", 0, UINT16_MAX, &mTimedInteractionTimeoutMs);
AddArgument("suppressResponse", 0, 1, &mSuppressResponse);
AddArgument("repeat-count", 1, UINT16_MAX, &mRepeatCount);
AddArgument("repeat-delay-ms", 0, UINT16_MAX, &mRepeatDelayInMs);
ModelCommand::AddArguments();
}

ClusterCommand(const char * commandName, CredentialIssuerCommands * credsIssuerConfig) :
InteractionModelCommands(this), ModelCommand(commandName, credsIssuerConfig)
{
AddArgument("timedInteractionTimeoutMs", 0, UINT16_MAX, &mTimedInteractionTimeoutMs);
AddArgument("suppressResponse", 0, 1, &mSuppressResponse);
AddArgument("repeat-count", 1, UINT16_MAX, &mRepeatCount);
AddArgument("repeat-delay-ms", 0, UINT16_MAX, &mRepeatDelayInMs);
AddArguments();
}

~ClusterCommand() {}
Expand Down Expand Up @@ -141,6 +124,23 @@ class ClusterCommand : public InteractionModelCommands, public ModelCommand, pub
}
}

protected:
ClusterCommand(const char * commandName, CredentialIssuerCommands * credsIssuerConfig) :
InteractionModelCommands(this), ModelCommand(commandName, credsIssuerConfig)
{
// Subclasses are responsible for calling AddArguments.
}

void AddArguments()
{
AddArgument("timedInteractionTimeoutMs", 0, UINT16_MAX, &mTimedInteractionTimeoutMs,
"If provided, do a timed invoke with the given timed interaction timeout.");
AddArgument("suppressResponse", 0, 1, &mSuppressResponse);
AddArgument("repeat-count", 1, UINT16_MAX, &mRepeatCount);
AddArgument("repeat-delay-ms", 0, UINT16_MAX, &mRepeatDelayInMs);
ModelCommand::AddArguments();
}

private:
chip::ClusterId mClusterId;
chip::CommandId mCommandId;
Expand Down
34 changes: 18 additions & 16 deletions examples/chip-tool/commands/clusters/WriteAttributeCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,15 @@ class WriteAttribute : public InteractionModelWriter, public ModelCommand, publi
AddArgument("cluster-id", 0, UINT32_MAX, &mClusterId);
AddArgument("attribute-id", 0, UINT32_MAX, &mAttributeId);
AddArgument("attribute-value", &mAttributeValue);
AddArgument("timedInteractionTimeoutMs", 0, UINT16_MAX, &mTimedInteractionTimeoutMs);
AddArgument("data-version", 0, UINT32_MAX, &mDataVersion);
AddArgument("suppressResponse", 0, 1, &mSuppressResponse);
ModelCommand::AddArguments();
AddArguments();
}

WriteAttribute(chip::ClusterId clusterId, CredentialIssuerCommands * credsIssuerConfig) :
InteractionModelWriter(this), ModelCommand("write-by-id", credsIssuerConfig), mClusterId(clusterId)
{
AddArgument("attribute-id", 0, UINT32_MAX, &mAttributeId);
AddArgument("attribute-value", &mAttributeValue);
AddArgument("timedInteractionTimeoutMs", 0, UINT16_MAX, &mTimedInteractionTimeoutMs);
AddArgument("data-version", 0, UINT32_MAX, &mDataVersion);
AddArgument("suppressResponse", 0, 1, &mSuppressResponse);
ModelCommand::AddArguments();
}

WriteAttribute(const char * attributeName, CredentialIssuerCommands * credsIssuerConfig) :
InteractionModelWriter(this), ModelCommand("write", credsIssuerConfig)
{
AddArgument("timedInteractionTimeoutMs", 0, UINT16_MAX, &mTimedInteractionTimeoutMs);
AddArgument("data-version", 0, UINT32_MAX, &mDataVersion);
AddArgument("suppressResponse", 0, 1, &mSuppressResponse);
AddArguments();
}

~WriteAttribute() {}
Expand Down Expand Up @@ -112,6 +98,22 @@ class WriteAttribute : public InteractionModelWriter, public ModelCommand, publi
return InteractionModelWriter::WriteGroupAttribute(groupId, fabricIndex, clusterId, attributeId, value, mDataVersion);
}

protected:
WriteAttribute(const char * attributeName, CredentialIssuerCommands * credsIssuerConfig) :
InteractionModelWriter(this), ModelCommand("write", credsIssuerConfig)
{
// Subclasses are responsible for calling AddArguments.
}

void AddArguments()
{
AddArgument("timedInteractionTimeoutMs", 0, UINT16_MAX, &mTimedInteractionTimeoutMs,
"If provided, do a timed write with the given timed interaction timeout.");
AddArgument("data-version", 0, UINT32_MAX, &mDataVersion);
AddArgument("suppressResponse", 0, 1, &mSuppressResponse);
ModelCommand::AddArguments();
}

private:
chip::ClusterId mClusterId;
chip::AttributeId mAttributeId;
Expand Down

0 comments on commit 1457282

Please sign in to comment.