OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "device/bluetooth/bluetooth_device_win.h" | 5 #include "device/bluetooth/bluetooth_device_win.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/containers/scoped_ptr_hash_map.h" | 9 #include "base/containers/scoped_ptr_hash_map.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/memory/scoped_vector.h" | 11 #include "base/memory/scoped_vector.h" |
12 #include "base/sequenced_task_runner.h" | 12 #include "base/sequenced_task_runner.h" |
13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
14 #include "device/bluetooth/bluetooth_adapter_win.h" | 14 #include "device/bluetooth/bluetooth_adapter_win.h" |
15 #include "device/bluetooth/bluetooth_remote_gatt_service_win.h" | |
15 #include "device/bluetooth/bluetooth_service_record_win.h" | 16 #include "device/bluetooth/bluetooth_service_record_win.h" |
16 #include "device/bluetooth/bluetooth_socket_thread.h" | 17 #include "device/bluetooth/bluetooth_socket_thread.h" |
17 #include "device/bluetooth/bluetooth_socket_win.h" | 18 #include "device/bluetooth/bluetooth_socket_win.h" |
18 #include "device/bluetooth/bluetooth_task_manager_win.h" | 19 #include "device/bluetooth/bluetooth_task_manager_win.h" |
19 #include "device/bluetooth/bluetooth_uuid.h" | 20 #include "device/bluetooth/bluetooth_uuid.h" |
20 | 21 |
21 namespace { | 22 namespace { |
22 | 23 |
23 const char kApiUnavailable[] = "This API is not implemented on this platform."; | 24 const char kApiUnavailable[] = "This API is not implemented on this platform."; |
24 | 25 |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
172 socket->Connect(this, uuid, base::Bind(callback, socket), error_callback); | 173 socket->Connect(this, uuid, base::Bind(callback, socket), error_callback); |
173 } | 174 } |
174 | 175 |
175 void BluetoothDeviceWin::ConnectToServiceInsecurely( | 176 void BluetoothDeviceWin::ConnectToServiceInsecurely( |
176 const BluetoothUUID& uuid, | 177 const BluetoothUUID& uuid, |
177 const ConnectToServiceCallback& callback, | 178 const ConnectToServiceCallback& callback, |
178 const ConnectToServiceErrorCallback& error_callback) { | 179 const ConnectToServiceErrorCallback& error_callback) { |
179 error_callback.Run(kApiUnavailable); | 180 error_callback.Run(kApiUnavailable); |
180 } | 181 } |
181 | 182 |
182 void BluetoothDeviceWin::CreateGattConnection( | 183 void BluetoothDeviceWin::CreateGattConnection( |
ortuno
2016/01/21 19:00:42
I noticed you didn't implement CreateGattConnectio
gogerald1
2016/01/21 20:00:20
Yes, I searched it for a while, haven't found any
| |
183 const GattConnectionCallback& callback, | 184 const GattConnectionCallback& callback, |
184 const ConnectErrorCallback& error_callback) { | 185 const ConnectErrorCallback& error_callback) { |
185 // TODO(armansito): Implement. | 186 // TODO(armansito): Implement. |
186 error_callback.Run(ERROR_UNSUPPORTED_DEVICE); | 187 error_callback.Run(ERROR_UNSUPPORTED_DEVICE); |
187 } | 188 } |
188 | 189 |
189 const BluetoothServiceRecordWin* BluetoothDeviceWin::GetServiceRecord( | 190 const BluetoothServiceRecordWin* BluetoothDeviceWin::GetServiceRecord( |
190 const device::BluetoothUUID& uuid) const { | 191 const device::BluetoothUUID& uuid) const { |
191 for (ServiceRecordList::const_iterator iter = service_record_list_.begin(); | 192 for (ServiceRecordList::const_iterator iter = service_record_list_.begin(); |
192 iter != service_record_list_.end(); | 193 iter != service_record_list_.end(); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
293 | 294 |
294 for (ScopedVector<BluetoothTaskManagerWin::ServiceRecordState>::const_iterator | 295 for (ScopedVector<BluetoothTaskManagerWin::ServiceRecordState>::const_iterator |
295 iter = device_state.service_record_states.begin(); | 296 iter = device_state.service_record_states.begin(); |
296 iter != device_state.service_record_states.end(); ++iter) { | 297 iter != device_state.service_record_states.end(); ++iter) { |
297 BluetoothServiceRecordWin* service_record = | 298 BluetoothServiceRecordWin* service_record = |
298 new BluetoothServiceRecordWin(device_state.address, (*iter)->name, | 299 new BluetoothServiceRecordWin(device_state.address, (*iter)->name, |
299 (*iter)->sdp_bytes, (*iter)->gatt_uuid); | 300 (*iter)->sdp_bytes, (*iter)->gatt_uuid); |
300 service_record_list_.push_back(service_record); | 301 service_record_list_.push_back(service_record); |
301 uuids_.push_back(service_record->uuid()); | 302 uuids_.push_back(service_record->uuid()); |
302 } | 303 } |
304 | |
305 if (!device_state.is_bluetooth_classic()) | |
306 UpdateGattServices(device_state); | |
307 } | |
308 | |
309 void BluetoothDeviceWin::UpdateGattServices( | |
310 const BluetoothTaskManagerWin::DeviceState& device_state) { | |
311 // Remove no longer exist gatt services first. | |
312 if (gatt_services_.size() != 0) { | |
313 std::vector<std::string> removed_services; | |
314 for (auto gatt_service : gatt_services_) { | |
315 BluetoothUUID uuid = gatt_service.second->GetUUID(); | |
316 ScopedVector<BluetoothTaskManagerWin::ServiceRecordState>::const_iterator | |
317 iter = device_state.service_record_states.begin(); | |
318 for (; iter != device_state.service_record_states.end(); ++iter) { | |
319 if (uuid == (*iter)->gatt_uuid) | |
320 break; | |
321 } | |
322 if (iter == device_state.service_record_states.end()) { | |
323 removed_services.push_back(gatt_service.first); | |
324 } | |
325 } | |
326 for (auto key : removed_services) { | |
327 gatt_services_.erase(key); | |
328 } | |
329 // Update previously discovered services. | |
330 for (auto gatt_service : gatt_services_) { | |
331 static_cast<BluetoothRemoteGattServiceWin*>(gatt_service.second) | |
332 ->Update(); | |
333 } | |
334 } | |
335 | |
336 // Return if no new services have been added. | |
337 if (gatt_services_.size() == device_state.service_record_states.size()) | |
338 return; | |
339 | |
340 // Add new services. | |
341 for (ScopedVector<BluetoothTaskManagerWin::ServiceRecordState>::const_iterator | |
342 iter = device_state.service_record_states.begin(); | |
343 iter != device_state.service_record_states.end(); ++iter) { | |
344 GattServiceMap::iterator it = gatt_services_.begin(); | |
345 for (; it != gatt_services_.end(); it++) { | |
346 if ((*iter)->gatt_uuid == it->second->GetUUID()) | |
347 break; | |
348 } | |
349 if (it == gatt_services_.end()) { | |
350 BluetoothRemoteGattServiceWin* primary_service = | |
351 new BluetoothRemoteGattServiceWin( | |
352 this, (*iter)->path, (*iter)->gatt_uuid, | |
353 (*iter)->gatt_attribute_handle, true, nullptr, ui_task_runner_); | |
354 gatt_services_.add(primary_service->GetIdentifier(), | |
355 scoped_ptr<BluetoothGattService>(primary_service)); | |
356 static_cast<BluetoothAdapterWin*>(adapter_) | |
357 ->NotifyGattServiceAdded(this, primary_service); | |
358 } | |
359 } | |
360 | |
361 static_cast<BluetoothAdapterWin*>(adapter_) | |
362 ->NotifyGattServicesDiscovered(this); | |
303 } | 363 } |
304 | 364 |
305 } // namespace device | 365 } // namespace device |
OLD | NEW |