Skip to content

Commit

Permalink
Restyling
Browse files Browse the repository at this point in the history
  • Loading branch information
woody-apple committed Jul 1, 2022
1 parent caba50b commit 5bc5e68
Show file tree
Hide file tree
Showing 11 changed files with 830 additions and 839 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,24 @@
[commissioner getDevice:mNodeId
queue:callbackQueue
completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) {
if (error != nil) {
SetCommandExitStatus(error, "Error getting connected device");
return;
}

CHIP_ERROR err;
if (device == nil) {
err = CHIP_ERROR_INTERNAL;
} else {
err = SendCommand(device, mEndPointId);
}

if (err != CHIP_NO_ERROR) {
ChipLogError(chipTool, "Error: %s", chip::ErrorStr(err));
SetCommandExitStatus(err);
return;
}
}];
if (error != nil) {
SetCommandExitStatus(error, "Error getting connected device");
return;
}

CHIP_ERROR err;
if (device == nil) {
err = CHIP_ERROR_INTERNAL;
} else {
err = SendCommand(device, mEndPointId);
}

if (err != CHIP_NO_ERROR) {
ChipLogError(chipTool, "Error: %s", chip::ErrorStr(err));
SetCommandExitStatus(err);
return;
}
}];
return CHIP_NO_ERROR;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,47 +111,46 @@
{
dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip-tool.command", DISPATCH_QUEUE_SERIAL);
MTRDeviceController * commissioner = CurrentCommissioner();
[commissioner
getDevice:mNodeId
queue:callbackQueue
completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) {
CHIP_ERROR err = CHIP_NO_ERROR;
if (error) {
err = MTRErrorToCHIPErrorCode(error);
LogNSError("Error: ", error);
SetCommandExitStatus(err);
} else if (device == nil) {
ChipLogError(chipTool, "Error: %s", chip::ErrorStr(CHIP_ERROR_INTERNAL));
SetCommandExitStatus(CHIP_ERROR_INTERNAL);
} else {
ChipLogProgress(chipTool, "Attempting to unpair device %llu", mNodeId);
MTROperationalCredentials * opCredsCluster = [[MTROperationalCredentials alloc] initWithDevice:device
endpoint:0
queue:callbackQueue];
[opCredsCluster readAttributeCurrentFabricIndexWithCompletionHandler:^(
NSNumber * _Nullable value, NSError * _Nullable readError) {
if (readError) {
CHIP_ERROR readErr = MTRErrorToCHIPErrorCode(readError);
LogNSError("Failed to get current fabric: ", readError);
SetCommandExitStatus(readErr);
return;
}
MTROperationalCredentialsClusterRemoveFabricParams * params =
[[MTROperationalCredentialsClusterRemoveFabricParams alloc] init];
params.fabricIndex = value;
[opCredsCluster removeFabricWithParams:params
completionHandler:^(MTROperationalCredentialsClusterNOCResponseParams * _Nullable data,
NSError * _Nullable removeError) {
CHIP_ERROR removeErr = CHIP_NO_ERROR;
if (removeError) {
removeErr = MTRErrorToCHIPErrorCode(removeError);
LogNSError("Failed to remove current fabric: ", removeError);
} else {
ChipLogProgress(chipTool, "Successfully unpaired deviceId %llu", mNodeId);
}
SetCommandExitStatus(removeErr);
}];
}];
}
}];
[commissioner getDevice:mNodeId
queue:callbackQueue
completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) {
CHIP_ERROR err = CHIP_NO_ERROR;
if (error) {
err = MTRErrorToCHIPErrorCode(error);
LogNSError("Error: ", error);
SetCommandExitStatus(err);
} else if (device == nil) {
ChipLogError(chipTool, "Error: %s", chip::ErrorStr(CHIP_ERROR_INTERNAL));
SetCommandExitStatus(CHIP_ERROR_INTERNAL);
} else {
ChipLogProgress(chipTool, "Attempting to unpair device %llu", mNodeId);
MTROperationalCredentials * opCredsCluster = [[MTROperationalCredentials alloc] initWithDevice:device
endpoint:0
queue:callbackQueue];
[opCredsCluster readAttributeCurrentFabricIndexWithCompletionHandler:^(
NSNumber * _Nullable value, NSError * _Nullable readError) {
if (readError) {
CHIP_ERROR readErr = MTRErrorToCHIPErrorCode(readError);
LogNSError("Failed to get current fabric: ", readError);
SetCommandExitStatus(readErr);
return;
}
MTROperationalCredentialsClusterRemoveFabricParams * params =
[[MTROperationalCredentialsClusterRemoveFabricParams alloc] init];
params.fabricIndex = value;
[opCredsCluster removeFabricWithParams:params
completionHandler:^(MTROperationalCredentialsClusterNOCResponseParams * _Nullable data,
NSError * _Nullable removeError) {
CHIP_ERROR removeErr = CHIP_NO_ERROR;
if (removeError) {
removeErr = MTRErrorToCHIPErrorCode(removeError);
LogNSError("Failed to remove current fabric: ", removeError);
} else {
ChipLogProgress(chipTool, "Successfully unpaired deviceId %llu", mNodeId);
}
SetCommandExitStatus(removeErr);
}];
}];
}
}];
}
3 changes: 1 addition & 2 deletions src/darwin/Framework/CHIP/MTRCluster_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@
#import "MTRDevice.h"
#import "MTRDevice_Internal.h"

