Skip to content

Commit

Permalink
Allow setting of OTA Provider delegate through the controller (#20517)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Aug 25, 2023
1 parent fb80444 commit 5348606
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/darwin/Framework/CHIP/MTRDeviceController.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ typedef void (^MTRDeviceConnectionCallback)(MTRBaseDevice * _Nullable device, NS

@class MTRCommissioningParameters;
@protocol MTRDevicePairingDelegate;
@protocol MTROTAProviderDelegate;

@interface MTRDeviceController : NSObject

Expand Down Expand Up @@ -119,6 +120,15 @@ typedef void (^MTRDeviceConnectionCallback)(MTRBaseDevice * _Nullable device, NS
*/
- (void)setPairingDelegate:(id<MTRDevicePairingDelegate>)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<MTROTAProviderDelegate>)delegate queue:(dispatch_queue_t)queue;

/**
* Shutdown the controller. Calls to shutdown after the first one are NO-OPs.
*/
Expand Down
15 changes: 15 additions & 0 deletions src/darwin/Framework/CHIP/MTRDeviceController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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";
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -610,6 +618,13 @@ - (void)setPairingDelegate:(id<MTRDevicePairingDelegate>)delegate queue:(dispatc
});
}

- (void)setOTAProviderDelegate:(id<MTROTAProviderDelegate>)delegate queue:(dispatch_queue_t)queue;
{
dispatch_async(_chipWorkQueue, ^{
self->_otaProviderDelegateBridge->setDelegate(delegate, queue);
});
}

- (BOOL)checkForInitError:(BOOL)condition logMsg:(NSString *)logMsg
{
if (condition) {
Expand Down

0 comments on commit 5348606

Please sign in to comment.