Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 3d91e4b

Browse files
bzbarsky-appleyyzhong-g
authored andcommittedDec 11, 2024
Clean up asyncGetCommissionerOnMatterQueue on MTRDeviceController. (project-chip#35947)
MTROperationalCredentialsDelegate always works with a concrete controller. Make that explicit. At that point, asyncGetCommissionerOnMatterQueue can only get called on an MTRDeviceController from and MTRBaseDevice that was created for an XPC controller. Having that just fail out is perfectly reasonable.
1 parent d62ec96 commit 3d91e4b

4 files changed

+9
-31
lines changed
 

‎src/darwin/Framework/CHIP/MTRDeviceController.mm

+2-23
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
#import "MTRLogging_Internal.h"
4444
#import "MTRMetricKeys.h"
4545
#import "MTRMetricsCollector.h"
46-
#import "MTROperationalCredentialsDelegate.h"
4746
#import "MTRP256KeypairBridge.h"
4847
#import "MTRPersistentStorageDelegateBridge.h"
4948
#import "MTRServerEndpoint_Internal.h"
@@ -124,7 +123,6 @@ @implementation MTRDeviceController {
124123
chip::Credentials::PartialDACVerifier * _partialDACVerifier;
125124
chip::Credentials::DefaultDACVerifier * _defaultDACVerifier;
126125
MTRDeviceControllerDelegateBridge * _deviceControllerDelegateBridge;
127-
MTROperationalCredentialsDelegate * _operationalCredentialsDelegate;
128126
MTRDeviceAttestationDelegateBridge * _deviceAttestationDelegateBridge;
129127
os_unfair_lock _underlyingDeviceMapLock;
130128
MTRCommissionableBrowser * _commissionableBrowser;
@@ -586,27 +584,8 @@ - (MTRTransportType)sessionTransportTypeForDevice:(MTRBaseDevice *)device
586584
- (void)asyncGetCommissionerOnMatterQueue:(void (^)(chip::Controller::DeviceCommissioner *))block
587585
errorHandler:(nullable MTRDeviceErrorHandler)errorHandler
588586
{
589-
{
590-
NSError * error;
591-
if (![self checkIsRunning:&error]) {
592-
if (errorHandler != nil) {
593-
errorHandler(error);
594-
}
595-
return;
596-
}
597-
}
598-
599-
dispatch_async(_chipWorkQueue, ^{
600-
NSError * error;
601-
if (![self checkIsRunning:&error]) {
602-
if (errorHandler != nil) {
603-
errorHandler(error);
604-
}
605-
return;
606-
}
607-
608-
block(self->_cppCommissioner);
609-
});
587+
MTR_ABSTRACT_METHOD();
588+
errorHandler([MTRError errorForCHIPErrorCode:CHIP_ERROR_INCORRECT_STATE]);
610589
}
611590

612591
- (void)asyncDispatchToMatterQueue:(dispatch_block_t)block errorHandler:(nullable MTRDeviceErrorHandler)errorHandler

‎src/darwin/Framework/CHIP/MTRDevice_XPC.mm

-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
#import "MTRLogging_Internal.h"
5050
#import "MTRMetricKeys.h"
5151
#import "MTRMetricsCollector.h"
52-
#import "MTROperationalCredentialsDelegate.h"
5352
#import "MTRP256KeypairBridge.h"
5453
#import "MTRPersistentStorageDelegateBridge.h"
5554
#import "MTRServerEndpoint_Internal.h"

‎src/darwin/Framework/CHIP/MTROperationalCredentialsDelegate.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#import <Foundation/Foundation.h>
2121
#import <Security/Security.h>
2222

23-
#import "MTRDeviceController.h"
23+
#import "MTRDeviceController_Concrete.h"
2424
#import "MTRError_Internal.h"
2525
#import "MTRKeypair.h"
2626
#import "MTROperationalCertificateIssuer.h"
@@ -38,7 +38,7 @@ class MTROperationalCredentialsDelegate : public chip::Controller::OperationalCr
3838
public:
3939
using ChipP256KeypairPtr = chip::Crypto::P256Keypair *;
4040

41-
MTROperationalCredentialsDelegate(MTRDeviceController * deviceController);
41+
MTROperationalCredentialsDelegate(MTRDeviceController_Concrete * deviceController);
4242
~MTROperationalCredentialsDelegate() {}
4343

4444
CHIP_ERROR Init(ChipP256KeypairPtr nocSigner, NSData * ipk, NSData * rootCert, NSData * _Nullable icaCert);
@@ -147,7 +147,7 @@ class MTROperationalCredentialsDelegate : public chip::Controller::OperationalCr
147147
NSData * _Nullable mRootCert;
148148
NSData * _Nullable mIntermediateCert;
149149

150-
MTRDeviceController * __weak mWeakController;
150+
MTRDeviceController_Concrete * __weak mWeakController;
151151
chip::Controller::DeviceCommissioner * _Nullable mCppCommissioner = nullptr;
152152
id<MTROperationalCertificateIssuer> _Nullable mOperationalCertificateIssuer;
153153
dispatch_queue_t _Nullable mOperationalCertificateIssuerQueue;

‎src/darwin/Framework/CHIP/MTROperationalCredentialsDelegate.mm

+4-4
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
using namespace Credentials;
4343
using namespace Crypto;
4444

45-
MTROperationalCredentialsDelegate::MTROperationalCredentialsDelegate(MTRDeviceController * deviceController)
45+
MTROperationalCredentialsDelegate::MTROperationalCredentialsDelegate(MTRDeviceController_Concrete * deviceController)
4646
: mWeakController(deviceController)
4747
{
4848
}
@@ -129,7 +129,7 @@
129129

130130
VerifyOrReturnError(mCppCommissioner != nullptr, CHIP_ERROR_INCORRECT_STATE);
131131

132-
MTRDeviceController * strongController = mWeakController;
132+
MTRDeviceController_Concrete * strongController = mWeakController;
133133
VerifyOrReturnError(strongController != nil, CHIP_ERROR_INCORRECT_STATE);
134134

135135
mOnNOCCompletionCallback = onCompletion;
@@ -168,14 +168,14 @@
168168
certificationDeclaration:AsData(certificationDeclarationSpan)
169169
firmwareInfo:firmwareInfo];
170170

171-
MTRDeviceController * __weak weakController = mWeakController;
171+
MTRDeviceController_Concrete * __weak weakController = mWeakController;
172172
dispatch_async(mOperationalCertificateIssuerQueue, ^{
173173
[mOperationalCertificateIssuer
174174
issueOperationalCertificateForRequest:csrInfo
175175
attestationInfo:attestationInfo
176176
controller:strongController
177177
completion:^(MTROperationalCertificateChain * _Nullable chain, NSError * _Nullable error) {
178-
MTRDeviceController * strongController = weakController;
178+
MTRDeviceController_Concrete * strongController = weakController;
179179
if (strongController == nil || !strongController.isRunning) {
180180
// No longer safe to touch "this"
181181
return;

0 commit comments

Comments
 (0)
Please sign in to comment.