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 <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
11 #include <memory> | 11 #include <memory> |
12 #include <set> | 12 #include <set> |
13 #include <string> | 13 #include <string> |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
16 #include "base/callback.h" | 16 #include "base/callback.h" |
17 #include "base/containers/scoped_ptr_hash_map.h" | 17 #include "base/containers/scoped_ptr_hash_map.h" |
18 #include "base/gtest_prod_util.h" | 18 #include "base/gtest_prod_util.h" |
19 #include "base/memory/ref_counted.h" | 19 #include "base/memory/ref_counted.h" |
| 20 #include "base/optional.h" |
20 #include "base/strings/string16.h" | 21 #include "base/strings/string16.h" |
21 #include "device/bluetooth/bluetooth_export.h" | 22 #include "device/bluetooth/bluetooth_export.h" |
22 #include "device/bluetooth/bluetooth_uuid.h" | 23 #include "device/bluetooth/bluetooth_uuid.h" |
23 #include "net/log/net_log.h" | 24 #include "net/log/net_log.h" |
24 | 25 |
25 namespace base { | 26 namespace base { |
26 class BinaryValue; | 27 class BinaryValue; |
27 } | 28 } |
28 | 29 |
29 namespace device { | 30 namespace device { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 DEVICE_VIDEO, | 71 DEVICE_VIDEO, |
71 DEVICE_PERIPHERAL, | 72 DEVICE_PERIPHERAL, |
72 DEVICE_JOYSTICK, | 73 DEVICE_JOYSTICK, |
73 DEVICE_GAMEPAD, | 74 DEVICE_GAMEPAD, |
74 DEVICE_KEYBOARD, | 75 DEVICE_KEYBOARD, |
75 DEVICE_MOUSE, | 76 DEVICE_MOUSE, |
76 DEVICE_TABLET, | 77 DEVICE_TABLET, |
77 DEVICE_KEYBOARD_MOUSE_COMBO | 78 DEVICE_KEYBOARD_MOUSE_COMBO |
78 }; | 79 }; |
79 | 80 |
80 // The value returned if the RSSI or transmit power cannot be read. | |
81 static const int kUnknownPower = 127; | |
82 // The value returned if the appearance is not present. | 81 // The value returned if the appearance is not present. |
83 static const uint16_t kAppearanceNotPresent = 0xffc0; | 82 static const uint16_t kAppearanceNotPresent = 0xffc0; |
84 | 83 |
85 struct DEVICE_BLUETOOTH_EXPORT ConnectionInfo { | 84 struct DEVICE_BLUETOOTH_EXPORT ConnectionInfo { |
86 int rssi; | 85 base::Optional<int8_t> rssi; |
87 int transmit_power; | 86 base::Optional<int8_t> transmit_power; |
88 int max_transmit_power; | 87 base::Optional<int8_t> max_transmit_power; |
89 | 88 |
90 ConnectionInfo(); | 89 ConnectionInfo(); |
91 ConnectionInfo(int rssi, int transmit_power, int max_transmit_power); | 90 ConnectionInfo(const base::Optional<int8_t>& rssi, |
| 91 const base::Optional<int8_t>& transmit_power, |
| 92 const base::Optional<int8_t>& max_transmit_power); |
92 ~ConnectionInfo(); | 93 ~ConnectionInfo(); |
93 }; | 94 }; |
94 | 95 |
95 // Possible errors passed back to an error callback function in case of a | 96 // Possible errors passed back to an error callback function in case of a |
96 // failed call to Connect(). | 97 // failed call to Connect(). |
97 enum ConnectErrorCode { | 98 enum ConnectErrorCode { |
98 ERROR_ATTRIBUTE_LENGTH_INVALID, | 99 ERROR_ATTRIBUTE_LENGTH_INVALID, |
99 ERROR_AUTH_CANCELED, | 100 ERROR_AUTH_CANCELED, |
100 ERROR_AUTH_FAILED, | 101 ERROR_AUTH_FAILED, |
101 ERROR_AUTH_REJECTED, | 102 ERROR_AUTH_REJECTED, |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 // such as vendor and product id. | 277 // such as vendor and product id. |
277 bool IsTrustable() const; | 278 bool IsTrustable() const; |
278 | 279 |
279 // Returns the set of UUIDs that this device supports. For classic Bluetooth | 280 // Returns the set of UUIDs that this device supports. For classic Bluetooth |
280 // devices this data is collected from both the EIR data and SDP tables, | 281 // devices this data is collected from both the EIR data and SDP tables, |
281 // for Low Energy devices this data is collected from AD and GATT primary | 282 // for Low Energy devices this data is collected from AD and GATT primary |
282 // services, for dual mode devices this may be collected from both./ | 283 // services, for dual mode devices this may be collected from both./ |
283 virtual UUIDList GetUUIDs() const = 0; | 284 virtual UUIDList GetUUIDs() const = 0; |
284 | 285 |
285 // The received signal strength, in dBm. This field is avaliable and valid | 286 // The received signal strength, in dBm. This field is avaliable and valid |
286 // only during discovery. If not during discovery, or RSSI wasn't reported, | 287 // only during discovery. If not during discovery, or RSSI wasn't reported |
287 // this method will return |kUnknownPower|. | 288 // this value will be absent. |
288 virtual int16_t GetInquiryRSSI() const = 0; | 289 virtual base::Optional<int8_t> GetInquiryRSSI() const = 0; |
289 | 290 |
290 // The transmitted power level. This field is avaliable only for LE devices | 291 // The transmitted power level. This field is avaliable only for LE devices |
291 // that include this field in AD. It is avaliable and valid only during | 292 // that include this field in AD. It is avaliable and valid only during |
292 // discovery. If not during discovery, or TxPower wasn't reported, this | 293 // discovery. If not during discovery, or TxPower wasn't reported, this |
293 // method will return |kUnknownPower|. | 294 // value will be absent. |
294 virtual int16_t GetInquiryTxPower() const = 0; | 295 virtual base::Optional<int8_t> GetInquiryTxPower() const = 0; |
295 | 296 |
296 // The ErrorCallback is used for methods that can fail in which case it | 297 // The ErrorCallback is used for methods that can fail in which case it |
297 // is called, in the success case the callback is simply not called. | 298 // is called, in the success case the callback is simply not called. |
298 typedef base::Callback<void()> ErrorCallback; | 299 typedef base::Callback<void()> ErrorCallback; |
299 | 300 |
300 // The ConnectErrorCallback is used for methods that can fail with an error, | 301 // The ConnectErrorCallback is used for methods that can fail with an error, |
301 // passed back as an error code argument to this callback. | 302 // passed back as an error code argument to this callback. |
302 // In the success case this callback is not called. | 303 // In the success case this callback is not called. |
303 typedef base::Callback<void(enum ConnectErrorCode)> ConnectErrorCallback; | 304 typedef base::Callback<void(enum ConnectErrorCode)> ConnectErrorCallback; |
304 | 305 |
(...skipping 16 matching lines...) Expand all Loading... |
321 // The RSSI indicates the power present in the received radio signal, measured | 322 // The RSSI indicates the power present in the received radio signal, measured |
322 // in dBm, to a resolution of 1dBm. Larger (typically, less negative) values | 323 // in dBm, to a resolution of 1dBm. Larger (typically, less negative) values |
323 // indicate a stronger signal. | 324 // indicate a stronger signal. |
324 // | 325 // |
325 // The transmit power indicates the strength of the signal broadcast from the | 326 // The transmit power indicates the strength of the signal broadcast from the |
326 // host's Bluetooth antenna when communicating with the device, measured in | 327 // host's Bluetooth antenna when communicating with the device, measured in |
327 // dBm, to a resolution of 1dBm. Larger (typically, less negative) values | 328 // dBm, to a resolution of 1dBm. Larger (typically, less negative) values |
328 // indicate a stronger signal. | 329 // indicate a stronger signal. |
329 // | 330 // |
330 // If the device isn't connected, then the ConnectionInfo struct passed into | 331 // If the device isn't connected, then the ConnectionInfo struct passed into |
331 // the callback will be populated with |kUnknownPower|. | 332 // the callback will be populated with absent values. |
332 virtual void GetConnectionInfo(const ConnectionInfoCallback& callback) = 0; | 333 virtual void GetConnectionInfo(const ConnectionInfoCallback& callback) = 0; |
333 | 334 |
334 // Initiates a connection to the device, pairing first if necessary. | 335 // Initiates a connection to the device, pairing first if necessary. |
335 // | 336 // |
336 // Method calls will be made on the supplied object |pairing_delegate| | 337 // Method calls will be made on the supplied object |pairing_delegate| |
337 // to indicate what display, and in response should make method calls | 338 // to indicate what display, and in response should make method calls |
338 // back to the device object. Not all devices require user responses | 339 // back to the device object. Not all devices require user responses |
339 // during pairing, so it is normal for |pairing_delegate| to receive no | 340 // during pairing, so it is normal for |pairing_delegate| to receive no |
340 // calls. To explicitly force a low-security connection without bonding, | 341 // calls. To explicitly force a low-security connection without bonding, |
341 // pass NULL, though this is ignored if the device is already paired. | 342 // pass NULL, though this is ignored if the device is already paired. |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 | 553 |
553 private: | 554 private: |
554 // Returns a localized string containing the device's bluetooth address and | 555 // Returns a localized string containing the device's bluetooth address and |
555 // a device type for display when |name_| is empty. | 556 // a device type for display when |name_| is empty. |
556 base::string16 GetAddressWithLocalizedDeviceTypeName() const; | 557 base::string16 GetAddressWithLocalizedDeviceTypeName() const; |
557 }; | 558 }; |
558 | 559 |
559 } // namespace device | 560 } // namespace device |
560 | 561 |
561 #endif // DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_ | 562 #endif // DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_ |
OLD | NEW |