Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MatterYamlTests][darwin-framework-tool] Ensure that WaitForCommissio… #29252

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,15 @@
#include <app/OperationalSessionSetup.h>
#include <lib/core/CHIPCallback.h>

NS_ASSUME_NONNULL_BEGIN
@interface MTRDeviceTestDelegate : NSObject <MTRDeviceDelegate>
@property CHIPCommandBridge * commandBridge;
- (instancetype)initWithCommandBridge:(CHIPCommandBridge *)commandBridge;
- (instancetype)init NS_UNAVAILABLE;
@end
NS_ASSUME_NONNULL_END

class WaitForCommissioneeCommand : public CHIPCommandBridge {
class WaitForCommissioneeCommand : public CHIPCommandBridge
{
public:
WaitForCommissioneeCommand()
: CHIPCommandBridge("wait-for-commissionee")
, mDeviceDelegate([[MTRDeviceTestDelegate alloc] initWithCommandBridge:this])
WaitForCommissioneeCommand() : CHIPCommandBridge("wait-for-commissionee")
{
AddArgument("nodeId", 0, UINT64_MAX, &mNodeId);
AddArgument("expire-existing-session", 0, 1, &mExpireExistingSession);
AddArgument(
"timeout", 0, UINT64_MAX, &mTimeoutSecs, "Time, in seconds, before this command is considered to have timed out.");
AddArgument("timeout", 0, UINT64_MAX, &mTimeoutSecs,
"Time, in seconds, before this command is considered to have timed out.");
}

/////////// CHIPCommandBridge Interface /////////
Expand All @@ -53,5 +44,4 @@ class WaitForCommissioneeCommand : public CHIPCommandBridge {
chip::NodeId mNodeId;
chip::Optional<uint16_t> mTimeoutSecs;
chip::Optional<bool> mExpireExistingSession;
id<MTRDeviceDelegate> _Nullable mDeviceDelegate;
};
Original file line number Diff line number Diff line change
Expand Up @@ -20,57 +20,18 @@

#import "MTRDevice_Externs.h"

@implementation MTRDeviceTestDelegate
- (instancetype)initWithCommandBridge:(CHIPCommandBridge *)commandBridge
{
if (!(self = [super init])) {
return nil;
}

_commandBridge = commandBridge;
return self;
}

- (void)device:(MTRDevice *)device stateChanged:(MTRDeviceState)state
{
if (state == MTRDeviceStateReachable) {
_commandBridge->SetCommandExitStatus(CHIP_NO_ERROR);
} else if (state == MTRDeviceStateUnreachable) {
_commandBridge->SetCommandExitStatus(CHIP_ERROR_NOT_FOUND);
} else if (state == MTRDeviceStateUnknown) {
_commandBridge->SetCommandExitStatus(CHIP_ERROR_NOT_FOUND);
} else {
// This should not happens.
chipDie();
}
}

- (void)device:(MTRDevice *)device receivedAttributeReport:(NSArray<NSDictionary<NSString *, id> *> *)attributeReport
{
}

- (void)device:(MTRDevice *)device receivedEventReport:(NSArray<NSDictionary<NSString *, id> *> *)eventReport
{
}
@end

CHIP_ERROR WaitForCommissioneeCommand::RunCommand()
{
MTRDeviceController * commissioner = CurrentCommissioner();
VerifyOrReturnError(nil != commissioner, CHIP_ERROR_INCORRECT_STATE);

auto * base_device = [MTRBaseDevice deviceWithNodeID:@(mNodeId) controller:commissioner];
VerifyOrReturnError(base_device != nil, CHIP_ERROR_INCORRECT_STATE);

if (mExpireExistingSession.ValueOr(true)) {
[base_device invalidateCASESession];
}
base_device = nil;

auto * device = [MTRDevice deviceWithNodeID:@(mNodeId) controller:commissioner];
VerifyOrReturnError(device != nil, CHIP_ERROR_INCORRECT_STATE);

auto queue = dispatch_queue_create("com.chip.wait_for_commissionee", DISPATCH_QUEUE_SERIAL);
[device setDelegate:mDeviceDelegate queue:queue];

SetCommandExitStatus(CHIP_NO_ERROR);
return CHIP_NO_ERROR;
}