#import "zap-generated/MTRClustersObjc.h"
#import "zap-generated/CHIPClusters.h"
#import "zap-generated/MTRClustersObjc.h"

using namespace chip::app::Clusters;


@interface MTRCluster ()
@property (readonly, nonatomic) dispatch_queue_t callbackQueue;
- (chip::Controller::ClusterBase *)getCluster;
Expand Down
6 changes: 2 additions & 4 deletions src/darwin/Framework/CHIP/MTRDeviceController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@

#include <platform/CHIPDeviceBuildConfig.h>

#include <controller/CommissioningWindowOpener.h>
#include <controller/CHIPDeviceController.h>
#include <controller/CHIPDeviceControllerFactory.h>
#include <controller/CommissioningWindowOpener.h>
#include <credentials/FabricTable.h>
#include <credentials/GroupDataProvider.h>
#include <credentials/attestation_verifier/DefaultDeviceAttestationVerifier.h>
Expand Down Expand Up @@ -519,9 +519,7 @@ - (MTRDevice *)getDeviceBeingCommissioned:(uint64_t)deviceId error:(NSError * __
return [[MTRDevice alloc] initWithDevice:deviceProxy];
}

- (BOOL)getDevice:(uint64_t)deviceID
queue:(dispatch_queue_t)queue
completionHandler:(MTRDeviceConnectionCallback)completionHandler
- (BOOL)getDevice:(uint64_t)deviceID queue:(dispatch_queue_t)queue completionHandler:(MTRDeviceConnectionCallback)completionHandler
{
__block CHIP_ERROR errorCode = CHIP_ERROR_INCORRECT_STATE;
if (![self isRunning]) {
Expand Down
4 changes: 1 addition & 3 deletions src/darwin/Framework/CHIP/MTRDeviceControllerOverXPC.m
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,7 @@ - (BOOL)deviceBeingCommissionedOverBLE:(uint64_t)deviceId
return NO;
}

- (BOOL)getDevice:(uint64_t)deviceID
queue:(dispatch_queue_t)queue
completionHandler:(MTRDeviceConnectionCallback)completionHandler
- (BOOL)getDevice:(uint64_t)deviceID queue:(dispatch_queue_t)queue completionHandler:(MTRDeviceConnectionCallback)completionHandler
{
dispatch_async(_workQueue, ^{
dispatch_group_t group = dispatch_group_create();
Expand Down
4 changes: 2 additions & 2 deletions src/darwin/Framework/CHIP/zap-generated/MTRClustersObjc.mm

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions src/darwin/Framework/CHIPTests/MTRClustersTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ - (void)testInitStack
[controller getDevice:nodeId
queue:dispatch_get_main_queue()
completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) {
XCTAssertEqual(error.code, 0);
[connectionExpectation fulfill];
connectionExpectation = nil;
}];
XCTAssertEqual(error.code, 0);
[connectionExpectation fulfill];
connectionExpectation = nil;
}];
[self waitForExpectationsWithTimeout:kCASESetupTimeoutInSeconds handler:nil];
}

