Skip to content

Commit

Permalink
Clean up asyncGetCommissionerOnMatterQueue on MTRDeviceController. (#…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
bzbarsky-apple authored Oct 7, 2024
1 parent 3a7c922 commit 7fd3d59
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 31 deletions.
25 changes: 2 additions & 23 deletions src/darwin/Framework/CHIP/MTRDeviceController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
#import "MTRLogging_Internal.h"
#import "MTRMetricKeys.h"
#import "MTRMetricsCollector.h"
#import "MTROperationalCredentialsDelegate.h"
#import "MTRP256KeypairBridge.h"
#import "MTRPersistentStorageDelegateBridge.h"
#import "MTRServerEndpoint_Internal.h"
Expand Down Expand Up @@ -124,7 +123,6 @@ @implementation MTRDeviceController {
chip::Credentials::PartialDACVerifier * _partialDACVerifier;
chip::Credentials::DefaultDACVerifier * _defaultDACVerifier;
MTRDeviceControllerDelegateBridge * _deviceControllerDelegateBridge;
MTROperationalCredentialsDelegate * _operationalCredentialsDelegate;
MTRDeviceAttestationDelegateBridge * _deviceAttestationDelegateBridge;
os_unfair_lock _underlyingDeviceMapLock;
MTRCommissionableBrowser * _commissionableBrowser;
Expand Down Expand Up @@ -586,27 +584,8 @@ - (MTRTransportType)sessionTransportTypeForDevice:(MTRBaseDevice *)device
- (void)asyncGetCommissionerOnMatterQueue:(void (^)(chip::Controller::DeviceCommissioner *))block
errorHandler:(nullable MTRDeviceErrorHandler)errorHandler
{
{
NSError * error;
if (![self checkIsRunning:&error]) {
if (errorHandler != nil) {
errorHandler(error);
}
return;
}
}

dispatch_async(_chipWorkQueue, ^{
NSError * error;
if (![self checkIsRunning:&error]) {
if (errorHandler != nil) {
errorHandler(error);
}
return;
}

block(self->_cppCommissioner);
});
MTR_ABSTRACT_METHOD();
errorHandler([MTRError errorForCHIPErrorCode:CHIP_ERROR_INCORRECT_STATE]);
}

- (void)asyncDispatchToMatterQueue:(dispatch_block_t)block errorHandler:(nullable MTRDeviceErrorHandler)errorHandler
Expand Down
1 change: 0 additions & 1 deletion src/darwin/Framework/CHIP/MTRDevice_XPC.mm
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
#import "MTRLogging_Internal.h"
#import "MTRMetricKeys.h"
#import "MTRMetricsCollector.h"
#import "MTROperationalCredentialsDelegate.h"
#import "MTRP256KeypairBridge.h"
#import "MTRPersistentStorageDelegateBridge.h"
#import "MTRServerEndpoint_Internal.h"
Expand Down
6 changes: 3 additions & 3 deletions src/darwin/Framework/CHIP/MTROperationalCredentialsDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#import <Foundation/Foundation.h>
#import <Security/Security.h>

#import "MTRDeviceController.h"
#import "MTRDeviceController_Concrete.h"
#import "MTRError_Internal.h"
#import "MTRKeypair.h"
#import "MTROperationalCertificateIssuer.h"
Expand All @@ -38,7 +38,7 @@ class MTROperationalCredentialsDelegate : public chip::Controller::OperationalCr
public:
using ChipP256KeypairPtr = chip::Crypto::P256Keypair *;

MTROperationalCredentialsDelegate(MTRDeviceController * deviceController);
MTROperationalCredentialsDelegate(MTRDeviceController_Concrete * deviceController);
~MTROperationalCredentialsDelegate() {}

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

MTRDeviceController * __weak mWeakController;
MTRDeviceController_Concrete * __weak mWeakController;
chip::Controller::DeviceCommissioner * _Nullable mCppCommissioner = nullptr;
id<MTROperationalCertificateIssuer> _Nullable mOperationalCertificateIssuer;
dispatch_queue_t _Nullable mOperationalCertificateIssuerQueue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
using namespace Credentials;
using namespace Crypto;

MTROperationalCredentialsDelegate::MTROperationalCredentialsDelegate(MTRDeviceController * deviceController)
MTROperationalCredentialsDelegate::MTROperationalCredentialsDelegate(MTRDeviceController_Concrete * deviceController)
: mWeakController(deviceController)
{
}
Expand Down Expand Up @@ -129,7 +129,7 @@

VerifyOrReturnError(mCppCommissioner != nullptr, CHIP_ERROR_INCORRECT_STATE);

MTRDeviceController * strongController = mWeakController;
MTRDeviceController_Concrete * strongController = mWeakController;
VerifyOrReturnError(strongController != nil, CHIP_ERROR_INCORRECT_STATE);

mOnNOCCompletionCallback = onCompletion;
Expand Down Expand Up @@ -168,14 +168,14 @@
certificationDeclaration:AsData(certificationDeclarationSpan)
firmwareInfo:firmwareInfo];

MTRDeviceController * __weak weakController = mWeakController;
MTRDeviceController_Concrete * __weak weakController = mWeakController;
dispatch_async(mOperationalCertificateIssuerQueue, ^{
[mOperationalCertificateIssuer
issueOperationalCertificateForRequest:csrInfo
attestationInfo:attestationInfo
controller:strongController
completion:^(MTROperationalCertificateChain * _Nullable chain, NSError * _Nullable error) {
MTRDeviceController * strongController = weakController;
MTRDeviceController_Concrete * strongController = weakController;
if (strongController == nil || !strongController.isRunning) {
// No longer safe to touch "this"
return;
Expand Down

0 comments on commit 7fd3d59

Please sign in to comment.