Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable arc for chip-device-ctrl #6992

Merged
merged 1 commit into from
Jun 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -335,6 +335,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