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