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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 DCHECK_EQ(result, device::BluetoothDevice::CanonicalizeAddress(result)); | 51 DCHECK_EQ(result, device::BluetoothDevice::CanonicalizeAddress(result)); |
52 return result; | 52 return result; |
53 } | 53 } |
54 | 54 |
55 bool BluetoothUUIDToWinBLEUUID(const device::BluetoothUUID& uuid, | 55 bool BluetoothUUIDToWinBLEUUID(const device::BluetoothUUID& uuid, |
56 BTH_LE_UUID* out_win_uuid) { | 56 BTH_LE_UUID* out_win_uuid) { |
57 if (!uuid.IsValid()) | 57 if (!uuid.IsValid()) |
58 return false; | 58 return false; |
59 | 59 |
60 if (uuid.format() == device::BluetoothUUID::kFormat16Bit) { | 60 if (uuid.format() == device::BluetoothUUID::kFormat16Bit) { |
61 out_win_uuid->IsShortUuid = true; | 61 out_win_uuid->IsShortUuid = TRUE; |
62 unsigned int data = 0; | 62 unsigned int data = 0; |
63 int result = sscanf_s(uuid.value().c_str(), "%04x", &data); | 63 int result = sscanf_s(uuid.value().c_str(), "%04x", &data); |
64 if (result != 1) | 64 if (result != 1) |
65 return false; | 65 return false; |
66 out_win_uuid->Value.ShortUuid = data; | 66 out_win_uuid->Value.ShortUuid = data; |
67 } else { | 67 } else { |
68 out_win_uuid->IsShortUuid = false; | 68 out_win_uuid->IsShortUuid = FALSE; |
69 unsigned int data[11]; | 69 unsigned int data[11]; |
70 int result = | 70 int result = |
71 sscanf_s(uuid.value().c_str(), | 71 sscanf_s(uuid.value().c_str(), |
72 "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", &data[0], | 72 "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", &data[0], |
73 &data[1], &data[2], &data[3], &data[4], &data[5], &data[6], | 73 &data[1], &data[2], &data[3], &data[4], &data[5], &data[6], |
74 &data[7], &data[8], &data[9], &data[10]); | 74 &data[7], &data[8], &data[9], &data[10]); |
75 if (result != 11) | 75 if (result != 11) |
76 return false; | 76 return false; |
77 out_win_uuid->Value.LongUuid.Data1 = data[0]; | 77 out_win_uuid->Value.LongUuid.Data1 = data[0]; |
78 out_win_uuid->Value.LongUuid.Data2 = data[1]; | 78 out_win_uuid->Value.LongUuid.Data2 = data[1]; |
(...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
784 &number_of_charateristics); | 784 &number_of_charateristics); |
785 } else { | 785 } else { |
786 hr = HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER); | 786 hr = HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER); |
787 } | 787 } |
788 | 788 |
789 ui_task_runner_->PostTask( | 789 ui_task_runner_->PostTask( |
790 FROM_HERE, base::Bind(callback, base::Passed(&win_characteristics_info), | 790 FROM_HERE, base::Bind(callback, base::Passed(&win_characteristics_info), |
791 number_of_charateristics, hr)); | 791 number_of_charateristics, hr)); |
792 } | 792 } |
793 | 793 |
| 794 void BluetoothTaskManagerWin::GetGattIncludedDescriptors( |
| 795 base::FilePath service_path, |
| 796 BTH_LE_GATT_CHARACTERISTIC characteristic, |
| 797 const GetGattIncludedDescriptorsCallback& callback) { |
| 798 scoped_ptr<BTH_LE_GATT_DESCRIPTOR> win_descriptors_info; |
| 799 uint16_t number_of_descriptors = 0; |
| 800 |
| 801 HRESULT hr = |
| 802 win::BluetoothLowEnergyWrapper::GetInstance() |
| 803 ->ReadDescriptorsOfACharacteristic( |
| 804 service_path, (PBTH_LE_GATT_CHARACTERISTIC)(&characteristic), |
| 805 &win_descriptors_info, &number_of_descriptors); |
| 806 |
| 807 ui_task_runner_->PostTask( |
| 808 FROM_HERE, base::Bind(callback, base::Passed(&win_descriptors_info), |
| 809 number_of_descriptors, hr)); |
| 810 } |
| 811 |
794 void BluetoothTaskManagerWin::PostGetGattIncludedCharacteristics( | 812 void BluetoothTaskManagerWin::PostGetGattIncludedCharacteristics( |
795 const base::FilePath& service_path, | 813 const base::FilePath& service_path, |
796 const BluetoothUUID& uuid, | 814 const BluetoothUUID& uuid, |
797 uint16_t attribute_handle, | 815 uint16_t attribute_handle, |
798 const GetGattIncludedCharacteristicsCallback& callback) { | 816 const GetGattIncludedCharacteristicsCallback& callback) { |
799 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 817 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
800 bluetooth_task_runner_->PostTask( | 818 bluetooth_task_runner_->PostTask( |
801 FROM_HERE, | 819 FROM_HERE, |
802 base::Bind(&BluetoothTaskManagerWin::GetGattIncludedCharacteristics, this, | 820 base::Bind(&BluetoothTaskManagerWin::GetGattIncludedCharacteristics, this, |
803 service_path, uuid, attribute_handle, callback)); | 821 service_path, uuid, attribute_handle, callback)); |
804 } | 822 } |
805 | 823 |
| 824 void BluetoothTaskManagerWin::PostGetGattIncludedDescriptors( |
| 825 const base::FilePath& service_path, |
| 826 const PBTH_LE_GATT_CHARACTERISTIC characteristic, |
| 827 const GetGattIncludedDescriptorsCallback& callback) { |
| 828 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
| 829 bluetooth_task_runner_->PostTask( |
| 830 FROM_HERE, |
| 831 base::Bind(&BluetoothTaskManagerWin::GetGattIncludedDescriptors, this, |
| 832 service_path, *characteristic, callback)); |
| 833 } |
| 834 |
806 } // namespace device | 835 } // namespace device |
OLD | NEW |