Skip to content

Commit

Permalink
Tell the Darwin OTA provider delegate which node we are dealing with. (
Browse files Browse the repository at this point in the history
…#21839)

* Tell the Darwin OTA provider delegate which node we are dealing with.

Fixes #21619

* Address review comment.
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Aug 16, 2022
1 parent 2140b7c commit 4349096
Show file tree
Hide file tree
Showing 7 changed files with 231 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,23 @@ typedef NS_ENUM(uint8_t, UserConsentState) {
@end

@interface OTAProviderDelegate : NSObject <MTROTAProviderDelegate>
- (void)handleQueryImage:(MTROtaSoftwareUpdateProviderClusterQueryImageParams * _Nonnull)params
completionHandler:(void (^_Nonnull)(MTROtaSoftwareUpdateProviderClusterQueryImageResponseParams * _Nullable data,
NSError * _Nullable error))completionHandler;
- (void)handleQueryImageForNodeID:(NSNumber * _Nonnull)nodeID
controller:(MTRDeviceController * _Nonnull)controller
params:(MTROtaSoftwareUpdateProviderClusterQueryImageParams * _Nonnull)params
completionHandler:(void (^_Nonnull)(MTROtaSoftwareUpdateProviderClusterQueryImageResponseParams * _Nullable data,
NSError * _Nullable error))completionHandler;

- (void)handleApplyUpdateRequest:(MTROtaSoftwareUpdateProviderClusterApplyUpdateRequestParams * _Nonnull)params
completionHandler:(void (^_Nonnull)(MTROtaSoftwareUpdateProviderClusterApplyUpdateResponseParams * _Nullable data,
NSError * _Nullable error))completionHandler;
- (void)handleApplyUpdateRequestForNodeID:(NSNumber * _Nonnull)nodeID
controller:(MTRDeviceController * _Nonnull)controller
params:(MTROtaSoftwareUpdateProviderClusterApplyUpdateRequestParams * _Nonnull)params
completionHandler:
(void (^_Nonnull)(MTROtaSoftwareUpdateProviderClusterApplyUpdateResponseParams * _Nullable data,
NSError * _Nullable error))completionHandler;

- (void)handleNotifyUpdateApplied:(MTROtaSoftwareUpdateProviderClusterNotifyUpdateAppliedParams * _Nonnull)params
completionHandler:(StatusCompletion _Nonnull)completionHandler;
- (void)handleNotifyUpdateAppliedForNodeID:(NSNumber * _Nonnull)nodeID
controller:(MTRDeviceController * _Nonnull)controller
params:(MTROtaSoftwareUpdateProviderClusterNotifyUpdateAppliedParams * _Nonnull)params
completionHandler:(StatusCompletion _Nonnull)completionHandler;

@property (strong, nonatomic, nullable) NSArray<DeviceSoftwareVersionModel *> * candidates;
@property (strong, nonatomic, nullable) DeviceSoftwareVersionModel * selectedCandidate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ - (instancetype)init
return self;
}

- (void)handleQueryImage:(MTROtaSoftwareUpdateProviderClusterQueryImageParams * _Nonnull)params
completionHandler:(void (^_Nonnull)(MTROtaSoftwareUpdateProviderClusterQueryImageResponseParams * _Nullable data,
NSError * _Nullable error))completionHandler
- (void)handleQueryImageForNodeID:(NSNumber * _Nonnull)nodeID
controller:(MTRDeviceController * _Nonnull)controller
params:(MTROtaSoftwareUpdateProviderClusterQueryImageParams * _Nonnull)params
completionHandler:(void (^_Nonnull)(MTROtaSoftwareUpdateProviderClusterQueryImageResponseParams * _Nullable data,
NSError * _Nullable error))completionHandler
{
NSError * error;

Expand Down Expand Up @@ -102,25 +104,32 @@ - (void)handleQueryImage:(MTROtaSoftwareUpdateProviderClusterQueryImageParams *
completionHandler(_selectedCandidate, error);
}

- (void)handleApplyUpdateRequest:(MTROtaSoftwareUpdateProviderClusterApplyUpdateRequestParams * _Nonnull)params
completionHandler:(void (^_Nonnull)(MTROtaSoftwareUpdateProviderClusterApplyUpdateResponseParams * _Nullable data,
NSError * _Nullable error))completionHandler
- (void)handleApplyUpdateRequestForNodeID:(NSNumber * _Nonnull)nodeID
controller:(MTRDeviceController * _Nonnull)controller
params:(MTROtaSoftwareUpdateProviderClusterApplyUpdateRequestParams * _Nonnull)params
completionHandler:
(void (^_Nonnull)(MTROtaSoftwareUpdateProviderClusterApplyUpdateResponseParams * _Nullable data,
NSError * _Nullable error))completionHandler
{
MTROtaSoftwareUpdateProviderClusterApplyUpdateResponseParams * applyUpdateResponseParams =
[[MTROtaSoftwareUpdateProviderClusterApplyUpdateResponseParams alloc] init];
applyUpdateResponseParams.action = @(MTROtaSoftwareUpdateProviderOTAApplyUpdateActionProceed);
completionHandler(applyUpdateResponseParams, nil);
}

- (void)handleNotifyUpdateApplied:(MTROtaSoftwareUpdateProviderClusterNotifyUpdateAppliedParams * _Nonnull)params
completionHandler:(StatusCompletion _Nonnull)completionHandler
- (void)handleNotifyUpdateAppliedForNodeID:(NSNumber * _Nonnull)nodeID
controller:(MTRDeviceController * _Nonnull)controller
params:(MTROtaSoftwareUpdateProviderClusterNotifyUpdateAppliedParams * _Nonnull)params
completionHandler:(StatusCompletion _Nonnull)completionHandler
{
completionHandler(nil);
}

- (void)handleBDXTransferSessionBegin:(NSString * _Nonnull)fileDesignator
offset:(NSNumber * _Nonnull)offset
completionHandler:(void (^)(NSError * error))completionHandler
- (void)handleBDXTransferSessionBeginForNodeID:(NSNumber * _Nonnull)nodeID
controller:(MTRDeviceController * _Nonnull)controller
fileDesignator:(NSString * _Nonnull)fileDesignator
offset:(NSNumber * _Nonnull)offset
completionHandler:(void (^)(NSError * error))completionHandler
{
NSLog(@"BDX TransferSession begin with %@ (offset: %@)", fileDesignator, offset);

Expand Down Expand Up @@ -161,18 +170,22 @@ - (void)handleBDXTransferSessionBegin:(NSString * _Nonnull)fileDesignator
completionHandler(nil);
}

- (void)handleBDXTransferSessionEnd:(NSError * _Nullable)error
- (void)handleBDXTransferSessionEndForNodeID:(NSNumber * _Nonnull)nodeID
controller:(MTRDeviceController * _Nonnull)controller
error:(NSError * _Nullable)error
{
NSLog(@"BDX TransferSession end with error: %@", error);
_mFileHandle = nil;
_mFileOffset = nil;
_mFileEndOffset = nil;
}

- (void)handleBDXQuery:(NSNumber * _Nonnull)blockSize
blockIndex:(NSNumber * _Nonnull)blockIndex
bytesToSkip:(NSNumber * _Nonnull)bytesToSkip
completionHandler:(void (^)(NSData * _Nullable data, BOOL isEOF))completionHandler
- (void)handleBDXQueryForNodeID:(NSNumber * _Nonnull)nodeID
controller:(MTRDeviceController * _Nonnull)controller
blockSize:(NSNumber * _Nonnull)blockSize
blockIndex:(NSNumber * _Nonnull)blockIndex
bytesToSkip:(NSNumber * _Nonnull)bytesToSkip
completionHandler:(void (^)(NSData * _Nullable data, BOOL isEOF))completionHandler
{
NSLog(@"BDX Query received blockSize: %@, blockIndex: %@", blockSize, blockIndex);

Expand Down
11 changes: 11 additions & 0 deletions src/darwin/Framework/CHIP/MTRControllerFactory.mm
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,17 @@ - (void)controllerShuttingDown:(MTRDeviceController *)controller
}
}

- (nullable MTRDeviceController *)runningControllerForFabricIndex:(chip::FabricIndex)fabricIndex
{
for (MTRDeviceController * existing in _controllers) {
if ([existing fabricIndex] == fabricIndex) {
return existing;
}
}

return nil;
}

- (MTRPersistentStorageDelegateBridge *)storageDelegateBridge
{
return _persistentStorageDelegateBridge;
Expand Down
7 changes: 7 additions & 0 deletions src/darwin/Framework/CHIP/MTRControllerFactory_Internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

#import "MTRControllerFactory.h"

#include <lib/core/DataModelTypes.h>

class MTRPersistentStorageDelegateBridge;

namespace chip {
Expand All @@ -40,6 +42,11 @@ NS_ASSUME_NONNULL_BEGIN

- (void)controllerShuttingDown:(MTRDeviceController *)controller;

/**
* Find a running controller, if any, for the given fabric index.
*/
- (nullable MTRDeviceController *)runningControllerForFabricIndex:(chip::FabricIndex)fabricIndex;

@property (readonly) MTRPersistentStorageDelegateBridge * storageDelegateBridge;
@property (readonly) chip::Credentials::GroupDataProvider * groupData;
@property (readonly) chip::Credentials::DeviceAttestationVerifier * deviceAttestationVerifier;
Expand Down
74 changes: 46 additions & 28 deletions src/darwin/Framework/CHIP/MTROTAProviderDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,50 +28,68 @@ NS_ASSUME_NONNULL_BEGIN
@protocol MTROTAProviderDelegate <NSObject>
@required
/**
* Notify the delegate when query image command is received
*
* Notify the delegate when the query image command is received from some node.
* The controller identifies the fabric the node is on, and the nodeID
* identifies the node within that fabric.
*/
- (void)handleQueryImage:(MTROtaSoftwareUpdateProviderClusterQueryImageParams *)params
completionHandler:(void (^)(MTROtaSoftwareUpdateProviderClusterQueryImageResponseParams * _Nullable data,
NSError * _Nullable error))completionHandler;
- (void)handleQueryImageForNodeID:(NSNumber *)nodeID
controller:(MTRDeviceController *)controller
params:(MTROtaSoftwareUpdateProviderClusterQueryImageParams *)params
completionHandler:(void (^)(MTROtaSoftwareUpdateProviderClusterQueryImageResponseParams * _Nullable data,
NSError * _Nullable error))completionHandler;

/**
* Notify the delegate when apply update request command is received
*
* Notify the delegate when the apply update request command is received from
* some node. The controller identifies the fabric the node is on, and the
* nodeID identifies the node within that fabric.
*/
- (void)handleApplyUpdateRequest:(MTROtaSoftwareUpdateProviderClusterApplyUpdateRequestParams *)params
completionHandler:(void (^)(MTROtaSoftwareUpdateProviderClusterApplyUpdateResponseParams * _Nullable data,
NSError * _Nullable error))completionHandler;
- (void)handleApplyUpdateRequestForNodeID:(NSNumber *)nodeID
controller:(MTRDeviceController *)controller
params:(MTROtaSoftwareUpdateProviderClusterApplyUpdateRequestParams *)params
completionHandler:(void (^)(MTROtaSoftwareUpdateProviderClusterApplyUpdateResponseParams * _Nullable data,
NSError * _Nullable error))completionHandler;

/**
* Notify the delegate when notify update applied command is received
*
* Notify the delegate when the notify update applied command is received from
* some node. The controller identifies the fabric the node is on, and the
* nodeID identifies the node within that fabric.
*/
- (void)handleNotifyUpdateApplied:(MTROtaSoftwareUpdateProviderClusterNotifyUpdateAppliedParams *)params
completionHandler:(StatusCompletion)completionHandler;
- (void)handleNotifyUpdateAppliedForNodeID:(NSNumber *)nodeID
controller:(MTRDeviceController *)controller
params:(MTROtaSoftwareUpdateProviderClusterNotifyUpdateAppliedParams *)params
completionHandler:(StatusCompletion)completionHandler;

/**
* Notify the delegate when a BDX Session starts
*
* Notify the delegate when a BDX Session starts for some node. The controller
* identifies the fabric the node is on, and the nodeID identifies the node
* within that fabric.
*/
- (void)handleBDXTransferSessionBegin:(NSString * _Nonnull)fileDesignator
offset:(NSNumber * _Nonnull)offset
completionHandler:(void (^)(NSError * error))completionHandler;
- (void)handleBDXTransferSessionBeginForNodeID:(NSNumber *)nodeID
controller:(MTRDeviceController *)controller
fileDesignator:(NSString *)fileDesignator
offset:(NSNumber *)offset
completionHandler:(void (^)(NSError * error))completionHandler;

/**
* Notify the delegate when a BDX Session ends
*
* Notify the delegate when a BDX Session ends for some node. The controller
* identifies the fabric the node is on, and the nodeID identifies the node
* within that fabric.
*/
- (void)handleBDXTransferSessionEnd:(NSError * _Nullable)error;
- (void)handleBDXTransferSessionEndForNodeID:(NSNumber *)nodeID
controller:(MTRDeviceController *)controller
error:(NSError * _Nullable)error;

/**
* Notify the delegate when a BDX Query message has been received
*
* Notify the delegate when a BDX Query message has been received for some node.
* The controller identifies the fabric the node is on, and the nodeID
* identifies the node within that fabric.
*/
- (void)handleBDXQuery:(NSNumber * _Nonnull)blockSize
blockIndex:(NSNumber * _Nonnull)blockIndex
bytesToSkip:(NSNumber * _Nonnull)bytesToSkip
completionHandler:(void (^)(NSData * _Nullable data, BOOL isEOF))completionHandler;
- (void)handleBDXQueryForNodeID:(NSNumber *)nodeID
controller:(MTRDeviceController *)controller
blockSize:(NSNumber *)blockSize
blockIndex:(NSNumber *)blockIndex
bytesToSkip:(NSNumber *)bytesToSkip
completionHandler:(void (^)(NSData * _Nullable data, BOOL isEOF))completionHandler;
@end

NS_ASSUME_NONNULL_END
Loading

0 comments on commit 4349096

Please sign in to comment.