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

Darwin: Keep MTRCommissionableBrowser around until OnBleScanStopped #33674

Merged
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
21 changes: 18 additions & 3 deletions src/darwin/Framework/CHIP/MTRCommissionableBrowser.mm
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ @implementation MTRCommissionableBrowserResult
#endif // CONFIG_NETWORK_LAYER_BLE
{
public:
#if CONFIG_NETWORK_LAYER_BLE
id mBleScannerDelegateOwner;
#endif // CONFIG_NETWORK_LAYER_BLE

CHIP_ERROR Start(id<MTRCommissionableBrowserDelegate> delegate, MTRDeviceController * controller, dispatch_queue_t queue)
{
assertChipStackLockedByCurrentThread();
Expand Down Expand Up @@ -90,7 +94,7 @@ CHIP_ERROR Start(id<MTRCommissionableBrowserDelegate> delegate, MTRDeviceControl
chip::Inet::InterfaceId::Null(), this);
}

CHIP_ERROR Stop()
CHIP_ERROR Stop(id owner)
{
assertChipStackLockedByCurrentThread();

Expand All @@ -109,7 +113,10 @@ CHIP_ERROR Stop()
mDiscoveredResults = nil;

#if CONFIG_NETWORK_LAYER_BLE
ReturnErrorOnFailure(PlatformMgrImpl().StopBleScan());
mBleScannerDelegateOwner = owner; // retain the owner until OnBleScanStopped is called
PlatformMgrImpl().StopBleScan(); // doesn't actually fail, and if it did we'd want to carry on regardless
#else
(void) owner;
#endif // CONFIG_NETWORK_LAYER_BLE

return ChipDnssdStopBrowse(this);
Expand Down Expand Up @@ -281,6 +288,7 @@ void OnBrowseStop(CHIP_ERROR error) override
void OnBleScanAdd(BLE_CONNECTION_OBJECT connObj, const ChipBLEDeviceIdentificationInfo & info) override
{
assertChipStackLockedByCurrentThread();
VerifyOrReturn(mDelegate != nil);

auto result = [[MTRCommissionableBrowserResult alloc] init];
result.instanceName = [NSString stringWithUTF8String:kBleKey];
Expand All @@ -303,6 +311,7 @@ void OnBleScanAdd(BLE_CONNECTION_OBJECT connObj, const ChipBLEDeviceIdentificati
void OnBleScanRemove(BLE_CONNECTION_OBJECT connObj) override
{
assertChipStackLockedByCurrentThread();
VerifyOrReturn(mDelegate != nil);

auto key = [NSString stringWithFormat:@"%@", connObj];
if ([mDiscoveredResults objectForKey:key] == nil) {
Expand All @@ -319,6 +328,12 @@ void OnBleScanRemove(BLE_CONNECTION_OBJECT connObj) override
[mDelegate controller:mController didFindCommissionableDevice:result];
});
}

void OnBleScanStopped() override
{
mBleScannerDelegateOwner = nil;
}

#endif // CONFIG_NETWORK_LAYER_BLE

private:
Expand Down Expand Up @@ -360,7 +375,7 @@ - (BOOL)start

- (BOOL)stop
{
VerifyOrReturnValue(CHIP_NO_ERROR == _browser.Stop(), NO);
VerifyOrReturnValue(CHIP_NO_ERROR == _browser.Stop(self), NO);
_delegate = nil;
_controller = nil;
_queue = nil;
Expand Down
Loading