| 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 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 689 properties->address.ReplaceValue(kJustWorksAddress); | 680 properties->address.ReplaceValue(kJustWorksAddress); |
| 690 properties->bluetooth_class.ReplaceValue(kJustWorksClass); | 681 properties->bluetooth_class.ReplaceValue(kJustWorksClass); |
| 691 properties->name.ReplaceValue("JustWorks"); | 682 properties->name.ReplaceValue("JustWorks"); |
| 692 properties->alias.ReplaceValue(kJustWorksName); | 683 properties->alias.ReplaceValue(kJustWorksName); |
| 693 | 684 |
| 694 } else if (device_path == dbus::ObjectPath(kLowEnergyPath)) { | 685 } else if (device_path == dbus::ObjectPath(kLowEnergyPath)) { |
| 695 properties->address.ReplaceValue(kLowEnergyAddress); | 686 properties->address.ReplaceValue(kLowEnergyAddress); |
| 696 properties->bluetooth_class.ReplaceValue(kLowEnergyClass); | 687 properties->bluetooth_class.ReplaceValue(kLowEnergyClass); |
| 697 properties->name.ReplaceValue("Heart Rate Monitor"); | 688 properties->name.ReplaceValue("Heart Rate Monitor"); |
| 698 properties->alias.ReplaceValue(kLowEnergyName); | 689 properties->alias.ReplaceValue(kLowEnergyName); |
| 690 properties->services_resolved.ReplaceValue(false); |
| 699 | 691 |
| 700 std::vector<std::string> uuids; | 692 std::vector<std::string> uuids; |
| 701 uuids.push_back(FakeBluetoothGattServiceClient::kHeartRateServiceUUID); | 693 uuids.push_back(FakeBluetoothGattServiceClient::kHeartRateServiceUUID); |
| 702 properties->uuids.ReplaceValue(uuids); | 694 properties->uuids.ReplaceValue(uuids); |
| 703 } else if (device_path == | 695 } else if (device_path == |
| 704 dbus::ObjectPath(kConnectedTrustedNotPairedDevicePath)) { | 696 dbus::ObjectPath(kConnectedTrustedNotPairedDevicePath)) { |
| 705 properties->address.ReplaceValue(kConnectedTrustedNotPairedDeviceAddress); | 697 properties->address.ReplaceValue(kConnectedTrustedNotPairedDeviceAddress); |
| 706 properties->bluetooth_class.ReplaceValue( | 698 properties->bluetooth_class.ReplaceValue( |
| 707 kConnectedTrustedNotPairedDeviceClass); | 699 kConnectedTrustedNotPairedDeviceClass); |
| 708 properties->trusted.ReplaceValue(true); | 700 properties->trusted.ReplaceValue(true); |
| 709 properties->connected.ReplaceValue(true); | 701 properties->connected.ReplaceValue(true); |
| 710 properties->paired.ReplaceValue(false); | 702 properties->paired.ReplaceValue(false); |
| 711 properties->name.ReplaceValue("Connected Pairable Device"); | 703 properties->name.ReplaceValue("Connected Pairable Device"); |
| 712 properties->alias.ReplaceValue(kConnectedTrustedNotPairedDeviceName); | 704 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 { | 705 } else { |
| 725 NOTREACHED(); | 706 NOTREACHED(); |
| 726 } | 707 } |
| 727 | 708 |
| 728 properties_map_.insert(std::make_pair(device_path, std::move(properties))); | 709 properties_map_.insert(std::make_pair(device_path, std::move(properties))); |
| 729 device_list_.push_back(device_path); | 710 device_list_.push_back(device_path); |
| 730 | 711 |
| 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_, | 712 FOR_EACH_OBSERVER(BluetoothDeviceClient::Observer, observers_, |
| 740 DeviceAdded(device_path)); | 713 DeviceAdded(device_path)); |
| 741 } | 714 } |
| 742 | 715 |
| 743 void FakeBluetoothDeviceClient::CreateDeviceWithProperties( | 716 void FakeBluetoothDeviceClient::CreateDeviceWithProperties( |
| 744 const dbus::ObjectPath& adapter_path, | 717 const dbus::ObjectPath& adapter_path, |
| 745 const IncomingDeviceProperties& props) { | 718 const IncomingDeviceProperties& props) { |
| 746 dbus::ObjectPath device_path(props.device_path); | 719 dbus::ObjectPath device_path(props.device_path); |
| 747 if (std::find(device_list_.begin(), device_list_.end(), device_path) != | 720 if (std::find(device_list_.begin(), device_list_.end(), device_path) != |
| 748 device_list_.end()) | 721 device_list_.end()) |
| (...skipping 995 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1744 } | 1717 } |
| 1745 properties->type.set_valid(true); | 1718 properties->type.set_valid(true); |
| 1746 | 1719 |
| 1747 properties_map_.insert(std::make_pair(device_path, std::move(properties))); | 1720 properties_map_.insert(std::make_pair(device_path, std::move(properties))); |
| 1748 device_list_.push_back(device_path); | 1721 device_list_.push_back(device_path); |
| 1749 FOR_EACH_OBSERVER(BluetoothDeviceClient::Observer, observers_, | 1722 FOR_EACH_OBSERVER(BluetoothDeviceClient::Observer, observers_, |
| 1750 DeviceAdded(device_path)); | 1723 DeviceAdded(device_path)); |
| 1751 } | 1724 } |
| 1752 | 1725 |
| 1753 } // namespace bluez | 1726 } // namespace bluez |
| OLD | NEW |