| 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 826 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 837 win_new_value->Data[i] = new_value[i]; | 837 win_new_value->Data[i] = new_value[i]; |
| 838 | 838 |
| 839 HRESULT hr = | 839 HRESULT hr = |
| 840 win::BluetoothLowEnergyWrapper::GetInstance()->WriteCharacteristicValue( | 840 win::BluetoothLowEnergyWrapper::GetInstance()->WriteCharacteristicValue( |
| 841 service_path, (PBTH_LE_GATT_CHARACTERISTIC)(&characteristic), | 841 service_path, (PBTH_LE_GATT_CHARACTERISTIC)(&characteristic), |
| 842 win_new_value.get()); | 842 win_new_value.get()); |
| 843 | 843 |
| 844 ui_task_runner_->PostTask(FROM_HERE, base::Bind(callback, hr)); | 844 ui_task_runner_->PostTask(FROM_HERE, base::Bind(callback, hr)); |
| 845 } | 845 } |
| 846 | 846 |
| 847 void BluetoothTaskManagerWin::RegisterGattCharacteristicValueChangedEvent( |
| 848 base::FilePath service_path, |
| 849 BTH_LE_GATT_CHARACTERISTIC characteristic, |
| 850 const GattEventRegistrationCallback& callback, |
| 851 PFNBLUETOOTH_GATT_EVENT_CALLBACK registered_callback, |
| 852 void* context) { |
| 853 BLUETOOTH_GATT_EVENT_HANDLE event_handle = NULL; |
| 854 |
| 855 BLUETOOTH_GATT_VALUE_CHANGED_EVENT_REGISTRATION event_parameter; |
| 856 memcpy(&(event_parameter.Characteristics[0]), &characteristic, |
| 857 sizeof(BTH_LE_GATT_CHARACTERISTIC)); |
| 858 event_parameter.NumCharacteristics = 1; |
| 859 HRESULT hr = |
| 860 win::BluetoothLowEnergyWrapper::GetInstance()->RegisterGattEvents( |
| 861 service_path, CharacteristicValueChangedEvent, &event_parameter, |
| 862 registered_callback, context, &event_handle); |
| 863 |
| 864 ui_task_runner_->PostTask(FROM_HERE, base::Bind(callback, event_handle, hr)); |
| 865 } |
| 866 |
| 847 void BluetoothTaskManagerWin::PostGetGattIncludedCharacteristics( | 867 void BluetoothTaskManagerWin::PostGetGattIncludedCharacteristics( |
| 848 const base::FilePath& service_path, | 868 const base::FilePath& service_path, |
| 849 const BluetoothUUID& uuid, | 869 const BluetoothUUID& uuid, |
| 850 uint16_t attribute_handle, | 870 uint16_t attribute_handle, |
| 851 const GetGattIncludedCharacteristicsCallback& callback) { | 871 const GetGattIncludedCharacteristicsCallback& callback) { |
| 852 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 872 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
| 853 bluetooth_task_runner_->PostTask( | 873 bluetooth_task_runner_->PostTask( |
| 854 FROM_HERE, | 874 FROM_HERE, |
| 855 base::Bind(&BluetoothTaskManagerWin::GetGattIncludedCharacteristics, this, | 875 base::Bind(&BluetoothTaskManagerWin::GetGattIncludedCharacteristics, this, |
| 856 service_path, uuid, attribute_handle, callback)); | 876 service_path, uuid, attribute_handle, callback)); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 869 | 889 |
| 870 void BluetoothTaskManagerWin::PostReadGattCharacteristicValue( | 890 void BluetoothTaskManagerWin::PostReadGattCharacteristicValue( |
| 871 const base::FilePath& service_path, | 891 const base::FilePath& service_path, |
| 872 const PBTH_LE_GATT_CHARACTERISTIC characteristic, | 892 const PBTH_LE_GATT_CHARACTERISTIC characteristic, |
| 873 const ReadGattCharacteristicValueCallback& callback) { | 893 const ReadGattCharacteristicValueCallback& callback) { |
| 874 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 894 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
| 875 bluetooth_task_runner_->PostTask( | 895 bluetooth_task_runner_->PostTask( |
| 876 FROM_HERE, | 896 FROM_HERE, |
| 877 base::Bind(&BluetoothTaskManagerWin::ReadGattCharacteristicValue, this, | 897 base::Bind(&BluetoothTaskManagerWin::ReadGattCharacteristicValue, this, |
| 878 service_path, *characteristic, callback)); | 898 service_path, *characteristic, callback)); |
| 879 FOR_EACH_OBSERVER(BluetoothTaskManagerWin::Observer, observers_, | |
| 880 OnAttemptReadGattCharacteristic()); | |
| 881 } | 899 } |
| 882 | 900 |
| 883 void BluetoothTaskManagerWin::PostWriteGattCharacteristicValue( | 901 void BluetoothTaskManagerWin::PostWriteGattCharacteristicValue( |
| 884 const base::FilePath& service_path, | 902 const base::FilePath& service_path, |
| 885 const PBTH_LE_GATT_CHARACTERISTIC characteristic, | 903 const PBTH_LE_GATT_CHARACTERISTIC characteristic, |
| 886 const std::vector<uint8_t>& new_value, | 904 const std::vector<uint8_t>& new_value, |
| 887 const HResultCallback& callback) { | 905 const HResultCallback& callback) { |
| 888 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 906 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
| 889 bluetooth_task_runner_->PostTask( | 907 bluetooth_task_runner_->PostTask( |
| 890 FROM_HERE, | 908 FROM_HERE, |
| 891 base::Bind(&BluetoothTaskManagerWin::WriteGattCharacteristicValue, this, | 909 base::Bind(&BluetoothTaskManagerWin::WriteGattCharacteristicValue, this, |
| 892 service_path, *characteristic, new_value, callback)); | 910 service_path, *characteristic, new_value, callback)); |
| 893 FOR_EACH_OBSERVER(BluetoothTaskManagerWin::Observer, observers_, | 911 } |
| 894 OnAttemptWriteGattCharacteristic()); | 912 |
| 913 void BluetoothTaskManagerWin::PostRegisterGattCharacteristicValueChangedEvent( |
| 914 const base::FilePath& service_path, |
| 915 const PBTH_LE_GATT_CHARACTERISTIC characteristic, |
| 916 const GattEventRegistrationCallback& callback, |
| 917 PFNBLUETOOTH_GATT_EVENT_CALLBACK registered_callback, |
| 918 void* context) { |
| 919 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
| 920 bluetooth_task_runner_->PostTask( |
| 921 FROM_HERE, |
| 922 base::Bind( |
| 923 &BluetoothTaskManagerWin::RegisterGattCharacteristicValueChangedEvent, |
| 924 this, service_path, *characteristic, callback, registered_callback, |
| 925 context)); |
| 926 } |
| 927 |
| 928 void BluetoothTaskManagerWin::UnregisterGattCharacteristicValueChangedEvent( |
| 929 BLUETOOTH_GATT_EVENT_HANDLE event_handle) { |
| 930 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
| 931 win::BluetoothLowEnergyWrapper::GetInstance()->UnregisterGattEvent( |
| 932 event_handle); |
| 895 } | 933 } |
| 896 | 934 |
| 897 } // namespace device | 935 } // namespace device |
| OLD | NEW |