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; |
| 23 class BluetoothUUID; |
22 | 24 |
23 struct BluetoothOutOfBandPairingData; | 25 struct BluetoothOutOfBandPairingData; |
24 | 26 |
25 // BluetoothAdapter represents a local Bluetooth adapter which may be used to | 27 // BluetoothAdapter represents a local Bluetooth adapter which may be used to |
26 // interact with remote Bluetooth devices. As well as providing support for | 28 // interact with remote Bluetooth devices. As well as providing support for |
27 // determining whether an adapter is present and whether the radio is powered, | 29 // determining whether an adapter is present and whether the radio is powered, |
28 // this class also provides support for obtaining the list of remote devices | 30 // this class also provides support for obtaining the list of remote devices |
29 // known to the adapter, discovering new devices, and providing notification of | 31 // known to the adapter, discovering new devices, and providing notification of |
30 // updates to device information. | 32 // updates to device information. |
31 class BluetoothAdapter : public base::RefCounted<BluetoothAdapter> { | 33 class BluetoothAdapter : public base::RefCounted<BluetoothAdapter> { |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 | 218 |
217 // Removes a previously added pairing delegate. | 219 // Removes a previously added pairing delegate. |
218 virtual void RemovePairingDelegate( | 220 virtual void RemovePairingDelegate( |
219 BluetoothDevice::PairingDelegate* pairing_delegate); | 221 BluetoothDevice::PairingDelegate* pairing_delegate); |
220 | 222 |
221 // Returns the first registered pairing delegate with the highest priority, | 223 // Returns the first registered pairing delegate with the highest priority, |
222 // or NULL if no delegate is registered. Used to select the delegate for | 224 // or NULL if no delegate is registered. Used to select the delegate for |
223 // incoming pairing requests. | 225 // incoming pairing requests. |
224 virtual BluetoothDevice::PairingDelegate* DefaultPairingDelegate(); | 226 virtual BluetoothDevice::PairingDelegate* DefaultPairingDelegate(); |
225 | 227 |
| 228 // Creates an RFCOMM service on this adapter advertised with UUID |uuid|, |
| 229 // listening on channel |channel|, which may be the constant |kChannelAuto| |
| 230 // to automatically allocate one. The socket will require encryption unless |
| 231 // |insecure| is set to true. |callback| will be called on success with a |
| 232 // BluetoothSocket instance that is to be owned by the received. |
| 233 // |error_callback| will be called on failure with a message indicating the |
| 234 // cause. |
| 235 typedef base::Callback<void(scoped_refptr<BluetoothSocket>)> |
| 236 CreateServiceCallback; |
| 237 typedef base::Callback<void(const std::string& message)> |
| 238 CreateServiceErrorCallback; |
| 239 static const int kChannelAuto; |
| 240 virtual void CreateRfcommService( |
| 241 const BluetoothUUID& uuid, |
| 242 int channel, |
| 243 bool insecure, |
| 244 const CreateServiceCallback& callback, |
| 245 const CreateServiceErrorCallback& error_callback) = 0; |
| 246 |
| 247 // Creates an L2CAP service on this adapter advertised with UUID |uuid|, |
| 248 // listening on PSM |psm|, which may be the constant |kPsmAuto| to |
| 249 // automatically allocate one. |callback| will be called on success with a |
| 250 // BluetoothSocket instance that is to be owned by the received. |
| 251 // |error_callback| will be called on failure with a message indicating the |
| 252 // cause. |
| 253 static const int kPsmAuto; |
| 254 virtual void CreateL2capService( |
| 255 const BluetoothUUID& uuid, |
| 256 int psm, |
| 257 const CreateServiceCallback& callback, |
| 258 const CreateServiceErrorCallback& error_callback) = 0; |
| 259 |
226 protected: | 260 protected: |
227 friend class base::RefCounted<BluetoothAdapter>; | 261 friend class base::RefCounted<BluetoothAdapter>; |
228 friend class BluetoothDiscoverySession; | 262 friend class BluetoothDiscoverySession; |
229 BluetoothAdapter(); | 263 BluetoothAdapter(); |
230 virtual ~BluetoothAdapter(); | 264 virtual ~BluetoothAdapter(); |
231 | 265 |
232 // Internal methods for initiating and terminating device discovery sessions. | 266 // Internal methods for initiating and terminating device discovery sessions. |
233 // An implementation of BluetoothAdapter keeps an internal reference count to | 267 // An implementation of BluetoothAdapter keeps an internal reference count to |
234 // make sure that the underlying controller is constantly searching for nearby | 268 // make sure that the underlying controller is constantly searching for nearby |
235 // devices and retrieving information from them as long as there are clients | 269 // devices and retrieving information from them as long as there are clients |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 std::set<BluetoothDiscoverySession*> discovery_sessions_; | 340 std::set<BluetoothDiscoverySession*> discovery_sessions_; |
307 | 341 |
308 // Note: This should remain the last member so it'll be destroyed and | 342 // Note: This should remain the last member so it'll be destroyed and |
309 // invalidate its weak pointers before any other members are destroyed. | 343 // invalidate its weak pointers before any other members are destroyed. |
310 base::WeakPtrFactory<BluetoothAdapter> weak_ptr_factory_; | 344 base::WeakPtrFactory<BluetoothAdapter> weak_ptr_factory_; |
311 }; | 345 }; |
312 | 346 |
313 } // namespace device | 347 } // namespace device |
314 | 348 |
315 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_H_ | 349 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_H_ |
OLD | NEW |