| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_chromeos.h" | 5 #include "device/bluetooth/bluetooth_device_chromeos.h" |
| 6 | 6 |
| 7 #include <stdio.h> | 7 #include <stdio.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 BluetoothDeviceChromeOS::~BluetoothDeviceChromeOS() { | 146 BluetoothDeviceChromeOS::~BluetoothDeviceChromeOS() { |
| 147 DBusThreadManager::Get()->GetBluetoothGattServiceClient()-> | 147 DBusThreadManager::Get()->GetBluetoothGattServiceClient()-> |
| 148 RemoveObserver(this); | 148 RemoveObserver(this); |
| 149 | 149 |
| 150 // Copy the GATT services list here and clear the original so that when we | 150 // Copy the GATT services list here and clear the original so that when we |
| 151 // send GattServiceRemoved(), GetGattServices() returns no services. | 151 // send GattServiceRemoved(), GetGattServices() returns no services. |
| 152 GattServiceMap gatt_services = gatt_services_; | 152 GattServiceMap gatt_services = gatt_services_; |
| 153 gatt_services_.clear(); | 153 gatt_services_.clear(); |
| 154 for (GattServiceMap::iterator iter = gatt_services.begin(); | 154 for (GattServiceMap::iterator iter = gatt_services.begin(); |
| 155 iter != gatt_services.end(); ++iter) { | 155 iter != gatt_services.end(); ++iter) { |
| 156 FOR_EACH_OBSERVER(BluetoothDevice::Observer, observers_, | 156 DCHECK(adapter_); |
| 157 GattServiceRemoved(this, iter->second)); | 157 adapter_->NotifyGattServiceRemoved( |
| 158 static_cast<BluetoothRemoteGattServiceChromeOS*>(iter->second)); |
| 158 delete iter->second; | 159 delete iter->second; |
| 159 } | 160 } |
| 160 } | 161 } |
| 161 | 162 |
| 162 void BluetoothDeviceChromeOS::AddObserver( | |
| 163 device::BluetoothDevice::Observer* observer) { | |
| 164 DCHECK(observer); | |
| 165 observers_.AddObserver(observer); | |
| 166 } | |
| 167 | |
| 168 void BluetoothDeviceChromeOS::RemoveObserver( | |
| 169 device::BluetoothDevice::Observer* observer) { | |
| 170 DCHECK(observer); | |
| 171 observers_.RemoveObserver(observer); | |
| 172 } | |
| 173 | |
| 174 uint32 BluetoothDeviceChromeOS::GetBluetoothClass() const { | 163 uint32 BluetoothDeviceChromeOS::GetBluetoothClass() const { |
| 175 BluetoothDeviceClient::Properties* properties = | 164 BluetoothDeviceClient::Properties* properties = |
| 176 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> | 165 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> |
| 177 GetProperties(object_path_); | 166 GetProperties(object_path_); |
| 178 DCHECK(properties); | 167 DCHECK(properties); |
| 179 | 168 |
| 180 return properties->bluetooth_class.value(); | 169 return properties->bluetooth_class.value(); |
| 181 } | 170 } |
| 182 | 171 |
| 183 std::string BluetoothDeviceChromeOS::GetDeviceName() const { | 172 std::string BluetoothDeviceChromeOS::GetDeviceName() const { |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 | 492 |
| 504 VLOG(1) << "Adding new remote GATT service for device: " << GetAddress(); | 493 VLOG(1) << "Adding new remote GATT service for device: " << GetAddress(); |
| 505 | 494 |
| 506 BluetoothRemoteGattServiceChromeOS* service = | 495 BluetoothRemoteGattServiceChromeOS* service = |
| 507 new BluetoothRemoteGattServiceChromeOS(adapter_, this, object_path); | 496 new BluetoothRemoteGattServiceChromeOS(adapter_, this, object_path); |
| 508 | 497 |
| 509 gatt_services_[service->GetIdentifier()] = service; | 498 gatt_services_[service->GetIdentifier()] = service; |
| 510 DCHECK(service->object_path() == object_path); | 499 DCHECK(service->object_path() == object_path); |
| 511 DCHECK(service->GetUUID().IsValid()); | 500 DCHECK(service->GetUUID().IsValid()); |
| 512 | 501 |
| 513 FOR_EACH_OBSERVER(device::BluetoothDevice::Observer, observers_, | 502 DCHECK(adapter_); |
| 514 GattServiceAdded(this, service)); | 503 adapter_->NotifyGattServiceAdded(service); |
| 515 } | 504 } |
| 516 | 505 |
| 517 void BluetoothDeviceChromeOS::GattServiceRemoved( | 506 void BluetoothDeviceChromeOS::GattServiceRemoved( |
| 518 const dbus::ObjectPath& object_path) { | 507 const dbus::ObjectPath& object_path) { |
| 519 GattServiceMap::iterator iter = gatt_services_.find(object_path.value()); | 508 GattServiceMap::iterator iter = gatt_services_.find(object_path.value()); |
| 520 if (iter == gatt_services_.end()) { | 509 if (iter == gatt_services_.end()) { |
| 521 VLOG(3) << "Unknown GATT service removed: " << object_path.value(); | 510 VLOG(3) << "Unknown GATT service removed: " << object_path.value(); |
| 522 return; | 511 return; |
| 523 } | 512 } |
| 524 | 513 |
| 525 VLOG(1) << "Removing remote GATT service from device: " << GetAddress(); | 514 VLOG(1) << "Removing remote GATT service from device: " << GetAddress(); |
| 526 | 515 |
| 527 BluetoothRemoteGattServiceChromeOS* service = | 516 BluetoothRemoteGattServiceChromeOS* service = |
| 528 static_cast<BluetoothRemoteGattServiceChromeOS*>(iter->second); | 517 static_cast<BluetoothRemoteGattServiceChromeOS*>(iter->second); |
| 529 DCHECK(service->object_path() == object_path); | 518 DCHECK(service->object_path() == object_path); |
| 530 gatt_services_.erase(iter); | 519 gatt_services_.erase(iter); |
| 531 FOR_EACH_OBSERVER(device::BluetoothDevice::Observer, observers_, | 520 |
| 532 GattServiceRemoved(this, service)); | 521 DCHECK(adapter_); |
| 522 adapter_->NotifyGattServiceRemoved(service); |
| 523 |
| 533 delete service; | 524 delete service; |
| 534 } | 525 } |
| 535 | 526 |
| 536 void BluetoothDeviceChromeOS::ConnectInternal( | 527 void BluetoothDeviceChromeOS::ConnectInternal( |
| 537 bool after_pairing, | 528 bool after_pairing, |
| 538 const base::Closure& callback, | 529 const base::Closure& callback, |
| 539 const ConnectErrorCallback& error_callback) { | 530 const ConnectErrorCallback& error_callback) { |
| 540 VLOG(1) << object_path_.value() << ": Connecting"; | 531 VLOG(1) << object_path_.value() << ": Connecting"; |
| 541 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> | 532 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> |
| 542 Connect( | 533 Connect( |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 709 void BluetoothDeviceChromeOS::OnForgetError( | 700 void BluetoothDeviceChromeOS::OnForgetError( |
| 710 const ErrorCallback& error_callback, | 701 const ErrorCallback& error_callback, |
| 711 const std::string& error_name, | 702 const std::string& error_name, |
| 712 const std::string& error_message) { | 703 const std::string& error_message) { |
| 713 LOG(WARNING) << object_path_.value() << ": Failed to remove device: " | 704 LOG(WARNING) << object_path_.value() << ": Failed to remove device: " |
| 714 << error_name << ": " << error_message; | 705 << error_name << ": " << error_message; |
| 715 error_callback.Run(); | 706 error_callback.Run(); |
| 716 } | 707 } |
| 717 | 708 |
| 718 } // namespace chromeos | 709 } // namespace chromeos |
| OLD | NEW |