From 4dd048fee13b1226cb9542c481bba30885313428 Mon Sep 17 00:00:00 2001 From: Carol Yang Date: Fri, 8 Jul 2022 18:50:02 -0700 Subject: [PATCH] Allow setting of OTA Provider delegate through the controller (#20517) * Allow setting of OTA Provider delegate through the controller * Update src/darwin/Framework/CHIP/MTRDeviceController.mm * Update src/darwin/Framework/CHIP/MTRDeviceController.h Co-authored-by: Justin Wood --- src/darwin/Framework/CHIP/MTRDeviceController.h | 10 ++++++++++ src/darwin/Framework/CHIP/MTRDeviceController.mm | 15 +++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/darwin/Framework/CHIP/MTRDeviceController.h b/src/darwin/Framework/CHIP/MTRDeviceController.h index 61db4061896d10..fe1f0eb8b61b22 100644 --- a/src/darwin/Framework/CHIP/MTRDeviceController.h +++ b/src/darwin/Framework/CHIP/MTRDeviceController.h @@ -27,6 +27,7 @@ typedef void (^MTRDeviceConnectionCallback)(MTRBaseDevice * _Nullable device, NS @class MTRCommissioningParameters; @protocol MTRDevicePairingDelegate; +@protocol MTROTAProviderDelegate; @interface MTRDeviceController : NSObject @@ -119,6 +120,15 @@ typedef void (^MTRDeviceConnectionCallback)(MTRBaseDevice * _Nullable device, NS */ - (void)setPairingDelegate:(id)delegate queue:(dispatch_queue_t)queue; +/** + * Set the Delegate for the OTA Provider as well as the Queue on which the Delegate callbacks will be triggered + * + * @param[in] delegate The delegate the OTA Provider should use + * + * @param[in] queue The queue on which the callbacks will be delivered + */ +- (void)setOTAProviderDelegate:(id)delegate queue:(dispatch_queue_t)queue; + /** * Shutdown the controller. Calls to shutdown after the first one are NO-OPs. */ diff --git a/src/darwin/Framework/CHIP/MTRDeviceController.mm b/src/darwin/Framework/CHIP/MTRDeviceController.mm index da9b475a2a491e..2a8f6dcac23d9a 100644 --- a/src/darwin/Framework/CHIP/MTRDeviceController.mm +++ b/src/darwin/Framework/CHIP/MTRDeviceController.mm @@ -25,6 +25,7 @@ #import "MTRError_Internal.h" #import "MTRKeypair.h" #import "MTRLogging.h" +#import "MTROTAProviderDelegateBridge.h" #import "MTROperationalCredentialsDelegate.h" #import "MTRP256KeypairBridge.h" #import "MTRPersistentStorageDelegateBridge.h" @@ -56,6 +57,7 @@ static NSString * const kErrorOperationalCredentialsInit = @"Init failure while creating operational credentials delegate"; static NSString * const kErrorOperationalKeypairInit = @"Init failure while creating operational keypair bridge"; static NSString * const kErrorPairingInit = @"Init failure while creating a pairing delegate"; +static NSString * const kErrorOtaProviderInit = @"Init failure while creating an OTA provider delegate"; static NSString * const kErrorPairDevice = @"Failure while pairing the device"; static NSString * const kErrorUnpairDevice = @"Failure while unpairing the device"; static NSString * const kErrorStopPairing = @"Failure while trying to stop the pairing process"; @@ -75,6 +77,7 @@ @interface MTRDeviceController () @property (readonly) chip::Controller::DeviceCommissioner * cppCommissioner; @property (readonly) MTRDevicePairingDelegateBridge * pairingDelegateBridge; +@property (readonly) MTROTAProviderDelegateBridge * otaProviderDelegateBridge; @property (readonly) MTROperationalCredentialsDelegate * operationalCredentialsDelegate; @property (readonly) MTRP256KeypairBridge signingKeypairBridge; @property (readonly) MTRP256KeypairBridge operationalKeypairBridge; @@ -95,6 +98,11 @@ - (instancetype)initWithFactory:(MTRControllerFactory *)factory queue:(dispatch_ return nil; } + _otaProviderDelegateBridge = new MTROTAProviderDelegateBridge(); + if ([self checkForInitError:(_otaProviderDelegateBridge != nullptr) logMsg:kErrorOtaProviderInit]) { + return nil; + } + _operationalCredentialsDelegate = new MTROperationalCredentialsDelegate(); if ([self checkForInitError:(_operationalCredentialsDelegate != nullptr) logMsg:kErrorOperationalCredentialsInit]) { return nil; @@ -610,6 +618,13 @@ - (void)setPairingDelegate:(id)delegate queue:(dispatc }); } +- (void)setOTAProviderDelegate:(id)delegate queue:(dispatch_queue_t)queue; +{ + dispatch_async(_chipWorkQueue, ^{ + self->_otaProviderDelegateBridge->setDelegate(delegate, queue); + }); +} + - (BOOL)checkForInitError:(BOOL)condition logMsg:(NSString *)logMsg { if (condition) {