SleepCommand.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Copyright (c) 2022 Project CHIP Authors
  3. * All rights reserved.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. #pragma once
  19. #include "../common/CHIPCommand.h"
  20. /**
  21. * This command blocks the event loop processing for a given amount of time.
  22. *
  23. * For example when the event loop is blocked the messages coming-in will not be acked,
  24. * forcing a retransmission on the other side.
  25. *
  26. */
  27. class SleepCommand : public CHIPCommand
  28. {
  29. public:
  30. SleepCommand(CredentialIssuerCommands * credIssuerCommands) : CHIPCommand("sleep", credIssuerCommands)
  31. {
  32. AddArgument("duration-in-ms", 0, UINT32_MAX, &mDurationInMs,
  33. "Block the event loop processing for duration-in-ms milliseconds.");
  34. }
  35. /////////// CHIPCommand Interface /////////
  36. CHIP_ERROR RunCommand() override;
  37. chip::System::Clock::Timeout GetWaitDuration() const override
  38. {
  39. // The allowed duration of this method is at least as long as the time specified for blocking the
  40. // event loop. In order to not fail on some small delays in processing some extra time before
  41. // failing is added.
  42. constexpr uint16_t mExtraTimeForFailure = 1000;
  43. return chip::System::Clock::Milliseconds32(mDurationInMs + mExtraTimeForFailure);
  44. }
  45. private:
  46. uint32_t mDurationInMs;
  47. };