Skip to content

Commit

Permalink
Fix completion naming in Darwin framework.
Browse files Browse the repository at this point in the history
This is a re-landing of PR project-chip#22557 but modified to preserve the old APIs.

* Rename all "completionHandler" selectors/arguments to "completion".
* Rename everything ending with "CompletionHandler" to end with "Completion".
* Make sure we consistently use "queue" for callback queues, not "clientQueue".
* Add MTR prefixes to remaining un-prefixed block typedefs.

The header changes not accompanied by backwards-compat shims are OK for the
following reasons:

* In MTRAttributeCacheContainer.h we're only changing an MTR_NEWLY_AVAILABLE
  thing.
* In MTRBaseDevice.h we're changing MTR_NEWLY_AVAILABLE things (except
  deregisterReportHandlersWithQueue, which has a shim).
* MTRCallbackBridgeBase_internal.h is not public API.
* In MTRDeviceController+XPC.h the changes are source and binary compatible.
* MTRDeviceController_Internal.h is not public API.
* MTRDeviceOverXPC.h is not public API.
* MTRCallbackBridge_internal.h is not public API.
  • Loading branch information
bzbarsky-apple committed Nov 2, 2022
1 parent a92b952 commit e5adce4
Show file tree
Hide file tree
Showing 48 changed files with 153,400 additions and 93,621 deletions.
2 changes: 2 additions & 0 deletions .restyled.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ exclude:
- "examples/platform/nxp/k32w/k32w0/scripts/demo_generated_certs/**/*"
- "integrations/cloudbuild/*.yaml" # uglier long command line content
- "scripts/run_codegen_targets.sh" # shellharden breaks for loops over command outputs
- "src/darwin/Framework/CHIP/zap-generated/MTRBaseClusters.h" # Too big?
- "src/darwin/Framework/CHIP/zap-generated/MTRBaseClusters.mm" # Too big?


