Skip to content

Commit

Permalink
Enable arc for chip-device-ctrl (#6992)
Browse files Browse the repository at this point in the history
  • Loading branch information
vivien-apple authored and pull[bot] committed Jul 26, 2021
1 parent 6514925 commit 3557240
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/controller/python/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ shared_library("ChipDeviceCtrl") {
"chip/ble/darwin/AdapterListing.mm",
"chip/ble/darwin/Scanning.mm",
]
cflags = [ "-fobjc-arc" ]
} else {
assert(false, "No BLE implementation available for the current OS.")
}
Expand Down
11 changes: 7 additions & 4 deletions src/controller/python/chip/ble/darwin/AdapterListing.mm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ @interface FakeBleAdapterInformation : NSObject <CBCentralManagerDelegate>
@property (strong, nonatomic) CBCentralManager * centralManager;
@property (nonatomic) bool advanced;
@property (nonatomic) bool hasStatus;
@property (assign, nonatomic) dispatch_semaphore_t statusSemaphore;
@property (strong, nonatomic) dispatch_semaphore_t statusSemaphore;

- (id)init;
- (bool)isPoweredOn;
Expand Down Expand Up @@ -84,9 +84,12 @@ - (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPerip

@end

extern "C" void * pychip_ble_adapter_list_new() { return static_cast<void *>([[FakeBleAdapterInformation alloc] init]); }
extern "C" void * pychip_ble_adapter_list_new() { return (__bridge_retained void *) [[FakeBleAdapterInformation alloc] init]; }

extern "C" void pychip_ble_adapter_list_delete(FakeBleAdapterInformation * adapterIterator) { [adapterIterator release]; }
extern "C" void pychip_ble_adapter_list_delete(FakeBleAdapterInformation * adapterIterator)
{
CFRelease((CFTypeRef) adapterIterator);
}

extern "C" bool pychip_ble_adapter_list_next(FakeBleAdapterInformation * adapterIterator)
{
Expand Down Expand Up @@ -115,5 +118,5 @@ - (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPerip

extern "C" void * pychip_ble_adapter_list_get_raw_adapter(FakeBleAdapterInformation * adapterIterator)
{
return static_cast<void *>(adapterIterator);
return (__bridge void *) adapterIterator;
}
2 changes: 1 addition & 1 deletion src/controller/python/chip/ble/darwin/Scanning.mm
Original file line number Diff line number Diff line change
Expand Up @@ -135,5 +135,5 @@ - (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPerip
completeCallback:completeCallback
timeoutMs:timeout];

return static_cast<void *>(scanner);
return (__bridge_retained void *) (scanner);
}
2 changes: 2 additions & 0 deletions src/platform/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,8 @@ if (chip_device_platform != "none" && chip_device_platform != "external") {
]
}
} else if (chip_device_platform == "darwin") {
cflags += [ "-fobjc-arc" ]

sources += [
"Darwin/BLEManagerImpl.cpp",
"Darwin/BLEManagerImpl.h",
Expand Down
4 changes: 4 additions & 0 deletions src/platform/Darwin/BleApplicationDelegateImpl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
* Provides an implementation of BleApplicationDelegate for Darwin platforms.
*/

#if !__has_feature(objc_arc)
#error This file must be compiled with ARC. Use -fobjc-arc flag (or convert project to ARC).
#endif

#include <ble/BleConfig.h>
#include <platform/Darwin/BleApplicationDelegate.h>

Expand Down
7 changes: 5 additions & 2 deletions src/platform/Darwin/BleConnectionDelegateImpl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
* Provides an implementation of BleConnectionDelegate for Darwin platforms.
*/

#if !__has_feature(objc_arc)
#error This file must be compiled with ARC. Use -fobjc-arc flag (or convert project to ARC).
#endif

#include <ble/BleConfig.h>
#include <ble/BleError.h>
#include <ble/BleLayer.h>
Expand Down Expand Up @@ -70,7 +74,7 @@ - (void)stop;
ble.appState = appState;
ble.onConnectionComplete = OnConnectionComplete;
ble.onConnectionError = OnConnectionError;
[ble.centralManager initWithDelegate:ble queue:ble.workQueue];
ble.centralManager = [ble.centralManager initWithDelegate:ble queue:ble.workQueue];
}

BLE_ERROR BleConnectionDelegateImpl::CancelConnection()
Expand Down Expand Up @@ -356,7 +360,6 @@ - (void)connect:(CBPeripheral *)peripheral
}

_peripheral = peripheral;
[_peripheral retain];
[_centralManager connectPeripheral:peripheral options:nil];
}

Expand Down
13 changes: 9 additions & 4 deletions src/platform/Darwin/BlePlatformDelegateImpl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
* Provides an implementation of BlePlatformDelegate for Darwin platforms.
*/

#if !__has_feature(objc_arc)
#error This file must be compiled with ARC. Use -fobjc-arc flag (or convert project to ARC).
#endif

#include <ble/BleConfig.h>
#include <ble/BleError.h>
#include <ble/BleLayer.h>
Expand All @@ -43,7 +47,7 @@
bool found = false;
CBUUID * serviceId = nil;
CBUUID * characteristicId = nil;
CBPeripheral * peripheral = (CBPeripheral *) connObj;
CBPeripheral * peripheral = (__bridge CBPeripheral *) connObj;

if (NULL != svcId) {
serviceId = [UUIDHelper GetShortestServiceUUID:svcId];
Expand Down Expand Up @@ -74,7 +78,7 @@
bool found = false;
CBUUID * serviceId = nil;
CBUUID * characteristicId = nil;
CBPeripheral * peripheral = (CBPeripheral *) connObj;
CBPeripheral * peripheral = (__bridge CBPeripheral *) connObj;

if (NULL != svcId) {
serviceId = [UUIDHelper GetShortestServiceUUID:svcId];
Expand All @@ -100,7 +104,8 @@

bool BlePlatformDelegateImpl::CloseConnection(BLE_CONNECTION_OBJECT connObj)
{
CBPeripheral * peripheral = (CBPeripheral *) connObj;
CBPeripheral * peripheral = (__bridge CBPeripheral *) connObj;

// CoreBluetooth API requires a CBCentralManager to close a connection which is a property of the peripheral.
CBCentralManager * manager = (CBCentralManager *) [peripheral valueForKey:@"manager"];
if (manager != nil)
Expand All @@ -124,7 +129,7 @@
CBUUID * serviceId = nil;
CBUUID * characteristicId = nil;
NSData * data = nil;
CBPeripheral * peripheral = (CBPeripheral *) connObj;
CBPeripheral * peripheral = (__bridge CBPeripheral *) connObj;

if (NULL != svcId) {
serviceId = [UUIDHelper GetShortestServiceUUID:svcId];
Expand Down
4 changes: 4 additions & 0 deletions src/platform/Darwin/KeyValueStoreManagerImpl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
* Platform-specific key value storage implementation for Darwin
*/

#if !__has_feature(objc_arc)
#error This file must be compiled with ARC. Use -fobjc-arc flag (or convert project to ARC).
#endif

#include <platform/KeyValueStoreManager.h>

#include <algorithm>
Expand Down
4 changes: 4 additions & 0 deletions src/platform/Darwin/UUIDHelperImpl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
* limitations under the License.
*/

#if !__has_feature(objc_arc)
#error This file must be compiled with ARC. Use -fobjc-arc flag (or convert project to ARC).
#endif

#import "UUIDHelper.h"

@implementation UUIDHelper
Expand Down

0 comments on commit 3557240

Please sign in to comment.