Skip to content

Commit

Permalink
[chip-tool] Simplify the interaction model APIs to make it easier to …
Browse files Browse the repository at this point in the history
…maintain/review (#24091)

* [chip-tool] Move common arguments from commands/clusters/ReportCommand.h to src/app/tests/suites/commands/interaction_model/InteractionModel.h and simplify the InteractionModel helper APIs

* [chip-tool] Move common arguments from commands/clusters/ClusterCommand.h to src/app/tests/suites/commands/interaction_model/InteractionModel.h and simplify the InteractionModel helper APIs

* [chip-tool] Move common arguments from commands/clusters/WriteAttributeCommand.h to src/app/tests/suites/commands/interaction_model/InteractionModel.h and simplify the InteractionModel helper APIs
  • Loading branch information
vivien-apple authored and pull[bot] committed Jan 19, 2024
1 parent ee92c59 commit 9010083
Show file tree
Hide file tree
Showing 5 changed files with 351 additions and 195 deletions.
10 changes: 2 additions & 8 deletions examples/chip-tool/commands/clusters/ClusterCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,14 @@ class ClusterCommand : public InteractionModelCommands, public ModelCommand, pub

CHIP_ERROR SendCommand(chip::DeviceProxy * device, std::vector<chip::EndpointId> endpointIds) override
{
return InteractionModelCommands::SendCommand(device, endpointIds.at(0), mClusterId, mCommandId, mPayload,
mTimedInteractionTimeoutMs, mSuppressResponse, mRepeatCount, mRepeatDelayInMs);
return InteractionModelCommands::SendCommand(device, endpointIds.at(0), mClusterId, mCommandId, mPayload);
}

template <class T>
CHIP_ERROR SendCommand(chip::DeviceProxy * device, chip::EndpointId endpointId, chip::ClusterId clusterId,
chip::CommandId commandId, const T & value)
{
return InteractionModelCommands::SendCommand(device, endpointId, clusterId, commandId, value, mTimedInteractionTimeoutMs,
mSuppressResponse, mRepeatCount, mRepeatDelayInMs);
return InteractionModelCommands::SendCommand(device, endpointId, clusterId, commandId, value);
}

CHIP_ERROR SendGroupCommand(chip::GroupId groupId, chip::FabricIndex fabricIndex) override
Expand Down Expand Up @@ -184,10 +182,6 @@ class ClusterCommand : public InteractionModelCommands, public ModelCommand, pub
private:
chip::ClusterId mClusterId;
chip::CommandId mCommandId;
chip::Optional<uint16_t> mTimedInteractionTimeoutMs;
chip::Optional<bool> mSuppressResponse;
chip::Optional<uint16_t> mRepeatCount;
chip::Optional<uint16_t> mRepeatDelayInMs;

CHIP_ERROR mError = CHIP_NO_ERROR;
CustomArgument mPayload;
Expand Down
49 changes: 8 additions & 41 deletions examples/chip-tool/commands/clusters/ReportCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ class ReadAttribute : public ReadCommand

CHIP_ERROR SendCommand(chip::DeviceProxy * device, std::vector<chip::EndpointId> endpointIds) override
{
return ReadCommand::ReadAttribute(device, endpointIds, mClusterIds, mAttributeIds, mFabricFiltered, mDataVersion);
return ReadCommand::ReadAttribute(device, endpointIds, mClusterIds, mAttributeIds);
}

private:
Expand All @@ -224,14 +224,12 @@ class ReadAttribute : public ReadCommand
{
AddArgument("fabric-filtered", 0, 1, &mFabricFiltered,
"Boolean indicating whether to do a fabric-filtered read. Defaults to true.");
AddArgument("data-version", 0, UINT32_MAX, &mDataVersion,
AddArgument("data-version", 0, UINT32_MAX, &mDataVersions,
"Comma-separated list of data versions for the clusters being read.");
}

std::vector<chip::ClusterId> mClusterIds;
std::vector<chip::AttributeId> mAttributeIds;
chip::Optional<bool> mFabricFiltered;
chip::Optional<std::vector<chip::DataVersion>> mDataVersion;
};

class SubscribeAttribute : public SubscribeCommand
Expand Down Expand Up @@ -269,8 +267,7 @@ class SubscribeAttribute : public SubscribeCommand

CHIP_ERROR SendCommand(chip::DeviceProxy * device, std::vector<chip::EndpointId> endpointIds) override
{
return SubscribeCommand::SubscribeAttribute(device, endpointIds, mClusterIds, mAttributeIds, mMinInterval, mMaxInterval,
mFabricFiltered, mDataVersion, mKeepSubscriptions, mAutoResubscribe);
return SubscribeCommand::SubscribeAttribute(device, endpointIds, mClusterIds, mAttributeIds);
}

private:
Expand All @@ -289,7 +286,7 @@ class SubscribeAttribute : public SubscribeCommand
"Server must send a report if this number of seconds has elapsed since the last report.");
AddArgument("fabric-filtered", 0, 1, &mFabricFiltered,
"Boolean indicating whether to do a fabric-filtered subscription. Defaults to true.");
AddArgument("data-version", 0, UINT32_MAX, &mDataVersion,
AddArgument("data-version", 0, UINT32_MAX, &mDataVersions,
"Comma-separated list of data versions for the clusters being subscribed to.");
AddArgument("keepSubscriptions", 0, 1, &mKeepSubscriptions,
"Boolean indicating whether to keep existing subscriptions when creating the new one. Defaults to false.");
Expand All @@ -299,13 +296,6 @@ class SubscribeAttribute : public SubscribeCommand

std::vector<chip::ClusterId> mClusterIds;
std::vector<chip::AttributeId> mAttributeIds;

uint16_t mMinInterval;
uint16_t mMaxInterval;
chip::Optional<bool> mFabricFiltered;
chip::Optional<std::vector<chip::DataVersion>> mDataVersion;
chip::Optional<bool> mKeepSubscriptions;
chip::Optional<bool> mAutoResubscribe;
};

