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 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 const char FakeBluetoothDeviceClient::kConnectedTrustedNotPairedDevicePath[] = | 246 const char FakeBluetoothDeviceClient::kConnectedTrustedNotPairedDevicePath[] = |
247 "/fake/hci0/devE"; | 247 "/fake/hci0/devE"; |
248 const char | 248 const char |
249 FakeBluetoothDeviceClient::kConnectedTrustedNotPairedDeviceAddress[] = | 249 FakeBluetoothDeviceClient::kConnectedTrustedNotPairedDeviceAddress[] = |
250 "11:22:33:44:55:66"; | 250 "11:22:33:44:55:66"; |
251 const char FakeBluetoothDeviceClient::kConnectedTrustedNotPairedDeviceName[] = | 251 const char FakeBluetoothDeviceClient::kConnectedTrustedNotPairedDeviceName[] = |
252 "Connected Pairable Device"; | 252 "Connected Pairable Device"; |
253 const uint32_t | 253 const uint32_t |
254 FakeBluetoothDeviceClient::kConnectedTrustedNotPairedDeviceClass = 0x7a020c; | 254 FakeBluetoothDeviceClient::kConnectedTrustedNotPairedDeviceClass = 0x7a020c; |
255 | 255 |
256 const char FakeBluetoothDeviceClient::kCachedLowEnergyPath[] = | |
257 "/fake/hci0/devF"; | |
258 const char FakeBluetoothDeviceClient::kCachedLowEnergyAddress[] = | |
259 "02:A5:11:0D:15:40"; | |
260 const char FakeBluetoothDeviceClient::kCachedLowEnergyName[] = | |
261 "Bluetooth 4.0 Heart Rate Monitor"; | |
262 const uint32_t FakeBluetoothDeviceClient::kCachedLowEnergyClass = | |
263 0x000918; // Major class "Health", Minor class "Heart/Pulse Rate Monitor." | |
264 | |
265 FakeBluetoothDeviceClient::Properties::Properties( | 256 FakeBluetoothDeviceClient::Properties::Properties( |
266 const PropertyChangedCallback& callback) | 257 const PropertyChangedCallback& callback) |
267 : BluetoothDeviceClient::Properties( | 258 : BluetoothDeviceClient::Properties( |
268 NULL, | 259 NULL, |
269 bluetooth_device::kBluetoothDeviceInterface, | 260 bluetooth_device::kBluetoothDeviceInterface, |
270 callback) {} | 261 callback) {} |
271 | 262 |
272 FakeBluetoothDeviceClient::Properties::~Properties() {} | 263 FakeBluetoothDeviceClient::Properties::~Properties() {} |
273 | 264 |
274 void FakeBluetoothDeviceClient::Properties::Get( | 265 void FakeBluetoothDeviceClient::Properties::Get( |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 // The device can be connected. | 419 // The device can be connected. |
429 properties->connected.ReplaceValue(true); | 420 properties->connected.ReplaceValue(true); |
430 callback.Run(); | 421 callback.Run(); |
431 | 422 |
432 // Expose GATT services if connected to LE device. | 423 // Expose GATT services if connected to LE device. |
433 if (object_path == dbus::ObjectPath(kLowEnergyPath)) { | 424 if (object_path == dbus::ObjectPath(kLowEnergyPath)) { |
434 FakeBluetoothGattServiceClient* gatt_service_client = | 425 FakeBluetoothGattServiceClient* gatt_service_client = |
435 static_cast<FakeBluetoothGattServiceClient*>( | 426 static_cast<FakeBluetoothGattServiceClient*>( |
436 bluez::BluezDBusManager::Get()->GetBluetoothGattServiceClient()); | 427 bluez::BluezDBusManager::Get()->GetBluetoothGattServiceClient()); |
437 gatt_service_client->ExposeHeartRateService(object_path); | 428 gatt_service_client->ExposeHeartRateService(object_path); |
| 429 properties->services_resolved.ReplaceValue(true); |
438 } | 430 } |
439 | 431 |
440 AddInputDeviceIfNeeded(object_path, properties); | 432 AddInputDeviceIfNeeded(object_path, properties); |
441 } | 433 } |
442 | 434 |
443 void FakeBluetoothDeviceClient::Disconnect( | 435 void FakeBluetoothDeviceClient::Disconnect( |
444 const dbus::ObjectPath& object_path, | 436 const dbus::ObjectPath& object_path, |
445 const base::Closure& callback, | 437 const base::Closure& callback, |
446 const ErrorCallback& error_callback) { | 438 const ErrorCallback& error_callback) { |
447 VLOG(1) << "Disconnect: " << object_path.value(); | 439 VLOG(1) << "Disconnect: " << object_path.value(); |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
736 properties->address.ReplaceValue(kJustWorksAddress); | 728 properties->address.ReplaceValue(kJustWorksAddress); |
737 properties->bluetooth_class.ReplaceValue(kJustWorksClass); | 729 properties->bluetooth_class.ReplaceValue(kJustWorksClass); |
738 properties->name.ReplaceValue("JustWorks"); | 730 properties->name.ReplaceValue("JustWorks"); |
739 properties->alias.ReplaceValue(kJustWorksName); | 731 properties->alias.ReplaceValue(kJustWorksName); |
740 | 732 |
741 } else if (device_path == dbus::ObjectPath(kLowEnergyPath)) { | 733 } else if (device_path == dbus::ObjectPath(kLowEnergyPath)) { |
742 properties->address.ReplaceValue(kLowEnergyAddress); | 734 properties->address.ReplaceValue(kLowEnergyAddress); |
743 properties->bluetooth_class.ReplaceValue(kLowEnergyClass); | 735 properties->bluetooth_class.ReplaceValue(kLowEnergyClass); |
744 properties->name.ReplaceValue("Heart Rate Monitor"); | 736 properties->name.ReplaceValue("Heart Rate Monitor"); |
745 properties->alias.ReplaceValue(kLowEnergyName); | 737 properties->alias.ReplaceValue(kLowEnergyName); |
| 738 properties->services_resolved.ReplaceValue(false); |
746 | 739 |
747 std::vector<std::string> uuids; | 740 std::vector<std::string> uuids; |
748 uuids.push_back(FakeBluetoothGattServiceClient::kHeartRateServiceUUID); | 741 uuids.push_back(FakeBluetoothGattServiceClient::kHeartRateServiceUUID); |
749 properties->uuids.ReplaceValue(uuids); | 742 properties->uuids.ReplaceValue(uuids); |
750 } else if (device_path == | 743 } else if (device_path == |
751 dbus::ObjectPath(kConnectedTrustedNotPairedDevicePath)) { | 744 dbus::ObjectPath(kConnectedTrustedNotPairedDevicePath)) { |
752 properties->address.ReplaceValue(kConnectedTrustedNotPairedDeviceAddress); | 745 properties->address.ReplaceValue(kConnectedTrustedNotPairedDeviceAddress); |
753 properties->bluetooth_class.ReplaceValue( | 746 properties->bluetooth_class.ReplaceValue( |
754 kConnectedTrustedNotPairedDeviceClass); | 747 kConnectedTrustedNotPairedDeviceClass); |
755 properties->trusted.ReplaceValue(true); | 748 properties->trusted.ReplaceValue(true); |
756 properties->connected.ReplaceValue(true); | 749 properties->connected.ReplaceValue(true); |
757 properties->paired.ReplaceValue(false); | 750 properties->paired.ReplaceValue(false); |
758 properties->name.ReplaceValue("Connected Pairable Device"); | 751 properties->name.ReplaceValue("Connected Pairable Device"); |
759 properties->alias.ReplaceValue(kConnectedTrustedNotPairedDeviceName); | 752 properties->alias.ReplaceValue(kConnectedTrustedNotPairedDeviceName); |
760 } else if (device_path == dbus::ObjectPath(kCachedLowEnergyPath)) { | |
761 properties->address.ReplaceValue(kLowEnergyAddress); | |
762 properties->bluetooth_class.ReplaceValue(kLowEnergyClass); | |
763 properties->name.ReplaceValue("Heart Rate Monitor"); | |
764 properties->alias.ReplaceValue(kLowEnergyName); | |
765 properties->alias.ReplaceValue(kLowEnergyName); | |
766 properties->services_resolved.ReplaceValue(false); | |
767 | |
768 std::vector<std::string> uuids; | |
769 uuids.push_back(FakeBluetoothGattServiceClient::kHeartRateServiceUUID); | |
770 properties->uuids.ReplaceValue(uuids); | |
771 } else { | 753 } else { |
772 NOTREACHED(); | 754 NOTREACHED(); |
773 } | 755 } |
774 | 756 |
775 properties_map_.insert(std::make_pair(device_path, std::move(properties))); | 757 properties_map_.insert(std::make_pair(device_path, std::move(properties))); |
776 device_list_.push_back(device_path); | 758 device_list_.push_back(device_path); |
777 | 759 |
778 // After the new properties| is added to the map, expose the heart rate | |
779 // service to emulate the device with cached GATT services. | |
780 if (device_path == dbus::ObjectPath(kCachedLowEnergyPath)) { | |
781 static_cast<FakeBluetoothGattServiceClient*>( | |
782 bluez::BluezDBusManager::Get()->GetBluetoothGattServiceClient()) | |
783 ->ExposeHeartRateServiceWithoutDelay(device_path); | |
784 } | |
785 | |
786 FOR_EACH_OBSERVER(BluetoothDeviceClient::Observer, observers_, | 760 FOR_EACH_OBSERVER(BluetoothDeviceClient::Observer, observers_, |
787 DeviceAdded(device_path)); | 761 DeviceAdded(device_path)); |
788 } | 762 } |
789 | 763 |
790 void FakeBluetoothDeviceClient::CreateDeviceWithProperties( | 764 void FakeBluetoothDeviceClient::CreateDeviceWithProperties( |
791 const dbus::ObjectPath& adapter_path, | 765 const dbus::ObjectPath& adapter_path, |
792 const IncomingDeviceProperties& props) { | 766 const IncomingDeviceProperties& props) { |
793 dbus::ObjectPath device_path(props.device_path); | 767 dbus::ObjectPath device_path(props.device_path); |
794 if (std::find(device_list_.begin(), device_list_.end(), device_path) != | 768 if (std::find(device_list_.begin(), device_list_.end(), device_path) != |
795 device_list_.end()) | 769 device_list_.end()) |
(...skipping 995 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1791 } | 1765 } |
1792 properties->type.set_valid(true); | 1766 properties->type.set_valid(true); |
1793 | 1767 |
1794 properties_map_.insert(std::make_pair(device_path, std::move(properties))); | 1768 properties_map_.insert(std::make_pair(device_path, std::move(properties))); |
1795 device_list_.push_back(device_path); | 1769 device_list_.push_back(device_path); |
1796 FOR_EACH_OBSERVER(BluetoothDeviceClient::Observer, observers_, | 1770 FOR_EACH_OBSERVER(BluetoothDeviceClient::Observer, observers_, |
1797 DeviceAdded(device_path)); | 1771 DeviceAdded(device_path)); |
1798 } | 1772 } |
1799 | 1773 |
1800 } // namespace bluez | 1774 } // namespace bluez |
OLD | NEW |