OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_WIN_H_ |
| 6 #define DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_WIN_H_ |
| 7 |
| 8 #include "base/macros.h" |
| 9 #include "device/bluetooth/bluetooth_adapter_win.h" |
| 10 #include "device/bluetooth/bluetooth_device_win.h" |
| 11 #include "device/bluetooth/bluetooth_gatt_characteristic.h" |
| 12 #include "device/bluetooth/bluetooth_remote_gatt_descriptor_win.h" |
| 13 #include "device/bluetooth/bluetooth_remote_gatt_service_win.h" |
| 14 #include "device/bluetooth/bluetooth_task_manager_win.h" |
| 15 |
| 16 namespace device { |
| 17 |
| 18 // The BluetoothRemoteGattCharacteristicWin class implements |
| 19 // BluetoothGattCharacteristic for remote GATT services on Windows 8 and later. |
| 20 class DEVICE_BLUETOOTH_EXPORT BluetoothRemoteGattCharacteristicWin |
| 21 : public BluetoothGattCharacteristic { |
| 22 public: |
| 23 BluetoothRemoteGattCharacteristicWin( |
| 24 BluetoothRemoteGattServiceWin* parent_service, |
| 25 BTH_LE_GATT_CHARACTERISTIC* characteristic_info, |
| 26 scoped_refptr<base::SequencedTaskRunner>& ui_task_runner); |
| 27 ~BluetoothRemoteGattCharacteristicWin(); |
| 28 |
| 29 // Override BluetoothGattCharacteristic interfaces. |
| 30 std::string GetIdentifier() const override; |
| 31 BluetoothUUID GetUUID() const override; |
| 32 bool IsLocal() const override; |
| 33 std::vector<uint8_t>& GetValue() const override; |
| 34 BluetoothGattService* GetService() const override; |
| 35 Properties GetProperties() const override; |
| 36 Permissions GetPermissions() const override; |
| 37 bool IsNotifying() const override; |
| 38 std::vector<BluetoothGattDescriptor*> GetDescriptors() const override; |
| 39 BluetoothGattDescriptor* GetDescriptor( |
| 40 const std::string& identifier) const override; |
| 41 bool AddDescriptor(BluetoothGattDescriptor* descriptor) override; |
| 42 bool UpdateValue(const std::vector<uint8_t>& value) override; |
| 43 void StartNotifySession(const NotifySessionCallback& callback, |
| 44 const ErrorCallback& error_callback) override; |
| 45 void ReadRemoteCharacteristic(const ValueCallback& callback, |
| 46 const ErrorCallback& error_callback) override; |
| 47 void WriteRemoteCharacteristic(const std::vector<uint8_t>& new_value, |
| 48 const base::Closure& callback, |
| 49 const ErrorCallback& error_callback) override; |
| 50 |
| 51 void NotifyGattDescriptorAdded(BluetoothRemoteGattDescriptorWin* descriptor); |
| 52 void OnRemoteCharacteristicValueChanged(BTH_LE_GATT_EVENT_TYPE type, |
| 53 PVOID event_parameter); |
| 54 void StopNotifySession(); |
| 55 void Update(); |
| 56 |
| 57 private: |
| 58 friend class BluetoothRemoteGattCharacteristicWinTest; |
| 59 |
| 60 void NotifyCharacteristicDiscComplIfNecessary(); |
| 61 void NotifyGattCharacteristicValueChanged(uint8_t* new_value, ULONG size); |
| 62 void GetIncludedDescriptorsCallback(PBTH_LE_GATT_DESCRIPTOR descriptors, |
| 63 uint16_t num, |
| 64 HRESULT hr); |
| 65 void ReadCharacteristicValueCallback(PBTH_LE_GATT_CHARACTERISTIC_VALUE value, |
| 66 HRESULT hr); |
| 67 void WriteRemoteCharacteristicCallback(HRESULT hr); |
| 68 void GattEventRegistrationCallback(BLUETOOTH_GATT_EVENT_HANDLE event_handle, |
| 69 HRESULT hr); |
| 70 void UpdateIncludedDescriptors(PBTH_LE_GATT_DESCRIPTOR descriptors, |
| 71 uint16_t num); |
| 72 |
| 73 BluetoothAdapterWin* adapter_; |
| 74 BluetoothRemoteGattServiceWin* parent_service_; |
| 75 scoped_refptr<BluetoothTaskManagerWin> task_manager_; |
| 76 |
| 77 // Characteristic info from OS and used to interact with the OS later. |
| 78 scoped_ptr<BTH_LE_GATT_CHARACTERISTIC> characteristic_info_; |
| 79 BluetoothUUID characteristic_uuid_; |
| 80 |
| 81 bool characteristic_value_initialized_; |
| 82 std::vector<uint8_t> characteristic_value_; |
| 83 |
| 84 // Flag to indicate NotifyGattCharacteristicAdded has been called. |
| 85 bool complete_notified_; |
| 86 |
| 87 typedef base::ScopedPtrHashMap<std::string, |
| 88 scoped_ptr<BluetoothRemoteGattDescriptorWin>> |
| 89 GattDescriptorMap; |
| 90 GattDescriptorMap included_descriptor_objects_; |
| 91 // Contain discovery completed included descriptors' identifier. |
| 92 std::set<std::string> completed_descriptors_; |
| 93 // Flag to indicate included descriptors have been discovered. |
| 94 bool descriptor_discovered_; |
| 95 |
| 96 std::vector<std::pair<ValueCallback, ErrorCallback>> |
| 97 read_remote_characteristic_value_callbacks_; |
| 98 std::vector<std::pair<base::Closure, ErrorCallback>> |
| 99 write_remote_characteristic_value_callback_; |
| 100 |
| 101 // Flag to indicate whether remote value change notification has been |
| 102 // registered. |
| 103 bool is_notifying_; |
| 104 int number_of_active_notify_sessions_; |
| 105 std::vector<std::pair<NotifySessionCallback, ErrorCallback>> |
| 106 start_notifying_callback_; |
| 107 BLUETOOTH_GATT_EVENT_HANDLE registered_event_handle_; |
| 108 |
| 109 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_; |
| 110 |
| 111 base::WeakPtrFactory<BluetoothRemoteGattCharacteristicWin> weak_ptr_factory_; |
| 112 DISALLOW_COPY_AND_ASSIGN(BluetoothRemoteGattCharacteristicWin); |
| 113 }; |
| 114 |
| 115 } // namespace device |
| 116 |
| 117 #endif // DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_WIN_H_ |
OLD | NEW |