changed_paths:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class ClusterCommand : public ModelCommand {
timedInvokeTimeout:mTimedInteractionTimeoutMs.HasValue()
? [NSNumber numberWithUnsignedShort:mTimedInteractionTimeoutMs.Value()]
: nil
clientQueue:callbackQueue
queue:callbackQueue
completion:^(
NSArray<NSDictionary<NSString *, id> *> * _Nullable values, NSError * _Nullable error) {
responsesNeeded--;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,25 @@
ChipLogProgress(chipTool, "Sending command to node 0x" ChipLogFormatX64, ChipLogValueX64(mNodeId));
[commissioner getBaseDevice:mNodeId
queue:callbackQueue
completionHandler:^(MTRBaseDevice * _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;
}
}];
completion:^(MTRBaseDevice * _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;
}
}];
return CHIP_NO_ERROR;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class ReadAttribute : public ModelCommand {
clusterID:[NSNumber numberWithUnsignedInteger:mClusterId]
attributeID:[NSNumber numberWithUnsignedInteger:mAttributeId]
params:params
clientQueue:callbackQueue
queue:callbackQueue
completion:^(NSArray<NSDictionary<NSString *, id> *> * _Nullable values, NSError * _Nullable error) {
if (error != nil) {
LogNSError("Error reading attribute", error);
Expand Down Expand Up @@ -135,7 +135,7 @@ class SubscribeAttribute : public ModelCommand {
minInterval:[NSNumber numberWithUnsignedInteger:mMinInterval]
maxInterval:[NSNumber numberWithUnsignedInteger:mMaxInterval]
params:params
clientQueue:callbackQueue
queue:callbackQueue
reportHandler:^(NSArray<NSDictionary<NSString *, id> *> * _Nullable values, NSError * _Nullable error) {
if (values) {
for (id item in values) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class WriteAttribute : public ModelCommand {
timedWriteTimeout:mTimedInteractionTimeoutMs.HasValue()
? [NSNumber numberWithUnsignedShort:mTimedInteractionTimeoutMs.Value()]
: nil
clientQueue:callbackQueue
queue:callbackQueue
completion:^(NSArray<NSDictionary<NSString *, id> *> * _Nullable values, NSError * _Nullable error) {
if (error != nil) {
LogNSError("Error writing attribute", error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@
[cluster openBasicCommissioningWindowWithParams:params
expectedValues:nil
expectedValueInterval:nil
completionHandler:^(NSError * _Nullable error) {
if (error == nil) {
self->SetCommandExitStatus(CHIP_NO_ERROR);
} else {
self->SetCommandExitStatus(MTRErrorToCHIPErrorCode(error));
}
}];
completion:^(NSError * _Nullable error) {
if (error == nil) {
self->SetCommandExitStatus(CHIP_NO_ERROR);
} else {
self->SetCommandExitStatus(MTRErrorToCHIPErrorCode(error));
}
}];
} else {
[device
openCommissioningWindowWithSetupPasscode:[MTRSetupPayload generateRandomSetupPasscode]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,46 +101,47 @@
{
dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip-tool.command", DISPATCH_QUEUE_SERIAL);
MTRDeviceController * commissioner = CurrentCommissioner();
[commissioner getBaseDevice:mNodeId
queue:callbackQueue
completionHandler:^(MTRBaseDevice * _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);
MTRBaseClusterOperationalCredentials * opCredsCluster =
[[MTRBaseClusterOperationalCredentials alloc] initWithDevice:device endpointID:@(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
getBaseDevice:mNodeId
queue:callbackQueue
completion:^(MTRBaseDevice * _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);
MTRBaseClusterOperationalCredentials * opCredsCluster =
[[MTRBaseClusterOperationalCredentials alloc] initWithDevice:device endpointID:@(0) queue:callbackQueue];
[opCredsCluster
readAttributeCurrentFabricIndexWithCompletion:^(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
completion:^(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);
}];
}];
}
}];
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,20 @@ typedef NS_ENUM(uint8_t, UserConsentState) {
- (void)handleQueryImageForNodeID:(NSNumber * _Nonnull)nodeID
controller:(MTRDeviceController * _Nonnull)controller
params:(MTROtaSoftwareUpdateProviderClusterQueryImageParams * _Nonnull)params
completionHandler:(void (^_Nonnull)(MTROtaSoftwareUpdateProviderClusterQueryImageResponseParams * _Nullable data,
NSError * _Nullable error))completionHandler;
completion:(void (^_Nonnull)(MTROtaSoftwareUpdateProviderClusterQueryImageResponseParams * _Nullable data,
NSError * _Nullable error))completion;

- (void)handleApplyUpdateRequestForNodeID:(NSNumber * _Nonnull)nodeID
controller:(MTRDeviceController * _Nonnull)controller
params:(MTROtaSoftwareUpdateProviderClusterApplyUpdateRequestParams * _Nonnull)params
completionHandler:
(void (^_Nonnull)(MTROtaSoftwareUpdateProviderClusterApplyUpdateResponseParams * _Nullable data,
NSError * _Nullable error))completionHandler;
completion:
(void (^_Nonnull)(MTROtaSoftwareUpdateProviderClusterApplyUpdateResponseParams * _Nullable data,
NSError * _Nullable error))completion;

- (void)handleNotifyUpdateAppliedForNodeID:(NSNumber * _Nonnull)nodeID
controller:(MTRDeviceController * _Nonnull)controller
params:(MTROtaSoftwareUpdateProviderClusterNotifyUpdateAppliedParams * _Nonnull)params
completionHandler:(StatusCompletion _Nonnull)completionHandler;
completion:(MTRStatusCompletion _Nonnull)completion;

@property (strong, nonatomic, nullable) NSArray<DeviceSoftwareVersionModel *> * candidates;
@property (strong, nonatomic, nullable) DeviceSoftwareVersionModel * selectedCandidate;
Expand Down
Loading

0 comments on commit e5adce4

Please sign in to comment.