Chromium Code Reviews| 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 |service| discovery complete, |service| is the included service of | |
| 56 // this service. | |
| 57 void GattServiceDiscoverComplete(BluetoothRemoteGattServiceWin* service); | |
|
scheib
2016/02/25 06:22:44
Discovery
gogerald1
2016/02/25 23:19:18
Done.
| |
| 58 | |
| 59 // Notify |characteristic| discovery complete, |characteristic| is the | |
| 60 // included characteritic of this service. | |
| 61 void GattCharacteristicDiscoverComplete( | |
|
scheib
2016/02/25 06:22:44
Discovery
gogerald1
2016/02/25 23:19:18
Done.
| |
| 62 BluetoothRemoteGattCharacteristicWin* characteristic); | |
| 63 | |
| 46 // Update included services and characteristics. | 64 // Update included services and characteristics. |
| 47 void Update(); | 65 void Update(); |
| 48 uint16_t GetAttributeHandle(); | 66 uint16_t GetAttributeHandle() const { return service_attribute_handle_; } |
| 67 BluetoothRemoteGattServiceWin* GetParentService() const { | |
| 68 return parent_service_; | |
| 69 } | |
| 49 | 70 |
| 50 private: | 71 private: |
| 72 void GetIncludedCharacteristicsCallback( | |
|
scheib
2016/02/25 06:22:44
OnGetIncludedCharacteristics. The previous name ca
gogerald1
2016/02/25 23:19:18
Done.
| |
| 73 scoped_ptr<BTH_LE_GATT_CHARACTERISTIC> characteristics, | |
| 74 uint16_t num, | |
| 75 HRESULT hr); | |
| 76 void GetIncludedServicesCallback(scoped_ptr<BTH_LE_GATT_SERVICE> services, | |
|
scheib
2016/02/25 06:22:44
OnGetIncludedServices
gogerald1
2016/02/25 23:19:18
Done.
| |
| 77 uint16_t num, | |
| 78 HRESULT hr); | |
| 79 void UpdateIncludedCharacteristics( | |
| 80 PBTH_LE_GATT_CHARACTERISTIC characteristics, | |
| 81 uint16_t num); | |
| 82 void UpdateIncludedServices(PBTH_LE_GATT_SERVICE services, uint16_t num); | |
| 83 | |
| 84 // Sends GattDiscoveryCompleteForService notification if necessary. | |
| 85 void NotifyServiceDiscComplIfNecessary(); | |
|
scheib
2016/02/25 06:22:44
https://google.github.io/styleguide/cppguide.html#
gogerald1
2016/02/25 23:19:18
Done.
| |
| 86 | |
| 87 // Checks if the characteristic with |uuid| and |attribute_handle| has already | |
| 88 // been discovered as included characteristic. | |
| 89 bool IsCharacteristicDiscovered(BTH_LE_UUID& uuid, uint16_t attribute_handle); | |
| 90 | |
| 91 // Checks if |characteristic| is still exist in this service according to | |
|
scheib
2016/02/25 06:22:44
"| still exists"
gogerald1
2016/02/25 23:19:18
Done.
gogerald1
2016/02/25 23:19:18
Done.
| |
| 92 // newly retreived |num| of included |characteristics|. | |
| 93 bool DoesCharacteristicExist( | |
|
scheib
2016/02/25 06:22:44
static
gogerald1
2016/02/25 23:19:18
Done.
| |
| 94 PBTH_LE_GATT_CHARACTERISTIC characteristics, | |
| 95 uint16_t num, | |
| 96 BluetoothRemoteGattCharacteristicWin* characteristic); | |
| 97 | |
| 98 void RemoveIncludedCharacteristic(std::string identifier); | |
| 99 void ClearIncludedCharacteristics(); | |
| 100 | |
| 101 // Checks if the service with |uuid| and |attribute_handle| has already been | |
| 102 // discovered as included service. | |
| 103 bool IsServiceDiscovered(BluetoothUUID& uuid, uint16_t attribute_handle); | |
| 104 | |
| 105 // Checks if |service| is still exist in this service according to newly | |
| 106 // retrieved |num| of included |services|. | |
| 107 bool DoesServiceExist(PBTH_LE_GATT_SERVICE services, | |
| 108 uint16_t num, | |
| 109 BluetoothRemoteGattServiceWin* service); | |
| 110 | |
| 111 void RemoveIncludedService(std::string identifier); | |
| 112 void ClearIncludedServices(); | |
| 113 | |
| 114 BluetoothAdapterWin* adapter_; | |
| 51 BluetoothDeviceWin* device_; | 115 BluetoothDeviceWin* device_; |
| 52 base::FilePath service_path_; | 116 base::FilePath service_path_; |
| 53 BluetoothUUID service_uuid_; | 117 BluetoothUUID service_uuid_; |
| 54 uint16_t service_attribute_handle_; | 118 uint16_t service_attribute_handle_; |
| 55 bool is_primary_; | 119 bool is_primary_; |
| 56 BluetoothRemoteGattServiceWin* parent_service_; | 120 BluetoothRemoteGattServiceWin* parent_service_; |
| 57 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_; | 121 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_; |
| 58 | 122 |
| 123 // BluetoothTaskManagerWin to handle asynchronously Bluetooth IO and platform | |
| 124 // dependent operations. | |
| 125 scoped_refptr<BluetoothTaskManagerWin> task_manager_; | |
| 126 | |
| 127 // The key of GattCharacteristicsMap is the identifier of | |
| 128 // BluetoothRemoteGattCharacteristicWin instance. | |
| 129 typedef std::unordered_map<std::string, | |
| 130 scoped_ptr<BluetoothRemoteGattCharacteristicWin>> | |
| 131 GattCharacteristicsMap; | |
| 132 GattCharacteristicsMap included_characteristic_; | |
|
scheib
2016/02/25 06:22:44
plural as it is a container, included_characterist
gogerald1
2016/02/25 23:19:18
Done.
| |
| 133 | |
| 134 // The element of the set is the identifier of | |
| 135 // BluetoothRemoteGattCharacteristicWin instance. | |
| 136 std::set<std::string> discovery_completed_included_charateristics_; | |
| 137 | |
| 138 // The key of GattServicesMap is the identifier of | |
| 139 // BluetoothRemoteGattServiceWin instance. | |
| 140 typedef std::unordered_map<std::string, | |
| 141 scoped_ptr<BluetoothRemoteGattServiceWin>> | |
| 142 GattServicesMap; | |
| 143 GattServicesMap included_service_; | |
|
scheib
2016/02/25 06:22:44
included_services_
gogerald1
2016/02/25 23:19:18
Done.
| |
| 144 | |
| 145 // The element of the set is the identifier of BluetoothRemoteGattServiceWin | |
| 146 // instance. | |
| 147 std::set<std::string> discovery_completed_included_services_; | |
| 148 | |
| 149 // Flag indicates if discovery complete notification has been send out to | |
| 150 // avoid duplicate notification. | |
| 151 bool discovery_complete_notified_; | |
| 152 | |
| 153 // Flag indicates if asynchronous discovery of included service has completed. | |
| 154 bool included_services_discovered_; | |
| 155 | |
| 156 // Flag indicates if asynchronous discovery of included characteristic has | |
| 157 // completed. | |
| 158 bool included_characteristics_discovered_; | |
| 159 | |
| 160 base::WeakPtrFactory<BluetoothRemoteGattServiceWin> weak_ptr_factory_; | |
| 59 DISALLOW_COPY_AND_ASSIGN(BluetoothRemoteGattServiceWin); | 161 DISALLOW_COPY_AND_ASSIGN(BluetoothRemoteGattServiceWin); |
| 60 }; | 162 }; |
| 61 | 163 |
| 62 } // namespace device. | 164 } // namespace device. |
| 63 #endif // DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_SERVICE_WIN_H_ | 165 #endif // DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_SERVICE_WIN_H_ |
| OLD | NEW |