| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/dbus/fake_bluetooth_device_client.h" | 5 #include "device/bluetooth/dbus/fake_bluetooth_device_client.h" |
| 6 | 6 |
| 7 #include <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <sys/socket.h> | 9 #include <sys/socket.h> |
| 10 #include <sys/types.h> | 10 #include <sys/types.h> |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 const char FakeBluetoothDeviceClient::kConnectedTrustedNotPairedDevicePath[] = | 211 const char FakeBluetoothDeviceClient::kConnectedTrustedNotPairedDevicePath[] = |
| 212 "/fake/hci0/devE"; | 212 "/fake/hci0/devE"; |
| 213 const char | 213 const char |
| 214 FakeBluetoothDeviceClient::kConnectedTrustedNotPairedDeviceAddress[] = | 214 FakeBluetoothDeviceClient::kConnectedTrustedNotPairedDeviceAddress[] = |
| 215 "11:22:33:44:55:66"; | 215 "11:22:33:44:55:66"; |
| 216 const char FakeBluetoothDeviceClient::kConnectedTrustedNotPairedDeviceName[] = | 216 const char FakeBluetoothDeviceClient::kConnectedTrustedNotPairedDeviceName[] = |
| 217 "Connected Pairable Device"; | 217 "Connected Pairable Device"; |
| 218 const uint32_t | 218 const uint32_t |
| 219 FakeBluetoothDeviceClient::kConnectedTrustedNotPairedDeviceClass = 0x7a020c; | 219 FakeBluetoothDeviceClient::kConnectedTrustedNotPairedDeviceClass = 0x7a020c; |
| 220 | 220 |
| 221 const char FakeBluetoothDeviceClient::kCachedLowEnergyPath[] = | |
| 222 "/fake/hci0/devF"; | |
| 223 const char FakeBluetoothDeviceClient::kCachedLowEnergyAddress[] = | |
| 224 "02:A5:11:0D:15:40"; | |
| 225 const char FakeBluetoothDeviceClient::kCachedLowEnergyName[] = | |
| 226 "Bluetooth 4.0 Heart Rate Monitor"; | |
| 227 const uint32_t FakeBluetoothDeviceClient::kCachedLowEnergyClass = | |
| 228 0x000918; // Major class "Health", Minor class "Heart/Pulse Rate Monitor." | |
| 229 | |
| 230 FakeBluetoothDeviceClient::Properties::Properties( | 221 FakeBluetoothDeviceClient::Properties::Properties( |
| 231 const PropertyChangedCallback& callback) | 222 const PropertyChangedCallback& callback) |
| 232 : BluetoothDeviceClient::Properties( | 223 : BluetoothDeviceClient::Properties( |
| 233 NULL, | 224 NULL, |
| 234 bluetooth_device::kBluetoothDeviceInterface, | 225 bluetooth_device::kBluetoothDeviceInterface, |
| 235 callback) {} | 226 callback) {} |
| 236 | 227 |
| 237 FakeBluetoothDeviceClient::Properties::~Properties() {} | 228 FakeBluetoothDeviceClient::Properties::~Properties() {} |
| 238 | 229 |
| 239 void FakeBluetoothDeviceClient::Properties::Get( | 230 void FakeBluetoothDeviceClient::Properties::Get( |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 // The device can be connected. | 384 // The device can be connected. |
| 394 properties->connected.ReplaceValue(true); | 385 properties->connected.ReplaceValue(true); |
| 395 callback.Run(); | 386 callback.Run(); |
| 396 | 387 |
| 397 // Expose GATT services if connected to LE device. | 388 // Expose GATT services if connected to LE device. |
| 398 if (object_path == dbus::ObjectPath(kLowEnergyPath)) { | 389 if (object_path == dbus::ObjectPath(kLowEnergyPath)) { |
| 399 FakeBluetoothGattServiceClient* gatt_service_client = | 390 FakeBluetoothGattServiceClient* gatt_service_client = |
| 400 static_cast<FakeBluetoothGattServiceClient*>( | 391 static_cast<FakeBluetoothGattServiceClient*>( |
| 401 bluez::BluezDBusManager::Get()->GetBluetoothGattServiceClient()); | 392 bluez::BluezDBusManager::Get()->GetBluetoothGattServiceClient()); |
| 402 gatt_service_client->ExposeHeartRateService(object_path); | 393 gatt_service_client->ExposeHeartRateService(object_path); |
| 394 properties->services_resolved.ReplaceValue(true); |
| 403 } | 395 } |
| 404 | 396 |
| 405 AddInputDeviceIfNeeded(object_path, properties); | 397 AddInputDeviceIfNeeded(object_path, properties); |
| 406 } | 398 } |
| 407 | 399 |
| 408 void FakeBluetoothDeviceClient::Disconnect( | 400 void FakeBluetoothDeviceClient::Disconnect( |
| 409 const dbus::ObjectPath& object_path, | 401 const dbus::ObjectPath& object_path, |
| 410 const base::Closure& callback, | 402 const base::Closure& callback, |
| 411 const ErrorCallback& error_callback) { | 403 const ErrorCallback& error_callback) { |
| 412 VLOG(1) << "Disconnect: " << object_path.value(); | 404 VLOG(1) << "Disconnect: " << object_path.value(); |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 689 properties->address.ReplaceValue(kJustWorksAddress); | 681 properties->address.ReplaceValue(kJustWorksAddress); |
| 690 properties->bluetooth_class.ReplaceValue(kJustWorksClass); | 682 properties->bluetooth_class.ReplaceValue(kJustWorksClass); |
| 691 properties->name.ReplaceValue("JustWorks"); | 683 properties->name.ReplaceValue("JustWorks"); |
| 692 properties->alias.ReplaceValue(kJustWorksName); | 684 properties->alias.ReplaceValue(kJustWorksName); |
| 693 | 685 |
| 694 } else if (device_path == dbus::ObjectPath(kLowEnergyPath)) { | 686 } else if (device_path == dbus::ObjectPath(kLowEnergyPath)) { |
| 695 properties->address.ReplaceValue(kLowEnergyAddress); | 687 properties->address.ReplaceValue(kLowEnergyAddress); |
| 696 properties->bluetooth_class.ReplaceValue(kLowEnergyClass); | 688 properties->bluetooth_class.ReplaceValue(kLowEnergyClass); |
| 697 properties->name.ReplaceValue("Heart Rate Monitor"); | 689 properties->name.ReplaceValue("Heart Rate Monitor"); |
| 698 properties->alias.ReplaceValue(kLowEnergyName); | 690 properties->alias.ReplaceValue(kLowEnergyName); |
| 691 properties->services_resolved.ReplaceValue(false); |
| 699 | 692 |
| 700 std::vector<std::string> uuids; | 693 std::vector<std::string> uuids; |
| 701 uuids.push_back(FakeBluetoothGattServiceClient::kHeartRateServiceUUID); | 694 uuids.push_back(FakeBluetoothGattServiceClient::kHeartRateServiceUUID); |
| 702 properties->uuids.ReplaceValue(uuids); | 695 properties->uuids.ReplaceValue(uuids); |
| 703 } else if (device_path == | 696 } else if (device_path == |
| 704 dbus::ObjectPath(kConnectedTrustedNotPairedDevicePath)) { | 697 dbus::ObjectPath(kConnectedTrustedNotPairedDevicePath)) { |
| 705 properties->address.ReplaceValue(kConnectedTrustedNotPairedDeviceAddress); | 698 properties->address.ReplaceValue(kConnectedTrustedNotPairedDeviceAddress); |
| 706 properties->bluetooth_class.ReplaceValue( | 699 properties->bluetooth_class.ReplaceValue( |
| 707 kConnectedTrustedNotPairedDeviceClass); | 700 kConnectedTrustedNotPairedDeviceClass); |
| 708 properties->trusted.ReplaceValue(true); | 701 properties->trusted.ReplaceValue(true); |
| 709 properties->connected.ReplaceValue(true); | 702 properties->connected.ReplaceValue(true); |
| 710 properties->paired.ReplaceValue(false); | 703 properties->paired.ReplaceValue(false); |
| 711 properties->name.ReplaceValue("Connected Pairable Device"); | 704 properties->name.ReplaceValue("Connected Pairable Device"); |
| 712 properties->alias.ReplaceValue(kConnectedTrustedNotPairedDeviceName); | 705 properties->alias.ReplaceValue(kConnectedTrustedNotPairedDeviceName); |
| 713 } else if (device_path == dbus::ObjectPath(kCachedLowEnergyPath)) { | |
| 714 properties->address.ReplaceValue(kLowEnergyAddress); | |
| 715 properties->bluetooth_class.ReplaceValue(kLowEnergyClass); | |
| 716 properties->name.ReplaceValue("Heart Rate Monitor"); | |
| 717 properties->alias.ReplaceValue(kLowEnergyName); | |
| 718 properties->alias.ReplaceValue(kLowEnergyName); | |
| 719 properties->services_resolved.ReplaceValue(false); | |
| 720 | |
| 721 std::vector<std::string> uuids; | |
| 722 uuids.push_back(FakeBluetoothGattServiceClient::kHeartRateServiceUUID); | |
| 723 properties->uuids.ReplaceValue(uuids); | |
| 724 } else { | 706 } else { |
| 725 NOTREACHED(); | 707 NOTREACHED(); |
| 726 } | 708 } |
| 727 | 709 |
| 728 properties_map_.insert(std::make_pair(device_path, std::move(properties))); | 710 properties_map_.insert(std::make_pair(device_path, std::move(properties))); |
| 729 device_list_.push_back(device_path); | 711 device_list_.push_back(device_path); |
| 730 | 712 |
| 731 // After the new properties| is added to the map, expose the heart rate | |
| 732 // service to emulate the device with cached GATT services. | |
| 733 if (device_path == dbus::ObjectPath(kCachedLowEnergyPath)) { | |
| 734 static_cast<FakeBluetoothGattServiceClient*>( | |
| 735 bluez::BluezDBusManager::Get()->GetBluetoothGattServiceClient()) | |
| 736 ->ExposeHeartRateServiceWithoutDelay(device_path); | |
| 737 } | |
| 738 | |
| 739 FOR_EACH_OBSERVER(BluetoothDeviceClient::Observer, observers_, | 713 FOR_EACH_OBSERVER(BluetoothDeviceClient::Observer, observers_, |
| 740 DeviceAdded(device_path)); | 714 DeviceAdded(device_path)); |
| 741 } | 715 } |
| 742 | 716 |
| 743 void FakeBluetoothDeviceClient::CreateDeviceWithProperties( | 717 void FakeBluetoothDeviceClient::CreateDeviceWithProperties( |
| 744 const dbus::ObjectPath& adapter_path, | 718 const dbus::ObjectPath& adapter_path, |
| 745 const IncomingDeviceProperties& props) { | 719 const IncomingDeviceProperties& props) { |
| 746 dbus::ObjectPath device_path(props.device_path); | 720 dbus::ObjectPath device_path(props.device_path); |
| 747 if (std::find(device_list_.begin(), device_list_.end(), device_path) != | 721 if (std::find(device_list_.begin(), device_list_.end(), device_path) != |
| 748 device_list_.end()) | 722 device_list_.end()) |
| (...skipping 995 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1744 } | 1718 } |
| 1745 properties->type.set_valid(true); | 1719 properties->type.set_valid(true); |
| 1746 | 1720 |
| 1747 properties_map_.insert(std::make_pair(device_path, std::move(properties))); | 1721 properties_map_.insert(std::make_pair(device_path, std::move(properties))); |
| 1748 device_list_.push_back(device_path); | 1722 device_list_.push_back(device_path); |
| 1749 FOR_EACH_OBSERVER(BluetoothDeviceClient::Observer, observers_, | 1723 FOR_EACH_OBSERVER(BluetoothDeviceClient::Observer, observers_, |
| 1750 DeviceAdded(device_path)); | 1724 DeviceAdded(device_path)); |
| 1751 } | 1725 } |
| 1752 | 1726 |
| 1753 } // namespace bluez | 1727 } // namespace bluez |
| OLD | NEW |