Expand All @@ -169,13 +169,13 @@ - (void)testReuseChipClusterObject
__block MTRDevice * device;
__block XCTestExpectation * connectionExpectation = [self expectationWithDescription:@"CASE established"];
[controller getDevice:nodeId
queue:dispatch_get_main_queue()
completionHandler:^(MTRDevice * _Nullable retrievedDevice, NSError * _Nullable error) {
XCTAssertEqual(error.code, 0);
[connectionExpectation fulfill];
connectionExpectation = nil;
device = retrievedDevice;
}];
queue:dispatch_get_main_queue()
completionHandler:^(MTRDevice * _Nullable retrievedDevice, NSError * _Nullable error) {
XCTAssertEqual(error.code, 0);
[connectionExpectation fulfill];
connectionExpectation = nil;
device = retrievedDevice;
}];
[self waitForExpectationsWithTimeout:kCASESetupTimeoutInSeconds handler:nil];

XCTestExpectation * expectation = [self expectationWithDescription:@"ReuseMTRClusterObjectFirstCall"];
Expand Down
8 changes: 4 additions & 4 deletions src/darwin/Framework/CHIPTests/MTRControllerTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,10 @@ - (void)testControllerInvalidAccess

XCTAssertFalse([controller isRunning]);
XCTAssertFalse([controller getDevice:1234
queue:dispatch_get_main_queue()
completionHandler:^(MTRDevice * _Nullable chipDevice, NSError * _Nullable error) {
XCTAssertEqual(error.code, MTRErrorCodeInvalidState);
}]);
queue:dispatch_get_main_queue()
completionHandler:^(MTRDevice * _Nullable chipDevice, NSError * _Nullable error) {
XCTAssertEqual(error.code, MTRErrorCodeInvalidState);
}]);

[factory shutdown];
XCTAssertFalse([factory isRunning]);
Expand Down
20 changes: 10 additions & 10 deletions src/darwin/Framework/CHIPTests/MTRDeviceTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ static void WaitForCommissionee(XCTestExpectation * expectation, dispatch_queue_
[controller getDevice:kDeviceId
queue:dispatch_get_main_queue()
completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) {
XCTAssertEqual(error.code, 0);
[expectation fulfill];
mConnectedDevice = device;
}];
XCTAssertEqual(error.code, 0);
[expectation fulfill];
mConnectedDevice = device;
}];
}

static MTRDevice * GetConnectedDevice(void)
Expand Down Expand Up @@ -178,12 +178,12 @@ - (void)initStack

__block XCTestExpectation * connectionExpectation = [self expectationWithDescription:@"CASE established"];
[controller getDevice:kDeviceId
queue:dispatch_get_main_queue()
completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) {
XCTAssertEqual(error.code, 0);
[connectionExpectation fulfill];
connectionExpectation = nil;
}];
queue:dispatch_get_main_queue()
completionHandler:^(MTRDevice * _Nullable device, NSError * _Nullable error) {
XCTAssertEqual(error.code, 0);
[connectionExpectation fulfill];
connectionExpectation = nil;
}];
[self waitForExpectationsWithTimeout:kCASESetupTimeoutInSeconds handler:nil];
}

Expand Down
Loading

0 comments on commit 5bc5e68

Please sign in to comment.