Skip to content

Commit 0e778e9

Browse files
Fix completion naming in Darwin framework.
* 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. Fixes project-chip#22529 Addresses part of project-chip#22420
1 parent 43d7fd2 commit 0e778e9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+39738
-43297
lines changed

examples/darwin-framework-tool/commands/clusters/ClusterCommandBridge.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class ClusterCommand : public ModelCommand {
8181
timedInvokeTimeout:mTimedInteractionTimeoutMs.HasValue()
8282
? [NSNumber numberWithUnsignedShort:mTimedInteractionTimeoutMs.Value()]
8383
: nil
84-
clientQueue:callbackQueue
84+
queue:callbackQueue
8585
completion:^(
8686
NSArray<NSDictionary<NSString *, id> *> * _Nullable values, NSError * _Nullable error) {
8787
responsesNeeded--;

examples/darwin-framework-tool/commands/clusters/ModelCommandBridge.mm

+19-19
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,25 @@
3131
ChipLogProgress(chipTool, "Sending command to node 0x" ChipLogFormatX64, ChipLogValueX64(mNodeId));
3232
[commissioner getBaseDevice:mNodeId
3333
queue:callbackQueue
34-
completionHandler:^(MTRBaseDevice * _Nullable device, NSError * _Nullable error) {
35-
if (error != nil) {
36-
SetCommandExitStatus(error, "Error getting connected device");
37-
return;
38-
}
39-
40-
CHIP_ERROR err;
41-
if (device == nil) {
42-
err = CHIP_ERROR_INTERNAL;
43-
} else {
44-
err = SendCommand(device, mEndPointId);
45-
}
46-
47-
if (err != CHIP_NO_ERROR) {
48-
ChipLogError(chipTool, "Error: %s", chip::ErrorStr(err));
49-
SetCommandExitStatus(err);
50-
return;
51-
}
52-
}];
34+
completion:^(MTRBaseDevice * _Nullable device, NSError * _Nullable error) {
35+
if (error != nil) {
36+
SetCommandExitStatus(error, "Error getting connected device");
37+
return;
38+
}
39+
40+
CHIP_ERROR err;
41+
if (device == nil) {
42+
err = CHIP_ERROR_INTERNAL;
43+
} else {
44+
err = SendCommand(device, mEndPointId);
45+
}
46+
47+
if (err != CHIP_NO_ERROR) {
48+
ChipLogError(chipTool, "Error: %s", chip::ErrorStr(err));
49+
SetCommandExitStatus(err);
50+
return;
51+
}
52+
}];
5353
return CHIP_NO_ERROR;
5454
}
5555

