From b0afbe165e243a3e9fd09cb4d8ba6f74c3ba2483 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Tue, 28 May 2024 12:54:04 -0400 Subject: [PATCH] Add a timeout argument to darwin-framework-tool data model commands. chip-tool has one, and this will make it easier to use in YAMLs that run in both. --- .../commands/clusters/ModelCommandBridge.h | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/examples/darwin-framework-tool/commands/clusters/ModelCommandBridge.h b/examples/darwin-framework-tool/commands/clusters/ModelCommandBridge.h index 2deb7cfb4cac5e..8e5bb8f9842210 100644 --- a/examples/darwin-framework-tool/commands/clusters/ModelCommandBridge.h +++ b/examples/darwin-framework-tool/commands/clusters/ModelCommandBridge.h @@ -21,6 +21,10 @@ #include "../common/CHIPCommandBridge.h" #include +#define DFT_MODEL_COMMAND_DEFAULT_TIMEOUT 20 +#define DFT_STRINGIFY_HELPER(arg) #arg +#define DFT_STRINGIFY(arg) DFT_STRINGIFY_HELPER(arg) + class ModelCommand : public CHIPCommandBridge { public: @@ -30,6 +34,10 @@ class ModelCommand : public CHIPCommandBridge { AddArgument("node-id", 0, UINT64_MAX, &mNodeId); AddArgument("endpoint-id", 0, UINT16_MAX, &mEndPointId); + AddArgument( + "timeout", 0, UINT16_MAX, &mTimeout, + "Amount of time to allow the command to run for before considering it to have timed out. Defaults to " DFT_STRINGIFY( + DFT_MODEL_COMMAND_DEFAULT_TIMEOUT) " seconds."); } void Shutdown() override; @@ -38,11 +46,19 @@ class ModelCommand : public CHIPCommandBridge /////////// CHIPCommand Interface ///////// CHIP_ERROR RunCommand() override; - chip::System::Clock::Timeout GetWaitDuration() const override { return chip::System::Clock::Seconds16(20); } + chip::System::Clock::Timeout GetWaitDuration() const override + { + return chip::System::Clock::Seconds16(mTimeout.ValueOr(DFT_MODEL_COMMAND_DEFAULT_TIMEOUT)); + } virtual CHIP_ERROR SendCommand(MTRBaseDevice * _Nonnull device, chip::EndpointId endPointId) = 0; private: chip::NodeId mNodeId; chip::EndpointId mEndPointId; + chip::Optional mTimeout; }; + +#undef DFT_STRINGIFY +#undef DFT_STRINGIFY_HELPER +#undef DFT_MODEL_COMMAND_DEFAULT_TIMEOUT