| 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 <string> | 10 #include <string> |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 virtual void DiscoveryStarted(bool success) {} | 92 virtual void DiscoveryStarted(bool success) {} |
| 93 virtual void DiscoveryStopped() {} | 93 virtual void DiscoveryStopped() {} |
| 94 // Called when the adapter has just been polled for the list of *all* known | 94 // Called when the adapter has just been polled for the list of *all* known |
| 95 // devices. This includes devices previously paired, devices paired using | 95 // devices. This includes devices previously paired, devices paired using |
| 96 // the underlying Operating System UI, and devices discovered recently due | 96 // the underlying Operating System UI, and devices discovered recently due |
| 97 // to an active discovery session. Note that for a given device (address), | 97 // to an active discovery session. Note that for a given device (address), |
| 98 // the associated state can change over time. For example, during a | 98 // the associated state can change over time. For example, during a |
| 99 // discovery session, the "friendly" name may initially be "unknown" before | 99 // discovery session, the "friendly" name may initially be "unknown" before |
| 100 // the actual name is retrieved in subsequent poll events. | 100 // the actual name is retrieved in subsequent poll events. |
| 101 virtual void DevicesPolled(const ScopedVector<DeviceState>& devices) {} | 101 virtual void DevicesPolled(const ScopedVector<DeviceState>& devices) {} |
| 102 virtual void OnBluetoothAttemptReadGattCharacteristic() {} |
| 103 virtual void OnBluetoothAttemptWriteGattCharacteristic() {} |
| 102 }; | 104 }; |
| 103 | 105 |
| 104 explicit BluetoothTaskManagerWin( | 106 explicit BluetoothTaskManagerWin( |
| 105 scoped_refptr<base::SequencedTaskRunner> ui_task_runner); | 107 scoped_refptr<base::SequencedTaskRunner> ui_task_runner); |
| 106 | 108 |
| 107 static BluetoothUUID BluetoothLowEnergyUuidToBluetoothUuid( | 109 static BluetoothUUID BluetoothLowEnergyUuidToBluetoothUuid( |
| 108 const BTH_LE_UUID& bth_le_uuid); | 110 const BTH_LE_UUID& bth_le_uuid); |
| 109 | 111 |
| 110 void AddObserver(Observer* observer); | 112 void AddObserver(Observer* observer); |
| 111 void RemoveObserver(Observer* observer); | 113 void RemoveObserver(Observer* observer); |
| 112 | 114 |
| 113 void Initialize(); | 115 void Initialize(); |
| 114 void InitializeWithBluetoothTaskRunner( | 116 void InitializeWithBluetoothTaskRunner( |
| 115 scoped_refptr<base::SequencedTaskRunner> bluetooth_task_runner); | 117 scoped_refptr<base::SequencedTaskRunner> bluetooth_task_runner); |
| 116 void Shutdown(); | 118 void Shutdown(); |
| 117 | 119 |
| 118 void PostSetPoweredBluetoothTask( | 120 void PostSetPoweredBluetoothTask( |
| 119 bool powered, | 121 bool powered, |
| 120 const base::Closure& callback, | 122 const base::Closure& callback, |
| 121 const BluetoothAdapter::ErrorCallback& error_callback); | 123 const BluetoothAdapter::ErrorCallback& error_callback); |
| 122 void PostStartDiscoveryTask(); | 124 void PostStartDiscoveryTask(); |
| 123 void PostStopDiscoveryTask(); | 125 void PostStopDiscoveryTask(); |
| 124 | 126 |
| 125 // Callbacks of asynchronous operations of GATT service. | 127 // Callbacks of asynchronous operations of GATT service. |
| 128 typedef base::Callback<void(HRESULT)> HResultCallback; |
| 126 typedef base::Callback< | 129 typedef base::Callback< |
| 127 void(scoped_ptr<BTH_LE_GATT_CHARACTERISTIC>, uint16_t, HRESULT)> | 130 void(scoped_ptr<BTH_LE_GATT_CHARACTERISTIC>, uint16_t, HRESULT)> |
| 128 GetGattIncludedCharacteristicsCallback; | 131 GetGattIncludedCharacteristicsCallback; |
| 129 typedef base::Callback< | 132 typedef base::Callback< |
| 130 void(scoped_ptr<BTH_LE_GATT_DESCRIPTOR>, uint16_t, HRESULT)> | 133 void(scoped_ptr<BTH_LE_GATT_DESCRIPTOR>, uint16_t, HRESULT)> |
| 131 GetGattIncludedDescriptorsCallback; | 134 GetGattIncludedDescriptorsCallback; |
| 135 typedef base::Callback<void(scoped_ptr<BTH_LE_GATT_CHARACTERISTIC_VALUE>, |
| 136 HRESULT)> |
| 137 ReadGattCharacteristicValueCallback; |
| 132 | 138 |
| 133 // Get all included characteristics of a given service. The service is | 139 // Get all included characteristics of a given service. The service is |
| 134 // uniquely identified by its |uuid| and |attribute_handle| with service | 140 // uniquely identified by its |uuid| and |attribute_handle| with service |
| 135 // device |service_path|. The result is returned asynchronously through | 141 // device |service_path|. The result is returned asynchronously through |
| 136 // |callback|. | 142 // |callback|. |
| 137 void PostGetGattIncludedCharacteristics( | 143 void PostGetGattIncludedCharacteristics( |
| 138 const base::FilePath& service_path, | 144 const base::FilePath& service_path, |
| 139 const BluetoothUUID& uuid, | 145 const BluetoothUUID& uuid, |
| 140 uint16_t attribute_handle, | 146 uint16_t attribute_handle, |
| 141 const GetGattIncludedCharacteristicsCallback& callback); | 147 const GetGattIncludedCharacteristicsCallback& callback); |
| 142 | 148 |
| 143 // Get all included descriptors of a given |characterisitc| in service | 149 // Get all included descriptors of a given |characterisitc| in service |
| 144 // with |service_path|. The result is returned asynchronously through | 150 // with |service_path|. The result is returned asynchronously through |
| 145 // |callback|. | 151 // |callback|. |
| 146 void PostGetGattIncludedDescriptors( | 152 void PostGetGattIncludedDescriptors( |
| 147 const base::FilePath& service_path, | 153 const base::FilePath& service_path, |
| 148 const PBTH_LE_GATT_CHARACTERISTIC characteristic, | 154 const PBTH_LE_GATT_CHARACTERISTIC characteristic, |
| 149 const GetGattIncludedDescriptorsCallback& callback); | 155 const GetGattIncludedDescriptorsCallback& callback); |
| 150 | 156 |
| 157 // Post read the value of a given |characteristic| in service with |
| 158 // |service_path|. The result is returned asynchronously through |callback|. |
| 159 void PostReadCharacteristicValue( |
| 160 const base::FilePath& device_path, |
| 161 const PBTH_LE_GATT_CHARACTERISTIC characteristic, |
| 162 const ReadGattCharacteristicValueCallback& callback); |
| 163 |
| 164 // Post write the value of a given |characteristic| in service with |
| 165 // |service_path| to |new_value|. The operation result is returned |
| 166 // asynchronously through |callback|. |
| 167 void PostWriteCharacteristicValue( |
| 168 const base::FilePath& service_path, |
| 169 const PBTH_LE_GATT_CHARACTERISTIC characteristic, |
| 170 const std::vector<uint8_t>& new_value, |
| 171 const HResultCallback& callback); |
| 172 |
| 151 private: | 173 private: |
| 152 friend class base::RefCountedThreadSafe<BluetoothTaskManagerWin>; | 174 friend class base::RefCountedThreadSafe<BluetoothTaskManagerWin>; |
| 153 friend class BluetoothTaskManagerWinTest; | 175 friend class BluetoothTaskManagerWinTest; |
| 154 | 176 |
| 155 static const int kPollIntervalMs; | 177 static const int kPollIntervalMs; |
| 156 | 178 |
| 157 virtual ~BluetoothTaskManagerWin(); | 179 virtual ~BluetoothTaskManagerWin(); |
| 158 | 180 |
| 159 // Logs Win32 errors occurring during polling on the worker thread. The method | 181 // Logs Win32 errors occurring during polling on the worker thread. The method |
| 160 // may discard messages to avoid logging being too verbose. | 182 // may discard messages to avoid logging being too verbose. |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 // GATT service related functions. | 263 // GATT service related functions. |
| 242 void GetGattIncludedCharacteristics( | 264 void GetGattIncludedCharacteristics( |
| 243 base::FilePath device_path, | 265 base::FilePath device_path, |
| 244 BluetoothUUID uuid, | 266 BluetoothUUID uuid, |
| 245 uint16_t attribute_handle, | 267 uint16_t attribute_handle, |
| 246 const GetGattIncludedCharacteristicsCallback& callback); | 268 const GetGattIncludedCharacteristicsCallback& callback); |
| 247 void GetGattIncludedDescriptors( | 269 void GetGattIncludedDescriptors( |
| 248 base::FilePath service_path, | 270 base::FilePath service_path, |
| 249 BTH_LE_GATT_CHARACTERISTIC characteristic, | 271 BTH_LE_GATT_CHARACTERISTIC characteristic, |
| 250 const GetGattIncludedDescriptorsCallback& callback); | 272 const GetGattIncludedDescriptorsCallback& callback); |
| 273 void ReadCharacteristicValue( |
| 274 base::FilePath device_path, |
| 275 BTH_LE_GATT_CHARACTERISTIC characteristic, |
| 276 const ReadGattCharacteristicValueCallback& callback); |
| 277 void WriteCharacteristicValue(base::FilePath service_path, |
| 278 BTH_LE_GATT_CHARACTERISTIC characteristic, |
| 279 std::vector<uint8_t> new_value, |
| 280 const HResultCallback& callback); |
| 251 | 281 |
| 252 // UI task runner reference. | 282 // UI task runner reference. |
| 253 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_; | 283 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_; |
| 254 | 284 |
| 255 scoped_refptr<base::SequencedWorkerPool> worker_pool_; | 285 scoped_refptr<base::SequencedWorkerPool> worker_pool_; |
| 256 scoped_refptr<base::SequencedTaskRunner> bluetooth_task_runner_; | 286 scoped_refptr<base::SequencedTaskRunner> bluetooth_task_runner_; |
| 257 | 287 |
| 258 // List of observers interested in event notifications. | 288 // List of observers interested in event notifications. |
| 259 base::ObserverList<Observer> observers_; | 289 base::ObserverList<Observer> observers_; |
| 260 | 290 |
| 261 // Weak reference of the adapter handle, let BluetoothClassicWrapper handle | 291 // Weak reference of the adapter handle, let BluetoothClassicWrapper handle |
| 262 // the close of |adapter_handle_|. | 292 // the close of |adapter_handle_|. |
| 263 HANDLE adapter_handle_; | 293 HANDLE adapter_handle_; |
| 264 | 294 |
| 265 // indicates whether the adapter is in discovery mode or not. | 295 // indicates whether the adapter is in discovery mode or not. |
| 266 bool discovering_; | 296 bool discovering_; |
| 267 | 297 |
| 268 // Use for discarding too many log messages. | 298 // Use for discarding too many log messages. |
| 269 base::TimeTicks current_logging_batch_ticks_; | 299 base::TimeTicks current_logging_batch_ticks_; |
| 270 int current_logging_batch_count_; | 300 int current_logging_batch_count_; |
| 271 | 301 |
| 272 DISALLOW_COPY_AND_ASSIGN(BluetoothTaskManagerWin); | 302 DISALLOW_COPY_AND_ASSIGN(BluetoothTaskManagerWin); |
| 273 }; | 303 }; |
| 274 | 304 |
| 275 } // namespace device | 305 } // namespace device |
| 276 | 306 |
| 277 #endif // DEVICE_BLUETOOTH_BLUETOOTH_TASK_MANAGER_WIN_H_ | 307 #endif // DEVICE_BLUETOOTH_BLUETOOTH_TASK_MANAGER_WIN_H_ |
| OLD | NEW |