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

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: 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::ReadCharacteristicValue(
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::WriteCharacteristicValue(
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 = sizeof(ULONG) + new_value.size();
834 PBTH_LE_GATT_CHARACTERISTIC_VALUE win_new_value =
835 (BTH_LE_GATT_CHARACTERISTIC_VALUE*)malloc(length);
836 win_new_value->DataSize = 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);
845 free(win_new_value);
846
847 ui_task_runner_->PostTask(FROM_HERE, base::Bind(callback, hr));
848 }
849
812 void BluetoothTaskManagerWin::PostGetGattIncludedCharacteristics( 850 void BluetoothTaskManagerWin::PostGetGattIncludedCharacteristics(
813 const base::FilePath& service_path, 851 const base::FilePath& service_path,
814 const BluetoothUUID& uuid, 852 const BluetoothUUID& uuid,
815 uint16_t attribute_handle, 853 uint16_t attribute_handle,
816 const GetGattIncludedCharacteristicsCallback& callback) { 854 const GetGattIncludedCharacteristicsCallback& callback) {
817 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); 855 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread());
818 bluetooth_task_runner_->PostTask( 856 bluetooth_task_runner_->PostTask(
819 FROM_HERE, 857 FROM_HERE,
820 base::Bind(&BluetoothTaskManagerWin::GetGattIncludedCharacteristics, this, 858 base::Bind(&BluetoothTaskManagerWin::GetGattIncludedCharacteristics, this,
821 service_path, uuid, attribute_handle, callback)); 859 service_path, uuid, attribute_handle, callback));
822 } 860 }
823 861
824 void BluetoothTaskManagerWin::PostGetGattIncludedDescriptors( 862 void BluetoothTaskManagerWin::PostGetGattIncludedDescriptors(
825 const base::FilePath& service_path, 863 const base::FilePath& service_path,
826 const PBTH_LE_GATT_CHARACTERISTIC characteristic, 864 const PBTH_LE_GATT_CHARACTERISTIC characteristic,
827 const GetGattIncludedDescriptorsCallback& callback) { 865 const GetGattIncludedDescriptorsCallback& callback) {
828 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); 866 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread());
829 bluetooth_task_runner_->PostTask( 867 bluetooth_task_runner_->PostTask(
830 FROM_HERE, 868 FROM_HERE,
831 base::Bind(&BluetoothTaskManagerWin::GetGattIncludedDescriptors, this, 869 base::Bind(&BluetoothTaskManagerWin::GetGattIncludedDescriptors, this,
832 service_path, *characteristic, callback)); 870 service_path, *characteristic, callback));
833 } 871 }
834 872
873 void BluetoothTaskManagerWin::PostReadCharacteristicValue(
874 const base::FilePath& service_path,
875 const PBTH_LE_GATT_CHARACTERISTIC characteristic,
876 const ReadGattCharacteristicValueCallback& callback) {
877 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread());
878 bluetooth_task_runner_->PostTask(
879 FROM_HERE, base::Bind(&BluetoothTaskManagerWin::ReadCharacteristicValue,
880 this, service_path, *characteristic, callback));
881 FOR_EACH_OBSERVER(BluetoothTaskManagerWin::Observer, observers_,
882 OnBluetoothAttemptReadGattCharacteristic());
883 }
884
885 void BluetoothTaskManagerWin::PostWriteCharacteristicValue(
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::WriteCharacteristicValue, this,
894 service_path, *characteristic, new_value, callback));
895 FOR_EACH_OBSERVER(BluetoothTaskManagerWin::Observer, observers_,
896 OnBluetoothAttemptWriteGattCharacteristic());
897 }
898
835 } // namespace device 899 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698