Darwin: Namespace common class names (#33459)
* Darwin: Namespace `Download` and `Downloads`
* Restyled by clang-format
* namespace `UUIDHelper`
* fix `gn` build for `MTRUUIDHelper`
* Restyled by clang-format
---------
Co-authored-by: Restyled.io <commits@restyled.io>
diff --git a/src/controller/python/chip/ble/darwin/Scanning.mm b/src/controller/python/chip/ble/darwin/Scanning.mm
index 292978b..564a984 100644
--- a/src/controller/python/chip/ble/darwin/Scanning.mm
+++ b/src/controller/python/chip/ble/darwin/Scanning.mm
@@ -1,7 +1,7 @@
#include <ble/Ble.h>
#include <lib/support/CHIPMem.h>
#include <lib/support/logging/CHIPLogging.h>
-#include <platform/Darwin/UUIDHelper.h>
+#include <platform/Darwin/MTRUUIDHelper.h>
#import <CoreBluetooth/CoreBluetooth.h>
@@ -45,7 +45,7 @@
{
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/darwin/Framework/CHIP/MTRDiagnosticLogsDownloader.mm b/src/darwin/Framework/CHIP/MTRDiagnosticLogsDownloader.mm
index 8d28320..782ff30 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 @@
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)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
- fabricIndex:(NSNumber *)fabricIndex
- nodeID:(NSNumber *)nodeID;
+- (MTRDownload * _Nullable)get:(NSString *)fileDesignator
+ fabricIndex:(NSNumber *)fabricIndex
+ nodeID:(NSNumber *)nodeID;
-- (Download * _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;
+- (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;
@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 @@
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 @@
__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 @@
@end
-@implementation Downloads
+@implementation MTRDownloads
- (instancetype)init
{
if (self = [super init]) {
@@ -315,15 +315,15 @@
- (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 @@
return nil;
}
-- (Download * _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
+- (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
{
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 @@
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 @@
}
// 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 @@
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 @@
{
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.
diff --git a/src/platform/Darwin/BUILD.gn b/src/platform/Darwin/BUILD.gn
index 9dbb846..a416e99 100644
--- a/src/platform/Darwin/BUILD.gn
+++ b/src/platform/Darwin/BUILD.gn
@@ -130,8 +130,8 @@
"BleConnectionDelegateImpl.mm",
"BlePlatformDelegate.h",
"BlePlatformDelegateImpl.mm",
- "UUIDHelper.h",
- "UUIDHelperImpl.mm",
+ "MTRUUIDHelper.h",
+ "MTRUUIDHelperImpl.mm",
]
}
}
diff --git a/src/platform/Darwin/BleConnectionDelegateImpl.mm b/src/platform/Darwin/BleConnectionDelegateImpl.mm
index 5eb1c4a..b0c1e2e 100644
--- a/src/platform/Darwin/BleConnectionDelegateImpl.mm
+++ b/src/platform/Darwin/BleConnectionDelegateImpl.mm
@@ -34,8 +34,8 @@
#include <setup_payload/SetupPayload.h>
#include <tracing/metric_event.h>
+#import "MTRUUIDHelper.h"
#import "PlatformMetricKeys.h"
-#import "UUIDHelper.h"
using namespace chip::Ble;
using namespace chip::DeviceLayer;
@@ -245,7 +245,7 @@
{
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 210cd87..b0d247f 100644
--- a/src/platform/Darwin/BlePlatformDelegateImpl.mm
+++ b/src/platform/Darwin/BlePlatformDelegateImpl.mm
@@ -29,7 +29,7 @@
#include <lib/support/logging/CHIPLogging.h>
#include <platform/Darwin/BlePlatformDelegate.h>
-#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 bf12cf9..faa0af9 100644
--- a/src/platform/Darwin/UUIDHelper.h
+++ b/src/platform/Darwin/MTRUUIDHelper.h
@@ -21,6 +21,6 @@
#import <CoreBluetooth/CoreBluetooth.h>
-@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 3f5b3df..8f1b863 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
{