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 #include "device/bluetooth/bluetooth_task_manager_win.h" | 5 #include "device/bluetooth/bluetooth_task_manager_win.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <winsock2.h> | 8 #include <winsock2.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
(...skipping 791 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
802 win::BluetoothLowEnergyWrapper::GetInstance() | 802 win::BluetoothLowEnergyWrapper::GetInstance() |
803 ->ReadDescriptorsOfACharacteristic( | 803 ->ReadDescriptorsOfACharacteristic( |
804 service_path, (PBTH_LE_GATT_CHARACTERISTIC)(&characteristic), | 804 service_path, (PBTH_LE_GATT_CHARACTERISTIC)(&characteristic), |
805 &win_descriptors_info, &number_of_descriptors); | 805 &win_descriptors_info, &number_of_descriptors); |
806 | 806 |
807 ui_task_runner_->PostTask( | 807 ui_task_runner_->PostTask( |
808 FROM_HERE, base::Bind(callback, base::Passed(&win_descriptors_info), | 808 FROM_HERE, base::Bind(callback, base::Passed(&win_descriptors_info), |
809 number_of_descriptors, hr)); | 809 number_of_descriptors, hr)); |
810 } | 810 } |
811 | 811 |
| 812 void BluetoothTaskManagerWin::ReadGattCharacteristicValue( |
| 813 base::FilePath service_path, |
| 814 BTH_LE_GATT_CHARACTERISTIC characteristic, |
| 815 const ReadGattCharacteristicValueCallback& callback) { |
| 816 scoped_ptr<BTH_LE_GATT_CHARACTERISTIC_VALUE> win_characteristic_value; |
| 817 HRESULT hr = |
| 818 win::BluetoothLowEnergyWrapper::GetInstance()->ReadCharacteristicValue( |
| 819 service_path, (PBTH_LE_GATT_CHARACTERISTIC)(&characteristic), |
| 820 &win_characteristic_value); |
| 821 |
| 822 ui_task_runner_->PostTask( |
| 823 FROM_HERE, |
| 824 base::Bind(callback, base::Passed(&win_characteristic_value), hr)); |
| 825 } |
| 826 |
| 827 void BluetoothTaskManagerWin::WriteGattCharacteristicValue( |
| 828 base::FilePath service_path, |
| 829 BTH_LE_GATT_CHARACTERISTIC characteristic, |
| 830 std::vector<uint8_t> new_value, |
| 831 const HResultCallback& callback) { |
| 832 ULONG length = (ULONG)(sizeof(ULONG) + new_value.size()); |
| 833 scoped_ptr<BTH_LE_GATT_CHARACTERISTIC_VALUE> win_new_value( |
| 834 (PBTH_LE_GATT_CHARACTERISTIC_VALUE)(new UCHAR[length])); |
| 835 win_new_value->DataSize = (ULONG)new_value.size(); |
| 836 for (ULONG i = 0; i < new_value.size(); i++) |
| 837 win_new_value->Data[i] = new_value[i]; |
| 838 |
| 839 HRESULT hr = |
| 840 win::BluetoothLowEnergyWrapper::GetInstance()->WriteCharacteristicValue( |
| 841 service_path, (PBTH_LE_GATT_CHARACTERISTIC)(&characteristic), |
| 842 win_new_value.get()); |
| 843 |
| 844 ui_task_runner_->PostTask(FROM_HERE, base::Bind(callback, hr)); |
| 845 } |
| 846 |
812 void BluetoothTaskManagerWin::PostGetGattIncludedCharacteristics( | 847 void BluetoothTaskManagerWin::PostGetGattIncludedCharacteristics( |
813 const base::FilePath& service_path, | 848 const base::FilePath& service_path, |
814 const BluetoothUUID& uuid, | 849 const BluetoothUUID& uuid, |
815 uint16_t attribute_handle, | 850 uint16_t attribute_handle, |
816 const GetGattIncludedCharacteristicsCallback& callback) { | 851 const GetGattIncludedCharacteristicsCallback& callback) { |
817 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 852 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
818 bluetooth_task_runner_->PostTask( | 853 bluetooth_task_runner_->PostTask( |
819 FROM_HERE, | 854 FROM_HERE, |
820 base::Bind(&BluetoothTaskManagerWin::GetGattIncludedCharacteristics, this, | 855 base::Bind(&BluetoothTaskManagerWin::GetGattIncludedCharacteristics, this, |
821 service_path, uuid, attribute_handle, callback)); | 856 service_path, uuid, attribute_handle, callback)); |
822 } | 857 } |
823 | 858 |
824 void BluetoothTaskManagerWin::PostGetGattIncludedDescriptors( | 859 void BluetoothTaskManagerWin::PostGetGattIncludedDescriptors( |
825 const base::FilePath& service_path, | 860 const base::FilePath& service_path, |
826 const PBTH_LE_GATT_CHARACTERISTIC characteristic, | 861 const PBTH_LE_GATT_CHARACTERISTIC characteristic, |
827 const GetGattIncludedDescriptorsCallback& callback) { | 862 const GetGattIncludedDescriptorsCallback& callback) { |
828 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 863 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
829 bluetooth_task_runner_->PostTask( | 864 bluetooth_task_runner_->PostTask( |
830 FROM_HERE, | 865 FROM_HERE, |
831 base::Bind(&BluetoothTaskManagerWin::GetGattIncludedDescriptors, this, | 866 base::Bind(&BluetoothTaskManagerWin::GetGattIncludedDescriptors, this, |
832 service_path, *characteristic, callback)); | 867 service_path, *characteristic, callback)); |
833 } | 868 } |
834 | 869 |
| 870 void BluetoothTaskManagerWin::PostReadGattCharacteristicValue( |
| 871 const base::FilePath& service_path, |
| 872 const PBTH_LE_GATT_CHARACTERISTIC characteristic, |
| 873 const ReadGattCharacteristicValueCallback& callback) { |
| 874 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
| 875 bluetooth_task_runner_->PostTask( |
| 876 FROM_HERE, |
| 877 base::Bind(&BluetoothTaskManagerWin::ReadGattCharacteristicValue, this, |
| 878 service_path, *characteristic, callback)); |
| 879 FOR_EACH_OBSERVER(BluetoothTaskManagerWin::Observer, observers_, |
| 880 OnAttemptReadGattCharacteristic()); |
| 881 } |
| 882 |
| 883 void BluetoothTaskManagerWin::PostWriteGattCharacteristicValue( |
| 884 const base::FilePath& service_path, |
| 885 const PBTH_LE_GATT_CHARACTERISTIC characteristic, |
| 886 const std::vector<uint8_t>& new_value, |
| 887 const HResultCallback& callback) { |
| 888 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
| 889 bluetooth_task_runner_->PostTask( |
| 890 FROM_HERE, |
| 891 base::Bind(&BluetoothTaskManagerWin::WriteGattCharacteristicValue, this, |
| 892 service_path, *characteristic, new_value, callback)); |
| 893 FOR_EACH_OBSERVER(BluetoothTaskManagerWin::Observer, observers_, |
| 894 OnAttemptWriteGattCharacteristic()); |
| 895 } |
| 896 |
835 } // namespace device | 897 } // namespace device |
OLD | NEW |