Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(627)

Side by Side Diff: device/bluetooth/bluetooth_task_manager_win.cc

Issue 1739383002: Implement read & write remote GATT characteristic value for Windows (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix conversion from 'size_t' to 'ULONG' error on trybot Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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()
819 ->ReadTheValueOfACharacteristic(
820 service_path, (PBTH_LE_GATT_CHARACTERISTIC)(&characteristic),
821 &win_characteristic_value);
822
823 ui_task_runner_->PostTask(
824 FROM_HERE,
825 base::Bind(callback, base::Passed(&win_characteristic_value), hr));
826 }
827
828 void BluetoothTaskManagerWin::WriteGattCharacteristicValue(
829 base::FilePath service_path,
830 BTH_LE_GATT_CHARACTERISTIC characteristic,
831 std::vector<uint8_t> new_value,
832 const HResultCallback& callback) {
833 ULONG length = (ULONG)(sizeof(ULONG) + new_value.size());
834 scoped_ptr<BTH_LE_GATT_CHARACTERISTIC_VALUE> win_new_value(
835 (PBTH_LE_GATT_CHARACTERISTIC_VALUE)(new UCHAR[length]));
836 win_new_value->DataSize = (ULONG)new_value.size();
837 for (ULONG i = 0; i < new_value.size(); i++)
838 win_new_value->Data[i] = new_value[i];
839
840 HRESULT hr =
841 win::BluetoothLowEnergyWrapper::GetInstance()
842 ->WriteTheValueOfACharacteristic(
843 service_path, (PBTH_LE_GATT_CHARACTERISTIC)(&characteristic),
844 win_new_value.get());
845
846 ui_task_runner_->PostTask(FROM_HERE, base::Bind(callback, hr));
847 }
848
812 void BluetoothTaskManagerWin::PostGetGattIncludedCharacteristics( 849 void BluetoothTaskManagerWin::PostGetGattIncludedCharacteristics(
813 const base::FilePath& service_path, 850 const base::FilePath& service_path,
814 const BluetoothUUID& uuid, 851 const BluetoothUUID& uuid,
815 uint16_t attribute_handle, 852 uint16_t attribute_handle,
816 const GetGattIncludedCharacteristicsCallback& callback) { 853 const GetGattIncludedCharacteristicsCallback& callback) {
817 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); 854 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread());
818 bluetooth_task_runner_->PostTask( 855 bluetooth_task_runner_->PostTask(
819 FROM_HERE, 856 FROM_HERE,
820 base::Bind(&BluetoothTaskManagerWin::GetGattIncludedCharacteristics, this, 857 base::Bind(&BluetoothTaskManagerWin::GetGattIncludedCharacteristics, this,
821 service_path, uuid, attribute_handle, callback)); 858 service_path, uuid, attribute_handle, callback));
822 } 859 }
823 860
824 void BluetoothTaskManagerWin::PostGetGattIncludedDescriptors( 861 void BluetoothTaskManagerWin::PostGetGattIncludedDescriptors(
825 const base::FilePath& service_path, 862 const base::FilePath& service_path,
826 const PBTH_LE_GATT_CHARACTERISTIC characteristic, 863 const PBTH_LE_GATT_CHARACTERISTIC characteristic,
827 const GetGattIncludedDescriptorsCallback& callback) { 864 const GetGattIncludedDescriptorsCallback& callback) {
828 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); 865 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread());
829 bluetooth_task_runner_->PostTask( 866 bluetooth_task_runner_->PostTask(
830 FROM_HERE, 867 FROM_HERE,
831 base::Bind(&BluetoothTaskManagerWin::GetGattIncludedDescriptors, this, 868 base::Bind(&BluetoothTaskManagerWin::GetGattIncludedDescriptors, this,
832 service_path, *characteristic, callback)); 869 service_path, *characteristic, callback));
833 } 870 }
834 871
872 void BluetoothTaskManagerWin::PostReadGattCharacteristicValue(
873 const base::FilePath& service_path,
874 const PBTH_LE_GATT_CHARACTERISTIC characteristic,
875 const ReadGattCharacteristicValueCallback& callback) {
876 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread());
877 bluetooth_task_runner_->PostTask(
878 FROM_HERE,
879 base::Bind(&BluetoothTaskManagerWin::ReadGattCharacteristicValue, this,
880 service_path, *characteristic, callback));
881 FOR_EACH_OBSERVER(BluetoothTaskManagerWin::Observer, observers_,
882 OnAttemptReadGattCharacteristic());
883 }
884
885 void BluetoothTaskManagerWin::PostWriteGattCharacteristicValue(
886 const base::FilePath& service_path,
887 const PBTH_LE_GATT_CHARACTERISTIC characteristic,
888 const std::vector<uint8_t>& new_value,
889 const HResultCallback& callback) {
890 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread());
891 bluetooth_task_runner_->PostTask(
892 FROM_HERE,
893 base::Bind(&BluetoothTaskManagerWin::WriteGattCharacteristicValue, this,
894 service_path, *characteristic, new_value, callback));
895 FOR_EACH_OBSERVER(BluetoothTaskManagerWin::Observer, observers_,
896 OnAttemptWriteGattCharacteristic());
897 }
898
835 } // namespace device 899 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698