| 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> |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 const BluetoothAudioSink::ErrorCallback& error_callback) override; | 76 const BluetoothAudioSink::ErrorCallback& error_callback) override; |
| 77 void RegisterAdvertisement( | 77 void RegisterAdvertisement( |
| 78 scoped_ptr<BluetoothAdvertisement::Data> advertisement_data, | 78 scoped_ptr<BluetoothAdvertisement::Data> advertisement_data, |
| 79 const CreateAdvertisementCallback& callback, | 79 const CreateAdvertisementCallback& callback, |
| 80 const CreateAdvertisementErrorCallback& error_callback) override; | 80 const CreateAdvertisementErrorCallback& error_callback) override; |
| 81 | 81 |
| 82 // BluetoothDiscoveryManagerMac::Observer overrides: | 82 // BluetoothDiscoveryManagerMac::Observer overrides: |
| 83 void ClassicDeviceFound(IOBluetoothDevice* device) override; | 83 void ClassicDeviceFound(IOBluetoothDevice* device) override; |
| 84 void ClassicDiscoveryStopped(bool unexpected) override; | 84 void ClassicDiscoveryStopped(bool unexpected) override; |
| 85 | 85 |
| 86 // BluetoothLowEnergyDiscoveryManagerMac::Observer override: | |
| 87 void LowEnergyDeviceUpdated(CBPeripheral* peripheral, | |
| 88 NSDictionary* advertisementData, | |
| 89 int rssi) override; | |
| 90 | |
| 91 // Registers that a new |device| has connected to the local host. | 86 // Registers that a new |device| has connected to the local host. |
| 92 void DeviceConnected(IOBluetoothDevice* device); | 87 void DeviceConnected(IOBluetoothDevice* device); |
| 93 | 88 |
| 94 protected: | 89 protected: |
| 95 // BluetoothAdapter override: | 90 // BluetoothAdapter override: |
| 96 void RemovePairingDelegateInternal( | 91 void RemovePairingDelegateInternal( |
| 97 device::BluetoothDevice::PairingDelegate* pairing_delegate) override; | 92 device::BluetoothDevice::PairingDelegate* pairing_delegate) override; |
| 98 | 93 |
| 99 private: | 94 private: |
| 95 // The length of time that must elapse since the last Inquiry response (on |
| 96 // Classic devices) or call to BluetoothLowEnergyDevice::Update() (on Low |
| 97 // Energy) before a discovered device is considered to be no longer available. |
| 98 const static NSTimeInterval kDiscoveryTimeoutSec; |
| 99 |
| 100 friend class BluetoothAdapterMacTest; | 100 friend class BluetoothAdapterMacTest; |
| 101 | 101 |
| 102 BluetoothAdapterMac(); | 102 BluetoothAdapterMac(); |
| 103 ~BluetoothAdapterMac() override; | 103 ~BluetoothAdapterMac() override; |
| 104 | 104 |
| 105 // BluetoothAdapter overrides: | 105 // BluetoothAdapter overrides: |
| 106 void AddDiscoverySession(BluetoothDiscoveryFilter* discovery_filter, | 106 void AddDiscoverySession(BluetoothDiscoveryFilter* discovery_filter, |
| 107 const base::Closure& callback, | 107 const base::Closure& callback, |
| 108 const ErrorCallback& error_callback) override; | 108 const ErrorCallback& error_callback) override; |
| 109 void RemoveDiscoverySession(BluetoothDiscoveryFilter* discovery_filter, | 109 void RemoveDiscoverySession(BluetoothDiscoveryFilter* discovery_filter, |
| 110 const base::Closure& callback, | 110 const base::Closure& callback, |
| 111 const ErrorCallback& error_callback) override; | 111 const ErrorCallback& error_callback) override; |
| 112 void SetDiscoveryFilter(scoped_ptr<BluetoothDiscoveryFilter> discovery_filter, | 112 void SetDiscoveryFilter(scoped_ptr<BluetoothDiscoveryFilter> discovery_filter, |
| 113 const base::Closure& callback, | 113 const base::Closure& callback, |
| 114 const ErrorCallback& error_callback) override; | 114 const ErrorCallback& error_callback) override; |
| 115 | 115 |
| 116 // Start classic and/or low energy discovery sessions, according to the | 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. | 117 // filter. If a discovery session is already running the filter is updated. |
| 118 bool StartDiscovery(BluetoothDiscoveryFilter* discovery_filter); | 118 bool StartDiscovery(BluetoothDiscoveryFilter* discovery_filter); |
| 119 | 119 |
| 120 void Init(); | 120 void Init(); |
| 121 void InitForTest(scoped_refptr<base::SequencedTaskRunner> ui_task_runner); | 121 void InitForTest(scoped_refptr<base::SequencedTaskRunner> ui_task_runner); |
| 122 void PollAdapter(); | 122 void PollAdapter(); |
| 123 | 123 |
| 124 // 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 |
| 125 // connected to the local host. | 125 // connected to the local host. |
| 126 void ClassicDeviceAdded(IOBluetoothDevice* device); | 126 void ClassicDeviceAdded(IOBluetoothDevice* device); |
| 127 | 127 |
| 128 // Updates |devices_| to include the currently paired devices, as well as any | 128 // BluetoothLowEnergyDiscoveryManagerMac::Observer override: |
| 129 // connected, but unpaired, devices. Notifies observers if any previously | 129 void LowEnergyDeviceUpdated(CBPeripheral* peripheral, |
| 130 // paired or connected devices are no longer present. | 130 NSDictionary* advertisementData, |
| 131 void UpdateDevices(); | 131 int rssi) override; |
| 132 |
| 133 // Removes from |devices_| any previously paired, connected or seen devices |
| 134 // which are no longer present. Notifies observers. |
| 135 void RemoveTimedOutDevices(); |
| 136 |
| 137 // Updates |devices_| to include the currently paired devices and notifies |
| 138 // observers. |
| 139 void AddPairedDevices(); |
| 132 | 140 |
| 133 std::string address_; | 141 std::string address_; |
| 134 std::string name_; | 142 std::string name_; |
| 135 bool powered_; | 143 bool powered_; |
| 136 | 144 |
| 137 int num_discovery_sessions_; | 145 int num_discovery_sessions_; |
| 138 | 146 |
| 139 // Discovery manager for Bluetooth Classic. | 147 // Discovery manager for Bluetooth Classic. |
| 140 scoped_ptr<BluetoothDiscoveryManagerMac> classic_discovery_manager_; | 148 scoped_ptr<BluetoothDiscoveryManagerMac> classic_discovery_manager_; |
| 141 | 149 |
| 142 // Discovery manager for Bluetooth Low Energy. | 150 // Discovery manager for Bluetooth Low Energy. |
| 143 scoped_ptr<BluetoothLowEnergyDiscoveryManagerMac> | 151 scoped_ptr<BluetoothLowEnergyDiscoveryManagerMac> |
| 144 low_energy_discovery_manager_; | 152 low_energy_discovery_manager_; |
| 145 | 153 |
| 146 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_; | 154 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_; |
| 147 | 155 |
| 148 base::WeakPtrFactory<BluetoothAdapterMac> weak_ptr_factory_; | 156 base::WeakPtrFactory<BluetoothAdapterMac> weak_ptr_factory_; |
| 149 | 157 |
| 150 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterMac); | 158 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterMac); |
| 151 }; | 159 }; |
| 152 | 160 |
| 153 } // namespace device | 161 } // namespace device |
| 154 | 162 |
| 155 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_MAC_H_ | 163 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_MAC_H_ |
| OLD | NEW |