examples/darwin-framework-tool/commands/clusters/ReportCommandBridge.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class ReadAttribute : public ModelCommand {
6060
clusterId:[NSNumber numberWithUnsignedInteger:mClusterId]
6161
attributeId:[NSNumber numberWithUnsignedInteger:mAttributeId]
6262
params:params
63-
clientQueue:callbackQueue
63+
queue:callbackQueue
6464
completion:^(NSArray<NSDictionary<NSString *, id> *> * _Nullable values, NSError * _Nullable error) {
6565
if (error != nil) {
6666
LogNSError("Error reading attribute", error);
@@ -135,7 +135,7 @@ class SubscribeAttribute : public ModelCommand {
135135
minInterval:[NSNumber numberWithUnsignedInteger:mMinInterval]
136136
maxInterval:[NSNumber numberWithUnsignedInteger:mMaxInterval]
137137
params:params
138-
clientQueue:callbackQueue
138+
queue:callbackQueue
139139
reportHandler:^(NSArray<NSDictionary<NSString *, id> *> * _Nullable values, NSError * _Nullable error) {
140140
if (values) {
141141
for (id item in values) {

examples/darwin-framework-tool/commands/clusters/WriteAttributeCommandBridge.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class WriteAttribute : public ModelCommand {
8181
timedWriteTimeout:mTimedInteractionTimeoutMs.HasValue()
8282
? [NSNumber numberWithUnsignedShort:mTimedInteractionTimeoutMs.Value()]
8383
: nil
84-
clientQueue:callbackQueue
84+
queue:callbackQueue
8585
completion:^(NSArray<NSDictionary<NSString *, id> *> * _Nullable values, NSError * _Nullable error) {
8686
if (error != nil) {
8787
LogNSError("Error writing attribute", error);

examples/darwin-framework-tool/commands/pairing/OpenCommissioningWindowCommand.mm

+8-8
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,19 @@
3434
params.commissioningTimeout = @(mCommissioningWindowTimeoutMs);
3535
params.timedInvokeTimeoutMs = @(10000);
3636
[cluster openBasicCommissioningWindowWithParams:params
37-
completionHandler:^(NSError * _Nullable error) {
38-
if (error == nil) {
39-
self->SetCommandExitStatus(CHIP_NO_ERROR);
40-
} else {
41-
self->SetCommandExitStatus(MTRErrorToCHIPErrorCode(error));
42-
}
43-
}];
37+
completion:^(NSError * _Nullable error) {
38+
if (error == nil) {
39+
self->SetCommandExitStatus(CHIP_NO_ERROR);
40+
} else {
41+
self->SetCommandExitStatus(MTRErrorToCHIPErrorCode(error));
42+
}
43+
}];
4444
} else {
4545
[device
4646
openCommissioningWindowWithSetupPasscode:[MTRSetupPayload generateRandomSetupPasscode]
4747
discriminator:@(mDiscriminator)
4848
duration:@(mCommissioningWindowTimeoutMs)
49-
clientQueue:mWorkQueue
49+
queue:mWorkQueue
5050
completion:^(MTRSetupPayload * _Nullable payload, NSError * error) {
5151
if (error != nil) {
5252
self->SetCommandExitStatus(MTRErrorToCHIPErrorCode(error));

examples/darwin-framework-tool/commands/pairing/PairingCommandBridge.mm

+43-42
Original file line numberDiff line numberDiff line change
@@ -111,46 +111,47 @@
111111
{
112112
dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip-tool.command", DISPATCH_QUEUE_SERIAL);
113113
MTRDeviceController * commissioner = CurrentCommissioner();
114-
[commissioner getBaseDevice:mNodeId
115-
queue:callbackQueue
116-
completionHandler:^(MTRBaseDevice * _Nullable device, NSError * _Nullable error) {
117-
CHIP_ERROR err = CHIP_NO_ERROR;
118-
if (error) {
119-
err = MTRErrorToCHIPErrorCode(error);
120-
LogNSError("Error: ", error);
121-
SetCommandExitStatus(err);
122-
} else if (device == nil) {
123-
ChipLogError(chipTool, "Error: %s", chip::ErrorStr(CHIP_ERROR_INTERNAL));
124-
SetCommandExitStatus(CHIP_ERROR_INTERNAL);
125-
} else {
126-
ChipLogProgress(chipTool, "Attempting to unpair device %llu", mNodeId);
127-
MTRBaseClusterOperationalCredentials * opCredsCluster =
128-
[[MTRBaseClusterOperationalCredentials alloc] initWithDevice:device endpoint:@(0) queue:callbackQueue];
129-
[opCredsCluster readAttributeCurrentFabricIndexWithCompletionHandler:^(
130-
NSNumber * _Nullable value, NSError * _Nullable readError) {
131-
if (readError) {
132-
CHIP_ERROR readErr = MTRErrorToCHIPErrorCode(readError);
133-
LogNSError("Failed to get current fabric: ", readError);
134-
SetCommandExitStatus(readErr);
135-
return;
136-
}
137-
MTROperationalCredentialsClusterRemoveFabricParams * params =
138-
[[MTROperationalCredentialsClusterRemoveFabricParams alloc] init];
139-
params.fabricIndex = value;
140-
[opCredsCluster
141-
removeFabricWithParams:params
142-
completionHandler:^(MTROperationalCredentialsClusterNOCResponseParams * _Nullable data,
143-
NSError * _Nullable removeError) {
144-
CHIP_ERROR removeErr = CHIP_NO_ERROR;
145-
if (removeError) {
146-
removeErr = MTRErrorToCHIPErrorCode(removeError);
147-
LogNSError("Failed to remove current fabric: ", removeError);
148-
} else {
149-
ChipLogProgress(chipTool, "Successfully unpaired deviceId %llu", mNodeId);
150-
}
151-
SetCommandExitStatus(removeErr);
152-
}];
153-
}];
154-
}
155-
}];
114+
[commissioner
115+
getBaseDevice:mNodeId
116+
queue:callbackQueue
117+
completion:^(MTRBaseDevice * _Nullable device, NSError * _Nullable error) {
118+
CHIP_ERROR err = CHIP_NO_ERROR;
119+
if (error) {
120+
err = MTRErrorToCHIPErrorCode(error);
121+
LogNSError("Error: ", error);
122+
SetCommandExitStatus(err);
123+
} else if (device == nil) {
124+
ChipLogError(chipTool, "Error: %s", chip::ErrorStr(CHIP_ERROR_INTERNAL));
125+
SetCommandExitStatus(CHIP_ERROR_INTERNAL);
126+
} else {
127+
ChipLogProgress(chipTool, "Attempting to unpair device %llu", mNodeId);
128+
MTRBaseClusterOperationalCredentials * opCredsCluster =
129+
[[MTRBaseClusterOperationalCredentials alloc] initWithDevice:device endpoint:@(0) queue:callbackQueue];
130+
[opCredsCluster
131+
readAttributeCurrentFabricIndexWithCompletion:^(NSNumber * _Nullable value, NSError * _Nullable readError) {
132+
if (readError) {
133+
CHIP_ERROR readErr = MTRErrorToCHIPErrorCode(readError);
134+
LogNSError("Failed to get current fabric: ", readError);
135+
SetCommandExitStatus(readErr);
136+
return;
137+
}
138+
MTROperationalCredentialsClusterRemoveFabricParams * params =
139+
[[MTROperationalCredentialsClusterRemoveFabricParams alloc] init];
140+
params.fabricIndex = value;
141+
[opCredsCluster
142+
removeFabricWithParams:params
143+
completion:^(MTROperationalCredentialsClusterNOCResponseParams * _Nullable data,
144+
NSError * _Nullable removeError) {
145+
CHIP_ERROR removeErr = CHIP_NO_ERROR;
146+
if (removeError) {
147+
removeErr = MTRErrorToCHIPErrorCode(removeError);
148+
LogNSError("Failed to remove current fabric: ", removeError);
149+
} else {
150+
ChipLogProgress(chipTool, "Successfully unpaired deviceId %llu", mNodeId);
151+
}
152+
SetCommandExitStatus(removeErr);
153+
}];
154+
}];
155+
}
156+
}];
156157
}

examples/darwin-framework-tool/commands/provider/OTAProviderDelegate.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,20 @@ typedef NS_ENUM(uint8_t, UserConsentState) {
4141
- (void)handleQueryImageForNodeID:(NSNumber * _Nonnull)nodeID
4242
controller:(MTRDeviceController * _Nonnull)controller
4343
params:(MTROtaSoftwareUpdateProviderClusterQueryImageParams * _Nonnull)params
44-
completionHandler:(void (^_Nonnull)(MTROtaSoftwareUpdateProviderClusterQueryImageResponseParams * _Nullable data,
45-
NSError * _Nullable error))completionHandler;
44+
completion:(void (^_Nonnull)(MTROtaSoftwareUpdateProviderClusterQueryImageResponseParams * _Nullable data,
45+
NSError * _Nullable error))completion;
4646

4747
- (void)handleApplyUpdateRequestForNodeID:(NSNumber * _Nonnull)nodeID
4848
controller:(MTRDeviceController * _Nonnull)controller
4949
params:(MTROtaSoftwareUpdateProviderClusterApplyUpdateRequestParams * _Nonnull)params
50-
completionHandler:
51-
(void (^_Nonnull)(MTROtaSoftwareUpdateProviderClusterApplyUpdateResponseParams * _Nullable data,
52-
NSError * _Nullable error))completionHandler;
50+
completion:
51+
(void (^_Nonnull)(MTROtaSoftwareUpdateProviderClusterApplyUpdateResponseParams * _Nullable data,
52+
NSError * _Nullable error))completion;
5353

5454
- (void)handleNotifyUpdateAppliedForNodeID:(NSNumber * _Nonnull)nodeID
5555
controller:(MTRDeviceController * _Nonnull)controller
5656
params:(MTROtaSoftwareUpdateProviderClusterNotifyUpdateAppliedParams * _Nonnull)params
57-
completionHandler:(StatusCompletion _Nonnull)completionHandler;
57+
completion:(MTRStatusCompletion _Nonnull)completion;
5858

5959
@property (strong, nonatomic, nullable) NSArray<DeviceSoftwareVersionModel *> * candidates;
6060
@property (strong, nonatomic, nullable) DeviceSoftwareVersionModel * selectedCandidate;

0 commit comments

Comments
 (0)