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

Side by Side Diff: device/bluetooth/bluetooth_device_mac.mm

Issue 735893002: Add GetConnectionInfo function for BluetoothDevice, replacing the existing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/bluetooth_device_mac.h" 5 #include "device/bluetooth/bluetooth_device_mac.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 } 86 }
87 87
88 uint16 BluetoothDeviceMac::GetProductID() const { 88 uint16 BluetoothDeviceMac::GetProductID() const {
89 return 0; 89 return 0;
90 } 90 }
91 91
92 uint16 BluetoothDeviceMac::GetDeviceID() const { 92 uint16 BluetoothDeviceMac::GetDeviceID() const {
93 return 0; 93 return 0;
94 } 94 }
95 95
96 int BluetoothDeviceMac::GetRSSI() const {
97 if (![device_ isConnected]) {
98 NOTIMPLEMENTED();
99 return kUnknownPower;
100 }
101
102 int rssi = [device_ rawRSSI];
103
104 // The API guarantees that +127 is returned in case the RSSI is not readable:
105 // http://goo.gl/bpURYv
106 if (rssi == 127)
107 return kUnknownPower;
108
109 return rssi;
110 }
111
112 int BluetoothDeviceMac::GetCurrentHostTransmitPower() const {
113 return GetHostTransmitPower(kReadCurrentTransmitPowerLevel);
114 }
115
116 int BluetoothDeviceMac::GetMaximumHostTransmitPower() const {
117 return GetHostTransmitPower(kReadMaximumTransmitPowerLevel);
118 }
119
120 bool BluetoothDeviceMac::IsPaired() const { 96 bool BluetoothDeviceMac::IsPaired() const {
121 return [device_ isPaired]; 97 return [device_ isPaired];
122 } 98 }
123 99
124 bool BluetoothDeviceMac::IsConnected() const { 100 bool BluetoothDeviceMac::IsConnected() const {
125 return [device_ isConnected]; 101 return [device_ isConnected];
126 } 102 }
127 103
128 bool BluetoothDeviceMac::IsConnectable() const { 104 bool BluetoothDeviceMac::IsConnectable() const {
129 return false; 105 return false;
(...skipping 27 matching lines...) Expand all
157 bool BluetoothDeviceMac::ExpectingPasskey() const { 133 bool BluetoothDeviceMac::ExpectingPasskey() const {
158 NOTIMPLEMENTED(); 134 NOTIMPLEMENTED();
159 return false; 135 return false;
160 } 136 }
161 137
162 bool BluetoothDeviceMac::ExpectingConfirmation() const { 138 bool BluetoothDeviceMac::ExpectingConfirmation() const {
163 NOTIMPLEMENTED(); 139 NOTIMPLEMENTED();
164 return false; 140 return false;
165 } 141 }
166 142
143 void GetConnectionInfo(const ConnectionInfoCallback& callback) {
144 ConnectionInfo connection_info;
145 if (![device_ isConnected]) {
146 callback.Run(connection_info);
147 return;
148 }
149
150 connection_info.rssi = [device_ rawRSSI];
151 // The API guarantees that +127 is returned in case the RSSI is not readable:
152 // http://goo.gl/bpURYv
153 if (connection_info.rssi == 127)
154 rssi = kUnknownPower;
Ilya Sherman 2014/11/19 22:18:07 nit: rssi -> connection_info.rssi
Tim Song 2014/12/06 00:51:37 Done.
155
156 connection_info.transmit_power =
157 GetHostTransmitPower(kReadCurrentTransmitPowerLevel);
158 connection.max_transmit_power =
Ilya Sherman 2014/11/19 22:18:07 nit: connection -> connection_info
Tim Song 2014/12/06 00:51:37 Done.
159 GetHostTransmitPower(kReadMaximumTransmitPowerLevel);
160
161 callback.Run(connection_info);
162 }
163
167 void BluetoothDeviceMac::Connect( 164 void BluetoothDeviceMac::Connect(
168 PairingDelegate* pairing_delegate, 165 PairingDelegate* pairing_delegate,
169 const base::Closure& callback, 166 const base::Closure& callback,
170 const ConnectErrorCallback& error_callback) { 167 const ConnectErrorCallback& error_callback) {
171 NOTIMPLEMENTED(); 168 NOTIMPLEMENTED();
172 } 169 }
173 170
174 void BluetoothDeviceMac::SetPinCode(const std::string& pincode) { 171 void BluetoothDeviceMac::SetPinCode(const std::string& pincode) {
175 NOTIMPLEMENTED(); 172 NOTIMPLEMENTED();
176 } 173 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 error_callback.Run(kApiUnavailable); 213 error_callback.Run(kApiUnavailable);
217 } 214 }
218 215
219 void BluetoothDeviceMac::CreateGattConnection( 216 void BluetoothDeviceMac::CreateGattConnection(
220 const GattConnectionCallback& callback, 217 const GattConnectionCallback& callback,
221 const ConnectErrorCallback& error_callback) { 218 const ConnectErrorCallback& error_callback) {
222 // TODO(armansito): Implement. 219 // TODO(armansito): Implement.
223 error_callback.Run(ERROR_UNSUPPORTED_DEVICE); 220 error_callback.Run(ERROR_UNSUPPORTED_DEVICE);
224 } 221 }
225 222
226 void BluetoothDeviceMac::StartConnectionMonitor(
227 const base::Closure& callback,
228 const ErrorCallback& error_callback) {
229 NOTIMPLEMENTED();
230 }
231
232 NSDate* BluetoothDeviceMac::GetLastInquiryUpdate() { 223 NSDate* BluetoothDeviceMac::GetLastInquiryUpdate() {
233 return [device_ getLastInquiryUpdate]; 224 return [device_ getLastInquiryUpdate];
234 } 225 }
235 226
236 int BluetoothDeviceMac::GetHostTransmitPower( 227 int BluetoothDeviceMac::GetHostTransmitPower(
237 BluetoothHCITransmitPowerLevelType power_level_type) const { 228 BluetoothHCITransmitPowerLevelType power_level_type) const {
238 IOBluetoothHostController* controller = 229 IOBluetoothHostController* controller =
239 [IOBluetoothHostController defaultController]; 230 [IOBluetoothHostController defaultController];
240 231
241 // Bail if the undocumented API is unavailable on this machine. 232 // Bail if the undocumented API is unavailable on this machine.
(...skipping 12 matching lines...) Expand all
254 245
255 return power_level; 246 return power_level;
256 } 247 }
257 248
258 // static 249 // static
259 std::string BluetoothDeviceMac::GetDeviceAddress(IOBluetoothDevice* device) { 250 std::string BluetoothDeviceMac::GetDeviceAddress(IOBluetoothDevice* device) {
260 return CanonicalizeAddress(base::SysNSStringToUTF8([device addressString])); 251 return CanonicalizeAddress(base::SysNSStringToUTF8([device addressString]));
261 } 252 }
262 253
263 } // namespace device 254 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698