Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(32)

Side by Side Diff: device/bluetooth/test/mock_bluetooth_central_manager_mac.mm

Issue 2339253002: bluetooth: mac: add connected LE devices to chooser (Closed)
Patch Set: Implementing RetrieveGattConnectedDevicesWithDiscoveryFilter() with tests Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "device/bluetooth/test/mock_bluetooth_central_manager_mac.h" 5 #import "device/bluetooth/test/mock_bluetooth_central_manager_mac.h"
6 6
7 #import "base/mac/scoped_nsobject.h"
7 #import "device/bluetooth/test/bluetooth_test_mac.h" 8 #import "device/bluetooth/test/bluetooth_test_mac.h"
8 #import "device/bluetooth/test/mock_bluetooth_cbperipheral_mac.h" 9 #import "device/bluetooth/test/mock_bluetooth_cbperipheral_mac.h"
9 10
10 @implementation MockCentralManager 11 using base::scoped_nsobject;
12
13 @implementation MockCentralManager {
14 scoped_nsobject<NSMutableDictionary> _connectedMockPeripheralPerServiceUUID;
15 }
11 16
12 @synthesize scanForPeripheralsCallCount = _scanForPeripheralsCallCount; 17 @synthesize scanForPeripheralsCallCount = _scanForPeripheralsCallCount;
13 @synthesize stopScanCallCount = _stopScanCallCount; 18 @synthesize stopScanCallCount = _stopScanCallCount;
14 @synthesize delegate = _delegate; 19 @synthesize delegate = _delegate;
15 @synthesize state = _state; 20 @synthesize state = _state;
16 @synthesize bluetoothTestMac = _bluetoothTestMac; 21 @synthesize bluetoothTestMac = _bluetoothTestMac;
17 22
23 - (instancetype)init {
24 self = [super init];
25 if (self) {
26 _connectedMockPeripheralPerServiceUUID.reset(
27 [[NSMutableDictionary alloc] init]);
28 }
29 return self;
30 }
31
18 - (BOOL)isKindOfClass:(Class)aClass { 32 - (BOOL)isKindOfClass:(Class)aClass {
19 if (aClass == [CBCentralManager class] || 33 if (aClass == [CBCentralManager class] ||
20 [aClass isSubclassOfClass:[CBCentralManager class]]) { 34 [aClass isSubclassOfClass:[CBCentralManager class]]) {
21 return YES; 35 return YES;
22 } 36 }
23 return [super isKindOfClass:aClass]; 37 return [super isKindOfClass:aClass];
24 } 38 }
25 39
26 - (BOOL)isMemberOfClass:(Class)aClass { 40 - (BOOL)isMemberOfClass:(Class)aClass {
27 if (aClass == [CBCentralManager class] || 41 if (aClass == [CBCentralManager class] ||
(...skipping 18 matching lines...) Expand all
46 _bluetoothTestMac->OnFakeBluetoothDeviceConnectGattCalled(); 60 _bluetoothTestMac->OnFakeBluetoothDeviceConnectGattCalled();
47 } 61 }
48 } 62 }
49 63
50 - (void)cancelPeripheralConnection:(CBPeripheral*)peripheral { 64 - (void)cancelPeripheralConnection:(CBPeripheral*)peripheral {
51 if (_bluetoothTestMac) { 65 if (_bluetoothTestMac) {
52 _bluetoothTestMac->OnFakeBluetoothGattDisconnect(); 66 _bluetoothTestMac->OnFakeBluetoothGattDisconnect();
53 } 67 }
54 } 68 }
55 69
70 - (NSArray*)retrieveConnectedPeripheralsWithServices:(NSArray*)services {
ortuno 2016/10/31 04:30:51 Save the services used in this function. That way
jlebel 2016/11/07 01:43:18 Done.
71 NSMutableArray* connectedPeripherals = [[NSMutableArray alloc] init];
72 for (CBUUID* uuid in services) {
73 NSSet* peripheralSet =
74 [_connectedMockPeripheralPerServiceUUID.get() objectForKey:uuid];
75 [connectedPeripherals addObjectsFromArray:peripheralSet.allObjects];
76 }
77 return connectedPeripherals;
78 }
79
80 - (void)setConnectedMockPeripheral:(CBPeripheral*)peripheral
81 withServiceUUIDs:(NSSet*)serviceUUIDs {
82 for (CBUUID* uuid in serviceUUIDs) {
83 NSMutableSet* peripheralSet =
84 [_connectedMockPeripheralPerServiceUUID.get() objectForKey:uuid];
85 if (!peripheralSet) {
86 peripheralSet = [NSMutableSet set];
87 [_connectedMockPeripheralPerServiceUUID.get() setObject:peripheralSet
88 forKey:uuid];
89 }
90 [peripheralSet addObject:peripheral];
91 }
92 }
93
56 @end 94 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698