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

Side by Side Diff: device/bluetooth/bluetooth_device.h

Issue 735893002: Add GetConnectionInfo function for BluetoothDevice, replacing the existing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixes Created 6 years 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_ 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_
6 #define DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_ 6 #define DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 DEVICE_GAMEPAD, 61 DEVICE_GAMEPAD,
62 DEVICE_KEYBOARD, 62 DEVICE_KEYBOARD,
63 DEVICE_MOUSE, 63 DEVICE_MOUSE,
64 DEVICE_TABLET, 64 DEVICE_TABLET,
65 DEVICE_KEYBOARD_MOUSE_COMBO 65 DEVICE_KEYBOARD_MOUSE_COMBO
66 }; 66 };
67 67
68 // The value returned if the RSSI or transmit power cannot be read. 68 // The value returned if the RSSI or transmit power cannot be read.
69 static const int kUnknownPower = 127; 69 static const int kUnknownPower = 127;
70 70
71 struct ConnectionInfo {
72 int rssi;
73 int transmit_power;
74 int max_transmit_power;
75
76 ConnectionInfo()
77 : rssi(kUnknownPower),
78 transmit_power(kUnknownPower),
79 max_transmit_power(kUnknownPower) {}
80
81 ConnectionInfo(int rssi, int transmit_power, int max_transmit_power)
82 : rssi(rssi),
83 transmit_power(transmit_power),
84 max_transmit_power(max_transmit_power) {}
armansito 2015/01/06 20:36:07 Even though this is a simple struct, I would move
Tim Song 2015/01/06 22:30:51 Done.
85 };
86
71 // Possible errors passed back to an error callback function in case of a 87 // Possible errors passed back to an error callback function in case of a
72 // failed call to Connect(). 88 // failed call to Connect().
73 enum ConnectErrorCode { 89 enum ConnectErrorCode {
74 ERROR_UNKNOWN, 90 ERROR_UNKNOWN,
75 ERROR_INPROGRESS, 91 ERROR_INPROGRESS,
76 ERROR_FAILED, 92 ERROR_FAILED,
77 ERROR_AUTH_FAILED, 93 ERROR_AUTH_FAILED,
78 ERROR_AUTH_CANCELED, 94 ERROR_AUTH_CANCELED,
79 ERROR_AUTH_REJECTED, 95 ERROR_AUTH_REJECTED,
80 ERROR_AUTH_TIMEOUT, 96 ERROR_AUTH_TIMEOUT,
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 // be a synthesized string containing the address and localized type name 212 // be a synthesized string containing the address and localized type name
197 // if the device has no obtained name. 213 // if the device has no obtained name.
198 virtual base::string16 GetName() const; 214 virtual base::string16 GetName() const;
199 215
200 // Returns the type of the device, limited to those we support or are 216 // Returns the type of the device, limited to those we support or are
201 // aware of, by decoding the bluetooth class information. The returned 217 // aware of, by decoding the bluetooth class information. The returned
202 // values are unique, and do not overlap, so DEVICE_KEYBOARD is not also 218 // values are unique, and do not overlap, so DEVICE_KEYBOARD is not also
203 // DEVICE_PERIPHERAL. 219 // DEVICE_PERIPHERAL.
204 DeviceType GetDeviceType() const; 220 DeviceType GetDeviceType() const;
205 221
206 // Gets the "received signal strength indication" (RSSI) of the current
207 // connection to the device. The RSSI indicates the power present in the
208 // received radio signal, measured in dBm, to a resolution of 1dBm. Larger
209 // (typically, less negative) values indicate a stronger signal.
210 // If the device is not currently connected, then returns the RSSI read from
211 // the last inquiry that returned the device, where available. In case of an
212 // error, returns |kUnknownPower|. Otherwise, returns the connection's RSSI.
213 virtual int GetRSSI() const = 0;
214
215 // These two methods are used to read the current or maximum transmit power
216 // ("Tx power") of the current connection to the device. The transmit power
217 // indicates the strength of the signal broadcast from the host's Bluetooth
218 // antenna when communicating with the device, measured in dBm, to a
219 // resolution of 1dBm. Larger (typically, less negative) values
220 // indicate a stronger signal.
221 // It is only meaningful to call this method when there is a connection
222 // established to the device. If there is no connection, or in case of an
223 // error, returns |kUnknownPower|. Otherwise, returns the connection's
224 // transmit power.
225 virtual int GetCurrentHostTransmitPower() const = 0;
226 virtual int GetMaximumHostTransmitPower() const = 0;
227
228 // Indicates whether the device is known to support pairing based on its 222 // Indicates whether the device is known to support pairing based on its
229 // device class and address. 223 // device class and address.
230 bool IsPairable() const; 224 bool IsPairable() const;
231 225
232 // Indicates whether the device is paired with the adapter. 226 // Indicates whether the device is paired with the adapter.
233 virtual bool IsPaired() const = 0; 227 virtual bool IsPaired() const = 0;
234 228
235 // Indicates whether the device is currently connected to the adapter. 229 // Indicates whether the device is currently connected to the adapter.
236 // Note that if IsConnected() is true, does not imply that the device is 230 // Note that if IsConnected() is true, does not imply that the device is
237 // connected to any application or service. If the device is not paired, it 231 // connected to any application or service. If the device is not paired, it
(...skipping 24 matching lines...) Expand all
262 256
263 // The ErrorCallback is used for methods that can fail in which case it 257 // The ErrorCallback is used for methods that can fail in which case it
264 // is called, in the success case the callback is simply not called. 258 // is called, in the success case the callback is simply not called.
265 typedef base::Callback<void()> ErrorCallback; 259 typedef base::Callback<void()> ErrorCallback;
266 260
267 // The ConnectErrorCallback is used for methods that can fail with an error, 261 // The ConnectErrorCallback is used for methods that can fail with an error,
268 // passed back as an error code argument to this callback. 262 // passed back as an error code argument to this callback.
269 // In the success case this callback is not called. 263 // In the success case this callback is not called.
270 typedef base::Callback<void(enum ConnectErrorCode)> ConnectErrorCallback; 264 typedef base::Callback<void(enum ConnectErrorCode)> ConnectErrorCallback;
271 265
266 typedef base::Callback<void(const ConnectionInfo&)> ConnectionInfoCallback;
267
272 // Indicates whether the device is currently pairing and expecting a 268 // Indicates whether the device is currently pairing and expecting a
273 // PIN Code to be returned. 269 // PIN Code to be returned.
274 virtual bool ExpectingPinCode() const = 0; 270 virtual bool ExpectingPinCode() const = 0;
275 271
276 // Indicates whether the device is currently pairing and expecting a 272 // Indicates whether the device is currently pairing and expecting a
277 // Passkey to be returned. 273 // Passkey to be returned.
278 virtual bool ExpectingPasskey() const = 0; 274 virtual bool ExpectingPasskey() const = 0;
279 275
280 // Indicates whether the device is currently pairing and expecting 276 // Indicates whether the device is currently pairing and expecting
281 // confirmation of a displayed passkey. 277 // confirmation of a displayed passkey.
282 virtual bool ExpectingConfirmation() const = 0; 278 virtual bool ExpectingConfirmation() const = 0;
283 279
280 // Returns the RSSI and TX power of the active connection to the device:
281 //
282 // The RSSI indicates the power present in the received radio signal, measured
283 // in dBm, to a resolution of 1dBm. Larger (typically, less negative) values
284 // indicate a stronger signal.
285 //
286 // The transmit power indicates the strength of the signal broadcast from the
287 // host's Bluetooth antenna when communicating with the device, measured in
288 // dBm, to a resolution of 1dBm. Larger (typically, less negative) values
289 // indicate a stronger signal.
290 //
291 // If the device isn't connected, then the ConnectionInfo struct passed into
292 // the callback will filled by |kUnknownPower|.
armansito 2015/01/06 20:36:07 nit: s/will filled by/will be populated with/
Tim Song 2015/01/06 22:30:51 Done.
293 virtual void GetConnectionInfo(const ConnectionInfoCallback& callback) = 0;
armansito 2015/01/06 20:36:08 Maybe it's better to have an ErrorCallback instead
Tim Song 2015/01/06 22:30:51 The underlying dbus/mac apis might return invalid
armansito 2015/01/06 22:39:29 That's what I figured why you chose to do it this
294
284 // Initiates a connection to the device, pairing first if necessary. 295 // Initiates a connection to the device, pairing first if necessary.
285 // 296 //
286 // Method calls will be made on the supplied object |pairing_delegate| 297 // Method calls will be made on the supplied object |pairing_delegate|
287 // to indicate what display, and in response should make method calls 298 // to indicate what display, and in response should make method calls
288 // back to the device object. Not all devices require user responses 299 // back to the device object. Not all devices require user responses
289 // during pairing, so it is normal for |pairing_delegate| to receive no 300 // during pairing, so it is normal for |pairing_delegate| to receive no
290 // calls. To explicitly force a low-security connection without bonding, 301 // calls. To explicitly force a low-security connection without bonding,
291 // pass NULL, though this is ignored if the device is already paired. 302 // pass NULL, though this is ignored if the device is already paired.
292 // 303 //
293 // If the request fails, |error_callback| will be called; otherwise, 304 // If the request fails, |error_callback| will be called; otherwise,
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 // BluetoothDevice::Disconnect or other unexpected circumstances, the 388 // BluetoothDevice::Disconnect or other unexpected circumstances, the
378 // returned BluetoothGattConnection will be automatically marked as inactive. 389 // returned BluetoothGattConnection will be automatically marked as inactive.
379 // To monitor the state of the connection, observe the 390 // To monitor the state of the connection, observe the
380 // BluetoothAdapter::Observer::DeviceChanged method. 391 // BluetoothAdapter::Observer::DeviceChanged method.
381 typedef base::Callback<void(scoped_ptr<BluetoothGattConnection>)> 392 typedef base::Callback<void(scoped_ptr<BluetoothGattConnection>)>
382 GattConnectionCallback; 393 GattConnectionCallback;
383 virtual void CreateGattConnection( 394 virtual void CreateGattConnection(
384 const GattConnectionCallback& callback, 395 const GattConnectionCallback& callback,
385 const ConnectErrorCallback& error_callback) = 0; 396 const ConnectErrorCallback& error_callback) = 0;
386 397
387 // Starts monitoring the connection properties, RSSI and TX power. These
388 // properties will be tracked, and updated when their values change. Exactly
389 // one of |callback| or |error_callback| will be run.
390 virtual void StartConnectionMonitor(const base::Closure& callback,
391 const ErrorCallback& error_callback) = 0;
392
393 // Returns the list of discovered GATT services. 398 // Returns the list of discovered GATT services.
394 virtual std::vector<BluetoothGattService*> GetGattServices() const; 399 virtual std::vector<BluetoothGattService*> GetGattServices() const;
395 400
396 // Returns the GATT service with device-specific identifier |identifier|. 401 // Returns the GATT service with device-specific identifier |identifier|.
397 // Returns NULL, if no such service exists. 402 // Returns NULL, if no such service exists.
398 virtual BluetoothGattService* GetGattService( 403 virtual BluetoothGattService* GetGattService(
399 const std::string& identifier) const; 404 const std::string& identifier) const;
400 405
401 // Returns the |address| in the canonical format: XX:XX:XX:XX:XX:XX, where 406 // Returns the |address| in the canonical format: XX:XX:XX:XX:XX:XX, where
402 // each 'X' is a hex digit. If the input |address| is invalid, returns an 407 // each 'X' is a hex digit. If the input |address| is invalid, returns an
(...skipping 13 matching lines...) Expand all
416 421
417 private: 422 private:
418 // Returns a localized string containing the device's bluetooth address and 423 // Returns a localized string containing the device's bluetooth address and
419 // a device type for display when |name_| is empty. 424 // a device type for display when |name_| is empty.
420 base::string16 GetAddressWithLocalizedDeviceTypeName() const; 425 base::string16 GetAddressWithLocalizedDeviceTypeName() const;
421 }; 426 };
422 427
423 } // namespace device 428 } // namespace device
424 429
425 #endif // DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_ 430 #endif // DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698