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