| 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 30 matching lines...) Expand all Loading... |
| 887 const HResultCallback& callback) { | 907 const HResultCallback& callback) { |
| 888 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 908 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
| 889 bluetooth_task_runner_->PostTask( | 909 bluetooth_task_runner_->PostTask( |
| 890 FROM_HERE, | 910 FROM_HERE, |
| 891 base::Bind(&BluetoothTaskManagerWin::WriteGattCharacteristicValue, this, | 911 base::Bind(&BluetoothTaskManagerWin::WriteGattCharacteristicValue, this, |
| 892 service_path, *characteristic, new_value, callback)); | 912 service_path, *characteristic, new_value, callback)); |
| 893 FOR_EACH_OBSERVER(BluetoothTaskManagerWin::Observer, observers_, | 913 FOR_EACH_OBSERVER(BluetoothTaskManagerWin::Observer, observers_, |
| 894 OnAttemptWriteGattCharacteristic()); | 914 OnAttemptWriteGattCharacteristic()); |
| 895 } | 915 } |
| 896 | 916 |
| 917 void BluetoothTaskManagerWin::PostRegisterGattCharacteristicValueChangedEvent( |
| 918 const base::FilePath& service_path, |
| 919 const PBTH_LE_GATT_CHARACTERISTIC characteristic, |
| 920 const GattEventRegistrationCallback& callback, |
| 921 PFNBLUETOOTH_GATT_EVENT_CALLBACK registered_callback, |
| 922 void* context) { |
| 923 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
| 924 bluetooth_task_runner_->PostTask( |
| 925 FROM_HERE, |
| 926 base::Bind( |
| 927 &BluetoothTaskManagerWin::RegisterGattCharacteristicValueChangedEvent, |
| 928 this, service_path, *characteristic, callback, registered_callback, |
| 929 context)); |
| 930 } |
| 931 |
| 932 void BluetoothTaskManagerWin::UnregisterGattCharacteristicValueChangedEvent( |
| 933 BLUETOOTH_GATT_EVENT_HANDLE event_handle) { |
| 934 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
| 935 win::BluetoothLowEnergyWrapper::GetInstance()->UnregisterGattEvent( |
| 936 event_handle); |
| 937 } |
| 938 |
| 897 } // namespace device | 939 } // namespace device |
| OLD | NEW |