| 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_TASK_MANAGER_WIN_H_ | 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_TASK_MANAGER_WIN_H_ |
| 6 #define DEVICE_BLUETOOTH_BLUETOOTH_TASK_MANAGER_WIN_H_ | 6 #define DEVICE_BLUETOOTH_BLUETOOTH_TASK_MANAGER_WIN_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <string> | 11 #include <string> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 17 #include "base/memory/scoped_vector.h" | |
| 18 #include "base/observer_list.h" | 17 #include "base/observer_list.h" |
| 19 #include "base/optional.h" | 18 #include "base/optional.h" |
| 20 #include "base/win/scoped_handle.h" | 19 #include "base/win/scoped_handle.h" |
| 21 #include "device/bluetooth/bluetooth_adapter.h" | 20 #include "device/bluetooth/bluetooth_adapter.h" |
| 22 #include "device/bluetooth/bluetooth_export.h" | 21 #include "device/bluetooth/bluetooth_export.h" |
| 23 #include "device/bluetooth/bluetooth_low_energy_win.h" | 22 #include "device/bluetooth/bluetooth_low_energy_win.h" |
| 24 | 23 |
| 25 namespace base { | 24 namespace base { |
| 26 | 25 |
| 27 class SequencedTaskRunner; | 26 class SequencedTaskRunner; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 58 // Properties specific to Bluetooth Classic devices. | 57 // Properties specific to Bluetooth Classic devices. |
| 59 std::vector<uint8_t> sdp_bytes; | 58 std::vector<uint8_t> sdp_bytes; |
| 60 // Properties specific to Bluetooth LE devices. | 59 // Properties specific to Bluetooth LE devices. |
| 61 BluetoothUUID gatt_uuid; | 60 BluetoothUUID gatt_uuid; |
| 62 uint16_t attribute_handle; | 61 uint16_t attribute_handle; |
| 63 // GATT service device path. | 62 // GATT service device path. |
| 64 // Note: Operation of the included characteristics and descriptors of this | 63 // Note: Operation of the included characteristics and descriptors of this |
| 65 // service must use service device path instead of resident device device | 64 // service must use service device path instead of resident device device |
| 66 // path. | 65 // path. |
| 67 base::FilePath path; | 66 base::FilePath path; |
| 67 |
| 68 private: |
| 69 DISALLOW_COPY_AND_ASSIGN(ServiceRecordState); |
| 68 }; | 70 }; |
| 69 | 71 |
| 70 struct DEVICE_BLUETOOTH_EXPORT DeviceState { | 72 struct DEVICE_BLUETOOTH_EXPORT DeviceState { |
| 71 DeviceState(); | 73 DeviceState(); |
| 72 ~DeviceState(); | 74 ~DeviceState(); |
| 73 | 75 |
| 74 bool is_bluetooth_classic() const { return path.empty(); } | 76 bool is_bluetooth_classic() const { return path.empty(); } |
| 75 | 77 |
| 76 // Properties common to Bluetooth Classic and LE devices. | 78 // Properties common to Bluetooth Classic and LE devices. |
| 77 std::string address; // This uniquely identifies the device. | 79 std::string address; // This uniquely identifies the device. |
| 78 base::Optional<std::string> name; // Friendly name | 80 base::Optional<std::string> name; // Friendly name |
| 79 bool visible; | 81 bool visible; |
| 80 bool connected; | 82 bool connected; |
| 81 bool authenticated; | 83 bool authenticated; |
| 82 ScopedVector<ServiceRecordState> service_record_states; | 84 std::vector<std::unique_ptr<ServiceRecordState>> service_record_states; |
| 83 // Properties specific to Bluetooth Classic devices. | 85 // Properties specific to Bluetooth Classic devices. |
| 84 uint32_t bluetooth_class; | 86 uint32_t bluetooth_class; |
| 85 // Properties specific to Bluetooth LE devices. | 87 // Properties specific to Bluetooth LE devices. |
| 86 base::FilePath path; | 88 base::FilePath path; |
| 89 |
| 90 private: |
| 91 DISALLOW_COPY_AND_ASSIGN(DeviceState); |
| 87 }; | 92 }; |
| 88 | 93 |
| 89 class DEVICE_BLUETOOTH_EXPORT Observer { | 94 class DEVICE_BLUETOOTH_EXPORT Observer { |
| 90 public: | 95 public: |
| 91 virtual ~Observer() {} | 96 virtual ~Observer() {} |
| 92 | 97 |
| 93 virtual void AdapterStateChanged(const AdapterState& state) {} | 98 virtual void AdapterStateChanged(const AdapterState& state) {} |
| 94 virtual void DiscoveryStarted(bool success) {} | 99 virtual void DiscoveryStarted(bool success) {} |
| 95 virtual void DiscoveryStopped() {} | 100 virtual void DiscoveryStopped() {} |
| 96 // Called when the adapter has just been polled for the list of *all* known | 101 // Called when the adapter has just been polled for the list of *all* known |
| 97 // devices. This includes devices previously paired, devices paired using | 102 // devices. This includes devices previously paired, devices paired using |
| 98 // the underlying Operating System UI, and devices discovered recently due | 103 // the underlying Operating System UI, and devices discovered recently due |
| 99 // to an active discovery session. Note that for a given device (address), | 104 // to an active discovery session. Note that for a given device (address), |
| 100 // the associated state can change over time. For example, during a | 105 // the associated state can change over time. For example, during a |
| 101 // discovery session, the "friendly" name may initially be "unknown" before | 106 // discovery session, the "friendly" name may initially be "unknown" before |
| 102 // the actual name is retrieved in subsequent poll events. | 107 // the actual name is retrieved in subsequent poll events. |
| 103 virtual void DevicesPolled(const ScopedVector<DeviceState>& devices) {} | 108 virtual void DevicesPolled( |
| 109 const std::vector<std::unique_ptr<DeviceState>>& devices) {} |
| 104 }; | 110 }; |
| 105 | 111 |
| 106 explicit BluetoothTaskManagerWin( | 112 explicit BluetoothTaskManagerWin( |
| 107 scoped_refptr<base::SequencedTaskRunner> ui_task_runner); | 113 scoped_refptr<base::SequencedTaskRunner> ui_task_runner); |
| 108 | 114 |
| 109 static BluetoothUUID BluetoothLowEnergyUuidToBluetoothUuid( | 115 static BluetoothUUID BluetoothLowEnergyUuidToBluetoothUuid( |
| 110 const BTH_LE_UUID& bth_le_uuid); | 116 const BTH_LE_UUID& bth_le_uuid); |
| 111 | 117 |
| 112 void AddObserver(Observer* observer); | 118 void AddObserver(Observer* observer); |
| 113 void RemoveObserver(Observer* observer); | 119 void RemoveObserver(Observer* observer); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 | 205 |
| 200 // Logs Win32 errors occurring during polling on the worker thread. The method | 206 // Logs Win32 errors occurring during polling on the worker thread. The method |
| 201 // may discard messages to avoid logging being too verbose. | 207 // may discard messages to avoid logging being too verbose. |
| 202 void LogPollingError(const char* message, int win32_error); | 208 void LogPollingError(const char* message, int win32_error); |
| 203 | 209 |
| 204 // Notify all Observers of updated AdapterState. Should only be called on the | 210 // Notify all Observers of updated AdapterState. Should only be called on the |
| 205 // UI thread. | 211 // UI thread. |
| 206 void OnAdapterStateChanged(const AdapterState* state); | 212 void OnAdapterStateChanged(const AdapterState* state); |
| 207 void OnDiscoveryStarted(bool success); | 213 void OnDiscoveryStarted(bool success); |
| 208 void OnDiscoveryStopped(); | 214 void OnDiscoveryStopped(); |
| 209 void OnDevicesPolled(const ScopedVector<DeviceState>* devices); | 215 void OnDevicesPolled(std::vector<std::unique_ptr<DeviceState>> devices); |
| 210 | 216 |
| 211 // Called on BluetoothTaskRunner. | 217 // Called on BluetoothTaskRunner. |
| 212 void StartPolling(); | 218 void StartPolling(); |
| 213 void PollAdapter(); | 219 void PollAdapter(); |
| 214 void PostAdapterStateToUi(); | 220 void PostAdapterStateToUi(); |
| 215 void SetPowered(bool powered, | 221 void SetPowered(bool powered, |
| 216 const base::Closure& callback, | 222 const base::Closure& callback, |
| 217 const BluetoothAdapter::ErrorCallback& error_callback); | 223 const BluetoothAdapter::ErrorCallback& error_callback); |
| 218 | 224 |
| 219 // Starts discovery. Once the discovery starts, it issues a discovery inquiry | 225 // Starts discovery. Once the discovery starts, it issues a discovery inquiry |
| (...skipping 11 matching lines...) Expand all Loading... |
| 231 | 237 |
| 232 // Fetch already known device information. Similar to |StartDiscovery|, except | 238 // Fetch already known device information. Similar to |StartDiscovery|, except |
| 233 // this function does not issue a discovery inquiry. Instead it gets the | 239 // this function does not issue a discovery inquiry. Instead it gets the |
| 234 // device info cached in the adapter. | 240 // device info cached in the adapter. |
| 235 void GetKnownDevices(); | 241 void GetKnownDevices(); |
| 236 | 242 |
| 237 // Looks for Bluetooth Classic and Low Energy devices, as well as the services | 243 // Looks for Bluetooth Classic and Low Energy devices, as well as the services |
| 238 // exposed by those devices. | 244 // exposed by those devices. |
| 239 bool SearchDevices(int timeout_multiplier, | 245 bool SearchDevices(int timeout_multiplier, |
| 240 bool search_cached_devices_only, | 246 bool search_cached_devices_only, |
| 241 ScopedVector<DeviceState>* device_list); | 247 std::vector<std::unique_ptr<DeviceState>>* device_list); |
| 242 | 248 |
| 243 // Sends a device search API call to the adapter to look for Bluetooth Classic | 249 // Sends a device search API call to the adapter to look for Bluetooth Classic |
| 244 // devices. | 250 // devices. |
| 245 bool SearchClassicDevices(int timeout_multiplier, | 251 bool SearchClassicDevices( |
| 246 bool search_cached_devices_only, | 252 int timeout_multiplier, |
| 247 ScopedVector<DeviceState>* device_list); | 253 bool search_cached_devices_only, |
| 254 std::vector<std::unique_ptr<DeviceState>>* device_list); |
| 248 | 255 |
| 249 // Enumerate Bluetooth Low Energy devices. | 256 // Enumerate Bluetooth Low Energy devices. |
| 250 bool SearchLowEnergyDevices(ScopedVector<DeviceState>* device_list); | 257 bool SearchLowEnergyDevices( |
| 258 std::vector<std::unique_ptr<DeviceState>>* device_list); |
| 251 | 259 |
| 252 // Discover services for the devices in |device_list|. | 260 // Discover services for the devices in |device_list|. |
| 253 bool DiscoverServices(ScopedVector<DeviceState>* device_list, | 261 bool DiscoverServices(std::vector<std::unique_ptr<DeviceState>>* device_list, |
| 254 bool search_cached_services_only); | 262 bool search_cached_services_only); |
| 255 | 263 |
| 256 // Discover Bluetooth Classic services for the given |device_address|. | 264 // Discover Bluetooth Classic services for the given |device_address|. |
| 257 bool DiscoverClassicDeviceServices( | 265 bool DiscoverClassicDeviceServices( |
| 258 const std::string& device_address, | 266 const std::string& device_address, |
| 259 const GUID& protocol_uuid, | 267 const GUID& protocol_uuid, |
| 260 bool search_cached_services_only, | 268 bool search_cached_services_only, |
| 261 ScopedVector<ServiceRecordState>* service_record_states); | 269 std::vector<std::unique_ptr<ServiceRecordState>>* service_record_states); |
| 262 | 270 |
| 263 // Discover Bluetooth Classic services for the given |device_address|. | 271 // Discover Bluetooth Classic services for the given |device_address|. |
| 264 // Returns a Win32 error code. | 272 // Returns a Win32 error code. |
| 265 int DiscoverClassicDeviceServicesWorker( | 273 int DiscoverClassicDeviceServicesWorker( |
| 266 const std::string& device_address, | 274 const std::string& device_address, |
| 267 const GUID& protocol_uuid, | 275 const GUID& protocol_uuid, |
| 268 bool search_cached_services_only, | 276 bool search_cached_services_only, |
| 269 ScopedVector<ServiceRecordState>* service_record_states); | 277 std::vector<std::unique_ptr<ServiceRecordState>>* service_record_states); |
| 270 | 278 |
| 271 // Discover Bluetooth Low Energy services for the given |device_path|. | 279 // Discover Bluetooth Low Energy services for the given |device_path|. |
| 272 bool DiscoverLowEnergyDeviceServices( | 280 bool DiscoverLowEnergyDeviceServices( |
| 273 const base::FilePath& device_path, | 281 const base::FilePath& device_path, |
| 274 ScopedVector<ServiceRecordState>* service_record_states); | 282 std::vector<std::unique_ptr<ServiceRecordState>>* service_record_states); |
| 275 | 283 |
| 276 // Search for device paths of the GATT services in |*service_record_states| | 284 // Search for device paths of the GATT services in |*service_record_states| |
| 277 // from |device_address|. | 285 // from |device_address|. |
| 278 bool SearchForGattServiceDevicePaths( | 286 bool SearchForGattServiceDevicePaths( |
| 279 const std::string device_address, | 287 const std::string device_address, |
| 280 ScopedVector<ServiceRecordState>* service_record_states); | 288 std::vector<std::unique_ptr<ServiceRecordState>>* service_record_states); |
| 281 | 289 |
| 282 // GATT service related functions. | 290 // GATT service related functions. |
| 283 void GetGattIncludedCharacteristics( | 291 void GetGattIncludedCharacteristics( |
| 284 base::FilePath device_path, | 292 base::FilePath device_path, |
| 285 BluetoothUUID uuid, | 293 BluetoothUUID uuid, |
| 286 uint16_t attribute_handle, | 294 uint16_t attribute_handle, |
| 287 const GetGattIncludedCharacteristicsCallback& callback); | 295 const GetGattIncludedCharacteristicsCallback& callback); |
| 288 void GetGattIncludedDescriptors( | 296 void GetGattIncludedDescriptors( |
| 289 base::FilePath service_path, | 297 base::FilePath service_path, |
| 290 BTH_LE_GATT_CHARACTERISTIC characteristic, | 298 BTH_LE_GATT_CHARACTERISTIC characteristic, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 // Use for discarding too many log messages. | 332 // Use for discarding too many log messages. |
| 325 base::TimeTicks current_logging_batch_ticks_; | 333 base::TimeTicks current_logging_batch_ticks_; |
| 326 int current_logging_batch_count_; | 334 int current_logging_batch_count_; |
| 327 | 335 |
| 328 DISALLOW_COPY_AND_ASSIGN(BluetoothTaskManagerWin); | 336 DISALLOW_COPY_AND_ASSIGN(BluetoothTaskManagerWin); |
| 329 }; | 337 }; |
| 330 | 338 |
| 331 } // namespace device | 339 } // namespace device |
| 332 | 340 |
| 333 #endif // DEVICE_BLUETOOTH_BLUETOOTH_TASK_MANAGER_WIN_H_ | 341 #endif // DEVICE_BLUETOOTH_BLUETOOTH_TASK_MANAGER_WIN_H_ |
| OLD | NEW |