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

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

Issue 2071323002: bluetooth: mac: Initial BluetoothRemoteGattCharacteristicMac implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Skip reconnect-during-disconnected-event test Created 4 years, 6 months 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 #include "device/bluetooth/test/mock_bluetooth_cbperipheral_mac.h" 5 #include "device/bluetooth/test/mock_bluetooth_cbperipheral_mac.h"
6 6
7 #include "base/mac/foundation_util.h" 7 #include "base/mac/foundation_util.h"
8 #include "base/mac/scoped_nsobject.h" 8 #include "base/mac/scoped_nsobject.h"
9 #include "device/bluetooth/test/bluetooth_test_mac.h" 9 #include "device/bluetooth/test/bluetooth_test_mac.h"
10 #include "device/bluetooth/test/mock_bluetooth_cbservice_mac.h" 10 #include "device/bluetooth/test/mock_bluetooth_cbservice_mac.h"
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 _state = state; 77 _state = state;
78 if (_state == CBPeripheralStateDisconnected) { 78 if (_state == CBPeripheralStateDisconnected) {
79 _services.reset(); 79 _services.reset();
80 } 80 }
81 } 81 }
82 82
83 - (void)discoverServices:(NSArray*)serviceUUIDs { 83 - (void)discoverServices:(NSArray*)serviceUUIDs {
84 if (_bluetoothTestMac) { 84 if (_bluetoothTestMac) {
85 _bluetoothTestMac->OnFakeBluetoothServiceDiscovery(); 85 _bluetoothTestMac->OnFakeBluetoothServiceDiscovery();
86 } 86 }
87 [_delegate peripheral:self.peripheral didDiscoverServices:nil];
88 }
89
90 - (void)discoverCharacteristics:(NSArray*)characteristics
91 forService:(CBService*)service {
87 } 92 }
88 93
89 - (void)removeAllServices { 94 - (void)removeAllServices {
90 [_services.get() removeAllObjects]; 95 [_services.get() removeAllObjects];
91 } 96 }
92 97
93 - (void)addServices:(NSArray*)services { 98 - (void)addServices:(NSArray*)services {
94 if (!_services.get()) { 99 if (!_services.get()) {
95 _services.reset([[NSMutableArray alloc] init]); 100 _services.reset([[NSMutableArray alloc] init]);
96 } 101 }
97 for (CBUUID* uuid in services) { 102 for (CBUUID* uuid in services) {
98 base::scoped_nsobject<MockCBService> service( 103 base::scoped_nsobject<MockCBService> service([[MockCBService alloc]
99 [[MockCBService alloc] initWithCBUUID:uuid primary:YES]); 104 initWithPeripheral:self.peripheral
105 CBUUID:uuid
106 primary:YES]);
100 [_services.get() addObject:service.get().service]; 107 [_services.get() addObject:service.get().service];
101 } 108 }
102 } 109 }
103 110
104 - (void)didDiscoverServicesWithError:(NSError*)error { 111 - (void)didDiscoverServicesWithError:(NSError*)error {
105 [_delegate peripheral:self.peripheral didDiscoverServices:error]; 112 [_delegate peripheral:self.peripheral didDiscoverServices:error];
106 } 113 }
107 114
108 - (void)removeService:(CBService*)service { 115 - (void)removeService:(CBService*)service {
109 base::scoped_nsobject<CBService> serviceToRemove(service, 116 base::scoped_nsobject<CBService> serviceToRemove(service,
110 base::scoped_policy::RETAIN); 117 base::scoped_policy::RETAIN);
111 DCHECK(serviceToRemove); 118 DCHECK(serviceToRemove);
112 [_services.get() removeObject:serviceToRemove]; 119 [_services.get() removeObject:serviceToRemove];
120 [self didModifyServices:@[ serviceToRemove ]];
121 }
122
123 - (void)didDiscoverCharactericsForAllServices {
124 for (CBService* service in _services.get()) {
125 [_delegate peripheral:self.peripheral
126 didDiscoverCharacteristicsForService:service
127 error:nil];
128 }
129 }
130
131 - (void)didModifyServices:(NSArray*)invalidatedServices {
113 // -[CBPeripheralDelegate peripheral:didModifyServices:] is only available 132 // -[CBPeripheralDelegate peripheral:didModifyServices:] is only available
114 // with 10.9. It is safe to call this method (even if chrome is running on 133 // with 10.9. It is safe to call this method (even if chrome is running on
115 // 10.8) since WebBluetooth is enabled only with 10.10. 134 // 10.8) since WebBluetooth is enabled only with 10.10.
116 DCHECK( 135 DCHECK(
117 [_delegate respondsToSelector:@selector(peripheral:didModifyServices:)]); 136 [_delegate respondsToSelector:@selector(peripheral:didModifyServices:)]);
118 #pragma clang diagnostic push 137 #pragma clang diagnostic push
119 #pragma clang diagnostic ignored "-Wpartial-availability" 138 #pragma clang diagnostic ignored "-Wpartial-availability"
120 [_delegate peripheral:self.peripheral didModifyServices:@[ serviceToRemove ]]; 139 [_delegate peripheral:self.peripheral didModifyServices:invalidatedServices];
121 #pragma clang diagnostic pop 140 #pragma clang diagnostic pop
122 } 141 }
123 142
124 - (NSUUID*)identifier { 143 - (NSUUID*)identifier {
125 return _identifier.get(); 144 return _identifier.get();
126 } 145 }
127 146
128 - (NSString*)name { 147 - (NSString*)name {
129 return _name.get(); 148 return _name.get();
130 } 149 }
131 150
132 - (NSArray*)services { 151 - (NSArray*)services {
133 return _services.get(); 152 return _services.get();
134 } 153 }
135 154
136 - (CBPeripheral*)peripheral { 155 - (CBPeripheral*)peripheral {
137 return ObjCCast<CBPeripheral>(self); 156 return ObjCCast<CBPeripheral>(self);
138 } 157 }
139 158
140 @end 159 @end
OLDNEW
« no previous file with comments | « device/bluetooth/test/mock_bluetooth_cbperipheral_mac.h ('k') | device/bluetooth/test/mock_bluetooth_cbservice_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698