From 04d38a5a2c24ad39126e6fb99e9baaa9381972e0 Mon Sep 17 00:00:00 2001 From: Kiel Oleson Date: Tue, 14 May 2024 15:34:35 -0700 Subject: [PATCH 1/5] Darwin: Namespace `Download` and `Downloads` --- .../CHIP/MTRDiagnosticLogsDownloader.mm | 52 +++++++++---------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/src/darwin/Framework/CHIP/MTRDiagnosticLogsDownloader.mm b/src/darwin/Framework/CHIP/MTRDiagnosticLogsDownloader.mm index 8d2832052979e7..6f3b5fdb66be79 100644 --- a/src/darwin/Framework/CHIP/MTRDiagnosticLogsDownloader.mm +++ b/src/darwin/Framework/CHIP/MTRDiagnosticLogsDownloader.mm @@ -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; @@ -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; @@ -69,24 +69,24 @@ - (void)success; - (void)failure:(NSError * _Nullable)error; @end -@interface Downloads : NSObject -@property (nonatomic, strong) NSMutableArray * downloads; +@interface MTRDownloads : NSObject +@property (nonatomic, strong) NSMutableArray * 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. @@ -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) { @@ -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 @@ -303,7 +303,7 @@ - (NSString *)_toTypeString:(MTRDiagnosticLogType)type @end -@implementation Downloads +@implementation MTRDownloads - (instancetype)init { if (self = [super init]) { @@ -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; } @@ -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(); @@ -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); @@ -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]; @@ -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); @@ -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. From 8c520bc14378beca47f015a5eb079f3176c74228 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Tue, 14 May 2024 22:36:49 +0000 Subject: [PATCH 2/5] Restyled by clang-format --- .../CHIP/MTRDiagnosticLogsDownloader.mm | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/darwin/Framework/CHIP/MTRDiagnosticLogsDownloader.mm b/src/darwin/Framework/CHIP/MTRDiagnosticLogsDownloader.mm index 6f3b5fdb66be79..782ff30ba5763f 100644 --- a/src/darwin/Framework/CHIP/MTRDiagnosticLogsDownloader.mm +++ b/src/darwin/Framework/CHIP/MTRDiagnosticLogsDownloader.mm @@ -73,15 +73,15 @@ @interface MTRDownloads : NSObject @property (nonatomic, strong) NSMutableArray * downloads; - (MTRDownload * _Nullable)get:(NSString *)fileDesignator - fabricIndex:(NSNumber *)fabricIndex - nodeID:(NSNumber *)nodeID; + fabricIndex:(NSNumber *)fabricIndex + nodeID:(NSNumber *)nodeID; - (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 (^)(MTRDownload * finishedDownload))done; + fabricIndex:(NSNumber *)fabricIndex + nodeID:(NSNumber *)nodeID + queue:(dispatch_queue_t)queue + completion:(void (^)(NSURL * _Nullable url, NSError * _Nullable error))completion + done:(void (^)(MTRDownload * finishedDownload))done; @end @interface MTRDiagnosticLogsDownloader () @@ -333,11 +333,11 @@ - (MTRDownload * _Nullable)get:(NSString *)fileDesignator fabricIndex:(NSNumber } - (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 (^)(MTRDownload * finishedDownload))done + fabricIndex:(NSNumber *)fabricIndex + nodeID:(NSNumber *)nodeID + queue:(dispatch_queue_t)queue + completion:(void (^)(NSURL * _Nullable url, NSError * _Nullable error))completion + done:(void (^)(MTRDownload * finishedDownload))done { assertChipStackLockedByCurrentThread(); From 319ec8f6acd54a4a4be5ff8b68f12634866f7b06 Mon Sep 17 00:00:00 2001 From: Kiel Oleson Date: Tue, 14 May 2024 18:23:24 -0700 Subject: [PATCH 3/5] namespace `UUIDHelper` --- src/controller/python/chip/ble/darwin/Scanning.mm | 4 ++-- src/platform/Darwin/BleConnectionDelegateImpl.mm | 4 ++-- src/platform/Darwin/BlePlatformDelegateImpl.mm | 8 ++++---- src/platform/Darwin/{UUIDHelper.h => MTRUUIDHelper.h} | 2 +- .../Darwin/{UUIDHelperImpl.mm => MTRUUIDHelperImpl.mm} | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) rename src/platform/Darwin/{UUIDHelper.h => MTRUUIDHelper.h} (95%) rename src/platform/Darwin/{UUIDHelperImpl.mm => MTRUUIDHelperImpl.mm} (97%) diff --git a/src/controller/python/chip/ble/darwin/Scanning.mm b/src/controller/python/chip/ble/darwin/Scanning.mm index 292978b424a787..564a984e094369 100644 --- a/src/controller/python/chip/ble/darwin/Scanning.mm +++ b/src/controller/python/chip/ble/darwin/Scanning.mm @@ -1,7 +1,7 @@ #include #include #include -#include +#include #import @@ -45,7 +45,7 @@ - (id)initWithContext:(PyObject *)context { self = [super init]; if (self) { - self.shortServiceUUID = [UUIDHelper GetShortestServiceUUID:&chip::Ble::CHIP_BLE_SVC_ID]; + self.shortServiceUUID = [MTRUUIDHelper GetShortestServiceUUID:&chip::Ble::CHIP_BLE_SVC_ID]; _workQueue = dispatch_queue_create("com.chip.python.ble.work_queue", DISPATCH_QUEUE_SERIAL); _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, _workQueue); diff --git a/src/platform/Darwin/BleConnectionDelegateImpl.mm b/src/platform/Darwin/BleConnectionDelegateImpl.mm index 5eb1c4a74aa082..0be0ecaae40bbe 100644 --- a/src/platform/Darwin/BleConnectionDelegateImpl.mm +++ b/src/platform/Darwin/BleConnectionDelegateImpl.mm @@ -35,7 +35,7 @@ #include #import "PlatformMetricKeys.h" -#import "UUIDHelper.h" +#import "MTRUUIDHelper.h" using namespace chip::Ble; using namespace chip::DeviceLayer; @@ -245,7 +245,7 @@ - (id)initWithQueue:(dispatch_queue_t)queue { self = [super init]; if (self) { - self.shortServiceUUID = [UUIDHelper GetShortestServiceUUID:&chip::Ble::CHIP_BLE_SVC_ID]; + self.shortServiceUUID = [MTRUUIDHelper GetShortestServiceUUID:&chip::Ble::CHIP_BLE_SVC_ID]; _chipWorkQueue = chip::DeviceLayer::PlatformMgrImpl().GetWorkQueue(); _workQueue = queue; _centralManager = [CBCentralManager alloc]; diff --git a/src/platform/Darwin/BlePlatformDelegateImpl.mm b/src/platform/Darwin/BlePlatformDelegateImpl.mm index 210cd872318056..b0d247f058ed7d 100644 --- a/src/platform/Darwin/BlePlatformDelegateImpl.mm +++ b/src/platform/Darwin/BlePlatformDelegateImpl.mm @@ -29,7 +29,7 @@ #include #include -#import "UUIDHelper.h" +#import "MTRUUIDHelper.h" using namespace ::chip; using namespace ::chip::Ble; @@ -47,7 +47,7 @@ return found; } - CBUUID * serviceId = [UUIDHelper GetShortestServiceUUID:svcId]; + CBUUID * serviceId = [MTRUUIDHelper GetShortestServiceUUID:svcId]; CBUUID * characteristicId = [CBUUID UUIDWithData:[NSData dataWithBytes:charId->bytes length:sizeof(charId->bytes)]]; CBPeripheral * peripheral = (__bridge CBPeripheral *) connObj; @@ -74,7 +74,7 @@ return found; } - CBUUID * serviceId = [UUIDHelper GetShortestServiceUUID:svcId]; + CBUUID * serviceId = [MTRUUIDHelper GetShortestServiceUUID:svcId]; CBUUID * characteristicId = characteristicId = [CBUUID UUIDWithData:[NSData dataWithBytes:charId->bytes length:sizeof(charId->bytes)]]; CBPeripheral * peripheral = (__bridge CBPeripheral *) connObj; @@ -131,7 +131,7 @@ return found; } - CBUUID * serviceId = [UUIDHelper GetShortestServiceUUID:svcId]; + CBUUID * serviceId = [MTRUUIDHelper GetShortestServiceUUID:svcId]; CBUUID * characteristicId = [CBUUID UUIDWithData:[NSData dataWithBytes:charId->bytes length:sizeof(charId->bytes)]]; NSData * data = [NSData dataWithBytes:pBuf->Start() length:pBuf->DataLength()]; CBPeripheral * peripheral = (__bridge CBPeripheral *) connObj; diff --git a/src/platform/Darwin/UUIDHelper.h b/src/platform/Darwin/MTRUUIDHelper.h similarity index 95% rename from src/platform/Darwin/UUIDHelper.h rename to src/platform/Darwin/MTRUUIDHelper.h index bf12cf9a92375e..faa0af95809f88 100644 --- a/src/platform/Darwin/UUIDHelper.h +++ b/src/platform/Darwin/MTRUUIDHelper.h @@ -21,6 +21,6 @@ #import -@interface UUIDHelper : NSObject +@interface MTRUUIDHelper : NSObject + (CBUUID *)GetShortestServiceUUID:(const chip::Ble::ChipBleUUID *)svcId; @end diff --git a/src/platform/Darwin/UUIDHelperImpl.mm b/src/platform/Darwin/MTRUUIDHelperImpl.mm similarity index 97% rename from src/platform/Darwin/UUIDHelperImpl.mm rename to src/platform/Darwin/MTRUUIDHelperImpl.mm index 3f5b3df0d7641b..8f1b863a760cf8 100644 --- a/src/platform/Darwin/UUIDHelperImpl.mm +++ b/src/platform/Darwin/MTRUUIDHelperImpl.mm @@ -20,9 +20,9 @@ #error This file must be compiled with ARC. Use -fobjc-arc flag (or convert project to ARC). #endif -#import "UUIDHelper.h" +#import "MTRUUIDHelper.h" -@implementation UUIDHelper +@implementation MTRUUIDHelper + (CBUUID *)GetShortestServiceUUID:(const chip::Ble::ChipBleUUID *)svcId { From 566f0f8ed12a72c2e8d8524dc5257b1604732c30 Mon Sep 17 00:00:00 2001 From: Kiel Oleson Date: Tue, 14 May 2024 18:30:41 -0700 Subject: [PATCH 4/5] fix `gn` build for `MTRUUIDHelper` --- src/platform/Darwin/BUILD.gn | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/platform/Darwin/BUILD.gn b/src/platform/Darwin/BUILD.gn index 9dbb8460ae0566..a416e99e5b24d4 100644 --- a/src/platform/Darwin/BUILD.gn +++ b/src/platform/Darwin/BUILD.gn @@ -130,8 +130,8 @@ static_library("Darwin") { "BleConnectionDelegateImpl.mm", "BlePlatformDelegate.h", "BlePlatformDelegateImpl.mm", - "UUIDHelper.h", - "UUIDHelperImpl.mm", + "MTRUUIDHelper.h", + "MTRUUIDHelperImpl.mm", ] } } From 832a251effb89dd4cb17cc108dc456e527a03231 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 15 May 2024 01:31:05 +0000 Subject: [PATCH 5/5] Restyled by clang-format --- src/platform/Darwin/BleConnectionDelegateImpl.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platform/Darwin/BleConnectionDelegateImpl.mm b/src/platform/Darwin/BleConnectionDelegateImpl.mm index 0be0ecaae40bbe..b0c1e2ef70a4bb 100644 --- a/src/platform/Darwin/BleConnectionDelegateImpl.mm +++ b/src/platform/Darwin/BleConnectionDelegateImpl.mm @@ -34,8 +34,8 @@ #include #include -#import "PlatformMetricKeys.h" #import "MTRUUIDHelper.h" +#import "PlatformMetricKeys.h" using namespace chip::Ble; using namespace chip::DeviceLayer;