Skip to content

Commit

Permalink
Darwin: Namespace Download and Downloads
Browse files Browse the repository at this point in the history
  • Loading branch information
kiel-apple committed May 14, 2024
1 parent c7f7984 commit 04d38a5
Showing 1 changed file with 26 additions and 26 deletions.
52 changes: 26 additions & 26 deletions src/darwin/Framework/CHIP/MTRDiagnosticLogsDownloader.mm
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

NS_ASSUME_NONNULL_BEGIN

@interface Download : NSObject
@interface MTRDownload : NSObject
@property (nonatomic) NSString * fileDesignator;
@property (nonatomic) NSNumber * fabricIndex;
@property (nonatomic) NSNumber * nodeID;
Expand All @@ -55,7 +55,7 @@ - (instancetype)initWithType:(MTRDiagnosticLogType)type
nodeID:(NSNumber *)nodeID
queue:(dispatch_queue_t)queue
completion:(void (^)(NSURL * _Nullable url, NSError * _Nullable error))completion
done:(void (^)(Download * finishedDownload))done;
done:(void (^)(MTRDownload * finishedDownload))done;

- (void)writeToFile:(NSData *)data error:(out NSError **)error;

Expand All @@ -69,24 +69,24 @@ - (void)success;
- (void)failure:(NSError * _Nullable)error;
@end

@interface Downloads : NSObject
@property (nonatomic, strong) NSMutableArray<Download *> * downloads;
@interface MTRDownloads : NSObject
@property (nonatomic, strong) NSMutableArray<MTRDownload *> * downloads;

- (Download * _Nullable)get:(NSString *)fileDesignator
- (MTRDownload * _Nullable)get:(NSString *)fileDesignator
fabricIndex:(NSNumber *)fabricIndex
nodeID:(NSNumber *)nodeID;

- (Download * _Nullable)add:(MTRDiagnosticLogType)type
- (MTRDownload * _Nullable)add:(MTRDiagnosticLogType)type
fabricIndex:(NSNumber *)fabricIndex
nodeID:(NSNumber *)nodeID
queue:(dispatch_queue_t)queue
completion:(void (^)(NSURL * _Nullable url, NSError * _Nullable error))completion
done:(void (^)(Download * finishedDownload))done;
done:(void (^)(MTRDownload * finishedDownload))done;
@end

@interface MTRDiagnosticLogsDownloader ()
@property (readonly) DiagnosticLogsDownloaderBridge * bridge;
@property (nonatomic, strong) Downloads * downloads;
@property (nonatomic, strong) MTRDownloads * downloads;

