| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_WIN_H_ | 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_WIN_H_ |
| 6 #define DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_WIN_H_ | 6 #define DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_WIN_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/scoped_vector.h" | 14 #include "base/memory/scoped_vector.h" |
| 15 #include "base/win/scoped_handle.h" | 15 #include "base/win/scoped_handle.h" |
| 16 #include "device/bluetooth/bluetooth_export.h" | 16 #include "device/bluetooth/bluetooth_export.h" |
| 17 #include "device/bluetooth/bluetooth_low_energy_defs_win.h" | 17 #include "device/bluetooth/bluetooth_low_energy_defs_win.h" |
| 18 | 18 |
| 19 namespace device { | 19 namespace device { |
| 20 namespace win { | 20 namespace win { |
| 21 | 21 |
| 22 // Represents a device registry property value | 22 // Represents a device registry property value |
| 23 class DEVICE_BLUETOOTH_EXPORT DeviceRegistryPropertyValue { | 23 class DEVICE_BLUETOOTH_EXPORT DeviceRegistryPropertyValue { |
| 24 public: | 24 public: |
| 25 // Creates a property value instance, where |property_type| is one of REG_xxx | 25 // Creates a property value instance, where |property_type| is one of REG_xxx |
| 26 // registry value type (e.g. REG_SZ, REG_DWORD), |value| is a byte array | 26 // registry value type (e.g. REG_SZ, REG_DWORD), |value| is a byte array |
| 27 // containing the property value and |value_size| is the number of bytes in | 27 // containing the property value and |value_size| is the number of bytes in |
| 28 // |value|. Note the returned instance takes ownership of the bytes in | 28 // |value|. Note the returned instance takes ownership of the bytes in |
| 29 // |value|. | 29 // |value|. |
| 30 static scoped_ptr<DeviceRegistryPropertyValue> Create( | 30 static scoped_ptr<DeviceRegistryPropertyValue> |
| 31 DWORD property_type, | 31 Create(DWORD property_type, scoped_ptr<uint8_t[]> value, size_t value_size); |
| 32 scoped_ptr<uint8_t[]> value, | |
| 33 size_t value_size); | |
| 34 ~DeviceRegistryPropertyValue(); | 32 ~DeviceRegistryPropertyValue(); |
| 35 | 33 |
| 36 // Returns the vaue type a REG_xxx value (e.g. REG_SZ, REG_DWORD, ...) | 34 // Returns the vaue type a REG_xxx value (e.g. REG_SZ, REG_DWORD, ...) |
| 37 DWORD property_type() const { return property_type_; } | 35 DWORD property_type() const { return property_type_; } |
| 38 | 36 |
| 39 std::string AsString() const; | 37 std::string AsString() const; |
| 40 DWORD AsDWORD() const; | 38 DWORD AsDWORD() const; |
| 41 | 39 |
| 42 private: | 40 private: |
| 43 DeviceRegistryPropertyValue(DWORD property_type, | 41 DeviceRegistryPropertyValue(DWORD property_type, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 }; | 74 }; |
| 77 | 75 |
| 78 // Returns true only on Windows platforms supporting Bluetooth Low Energy. | 76 // Returns true only on Windows platforms supporting Bluetooth Low Energy. |
| 79 bool IsBluetoothLowEnergySupported(); | 77 bool IsBluetoothLowEnergySupported(); |
| 80 | 78 |
| 81 struct BluetoothLowEnergyServiceInfo { | 79 struct BluetoothLowEnergyServiceInfo { |
| 82 BluetoothLowEnergyServiceInfo(); | 80 BluetoothLowEnergyServiceInfo(); |
| 83 ~BluetoothLowEnergyServiceInfo(); | 81 ~BluetoothLowEnergyServiceInfo(); |
| 84 | 82 |
| 85 BTH_LE_UUID uuid; | 83 BTH_LE_UUID uuid; |
| 84 USHORT attribute_handle; |
| 85 base::FilePath path; |
| 86 }; | 86 }; |
| 87 | 87 |
| 88 struct BluetoothLowEnergyDeviceInfo { | 88 struct BluetoothLowEnergyDeviceInfo { |
| 89 BluetoothLowEnergyDeviceInfo(); | 89 BluetoothLowEnergyDeviceInfo(); |
| 90 ~BluetoothLowEnergyDeviceInfo(); | 90 ~BluetoothLowEnergyDeviceInfo(); |
| 91 | 91 |
| 92 base::FilePath path; | 92 base::FilePath path; |
| 93 std::string id; | 93 std::string id; |
| 94 std::string friendly_name; | 94 std::string friendly_name; |
| 95 BLUETOOTH_ADDRESS address; | 95 BLUETOOTH_ADDRESS address; |
| 96 bool visible; | 96 bool visible; |
| 97 bool authenticated; | 97 bool authenticated; |
| 98 bool connected; | 98 bool connected; |
| 99 }; | 99 }; |
| 100 | 100 |
| 101 // Enumerates the list of known (i.e. already paired) Bluetooth LE devices on | 101 // Enumerates the list of known (i.e. already paired) Bluetooth LE devices on |
| 102 // this machine. In case of error, returns false and sets |error| with an error | 102 // this machine. In case of error, returns false and sets |error| with an error |
| 103 // message describing the problem. | 103 // message describing the problem. |
| 104 // Note: This function returns an error if Bluetooth Low Energy is not supported | 104 // Note: This function returns an error if Bluetooth Low Energy is not supported |
| 105 // on this Windows platform. | 105 // on this Windows platform. |
| 106 bool EnumerateKnownBluetoothLowEnergyDevices( | 106 bool EnumerateKnownBluetoothLowEnergyDevices( |
| 107 GUID guid, |
| 107 ScopedVector<BluetoothLowEnergyDeviceInfo>* devices, | 108 ScopedVector<BluetoothLowEnergyDeviceInfo>* devices, |
| 108 std::string* error); | 109 std::string* error); |
| 109 | 110 |
| 110 // Enumerates the list of known (i.e. cached) GATT services for a given | 111 // Enumerates the list of known (i.e. cached) GATT services for a given |
| 111 // Bluetooth LE device |device_path| into |services|. In case of error, returns | 112 // Bluetooth LE device |device_path| into |services|. In case of error, returns |
| 112 // false and sets |error| with an error message describing the problem. Note: | 113 // false and sets |error| with an error message describing the problem. Note: |
| 113 // This function returns an error if Bluetooth Low Energy is not supported on | 114 // This function returns an error if Bluetooth Low Energy is not supported on |
| 114 // this Windows platform. | 115 // this Windows platform. |
| 115 bool EnumerateKnownBluetoothLowEnergyServices( | 116 bool EnumerateKnownBluetoothLowEnergyServices( |
| 116 const base::FilePath& device_path, | 117 const base::FilePath& device_path, |
| 117 ScopedVector<BluetoothLowEnergyServiceInfo>* services, | 118 ScopedVector<BluetoothLowEnergyServiceInfo>* services, |
| 118 std::string* error); | 119 std::string* error); |
| 119 | 120 |
| 120 bool DEVICE_BLUETOOTH_EXPORT | 121 bool DEVICE_BLUETOOTH_EXPORT |
| 121 ExtractBluetoothAddressFromDeviceInstanceIdForTesting( | 122 ExtractBluetoothAddressFromDeviceInstanceIdForTesting( |
| 122 const std::string& instance_id, | 123 const std::string& instance_id, |
| 123 BLUETOOTH_ADDRESS* btha, | 124 BLUETOOTH_ADDRESS* btha, |
| 124 std::string* error); | 125 std::string* error); |
| 125 | 126 |
| 127 HRESULT ReadPrimaryServicesOfADevice(HANDLE device_handle, |
| 128 BTH_LE_GATT_SERVICE** out_primary_services, |
| 129 USHORT* out_counts); |
| 130 |
| 131 HRESULT ReadCharacteristicsOfAService( |
| 132 HANDLE device_handle, |
| 133 const PBTH_LE_GATT_SERVICE service_uuid, |
| 134 BTH_LE_GATT_CHARACTERISTIC** out_included_characteristics, |
| 135 USHORT* out_counts); |
| 136 |
| 137 HRESULT ReadIncludedServicesOfAService( |
| 138 HANDLE device_handle, |
| 139 const PBTH_LE_GATT_SERVICE service_uuid, |
| 140 BTH_LE_GATT_SERVICE** out_included_services, |
| 141 USHORT* out_counts); |
| 142 |
| 143 HRESULT ReadTheValueOfACharacteristic( |
| 144 HANDLE device_handle, |
| 145 const PBTH_LE_GATT_CHARACTERISTIC characteristic, |
| 146 BTH_LE_GATT_CHARACTERISTIC_VALUE** out_characteristic_value); |
| 147 |
| 148 HRESULT WriteTheValueOfACharacteristic( |
| 149 HANDLE device_handle, |
| 150 const PBTH_LE_GATT_CHARACTERISTIC characteristic, |
| 151 BTH_LE_GATT_CHARACTERISTIC_VALUE* new_value); |
| 152 |
| 153 HRESULT ReliableWriteTheValueOfACharacteristic( |
| 154 HANDLE device_handle, |
| 155 const PBTH_LE_GATT_CHARACTERISTIC characteristic, |
| 156 BTH_LE_GATT_CHARACTERISTIC_VALUE* new_value); |
| 157 |
| 158 HRESULT ReadDescriptorsOfACharacteristic( |
| 159 HANDLE device_handle, |
| 160 const PBTH_LE_GATT_CHARACTERISTIC characteristic, |
| 161 BTH_LE_GATT_DESCRIPTOR** out_included_descriptors, |
| 162 USHORT* out_counts); |
| 163 |
| 164 HRESULT ReadTheValueOfADescriptor(HANDLE device_handle, |
| 165 const PBTH_LE_GATT_DESCRIPTOR descriptor, |
| 166 BTH_LE_GATT_DESCRIPTOR_VALUE** out_value); |
| 167 |
| 168 HRESULT WriteTheDescriptorValue(HANDLE device_handle, |
| 169 const PBTH_LE_GATT_DESCRIPTOR descriptor, |
| 170 BTH_LE_GATT_DESCRIPTOR_VALUE* new_value); |
| 171 |
| 172 HRESULT RegisterGattEvents(HANDLE device_handle, |
| 173 BTH_LE_GATT_EVENT_TYPE type, |
| 174 PVOID event_parameter, |
| 175 PFNBLUETOOTH_GATT_EVENT_CALLBACK callback, |
| 176 PVOID context, |
| 177 BLUETOOTH_GATT_EVENT_HANDLE* out_handle); |
| 178 |
| 179 HRESULT UnregisterGattEvent(BLUETOOTH_GATT_EVENT_HANDLE event_handle); |
| 180 |
| 126 } // namespace win | 181 } // namespace win |
| 127 } // namespace device | 182 } // namespace device |
| 128 | 183 |
| 129 #endif // DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_WIN_H_ | 184 #endif // DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_WIN_H_ |
| OLD | NEW |