| OLD | NEW | 
|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_MAC_H_ | 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_MAC_H_ | 
| 6 #define DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_MAC_H_ | 6 #define DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_MAC_H_ | 
| 7 | 7 | 
| 8 #include <IOKit/IOReturn.h> | 8 #include <IOKit/IOReturn.h> | 
| 9 | 9 | 
| 10 #include <string> | 10 #include <string> | 
| 11 #include <vector> | 11 #include <vector> | 
| 12 | 12 | 
| 13 #include "base/containers/hash_tables.h" | 13 #include "base/containers/hash_tables.h" | 
| 14 #include "base/mac/scoped_nsobject.h" | 14 #include "base/mac/scoped_nsobject.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 "base/observer_list.h" | 17 #include "base/observer_list.h" | 
| 18 #include "device/bluetooth/bluetooth_adapter.h" | 18 #include "device/bluetooth/bluetooth_adapter.h" | 
| 19 #include "device/bluetooth/bluetooth_audio_sink.h" | 19 #include "device/bluetooth/bluetooth_audio_sink.h" | 
| 20 #include "device/bluetooth/bluetooth_discovery_manager_mac.h" | 20 #include "device/bluetooth/bluetooth_discovery_manager_mac.h" | 
| 21 #include "device/bluetooth/bluetooth_export.h" | 21 #include "device/bluetooth/bluetooth_export.h" | 
|  | 22 #include "device/bluetooth/bluetooth_low_energy_device_mac.h" | 
|  | 23 #include "device/bluetooth/bluetooth_low_energy_discovery_manager_mac.h" | 
| 22 | 24 | 
| 23 @class IOBluetoothDevice; | 25 @class IOBluetoothDevice; | 
| 24 @class NSArray; | 26 @class NSArray; | 
| 25 @class NSDate; | 27 @class NSDate; | 
| 26 | 28 | 
| 27 namespace base { | 29 namespace base { | 
| 28 | 30 | 
| 29 class SequencedTaskRunner; | 31 class SequencedTaskRunner; | 
| 30 | 32 | 
| 31 }  // namespace base | 33 }  // namespace base | 
| 32 | 34 | 
| 33 namespace device { | 35 namespace device { | 
| 34 | 36 | 
| 35 class BluetoothAdapterMacTest; | 37 class BluetoothAdapterMacTest; | 
| 36 | 38 | 
| 37 class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterMac | 39 class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterMac | 
| 38     : public BluetoothAdapter, | 40     : public BluetoothAdapter, | 
| 39       public BluetoothDiscoveryManagerMac::Observer { | 41       public BluetoothDiscoveryManagerMac::Observer, | 
|  | 42       public BluetoothLowEnergyDiscoveryManagerMac::Observer { | 
| 40  public: | 43  public: | 
| 41   static base::WeakPtr<BluetoothAdapter> CreateAdapter(); | 44   static base::WeakPtr<BluetoothAdapter> CreateAdapter(); | 
| 42 | 45 | 
| 43   // BluetoothAdapter: | 46   // BluetoothAdapter overrides: | 
| 44   std::string GetAddress() const override; | 47   std::string GetAddress() const override; | 
| 45   std::string GetName() const override; | 48   std::string GetName() const override; | 
| 46   void SetName(const std::string& name, | 49   void SetName(const std::string& name, | 
| 47                const base::Closure& callback, | 50                const base::Closure& callback, | 
| 48                const ErrorCallback& error_callback) override; | 51                const ErrorCallback& error_callback) override; | 
| 49   bool IsInitialized() const override; | 52   bool IsInitialized() const override; | 
| 50   bool IsPresent() const override; | 53   bool IsPresent() const override; | 
| 51   bool IsPowered() const override; | 54   bool IsPowered() const override; | 
| 52   void SetPowered(bool powered, | 55   void SetPowered(bool powered, | 
| 53                   const base::Closure& callback, | 56                   const base::Closure& callback, | 
| (...skipping 15 matching lines...) Expand all  Loading... | 
| 69       const CreateServiceErrorCallback& error_callback) override; | 72       const CreateServiceErrorCallback& error_callback) override; | 
| 70   void RegisterAudioSink( | 73   void RegisterAudioSink( | 
| 71       const BluetoothAudioSink::Options& options, | 74       const BluetoothAudioSink::Options& options, | 
| 72       const AcquiredCallback& callback, | 75       const AcquiredCallback& callback, | 
| 73       const BluetoothAudioSink::ErrorCallback& error_callback) override; | 76       const BluetoothAudioSink::ErrorCallback& error_callback) override; | 
| 74   void RegisterAdvertisement( | 77   void RegisterAdvertisement( | 
| 75       scoped_ptr<BluetoothAdvertisement::Data> advertisement_data, | 78       scoped_ptr<BluetoothAdvertisement::Data> advertisement_data, | 
| 76       const CreateAdvertisementCallback& callback, | 79       const CreateAdvertisementCallback& callback, | 
| 77       const CreateAdvertisementErrorCallback& error_callback) override; | 80       const CreateAdvertisementErrorCallback& error_callback) override; | 
| 78 | 81 | 
| 79   // BluetoothDiscoveryManagerMac::Observer overrides | 82   // BluetoothDiscoveryManagerMac::Observer overrides: | 
| 80   void DeviceFound(IOBluetoothDevice* device) override; | 83   void ClassicDeviceFound(IOBluetoothDevice* device) override; | 
| 81   void DiscoveryStopped(bool unexpected) override; | 84   void ClassicDiscoveryStopped(bool unexpected) override; | 
|  | 85 | 
|  | 86   // BluetoothLowEnergyDiscoveryManagerMac::Observer override: | 
|  | 87   void LowEnergyDeviceUpdated(CBPeripheral* peripheral, | 
|  | 88                               NSDictionary* advertisementData, | 
|  | 89                               int rssi) override; | 
| 82 | 90 | 
| 83   // Registers that a new |device| has connected to the local host. | 91   // Registers that a new |device| has connected to the local host. | 
| 84   void DeviceConnected(IOBluetoothDevice* device); | 92   void DeviceConnected(IOBluetoothDevice* device); | 
| 85 | 93 | 
| 86  protected: | 94  protected: | 
| 87   // BluetoothAdapter: | 95   // BluetoothAdapter override: | 
| 88   void RemovePairingDelegateInternal( | 96   void RemovePairingDelegateInternal( | 
| 89       device::BluetoothDevice::PairingDelegate* pairing_delegate) override; | 97       device::BluetoothDevice::PairingDelegate* pairing_delegate) override; | 
| 90 | 98 | 
| 91  private: | 99  private: | 
| 92   friend class BluetoothAdapterMacTest; | 100   friend class BluetoothAdapterMacTest; | 
| 93 | 101 | 
| 94   BluetoothAdapterMac(); | 102   BluetoothAdapterMac(); | 
| 95   ~BluetoothAdapterMac() override; | 103   ~BluetoothAdapterMac() override; | 
| 96 | 104 | 
| 97   // BluetoothAdapter: | 105   // BluetoothAdapter overrides: | 
| 98   void AddDiscoverySession(BluetoothDiscoveryFilter* discovery_filter, | 106   void AddDiscoverySession(BluetoothDiscoveryFilter* discovery_filter, | 
| 99                            const base::Closure& callback, | 107                            const base::Closure& callback, | 
| 100                            const ErrorCallback& error_callback) override; | 108                            const ErrorCallback& error_callback) override; | 
| 101   void RemoveDiscoverySession(BluetoothDiscoveryFilter* discovery_filter, | 109   void RemoveDiscoverySession(BluetoothDiscoveryFilter* discovery_filter, | 
| 102                               const base::Closure& callback, | 110                               const base::Closure& callback, | 
| 103                               const ErrorCallback& error_callback) override; | 111                               const ErrorCallback& error_callback) override; | 
| 104   void SetDiscoveryFilter(scoped_ptr<BluetoothDiscoveryFilter> discovery_filter, | 112   void SetDiscoveryFilter(scoped_ptr<BluetoothDiscoveryFilter> discovery_filter, | 
| 105                           const base::Closure& callback, | 113                           const base::Closure& callback, | 
| 106                           const ErrorCallback& error_callback) override; | 114                           const ErrorCallback& error_callback) override; | 
| 107 | 115 | 
|  | 116   // Start classic and/or low energy discovery sessions, according to the | 
|  | 117   // filter.  If a discovery session is already running the filter is updated. | 
|  | 118   bool StartDiscovery(BluetoothDiscoveryFilter* discovery_filter); | 
|  | 119 | 
| 108   void Init(); | 120   void Init(); | 
| 109   void InitForTest(scoped_refptr<base::SequencedTaskRunner> ui_task_runner); | 121   void InitForTest(scoped_refptr<base::SequencedTaskRunner> ui_task_runner); | 
| 110   void PollAdapter(); | 122   void PollAdapter(); | 
| 111 | 123 | 
| 112   // Registers that a new |device| has replied to an Inquiry, is paired, or has | 124   // Registers that a new |device| has replied to an Inquiry, is paired, or has | 
| 113   // connected to the local host. | 125   // connected to the local host. | 
| 114   void DeviceAdded(IOBluetoothDevice* device); | 126   void ClassicDeviceAdded(IOBluetoothDevice* device); | 
| 115 | 127 | 
| 116   // Updates |devices_| to include the currently paired devices, as well as any | 128   // Updates |devices_| to include the currently paired devices, as well as any | 
| 117   // connected, but unpaired, devices. Notifies observers if any previously | 129   // connected, but unpaired, devices. Notifies observers if any previously | 
| 118   // paired or connected devices are no longer present. | 130   // paired or connected devices are no longer present. | 
| 119   void UpdateDevices(); | 131   void UpdateDevices(); | 
| 120 | 132 | 
| 121   std::string address_; | 133   std::string address_; | 
| 122   std::string name_; | 134   std::string name_; | 
| 123   bool powered_; | 135   bool powered_; | 
| 124 | 136 | 
| 125   int num_discovery_sessions_; | 137   int num_discovery_sessions_; | 
| 126 | 138 | 
| 127   // Discovery manager for Bluetooth Classic. | 139   // Discovery manager for Bluetooth Classic. | 
| 128   scoped_ptr<BluetoothDiscoveryManagerMac> classic_discovery_manager_; | 140   scoped_ptr<BluetoothDiscoveryManagerMac> classic_discovery_manager_; | 
| 129 | 141 | 
|  | 142   // Discovery manager for Bluetooth Low Energy. | 
|  | 143   scoped_ptr<BluetoothLowEnergyDiscoveryManagerMac> | 
|  | 144       low_energy_discovery_manager_; | 
|  | 145 | 
| 130   scoped_refptr<base::SequencedTaskRunner> ui_task_runner_; | 146   scoped_refptr<base::SequencedTaskRunner> ui_task_runner_; | 
| 131 | 147 | 
| 132   base::WeakPtrFactory<BluetoothAdapterMac> weak_ptr_factory_; | 148   base::WeakPtrFactory<BluetoothAdapterMac> weak_ptr_factory_; | 
| 133 | 149 | 
| 134   DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterMac); | 150   DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterMac); | 
| 135 }; | 151 }; | 
| 136 | 152 | 
| 137 }  // namespace device | 153 }  // namespace device | 
| 138 | 154 | 
| 139 #endif  // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_MAC_H_ | 155 #endif  // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_MAC_H_ | 
| OLD | NEW | 
|---|