Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2458)

Unified Diff: device/bluetooth/bluetooth_device_win.cc

Issue 1681853003: Add BluetoothRemoteGattServiceWin to BluetoothDeviceWin (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add PlatformSupportsLowEnergy check in the unittests Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « device/bluetooth/bluetooth_device_win.h ('k') | device/bluetooth/bluetooth_low_energy_win_fake.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/bluetooth/bluetooth_device_win.cc
diff --git a/device/bluetooth/bluetooth_device_win.cc b/device/bluetooth/bluetooth_device_win.cc
index 8678576feeb91dfb76a3ecc70396962cae082ece..d63b9d0434863ac671596c8e8ab87d7dd7694967 100644
--- a/device/bluetooth/bluetooth_device_win.cc
+++ b/device/bluetooth/bluetooth_device_win.cc
@@ -12,6 +12,7 @@
#include "base/sequenced_task_runner.h"
#include "base/strings/stringprintf.h"
#include "device/bluetooth/bluetooth_adapter_win.h"
+#include "device/bluetooth/bluetooth_remote_gatt_service_win.h"
#include "device/bluetooth/bluetooth_service_record_win.h"
#include "device/bluetooth/bluetooth_socket_thread.h"
#include "device/bluetooth/bluetooth_socket_win.h"
@@ -300,6 +301,84 @@ void BluetoothDeviceWin::UpdateServices(
service_record_list_.push_back(service_record);
uuids_.push_back(service_record->uuid());
}
+
+ if (!device_state.is_bluetooth_classic())
+ UpdateGattServices(device_state.service_record_states);
+}
+
+bool BluetoothDeviceWin::IsGattServiceDiscovered(BluetoothUUID& uuid,
+ uint16_t attribute_handle) {
+ GattServiceMap::iterator it = gatt_services_.begin();
+ for (; it != gatt_services_.end(); it++) {
+ uint16_t it_att_handle =
+ static_cast<BluetoothRemoteGattServiceWin*>(it->second)
+ ->GetAttributeHandle();
+ BluetoothUUID it_uuid = it->second->GetUUID();
+ if (attribute_handle == it_att_handle && uuid == it_uuid) {
+ return true;
+ }
+ }
+ return false;
+}
+
+bool BluetoothDeviceWin::DoesGattServiceExist(
+ const ScopedVector<BluetoothTaskManagerWin::ServiceRecordState>&
+ service_state,
+ BluetoothGattService* service) {
+ uint16_t attribute_handle =
+ static_cast<BluetoothRemoteGattServiceWin*>(service)
+ ->GetAttributeHandle();
+ BluetoothUUID uuid = service->GetUUID();
+ ScopedVector<BluetoothTaskManagerWin::ServiceRecordState>::const_iterator it =
+ service_state.begin();
+ for (; it != service_state.end(); ++it) {
+ if (attribute_handle == (*it)->attribute_handle && uuid == (*it)->gatt_uuid)
+ return true;
+ }
+ return false;
+}
+
+void BluetoothDeviceWin::UpdateGattServices(
+ const ScopedVector<BluetoothTaskManagerWin::ServiceRecordState>&
+ service_state) {
+ // First, remove no longer exist GATT service.
+ {
+ std::vector<std::string> to_be_removed_services;
+ for (const auto& gatt_service : gatt_services_) {
+ if (!DoesGattServiceExist(service_state, gatt_service.second)) {
+ to_be_removed_services.push_back(gatt_service.first);
+ }
+ }
+ for (const auto& service : to_be_removed_services) {
+ gatt_services_.erase(service);
+ }
+ // Update previously discovered services.
+ for (auto gatt_service : gatt_services_) {
+ static_cast<BluetoothRemoteGattServiceWin*>(gatt_service.second)
+ ->Update();
+ }
+ }
+
+ // Return if no new services have been added.
+ if (gatt_services_.size() == service_state.size())
+ return;
+
+ // Add new services.
+ for (ScopedVector<BluetoothTaskManagerWin::ServiceRecordState>::const_iterator
+ it = service_state.begin();
+ it != service_state.end(); ++it) {
+ if (!IsGattServiceDiscovered((*it)->gatt_uuid, (*it)->attribute_handle)) {
+ BluetoothRemoteGattServiceWin* primary_service =
+ new BluetoothRemoteGattServiceWin(this, (*it)->path, (*it)->gatt_uuid,
+ (*it)->attribute_handle, true,
+ nullptr, ui_task_runner_);
+ gatt_services_.add(primary_service->GetIdentifier(),
+ scoped_ptr<BluetoothGattService>(primary_service));
+ adapter_->NotifyGattServiceAdded(primary_service);
+ }
+ }
+
+ adapter_->NotifyGattServicesDiscovered(this);
}
} // namespace device
« no previous file with comments | « device/bluetooth/bluetooth_device_win.h ('k') | device/bluetooth/bluetooth_low_energy_win_fake.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698