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_ADAPTER_H_ | 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_H_ |
6 #define DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_H_ | 6 #define DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
11 #include <string> | 11 #include <string> |
12 #include <utility> | 12 #include <utility> |
13 | 13 |
14 #include "base/callback.h" | 14 #include "base/callback.h" |
15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
17 #include "device/bluetooth/bluetooth_device.h" | 17 #include "device/bluetooth/bluetooth_device.h" |
18 | 18 |
19 namespace device { | 19 namespace device { |
20 | 20 |
21 class BluetoothDiscoverySession; | 21 class BluetoothDiscoverySession; |
22 class BluetoothSocket; | 22 class BluetoothSocket; |
23 class BluetoothUUID; | 23 class BluetoothUUID; |
24 | 24 |
25 struct BluetoothOutOfBandPairingData; | |
26 | |
27 // BluetoothAdapter represents a local Bluetooth adapter which may be used to | 25 // BluetoothAdapter represents a local Bluetooth adapter which may be used to |
28 // interact with remote Bluetooth devices. As well as providing support for | 26 // interact with remote Bluetooth devices. As well as providing support for |
29 // determining whether an adapter is present and whether the radio is powered, | 27 // determining whether an adapter is present and whether the radio is powered, |
30 // this class also provides support for obtaining the list of remote devices | 28 // this class also provides support for obtaining the list of remote devices |
31 // known to the adapter, discovering new devices, and providing notification of | 29 // known to the adapter, discovering new devices, and providing notification of |
32 // updates to device information. | 30 // updates to device information. |
33 class BluetoothAdapter : public base::RefCounted<BluetoothAdapter> { | 31 class BluetoothAdapter : public base::RefCounted<BluetoothAdapter> { |
34 public: | 32 public: |
35 // Interface for observing changes from bluetooth adapters. | 33 // Interface for observing changes from bluetooth adapters. |
36 class Observer { | 34 class Observer { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 // phases or pairing information deleted. |device| should not be | 76 // phases or pairing information deleted. |device| should not be |
79 // cached. Instead, copy its Bluetooth address. | 77 // cached. Instead, copy its Bluetooth address. |
80 virtual void DeviceRemoved(BluetoothAdapter* adapter, | 78 virtual void DeviceRemoved(BluetoothAdapter* adapter, |
81 BluetoothDevice* device) {} | 79 BluetoothDevice* device) {} |
82 }; | 80 }; |
83 | 81 |
84 // The ErrorCallback is used for methods that can fail in which case it is | 82 // The ErrorCallback is used for methods that can fail in which case it is |
85 // called, in the success case the callback is simply not called. | 83 // called, in the success case the callback is simply not called. |
86 typedef base::Closure ErrorCallback; | 84 typedef base::Closure ErrorCallback; |
87 | 85 |
88 // The BluetoothOutOfBandPairingDataCallback is used to return | |
89 // BluetoothOutOfBandPairingData to the caller. | |
90 typedef base::Callback<void(const BluetoothOutOfBandPairingData& data)> | |
91 BluetoothOutOfBandPairingDataCallback; | |
92 | |
93 // The InitCallback is used to trigger a callback after asynchronous | 86 // The InitCallback is used to trigger a callback after asynchronous |
94 // initialization, if initialization is asynchronous on the platform. | 87 // initialization, if initialization is asynchronous on the platform. |
95 typedef base::Callback<void()> InitCallback; | 88 typedef base::Callback<void()> InitCallback; |
96 | 89 |
97 // Returns a weak pointer to a new adapter. For platforms with asynchronous | 90 // Returns a weak pointer to a new adapter. For platforms with asynchronous |
98 // initialization, the returned adapter will run the |init_callback| once | 91 // initialization, the returned adapter will run the |init_callback| once |
99 // asynchronous initialization is complete. | 92 // asynchronous initialization is complete. |
100 // Caution: The returned pointer also transfers ownership of the adapter. The | 93 // Caution: The returned pointer also transfers ownership of the adapter. The |
101 // caller is expected to call |AddRef()| on the returned pointer, typically by | 94 // caller is expected to call |AddRef()| on the returned pointer, typically by |
102 // storing it into a |scoped_refptr|. | 95 // storing it into a |scoped_refptr|. |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 typedef std::vector<BluetoothDevice*> DeviceList; | 179 typedef std::vector<BluetoothDevice*> DeviceList; |
187 virtual DeviceList GetDevices(); | 180 virtual DeviceList GetDevices(); |
188 typedef std::vector<const BluetoothDevice*> ConstDeviceList; | 181 typedef std::vector<const BluetoothDevice*> ConstDeviceList; |
189 virtual ConstDeviceList GetDevices() const; | 182 virtual ConstDeviceList GetDevices() const; |
190 | 183 |
191 // Returns a pointer to the device with the given address |address| or NULL if | 184 // Returns a pointer to the device with the given address |address| or NULL if |
192 // no such device is known. | 185 // no such device is known. |
193 virtual BluetoothDevice* GetDevice(const std::string& address); | 186 virtual BluetoothDevice* GetDevice(const std::string& address); |
194 virtual const BluetoothDevice* GetDevice(const std::string& address) const; | 187 virtual const BluetoothDevice* GetDevice(const std::string& address) const; |
195 | 188 |
196 // Requests the local Out Of Band pairing data. | |
197 virtual void ReadLocalOutOfBandPairingData( | |
198 const BluetoothOutOfBandPairingDataCallback& callback, | |
199 const ErrorCallback& error_callback) = 0; | |
200 | |
201 // Possible priorities for AddPairingDelegate(), low is intended for | 189 // Possible priorities for AddPairingDelegate(), low is intended for |
202 // permanent UI and high is intended for interactive UI or applications. | 190 // permanent UI and high is intended for interactive UI or applications. |
203 enum PairingDelegatePriority { | 191 enum PairingDelegatePriority { |
204 PAIRING_DELEGATE_PRIORITY_LOW, | 192 PAIRING_DELEGATE_PRIORITY_LOW, |
205 PAIRING_DELEGATE_PRIORITY_HIGH | 193 PAIRING_DELEGATE_PRIORITY_HIGH |
206 }; | 194 }; |
207 | 195 |
208 // Adds a default pairing delegate with priority |priority|. Method calls | 196 // Adds a default pairing delegate with priority |priority|. Method calls |
209 // will be made on |pairing_delegate| for incoming pairing requests if the | 197 // will be made on |pairing_delegate| for incoming pairing requests if the |
210 // priority is higher than any other registered; or for those of the same | 198 // priority is higher than any other registered; or for those of the same |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 std::set<BluetoothDiscoverySession*> discovery_sessions_; | 328 std::set<BluetoothDiscoverySession*> discovery_sessions_; |
341 | 329 |
342 // Note: This should remain the last member so it'll be destroyed and | 330 // Note: This should remain the last member so it'll be destroyed and |
343 // invalidate its weak pointers before any other members are destroyed. | 331 // invalidate its weak pointers before any other members are destroyed. |
344 base::WeakPtrFactory<BluetoothAdapter> weak_ptr_factory_; | 332 base::WeakPtrFactory<BluetoothAdapter> weak_ptr_factory_; |
345 }; | 333 }; |
346 | 334 |
347 } // namespace device | 335 } // namespace device |
348 | 336 |
349 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_H_ | 337 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_H_ |
OLD | NEW |