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

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

Issue 1950033002: bluetooth: mac: Initial BluetoothRemoteGattCharacteristicMac implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@servicescan_cleanup
Patch Set: Updating the characteristic property conversion 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 = nil; 79 _services = nil;
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(
99 [[MockCBService alloc] initWithCBUUID:uuid primary:YES]); 104 [[MockCBService alloc] initWithCBUUID:uuid primary:YES]);
100 [_services.get() addObject:service.get().service]; 105 [_services.get() addObject:service.get().service];
101 } 106 }
102 } 107 }
103 108
104 - (void)didDiscoverServicesWithError:(NSError*)error { 109 - (void)didDiscoverServicesWithError:(NSError*)error {
105 [_delegate peripheral:self.peripheral didDiscoverServices:error]; 110 [_delegate peripheral:self.peripheral didDiscoverServices:error];
106 } 111 }
107 112
108 - (void)removeService:(CBService*)service { 113 - (void)removeService:(CBService*)service {
109 base::scoped_nsobject<CBService> serviceToRemove(service, 114 base::scoped_nsobject<CBService> serviceToRemove(service,
110 base::scoped_policy::RETAIN); 115 base::scoped_policy::RETAIN);
111 DCHECK(serviceToRemove); 116 DCHECK(serviceToRemove);
112 [_services.get() removeObject:serviceToRemove]; 117 [_services.get() removeObject:serviceToRemove];
118 [self didModifyServices:@[ serviceToRemove ]];
119 }
120
121 - (void)didDiscoverCharactericsForAllServices {
122 for (CBService* service in _services.get()) {
123 [_delegate peripheral:self.peripheral
124 didDiscoverCharacteristicsForService:service
125 error:nil];
126 }
127 }
128
129 - (void)didModifyServices:(NSArray*)invalidatedServices {
113 // -[CBPeripheralDelegate peripheral:didModifyServices:] is only available 130 // -[CBPeripheralDelegate peripheral:didModifyServices:] is only available
114 // with 10.9. It is safe to call this method (even if chrome is running on 131 // 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. 132 // 10.8) since WebBluetooth is enabled only with 10.10.
116 DCHECK( 133 DCHECK(
117 [_delegate respondsToSelector:@selector(peripheral:didModifyServices:)]); 134 [_delegate respondsToSelector:@selector(peripheral:didModifyServices:)]);
118 #pragma clang diagnostic push 135 #pragma clang diagnostic push
119 #pragma clang diagnostic ignored "-Wpartial-availability" 136 #pragma clang diagnostic ignored "-Wpartial-availability"
120 [_delegate peripheral:self.peripheral didModifyServices:@[ serviceToRemove ]]; 137 [_delegate peripheral:self.peripheral didModifyServices:invalidatedServices];
121 #pragma clang diagnostic pop 138 #pragma clang diagnostic pop
122 } 139 }
123 140
124 - (NSUUID*)identifier { 141 - (NSUUID*)identifier {
125 return _identifier.get(); 142 return _identifier.get();
126 } 143 }
127 144
128 - (NSString*)name { 145 - (NSString*)name {
129 return _name.get(); 146 return _name.get();
130 } 147 }
131 148
132 - (NSArray*)services { 149 - (NSArray*)services {
133 return _services.get(); 150 return _services.get();
134 } 151 }
135 152
136 - (CBPeripheral*)peripheral { 153 - (CBPeripheral*)peripheral {
137 return ObjCCast<CBPeripheral>(self); 154 return ObjCCast<CBPeripheral>(self);
138 } 155 }
139 156
140 @end 157 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698