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_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 Loading... |
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 { | |
92 } | 87 } |
93 | 88 |
94 - (void)removeAllServices { | 89 - (void)removeAllServices { |
95 [_services.get() removeAllObjects]; | 90 [_services.get() removeAllObjects]; |
96 } | 91 } |
97 | 92 |
98 - (void)addServices:(NSArray*)services { | 93 - (void)addServices:(NSArray*)services { |
99 if (!_services.get()) { | 94 if (!_services.get()) { |
100 _services.reset([[NSMutableArray alloc] init]); | 95 _services.reset([[NSMutableArray alloc] init]); |
101 } | 96 } |
102 for (CBUUID* uuid in services) { | 97 for (CBUUID* uuid in services) { |
103 base::scoped_nsobject<MockCBService> service([[MockCBService alloc] | 98 base::scoped_nsobject<MockCBService> service( |
104 initWithPeripheral:self.peripheral | 99 [[MockCBService alloc] initWithCBUUID:uuid primary:YES]); |
105 CBUUID:uuid | |
106 primary:YES]); | |
107 [_services.get() addObject:service.get().service]; | 100 [_services.get() addObject:service.get().service]; |
108 } | 101 } |
109 } | 102 } |
110 | 103 |
111 - (void)didDiscoverServicesWithError:(NSError*)error { | 104 - (void)didDiscoverServicesWithError:(NSError*)error { |
112 [_delegate peripheral:self.peripheral didDiscoverServices:error]; | 105 [_delegate peripheral:self.peripheral didDiscoverServices:error]; |
113 } | 106 } |
114 | 107 |
115 - (void)removeService:(CBService*)service { | 108 - (void)removeService:(CBService*)service { |
116 base::scoped_nsobject<CBService> serviceToRemove(service, | 109 base::scoped_nsobject<CBService> serviceToRemove(service, |
117 base::scoped_policy::RETAIN); | 110 base::scoped_policy::RETAIN); |
118 DCHECK(serviceToRemove); | 111 DCHECK(serviceToRemove); |
119 [_services.get() removeObject:serviceToRemove]; | 112 [_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 { | |
132 // -[CBPeripheralDelegate peripheral:didModifyServices:] is only available | 113 // -[CBPeripheralDelegate peripheral:didModifyServices:] is only available |
133 // with 10.9. It is safe to call this method (even if chrome is running on | 114 // with 10.9. It is safe to call this method (even if chrome is running on |
134 // 10.8) since WebBluetooth is enabled only with 10.10. | 115 // 10.8) since WebBluetooth is enabled only with 10.10. |
135 DCHECK( | 116 DCHECK( |
136 [_delegate respondsToSelector:@selector(peripheral:didModifyServices:)]); | 117 [_delegate respondsToSelector:@selector(peripheral:didModifyServices:)]); |
137 #pragma clang diagnostic push | 118 #pragma clang diagnostic push |
138 #pragma clang diagnostic ignored "-Wpartial-availability" | 119 #pragma clang diagnostic ignored "-Wpartial-availability" |
139 [_delegate peripheral:self.peripheral didModifyServices:invalidatedServices]; | 120 [_delegate peripheral:self.peripheral didModifyServices:@[ serviceToRemove ]]; |
140 #pragma clang diagnostic pop | 121 #pragma clang diagnostic pop |
141 } | 122 } |
142 | 123 |
143 - (NSUUID*)identifier { | 124 - (NSUUID*)identifier { |
144 return _identifier.get(); | 125 return _identifier.get(); |
145 } | 126 } |
146 | 127 |
147 - (NSString*)name { | 128 - (NSString*)name { |
148 return _name.get(); | 129 return _name.get(); |
149 } | 130 } |
150 | 131 |
151 - (NSArray*)services { | 132 - (NSArray*)services { |
152 return _services.get(); | 133 return _services.get(); |
153 } | 134 } |
154 | 135 |
155 - (CBPeripheral*)peripheral { | 136 - (CBPeripheral*)peripheral { |
156 return ObjCCast<CBPeripheral>(self); | 137 return ObjCCast<CBPeripheral>(self); |
157 } | 138 } |
158 | 139 |
159 @end | 140 @end |
OLD | NEW |