| OLD | NEW |
| 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_cbcharacteristic_mac.h" | 10 #include "device/bluetooth/test/mock_bluetooth_cbcharacteristic_mac.h" |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 } | 116 } |
| 117 | 117 |
| 118 - (void)writeValue:(NSData*)data forDescriptor:(CBDescriptor*)descriptor { | 118 - (void)writeValue:(NSData*)data forDescriptor:(CBDescriptor*)descriptor { |
| 119 DCHECK(_bluetoothTestMac); | 119 DCHECK(_bluetoothTestMac); |
| 120 const uint8_t* buffer = static_cast<const uint8_t*>(data.bytes); | 120 const uint8_t* buffer = static_cast<const uint8_t*>(data.bytes); |
| 121 std::vector<uint8_t> value(buffer, buffer + data.length); | 121 std::vector<uint8_t> value(buffer, buffer + data.length); |
| 122 _bluetoothTestMac->OnFakeBluetoothDescriptorWriteValue(value); | 122 _bluetoothTestMac->OnFakeBluetoothDescriptorWriteValue(value); |
| 123 } | 123 } |
| 124 | 124 |
| 125 - (void)removeAllServices { | 125 - (void)removeAllServices { |
| 126 [_services.get() removeAllObjects]; | 126 [_services removeAllObjects]; |
| 127 } | 127 } |
| 128 | 128 |
| 129 - (void)addServices:(NSArray*)services { | 129 - (void)addServices:(NSArray*)services { |
| 130 if (!_services.get()) { | 130 if (!_services) { |
| 131 _services.reset([[NSMutableArray alloc] init]); | 131 _services.reset([[NSMutableArray alloc] init]); |
| 132 } | 132 } |
| 133 for (CBUUID* uuid in services) { | 133 for (CBUUID* uuid in services) { |
| 134 base::scoped_nsobject<MockCBService> service([[MockCBService alloc] | 134 base::scoped_nsobject<MockCBService> service([[MockCBService alloc] |
| 135 initWithPeripheral:self.peripheral | 135 initWithPeripheral:self.peripheral |
| 136 CBUUID:uuid | 136 CBUUID:uuid |
| 137 primary:YES]); | 137 primary:YES]); |
| 138 [_services.get() addObject:service.get().service]; | 138 [_services addObject:[service service]]; |
| 139 } | 139 } |
| 140 } | 140 } |
| 141 | 141 |
| 142 - (void)didDiscoverServicesWithError:(NSError*)error { | 142 - (void)didDiscoverServicesWithError:(NSError*)error { |
| 143 [_delegate peripheral:self.peripheral didDiscoverServices:error]; | 143 [_delegate peripheral:self.peripheral didDiscoverServices:error]; |
| 144 } | 144 } |
| 145 | 145 |
| 146 - (void)removeService:(CBService*)service { | 146 - (void)removeService:(CBService*)service { |
| 147 base::scoped_nsobject<CBService> serviceToRemove(service, | 147 base::scoped_nsobject<CBService> serviceToRemove(service, |
| 148 base::scoped_policy::RETAIN); | 148 base::scoped_policy::RETAIN); |
| 149 DCHECK(serviceToRemove); | 149 DCHECK(serviceToRemove); |
| 150 [_services.get() removeObject:serviceToRemove]; | 150 [_services removeObject:serviceToRemove]; |
| 151 [self didModifyServices:@[ serviceToRemove ]]; | 151 [self didModifyServices:@[ serviceToRemove ]]; |
| 152 } | 152 } |
| 153 | 153 |
| 154 - (void)mockDidDiscoverServices { | 154 - (void)mockDidDiscoverServices { |
| 155 [_delegate peripheral:self.peripheral didDiscoverServices:nil]; | 155 [_delegate peripheral:self.peripheral didDiscoverServices:nil]; |
| 156 } | 156 } |
| 157 | 157 |
| 158 - (void)mockDidDiscoverCharacteristicsForService:(CBService*)service { | 158 - (void)mockDidDiscoverCharacteristicsForService:(CBService*)service { |
| 159 [_delegate peripheral:self.peripheral | 159 [_delegate peripheral:self.peripheral |
| 160 didDiscoverCharacteristicsForService:service | 160 didDiscoverCharacteristicsForService:service |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 } | 193 } |
| 194 | 194 |
| 195 - (void)didDiscoverDescriptorsWithCharacteristic: | 195 - (void)didDiscoverDescriptorsWithCharacteristic: |
| 196 (MockCBCharacteristic*)characteristic_mock { | 196 (MockCBCharacteristic*)characteristic_mock { |
| 197 [_delegate peripheral:self.peripheral | 197 [_delegate peripheral:self.peripheral |
| 198 didDiscoverDescriptorsForCharacteristic:characteristic_mock.characteristic | 198 didDiscoverDescriptorsForCharacteristic:characteristic_mock.characteristic |
| 199 error:nil]; | 199 error:nil]; |
| 200 } | 200 } |
| 201 | 201 |
| 202 - (NSUUID*)identifier { | 202 - (NSUUID*)identifier { |
| 203 return _identifier.get(); | 203 return _identifier; |
| 204 } | 204 } |
| 205 | 205 |
| 206 - (NSString*)name { | 206 - (NSString*)name { |
| 207 return _name.get(); | 207 return _name; |
| 208 } | 208 } |
| 209 | 209 |
| 210 - (NSArray*)services { | 210 - (NSArray*)services { |
| 211 return _services.get(); | 211 return _services; |
| 212 } | 212 } |
| 213 | 213 |
| 214 - (CBPeripheral*)peripheral { | 214 - (CBPeripheral*)peripheral { |
| 215 return ObjCCast<CBPeripheral>(self); | 215 return ObjCCast<CBPeripheral>(self); |
| 216 } | 216 } |
| 217 | 217 |
| 218 - (void)setNotifyValue:(BOOL)notification | 218 - (void)setNotifyValue:(BOOL)notification |
| 219 forCharacteristic:(CBCharacteristic*)characteristic { | 219 forCharacteristic:(CBCharacteristic*)characteristic { |
| 220 _bluetoothTestMac->OnFakeBluetoothGattSetCharacteristicNotification( | 220 _bluetoothTestMac->OnFakeBluetoothGattSetCharacteristicNotification( |
| 221 notification == YES); | 221 notification == YES); |
| 222 } | 222 } |
| 223 | 223 |
| 224 @end | 224 @end |
| OLD | NEW |