OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_REMOTE_GATT_SERVICE_WIN_H_ | 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_SERVICE_WIN_H_ |
6 #define DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_SERVICE_WIN_H_ | 6 #define DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_SERVICE_WIN_H_ |
7 | 7 |
| 8 #include <set> |
| 9 |
8 #include "base/files/file.h" | 10 #include "base/files/file.h" |
9 #include "device/bluetooth/bluetooth_device_win.h" | 11 #include "base/memory/weak_ptr.h" |
| 12 #include "base/sequenced_task_runner.h" |
10 #include "device/bluetooth/bluetooth_gatt_service.h" | 13 #include "device/bluetooth/bluetooth_gatt_service.h" |
| 14 #include "device/bluetooth/bluetooth_low_energy_defs_win.h" |
11 | 15 |
12 namespace device { | 16 namespace device { |
13 | 17 |
| 18 class BluetoothAdapterWin; |
| 19 class BluetoothDeviceWin; |
| 20 class BluetoothRemoteGattCharacteristicWin; |
| 21 class BluetoothTaskManagerWin; |
| 22 |
14 // The BluetoothRemoteGattServiceWin class implements BluetoothGattService | 23 // The BluetoothRemoteGattServiceWin class implements BluetoothGattService |
15 // for remote GATT services on Windows 8 and later. | 24 // for remote GATT services on Windows 8 and later. |
16 class DEVICE_BLUETOOTH_EXPORT BluetoothRemoteGattServiceWin | 25 class DEVICE_BLUETOOTH_EXPORT BluetoothRemoteGattServiceWin |
17 : public BluetoothGattService { | 26 : public BluetoothGattService { |
18 public: | 27 public: |
19 BluetoothRemoteGattServiceWin( | 28 BluetoothRemoteGattServiceWin( |
20 BluetoothDeviceWin* device, | 29 BluetoothDeviceWin* device, |
21 base::FilePath service_path, | 30 base::FilePath service_path, |
22 BluetoothUUID service_uuid, | 31 BluetoothUUID service_uuid, |
23 uint16_t service_attribute_handle, | 32 uint16_t service_attribute_handle, |
(...skipping 12 matching lines...) Expand all Loading... |
36 std::vector<BluetoothGattService*> GetIncludedServices() const override; | 45 std::vector<BluetoothGattService*> GetIncludedServices() const override; |
37 BluetoothGattCharacteristic* GetCharacteristic( | 46 BluetoothGattCharacteristic* GetCharacteristic( |
38 const std::string& identifier) const override; | 47 const std::string& identifier) const override; |
39 bool AddCharacteristic(BluetoothGattCharacteristic* characteristic) override; | 48 bool AddCharacteristic(BluetoothGattCharacteristic* characteristic) override; |
40 bool AddIncludedService(BluetoothGattService* service) override; | 49 bool AddIncludedService(BluetoothGattService* service) override; |
41 void Register(const base::Closure& callback, | 50 void Register(const base::Closure& callback, |
42 const ErrorCallback& error_callback) override; | 51 const ErrorCallback& error_callback) override; |
43 void Unregister(const base::Closure& callback, | 52 void Unregister(const base::Closure& callback, |
44 const ErrorCallback& error_callback) override; | 53 const ErrorCallback& error_callback) override; |
45 | 54 |
| 55 // Notify |characteristic| discovery complete, |characteristic| is the |
| 56 // included characteritic of this service. |
| 57 void GattCharacteristicDiscoveryComplete( |
| 58 BluetoothRemoteGattCharacteristicWin* characteristic); |
| 59 |
46 // Update included services and characteristics. | 60 // Update included services and characteristics. |
47 void Update(); | 61 void Update(); |
48 uint16_t GetAttributeHandle(); | 62 uint16_t GetAttributeHandle() const { return service_attribute_handle_; } |
49 | 63 |
50 private: | 64 private: |
| 65 void OnGetIncludedCharacteristics( |
| 66 scoped_ptr<BTH_LE_GATT_CHARACTERISTIC> characteristics, |
| 67 uint16_t num, |
| 68 HRESULT hr); |
| 69 void UpdateIncludedCharacteristics( |
| 70 PBTH_LE_GATT_CHARACTERISTIC characteristics, |
| 71 uint16_t num); |
| 72 |
| 73 // Sends GattDiscoveryCompleteForService notification if necessary. |
| 74 void NotifyGattDiscoveryCompleteForServiceIfNecessary(); |
| 75 |
| 76 // Checks if the characteristic with |uuid| and |attribute_handle| has already |
| 77 // been discovered as included characteristic. |
| 78 bool IsCharacteristicDiscovered(BTH_LE_UUID& uuid, uint16_t attribute_handle); |
| 79 |
| 80 // Checks if |characteristic| still exists in this service according to newly |
| 81 // retreived |num| of included |characteristics|. |
| 82 static bool DoesCharacteristicExist( |
| 83 PBTH_LE_GATT_CHARACTERISTIC characteristics, |
| 84 uint16_t num, |
| 85 BluetoothRemoteGattCharacteristicWin* characteristic); |
| 86 |
| 87 void RemoveIncludedCharacteristic(std::string identifier); |
| 88 void ClearIncludedCharacteristics(); |
| 89 |
| 90 BluetoothAdapterWin* adapter_; |
51 BluetoothDeviceWin* device_; | 91 BluetoothDeviceWin* device_; |
52 base::FilePath service_path_; | 92 base::FilePath service_path_; |
53 BluetoothUUID service_uuid_; | 93 BluetoothUUID service_uuid_; |
54 uint16_t service_attribute_handle_; | 94 uint16_t service_attribute_handle_; |
55 bool is_primary_; | 95 bool is_primary_; |
56 BluetoothRemoteGattServiceWin* parent_service_; | 96 BluetoothRemoteGattServiceWin* parent_service_; |
57 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_; | 97 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_; |
| 98 std::string service_identifier_; |
58 | 99 |
| 100 // BluetoothTaskManagerWin to handle asynchronously Bluetooth IO and platform |
| 101 // dependent operations. |
| 102 scoped_refptr<BluetoothTaskManagerWin> task_manager_; |
| 103 |
| 104 // The key of GattCharacteristicsMap is the identifier of |
| 105 // BluetoothRemoteGattCharacteristicWin instance. |
| 106 typedef std::unordered_map<std::string, |
| 107 scoped_ptr<BluetoothRemoteGattCharacteristicWin>> |
| 108 GattCharacteristicsMap; |
| 109 GattCharacteristicsMap included_characteristics_; |
| 110 |
| 111 // The element of the set is the identifier of |
| 112 // BluetoothRemoteGattCharacteristicWin instance. |
| 113 std::set<std::string> discovery_completed_included_charateristics_; |
| 114 |
| 115 // Flag indicates if discovery complete notification has been send out to |
| 116 // avoid duplicate notification. |
| 117 bool discovery_complete_notified_; |
| 118 |
| 119 // Flag indicates if asynchronous discovery of included characteristic has |
| 120 // completed. |
| 121 bool included_characteristics_discovered_; |
| 122 |
| 123 base::WeakPtrFactory<BluetoothRemoteGattServiceWin> weak_ptr_factory_; |
59 DISALLOW_COPY_AND_ASSIGN(BluetoothRemoteGattServiceWin); | 124 DISALLOW_COPY_AND_ASSIGN(BluetoothRemoteGattServiceWin); |
60 }; | 125 }; |
61 | 126 |
62 } // namespace device. | 127 } // namespace device. |
63 #endif // DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_SERVICE_WIN_H_ | 128 #endif // DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_SERVICE_WIN_H_ |
OLD | NEW |