class ReadEvent : public ReadCommand
Expand Down Expand Up @@ -344,14 +334,12 @@ class ReadEvent : public ReadCommand

CHIP_ERROR SendCommand(chip::DeviceProxy * device, std::vector<chip::EndpointId> endpointIds) override
{
return ReadCommand::ReadEvent(device, endpointIds, mClusterIds, mEventIds, mFabricFiltered, mEventNumber);
return ReadCommand::ReadEvent(device, endpointIds, mClusterIds, mEventIds);
}

private:
std::vector<chip::ClusterId> mClusterIds;
std::vector<chip::EventId> mEventIds;
chip::Optional<bool> mFabricFiltered;
chip::Optional<chip::EventNumber> mEventNumber;
};

class SubscribeEvent : public SubscribeCommand
Expand Down Expand Up @@ -409,21 +397,12 @@ class SubscribeEvent : public SubscribeCommand

CHIP_ERROR SendCommand(chip::DeviceProxy * device, std::vector<chip::EndpointId> endpointIds) override
{
return SubscribeCommand::SubscribeEvent(device, endpointIds, mClusterIds, mEventIds, mMinInterval, mMaxInterval,
mFabricFiltered, mEventNumber, mKeepSubscriptions, mIsUrgents, mAutoResubscribe);
return SubscribeCommand::SubscribeEvent(device, endpointIds, mClusterIds, mEventIds);
}

private:
std::vector<chip::ClusterId> mClusterIds;
std::vector<chip::EventId> mEventIds;

uint16_t mMinInterval;
uint16_t mMaxInterval;
chip::Optional<bool> mFabricFiltered;
chip::Optional<chip::EventNumber> mEventNumber;
chip::Optional<bool> mKeepSubscriptions;
chip::Optional<std::vector<bool>> mIsUrgents;
chip::Optional<bool> mAutoResubscribe;
};

class ReadAll : public ReadCommand
Expand Down Expand Up @@ -458,18 +437,13 @@ class ReadAll : public ReadCommand

CHIP_ERROR SendCommand(chip::DeviceProxy * device, std::vector<chip::EndpointId> endpointIds) override
{
return ReadCommand::ReadAll(device, endpointIds, mClusterIds, mAttributeIds, mEventIds, mFabricFiltered, mDataVersions,
mEventNumber);
return ReadCommand::ReadAll(device, endpointIds, mClusterIds, mAttributeIds, mEventIds);
}

private:
std::vector<chip::ClusterId> mClusterIds;
std::vector<chip::AttributeId> mAttributeIds;
std::vector<chip::EventId> mEventIds;

chip::Optional<bool> mFabricFiltered;
chip::Optional<std::vector<chip::DataVersion>> mDataVersions;
chip::Optional<chip::EventNumber> mEventNumber;
};

class SubscribeAll : public SubscribeCommand
Expand Down Expand Up @@ -502,18 +476,11 @@ class SubscribeAll : public SubscribeCommand

CHIP_ERROR SendCommand(chip::DeviceProxy * device, std::vector<chip::EndpointId> endpointIds) override
{
return SubscribeCommand::SubscribeAll(device, endpointIds, mClusterIds, mAttributeIds, mEventIds, mMinInterval,
mMaxInterval, mFabricFiltered, mEventNumber, mKeepSubscriptions);
return SubscribeCommand::SubscribeAll(device, endpointIds, mClusterIds, mAttributeIds, mEventIds);
}

private:
std::vector<chip::ClusterId> mClusterIds;
std::vector<chip::AttributeId> mAttributeIds;
std::vector<chip::EventId> mEventIds;

uint16_t mMinInterval;
uint16_t mMaxInterval;
chip::Optional<bool> mFabricFiltered;
chip::Optional<chip::EventNumber> mEventNumber;
chip::Optional<bool> mKeepSubscriptions;
};
10 changes: 1 addition & 9 deletions examples/chip-tool/commands/clusters/WriteAttributeCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,7 @@ class WriteAttribute : public InteractionModelWriter, public ModelCommand, publi
CHIP_ERROR SendCommand(chip::DeviceProxy * device, std::vector<chip::EndpointId> endpointIds,
std::vector<chip::ClusterId> clusterIds, std::vector<chip::AttributeId> attributeIds, const T & values)
{
return InteractionModelWriter::WriteAttribute(device, endpointIds, clusterIds, attributeIds, values,
mTimedInteractionTimeoutMs, mSuppressResponse, mDataVersions, mRepeatCount,
mRepeatDelayInMs);
return InteractionModelWriter::WriteAttribute(device, endpointIds, clusterIds, attributeIds, values);
}

CHIP_ERROR SendGroupCommand(chip::GroupId groupId, chip::FabricIndex fabricIndex, std::vector<chip::ClusterId> clusterIds,
Expand Down Expand Up @@ -249,12 +247,6 @@ class WriteAttribute : public InteractionModelWriter, public ModelCommand, publi
std::vector<chip::AttributeId> mAttributeIds;

CHIP_ERROR mError = CHIP_NO_ERROR;
chip::Optional<uint16_t> mTimedInteractionTimeoutMs;
chip::Optional<std::vector<chip::DataVersion>> mDataVersions;
chip::Optional<bool> mSuppressResponse;
chip::Optional<uint16_t> mRepeatCount;
chip::Optional<uint16_t> mRepeatDelayInMs;

T mAttributeValues;
};

Expand Down
Loading

0 comments on commit 9010083

Please sign in to comment.