| 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 #include "device/bluetooth/bluetooth_export.h" | 18 #include "device/bluetooth/bluetooth_export.h" |
| 19 | 19 |
| 20 namespace device { | 20 namespace device { |
| 21 | 21 |
| 22 class BluetoothDiscoverySession; | 22 class BluetoothDiscoverySession; |
| 23 class BluetoothGattCharacteristic; | 23 class BluetoothGattCharacteristic; |
| 24 class BluetoothGattDescriptor; | 24 class BluetoothGattDescriptor; |
| 25 class BluetoothGattService; | 25 class BluetoothGattService; |
| 26 class BluetoothSocket; | 26 class BluetoothSocket; |
| 27 class BluetoothUUID; | 27 class BluetoothUUID; |
| 28 struct BluetoothAdapterDeleter; |
| 28 | 29 |
| 29 // BluetoothAdapter represents a local Bluetooth adapter which may be used to | 30 // BluetoothAdapter represents a local Bluetooth adapter which may be used to |
| 30 // interact with remote Bluetooth devices. As well as providing support for | 31 // interact with remote Bluetooth devices. As well as providing support for |
| 31 // determining whether an adapter is present and whether the radio is powered, | 32 // determining whether an adapter is present and whether the radio is powered, |
| 32 // this class also provides support for obtaining the list of remote devices | 33 // this class also provides support for obtaining the list of remote devices |
| 33 // known to the adapter, discovering new devices, and providing notification of | 34 // known to the adapter, discovering new devices, and providing notification of |
| 34 // updates to device information. | 35 // updates to device information. |
| 35 class DEVICE_BLUETOOTH_EXPORT BluetoothAdapter | 36 class DEVICE_BLUETOOTH_EXPORT BluetoothAdapter |
| 36 : public base::RefCounted<BluetoothAdapter> { | 37 : public base::RefCountedThreadSafe<BluetoothAdapter, |
| 38 BluetoothAdapterDeleter> { |
| 37 public: | 39 public: |
| 38 // Interface for observing changes from bluetooth adapters. | 40 // Interface for observing changes from bluetooth adapters. |
| 39 class Observer { | 41 class Observer { |
| 40 public: | 42 public: |
| 41 virtual ~Observer() {} | 43 virtual ~Observer() {} |
| 42 | 44 |
| 43 // Called when the presence of the adapter |adapter| changes. When |present| | 45 // Called when the presence of the adapter |adapter| changes. When |present| |
| 44 // is true the adapter is now present, false means the adapter has been | 46 // is true the adapter is now present, false means the adapter has been |
| 45 // removed from the system. | 47 // removed from the system. |
| 46 virtual void AdapterPresentChanged(BluetoothAdapter* adapter, | 48 virtual void AdapterPresentChanged(BluetoothAdapter* adapter, |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 // BluetoothSocket instance that is to be owned by the received. | 329 // BluetoothSocket instance that is to be owned by the received. |
| 328 // |error_callback| will be called on failure with a message indicating the | 330 // |error_callback| will be called on failure with a message indicating the |
| 329 // cause. | 331 // cause. |
| 330 virtual void CreateL2capService( | 332 virtual void CreateL2capService( |
| 331 const BluetoothUUID& uuid, | 333 const BluetoothUUID& uuid, |
| 332 const ServiceOptions& options, | 334 const ServiceOptions& options, |
| 333 const CreateServiceCallback& callback, | 335 const CreateServiceCallback& callback, |
| 334 const CreateServiceErrorCallback& error_callback) = 0; | 336 const CreateServiceErrorCallback& error_callback) = 0; |
| 335 | 337 |
| 336 protected: | 338 protected: |
| 337 friend class base::RefCounted<BluetoothAdapter>; | 339 friend class base::RefCountedThreadSafe<BluetoothAdapter, |
| 340 BluetoothAdapterDeleter>; |
| 341 friend struct BluetoothAdapterDeleter; |
| 338 friend class BluetoothDiscoverySession; | 342 friend class BluetoothDiscoverySession; |
| 339 BluetoothAdapter(); | 343 BluetoothAdapter(); |
| 340 virtual ~BluetoothAdapter(); | 344 virtual ~BluetoothAdapter(); |
| 341 | 345 |
| 346 // Called by RefCountedThreadSafeDeleteOnCorrectThread to destroy this. |
| 347 virtual void DeleteOnCorrectThread() const = 0; |
| 348 |
| 342 // Internal methods for initiating and terminating device discovery sessions. | 349 // Internal methods for initiating and terminating device discovery sessions. |
| 343 // An implementation of BluetoothAdapter keeps an internal reference count to | 350 // An implementation of BluetoothAdapter keeps an internal reference count to |
| 344 // make sure that the underlying controller is constantly searching for nearby | 351 // make sure that the underlying controller is constantly searching for nearby |
| 345 // devices and retrieving information from them as long as there are clients | 352 // devices and retrieving information from them as long as there are clients |
| 346 // who have requested discovery. These methods behave in the following way: | 353 // who have requested discovery. These methods behave in the following way: |
| 347 // | 354 // |
| 348 // On a call to AddDiscoverySession: | 355 // On a call to AddDiscoverySession: |
| 349 // - If there is a pending request to the subsystem, queue this request to | 356 // - If there is a pending request to the subsystem, queue this request to |
| 350 // execute once the pending requests are done. | 357 // execute once the pending requests are done. |
| 351 // - If the count is 0, issue a request to the subsystem to start | 358 // - If the count is 0, issue a request to the subsystem to start |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 // will remove itself from this list when it gets destroyed or becomes | 420 // will remove itself from this list when it gets destroyed or becomes |
| 414 // inactive by calling DiscoverySessionBecameInactive(), hence no pointers to | 421 // inactive by calling DiscoverySessionBecameInactive(), hence no pointers to |
| 415 // deallocated sessions are kept. | 422 // deallocated sessions are kept. |
| 416 std::set<BluetoothDiscoverySession*> discovery_sessions_; | 423 std::set<BluetoothDiscoverySession*> discovery_sessions_; |
| 417 | 424 |
| 418 // Note: This should remain the last member so it'll be destroyed and | 425 // Note: This should remain the last member so it'll be destroyed and |
| 419 // invalidate its weak pointers before any other members are destroyed. | 426 // invalidate its weak pointers before any other members are destroyed. |
| 420 base::WeakPtrFactory<BluetoothAdapter> weak_ptr_factory_; | 427 base::WeakPtrFactory<BluetoothAdapter> weak_ptr_factory_; |
| 421 }; | 428 }; |
| 422 | 429 |
| 430 // Trait for RefCountedThreadSafe that deletes BluetoothAdapter. |
| 431 struct BluetoothAdapterDeleter { |
| 432 static void Destruct(const BluetoothAdapter* adapter) { |
| 433 adapter->DeleteOnCorrectThread(); |
| 434 } |
| 435 }; |
| 436 |
| 423 } // namespace device | 437 } // namespace device |
| 424 | 438 |
| 425 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_H_ | 439 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_H_ |
| OLD | NEW |