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