WaitForCommissioneeCommand.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Copyright (c) 2023 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. #include <app/OperationalSessionSetup.h>
  21. #include <lib/core/CHIPCallback.h>
  22. class WaitForCommissioneeCommand : public CHIPCommand
  23. {
  24. public:
  25. WaitForCommissioneeCommand(CredentialIssuerCommands * credIssuerCommands) :
  26. CHIPCommand("wait-for-commissionee", credIssuerCommands, "Establish a CASE session to the provided node id."),
  27. mOnDeviceConnectedCallback(OnDeviceConnectedFn, this), mOnDeviceConnectionFailureCallback(OnDeviceConnectionFailureFn, this)
  28. {
  29. AddArgument("nodeId", 0, UINT64_MAX, &mNodeId);
  30. AddArgument("expire-existing-session", 0, 1, &mExpireExistingSession);
  31. AddArgument("timeout", 0, UINT64_MAX, &mTimeoutSecs,
  32. "Time, in seconds, before this command is considered to have timed out.");
  33. }
  34. /////////// CHIPCommand Interface /////////
  35. CHIP_ERROR RunCommand() override;
  36. chip::System::Clock::Timeout GetWaitDuration() const override
  37. {
  38. return chip::System::Clock::Seconds16(mTimeoutSecs.ValueOr(10));
  39. }
  40. private:
  41. chip::NodeId mNodeId;
  42. chip::Optional<uint16_t> mTimeoutSecs;
  43. chip::Optional<bool> mExpireExistingSession;
  44. static void OnDeviceConnectedFn(void * context, chip::Messaging::ExchangeManager & exchangeMgr,
  45. const chip::SessionHandle & sessionHandle);
  46. static void OnDeviceConnectionFailureFn(void * context, const chip::ScopedNodeId & peerId, CHIP_ERROR error);
  47. chip::Callback::Callback<chip::OnDeviceConnected> mOnDeviceConnectedCallback;
  48. chip::Callback::Callback<chip::OnDeviceConnectionFailure> mOnDeviceConnectionFailureCallback;
  49. };