| 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 OnAttemptReadGattCharacteristic() {} | |
| 103 virtual void OnAttemptWriteGattCharacteristic() {} | |
| 104 }; | 102 }; |
| 105 | 103 |
| 106 explicit BluetoothTaskManagerWin( | 104 explicit BluetoothTaskManagerWin( |
| 107 scoped_refptr<base::SequencedTaskRunner> ui_task_runner); | 105 scoped_refptr<base::SequencedTaskRunner> ui_task_runner); |
| 108 | 106 |
| 109 static BluetoothUUID BluetoothLowEnergyUuidToBluetoothUuid( | 107 static BluetoothUUID BluetoothLowEnergyUuidToBluetoothUuid( |
| 110 const BTH_LE_UUID& bth_le_uuid); | 108 const BTH_LE_UUID& bth_le_uuid); |
| 111 | 109 |
| 112 void AddObserver(Observer* observer); | 110 void AddObserver(Observer* observer); |
| 113 void RemoveObserver(Observer* observer); | 111 void RemoveObserver(Observer* observer); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 128 typedef base::Callback<void(HRESULT)> HResultCallback; | 126 typedef base::Callback<void(HRESULT)> HResultCallback; |
| 129 typedef base::Callback< | 127 typedef base::Callback< |
| 130 void(scoped_ptr<BTH_LE_GATT_CHARACTERISTIC>, uint16_t, HRESULT)> | 128 void(scoped_ptr<BTH_LE_GATT_CHARACTERISTIC>, uint16_t, HRESULT)> |
| 131 GetGattIncludedCharacteristicsCallback; | 129 GetGattIncludedCharacteristicsCallback; |
| 132 typedef base::Callback< | 130 typedef base::Callback< |
| 133 void(scoped_ptr<BTH_LE_GATT_DESCRIPTOR>, uint16_t, HRESULT)> | 131 void(scoped_ptr<BTH_LE_GATT_DESCRIPTOR>, uint16_t, HRESULT)> |
| 134 GetGattIncludedDescriptorsCallback; | 132 GetGattIncludedDescriptorsCallback; |
| 135 typedef base::Callback<void(scoped_ptr<BTH_LE_GATT_CHARACTERISTIC_VALUE>, | 133 typedef base::Callback<void(scoped_ptr<BTH_LE_GATT_CHARACTERISTIC_VALUE>, |
| 136 HRESULT)> | 134 HRESULT)> |
| 137 ReadGattCharacteristicValueCallback; | 135 ReadGattCharacteristicValueCallback; |
| 136 typedef base::Callback<void(BLUETOOTH_GATT_EVENT_HANDLE, HRESULT)> |
| 137 GattEventRegistrationCallback; |
| 138 | 138 |
| 139 // Get all included characteristics of a given service. The service is | 139 // Get all included characteristics of a given service. The service is |
| 140 // uniquely identified by its |uuid| and |attribute_handle| with service | 140 // uniquely identified by its |uuid| and |attribute_handle| with service |
| 141 // device |service_path|. The result is returned asynchronously through | 141 // device |service_path|. The result is returned asynchronously through |
| 142 // |callback|. | 142 // |callback|. |
| 143 void PostGetGattIncludedCharacteristics( | 143 void PostGetGattIncludedCharacteristics( |
| 144 const base::FilePath& service_path, | 144 const base::FilePath& service_path, |
| 145 const BluetoothUUID& uuid, | 145 const BluetoothUUID& uuid, |
| 146 uint16_t attribute_handle, | 146 uint16_t attribute_handle, |
| 147 const GetGattIncludedCharacteristicsCallback& callback); | 147 const GetGattIncludedCharacteristicsCallback& callback); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 163 | 163 |
| 164 // Post write the value of a given |characteristic| in service with | 164 // Post write the value of a given |characteristic| in service with |
| 165 // |service_path| to |new_value|. The operation result is returned | 165 // |service_path| to |new_value|. The operation result is returned |
| 166 // asynchronously through |callback|. | 166 // asynchronously through |callback|. |
| 167 void PostWriteGattCharacteristicValue( | 167 void PostWriteGattCharacteristicValue( |
| 168 const base::FilePath& service_path, | 168 const base::FilePath& service_path, |
| 169 const PBTH_LE_GATT_CHARACTERISTIC characteristic, | 169 const PBTH_LE_GATT_CHARACTERISTIC characteristic, |
| 170 const std::vector<uint8_t>& new_value, | 170 const std::vector<uint8_t>& new_value, |
| 171 const HResultCallback& callback); | 171 const HResultCallback& callback); |
| 172 | 172 |
| 173 // Post register a given |characteristic|'s value change notification of a |
| 174 // service with |service_path|. |registered_callback| is the function to be |
| 175 // invoked if the event occured. |context| is a void pointer from caller which |
| 176 // will be given back to caller through |registered_callback|. The operation |
| 177 // result is returned asynchronously through |callback|. |
| 178 void PostRegisterGattCharacteristicValueChangedEvent( |
| 179 const base::FilePath& service_path, |
| 180 const PBTH_LE_GATT_CHARACTERISTIC characteristic, |
| 181 const GattEventRegistrationCallback& callback, |
| 182 PFNBLUETOOTH_GATT_EVENT_CALLBACK registered_callback, |
| 183 void* context); |
| 184 |
| 185 // Unregister characteristic value change notification. |event_handle| was |
| 186 // returned by PostRegisterGattCharacteristicValueChangedEvent. |
| 187 void UnregisterGattCharacteristicValueChangedEvent( |
| 188 BLUETOOTH_GATT_EVENT_HANDLE event_handle); |
| 189 |
| 173 private: | 190 private: |
| 174 friend class base::RefCountedThreadSafe<BluetoothTaskManagerWin>; | 191 friend class base::RefCountedThreadSafe<BluetoothTaskManagerWin>; |
| 175 friend class BluetoothTaskManagerWinTest; | 192 friend class BluetoothTaskManagerWinTest; |
| 176 | 193 |
| 177 static const int kPollIntervalMs; | 194 static const int kPollIntervalMs; |
| 178 | 195 |
| 179 virtual ~BluetoothTaskManagerWin(); | 196 virtual ~BluetoothTaskManagerWin(); |
| 180 | 197 |
| 181 // Logs Win32 errors occurring during polling on the worker thread. The method | 198 // Logs Win32 errors occurring during polling on the worker thread. The method |
| 182 // may discard messages to avoid logging being too verbose. | 199 // may discard messages to avoid logging being too verbose. |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 BTH_LE_GATT_CHARACTERISTIC characteristic, | 288 BTH_LE_GATT_CHARACTERISTIC characteristic, |
| 272 const GetGattIncludedDescriptorsCallback& callback); | 289 const GetGattIncludedDescriptorsCallback& callback); |
| 273 void ReadGattCharacteristicValue( | 290 void ReadGattCharacteristicValue( |
| 274 base::FilePath device_path, | 291 base::FilePath device_path, |
| 275 BTH_LE_GATT_CHARACTERISTIC characteristic, | 292 BTH_LE_GATT_CHARACTERISTIC characteristic, |
| 276 const ReadGattCharacteristicValueCallback& callback); | 293 const ReadGattCharacteristicValueCallback& callback); |
| 277 void WriteGattCharacteristicValue(base::FilePath service_path, | 294 void WriteGattCharacteristicValue(base::FilePath service_path, |
| 278 BTH_LE_GATT_CHARACTERISTIC characteristic, | 295 BTH_LE_GATT_CHARACTERISTIC characteristic, |
| 279 std::vector<uint8_t> new_value, | 296 std::vector<uint8_t> new_value, |
| 280 const HResultCallback& callback); | 297 const HResultCallback& callback); |
| 298 void RegisterGattCharacteristicValueChangedEvent( |
| 299 base::FilePath service_path, |
| 300 BTH_LE_GATT_CHARACTERISTIC characteristic, |
| 301 const GattEventRegistrationCallback& callback, |
| 302 PFNBLUETOOTH_GATT_EVENT_CALLBACK registered_callback, |
| 303 void* context); |
| 281 | 304 |
| 282 // UI task runner reference. | 305 // UI task runner reference. |
| 283 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_; | 306 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_; |
| 284 | 307 |
| 285 scoped_refptr<base::SequencedWorkerPool> worker_pool_; | 308 scoped_refptr<base::SequencedWorkerPool> worker_pool_; |
| 286 scoped_refptr<base::SequencedTaskRunner> bluetooth_task_runner_; | 309 scoped_refptr<base::SequencedTaskRunner> bluetooth_task_runner_; |
| 287 | 310 |
| 288 // List of observers interested in event notifications. | 311 // List of observers interested in event notifications. |
| 289 base::ObserverList<Observer> observers_; | 312 base::ObserverList<Observer> observers_; |
| 290 | 313 |
| 291 // Weak reference of the adapter handle, let BluetoothClassicWrapper handle | 314 // Weak reference of the adapter handle, let BluetoothClassicWrapper handle |
| 292 // the close of |adapter_handle_|. | 315 // the close of |adapter_handle_|. |
| 293 HANDLE adapter_handle_; | 316 HANDLE adapter_handle_; |
| 294 | 317 |
| 295 // indicates whether the adapter is in discovery mode or not. | 318 // indicates whether the adapter is in discovery mode or not. |
| 296 bool discovering_; | 319 bool discovering_; |
| 297 | 320 |
| 298 // Use for discarding too many log messages. | 321 // Use for discarding too many log messages. |
| 299 base::TimeTicks current_logging_batch_ticks_; | 322 base::TimeTicks current_logging_batch_ticks_; |
| 300 int current_logging_batch_count_; | 323 int current_logging_batch_count_; |
| 301 | 324 |
| 302 DISALLOW_COPY_AND_ASSIGN(BluetoothTaskManagerWin); | 325 DISALLOW_COPY_AND_ASSIGN(BluetoothTaskManagerWin); |
| 303 }; | 326 }; |
| 304 | 327 |
| 305 } // namespace device | 328 } // namespace device |
| 306 | 329 |
| 307 #endif // DEVICE_BLUETOOTH_BLUETOOTH_TASK_MANAGER_WIN_H_ | 330 #endif // DEVICE_BLUETOOTH_BLUETOOTH_TASK_MANAGER_WIN_H_ |
| OLD | NEW |