/**
* Notify the delegate when a BDX Session starts for some logs.
Expand Down Expand Up @@ -134,21 +134,21 @@ - (void)handleBDXTransferSessionEndForFileDesignator:(NSString *)fileDesignator
CHIP_ERROR OnTransferEnd(chip::bdx::BDXTransferProxy * transfer, CHIP_ERROR error) override;
CHIP_ERROR OnTransferData(chip::bdx::BDXTransferProxy * transfer, const chip::ByteSpan & data) override;

CHIP_ERROR StartBDXTransferTimeout(Download * download, uint16_t timeoutInSeconds);
void CancelBDXTransferTimeout(Download * download);
CHIP_ERROR StartBDXTransferTimeout(MTRDownload * download, uint16_t timeoutInSeconds);
void CancelBDXTransferTimeout(MTRDownload * download);

private:
static void OnTransferTimeout(chip::System::Layer * layer, void * context);
MTRDiagnosticLogsDownloader * __weak mDelegate;
};

@implementation Download
@implementation MTRDownload
- (instancetype)initWithType:(MTRDiagnosticLogType)type
fabricIndex:(NSNumber *)fabricIndex
nodeID:(NSNumber *)nodeID
queue:(dispatch_queue_t)queue
completion:(void (^)(NSURL * _Nullable url, NSError * _Nullable error))completion
done:(void (^)(Download * finishedDownload))done;
done:(void (^)(MTRDownload * finishedDownload))done;
{
self = [super init];
if (self) {
Expand All @@ -158,7 +158,7 @@ - (instancetype)initWithType:(MTRDiagnosticLogType)type
__weak typeof(self) weakSelf = self;
auto bdxTransferDone = ^(NSError * bdxError) {
dispatch_async(queue, ^{
Download * strongSelf = weakSelf;
MTRDownload * strongSelf = weakSelf;
if (strongSelf) {
// If a fileHandle exists, it means that the BDX session has been initiated and a file has
// been created to host the data of the session. So even if there is an error there may be some
Expand Down Expand Up @@ -303,7 +303,7 @@ - (NSString *)_toTypeString:(MTRDiagnosticLogType)type

@end

@implementation Downloads
@implementation MTRDownloads
- (instancetype)init
{
if (self = [super init]) {
Expand All @@ -315,15 +315,15 @@ - (instancetype)init
- (void)dealloc
{
auto error = [MTRError errorForCHIPErrorCode:CHIP_ERROR_INTERNAL];
for (Download * download in _downloads) {
for (MTRDownload * download in _downloads) {
[download failure:error];
}
_downloads = nil;
}

- (Download * _Nullable)get:(NSString *)fileDesignator fabricIndex:(NSNumber *)fabricIndex nodeID:(NSNumber *)nodeID
- (MTRDownload * _Nullable)get:(NSString *)fileDesignator fabricIndex:(NSNumber *)fabricIndex nodeID:(NSNumber *)nodeID
{
for (Download * download in _downloads) {
for (MTRDownload * download in _downloads) {
if ([download matches:fileDesignator fabricIndex:fabricIndex nodeID:nodeID]) {
return download;
}
Expand All @@ -332,23 +332,23 @@ - (Download * _Nullable)get:(NSString *)fileDesignator fabricIndex:(NSNumber *)f
return nil;
}

- (Download * _Nullable)add:(MTRDiagnosticLogType)type
- (MTRDownload * _Nullable)add:(MTRDiagnosticLogType)type
fabricIndex:(NSNumber *)fabricIndex
nodeID:(NSNumber *)nodeID
queue:(dispatch_queue_t)queue
completion:(void (^)(NSURL * _Nullable url, NSError * _Nullable error))completion
done:(void (^)(Download * finishedDownload))done
done:(void (^)(MTRDownload * finishedDownload))done
{
assertChipStackLockedByCurrentThread();

auto download = [[Download alloc] initWithType:type fabricIndex:fabricIndex nodeID:nodeID queue:queue completion:completion done:done];
auto download = [[MTRDownload alloc] initWithType:type fabricIndex:fabricIndex nodeID:nodeID queue:queue completion:completion done:done];
VerifyOrReturnValue(nil != download, nil);

[_downloads addObject:download];
return download;
}

- (void)remove:(Download *)download
- (void)remove:(MTRDownload *)download
{
assertChipStackLockedByCurrentThread();

Expand All @@ -362,7 +362,7 @@ - (instancetype)init
assertChipStackLockedByCurrentThread();

if (self = [super init]) {
_downloads = [[Downloads alloc] init];
_downloads = [[MTRDownloads alloc] init];
_bridge = new DiagnosticLogsDownloaderBridge(self);
if (_bridge == nullptr) {
MTR_LOG_ERROR("Error: %@", kErrorInitDiagnosticLogsDownloader);
Expand Down Expand Up @@ -406,7 +406,7 @@ - (void)downloadLogFromNodeWithID:(NSNumber *)nodeID
}

// This block is always called when a download is finished.
auto done = ^(Download * finishedDownload) {
auto done = ^(MTRDownload * finishedDownload) {
[controller asyncDispatchToMatterQueue:^() {
[self->_downloads remove:finishedDownload];

Expand Down Expand Up @@ -593,13 +593,13 @@ - (void)handleBDXTransferSessionEndForFileDesignator:(NSString *)fileDesignator
return CHIP_NO_ERROR;
}

CHIP_ERROR DiagnosticLogsDownloaderBridge::StartBDXTransferTimeout(Download * download, uint16_t timeoutInSeconds)
CHIP_ERROR DiagnosticLogsDownloaderBridge::StartBDXTransferTimeout(MTRDownload * download, uint16_t timeoutInSeconds)
{
assertChipStackLockedByCurrentThread();
return chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds16(timeoutInSeconds), OnTransferTimeout, (__bridge void *) download);
}

void DiagnosticLogsDownloaderBridge::CancelBDXTransferTimeout(Download * download)
void DiagnosticLogsDownloaderBridge::CancelBDXTransferTimeout(MTRDownload * download)
{
assertChipStackLockedByCurrentThread();
chip::DeviceLayer::SystemLayer().CancelTimer(OnTransferTimeout, (__bridge void *) download);
Expand All @@ -609,7 +609,7 @@ - (void)handleBDXTransferSessionEndForFileDesignator:(NSString *)fileDesignator
{
assertChipStackLockedByCurrentThread();

auto * download = (__bridge Download *) context;
auto * download = (__bridge MTRDownload *) context;
VerifyOrReturn(nil != download);

// If there is no abortHandler, it means that the BDX transfer has not started.
Expand Down

0 comments on commit 04d38a5

Please sign in to comment.