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 #include <utility> | 5 #include <utility> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "device/bluetooth/device.h" | 10 #include "device/bluetooth/device.h" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
88 GetServicesImpl(callback); | 88 GetServicesImpl(callback); |
89 return; | 89 return; |
90 } | 90 } |
91 | 91 |
92 // pending_services_requests_ is owned by Device, so base::Unretained is | 92 // pending_services_requests_ is owned by Device, so base::Unretained is |
93 // safe. | 93 // safe. |
94 pending_services_requests_.push_back( | 94 pending_services_requests_.push_back( |
95 base::Bind(&Device::GetServicesImpl, base::Unretained(this), callback)); | 95 base::Bind(&Device::GetServicesImpl, base::Unretained(this), callback)); |
96 } | 96 } |
97 | 97 |
98 void Device::GetCharacteristics(const std::string& service_id, | |
99 const GetCharacteristicsCallback& callback) { | |
100 device::BluetoothDevice* device = adapter_->GetDevice(GetAddress()); | |
101 DCHECK(device); | |
102 | |
103 if (device->IsGattServicesDiscoveryComplete()) { | |
104 GetCharacteristicsImpl(service_id, callback); | |
105 return; | |
106 } | |
107 | |
108 // pending_services_requests_ is owned by Device, so base::Unretained is | |
109 // safe. | |
110 pending_services_requests_.push_back( | |
111 base::Bind(&Device::GetCharacteristicsImpl, base::Unretained(this), | |
112 service_id, callback)); | |
113 } | |
114 | |
98 Device::Device(scoped_refptr<device::BluetoothAdapter> adapter, | 115 Device::Device(scoped_refptr<device::BluetoothAdapter> adapter, |
99 std::unique_ptr<device::BluetoothGattConnection> connection) | 116 std::unique_ptr<device::BluetoothGattConnection> connection) |
100 : adapter_(std::move(adapter)), connection_(std::move(connection)) { | 117 : adapter_(std::move(adapter)), connection_(std::move(connection)) { |
101 adapter_->AddObserver(this); | 118 adapter_->AddObserver(this); |
102 } | 119 } |
103 | 120 |
104 void Device::GetServicesImpl(const GetServicesCallback& callback) { | 121 void Device::GetServicesImpl(const GetServicesCallback& callback) { |
105 device::BluetoothDevice* device = adapter_->GetDevice(GetAddress()); | 122 device::BluetoothDevice* device = adapter_->GetDevice(GetAddress()); |
106 DCHECK(device); | 123 DCHECK(device); |
107 | 124 |
(...skipping 11 matching lines...) Expand all Loading... | |
119 const device::BluetoothRemoteGattService& service) { | 136 const device::BluetoothRemoteGattService& service) { |
120 mojom::ServiceInfoPtr service_info = mojom::ServiceInfo::New(); | 137 mojom::ServiceInfoPtr service_info = mojom::ServiceInfo::New(); |
121 | 138 |
122 service_info->id = service.GetIdentifier(); | 139 service_info->id = service.GetIdentifier(); |
123 service_info->uuid = service.GetUUID(); | 140 service_info->uuid = service.GetUUID(); |
124 service_info->is_primary = service.IsPrimary(); | 141 service_info->is_primary = service.IsPrimary(); |
125 | 142 |
126 return service_info; | 143 return service_info; |
127 } | 144 } |
128 | 145 |
146 void Device::GetCharacteristicsImpl( | |
147 const std::string& service_id, | |
148 const GetCharacteristicsCallback& callback) { | |
149 device::BluetoothDevice* device = adapter_->GetDevice(GetAddress()); | |
150 DCHECK(device); | |
151 device::BluetoothRemoteGattService* service = | |
152 device->GetGattService(service_id); | |
153 DCHECK(service); | |
154 | |
155 std::vector<mojom::CharacteristicInfoPtr> characteristics; | |
156 | |
157 for (const device::BluetoothRemoteGattCharacteristic* characteristic : | |
158 service->GetCharacteristics()) { | |
scheib
2017/01/13 05:24:40
for (const auto* characteristic : service->GetChar
mbrunson
2017/01/13 21:21:13
Done.
| |
159 mojom::CharacteristicInfoPtr characteristic_info = | |
160 mojom::CharacteristicInfo::New(); | |
161 | |
162 characteristic_info->id = characteristic->GetIdentifier(); | |
163 characteristic_info->uuid = characteristic->GetUUID(); | |
164 characteristic_info->properties = characteristic->GetProperties(); | |
165 | |
166 characteristics.push_back(std::move(characteristic_info)); | |
167 } | |
168 | |
169 callback.Run(std::move(characteristics)); | |
170 } | |
171 | |
129 const std::string& Device::GetAddress() { | 172 const std::string& Device::GetAddress() { |
130 return connection_->GetDeviceAddress(); | 173 return connection_->GetDeviceAddress(); |
131 } | 174 } |
132 | 175 |
133 } // namespace bluetooth | 176 } // namespace bluetooth |
OLD | NEW |