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 "chromeos/dbus/fake_bluetooth_device_client.h" | 5 #include "chromeos/dbus/fake_bluetooth_device_client.h" |
6 | 6 |
7 #include <fcntl.h> | 7 #include <fcntl.h> |
8 #include <unistd.h> | 8 #include <unistd.h> |
9 #include <sys/types.h> | 9 #include <sys/types.h> |
10 #include <sys/socket.h> | 10 #include <sys/socket.h> |
(...skipping 26 matching lines...) Expand all Loading... |
37 | 37 |
38 namespace { | 38 namespace { |
39 | 39 |
40 // Default interval between simulated events. | 40 // Default interval between simulated events. |
41 const int kSimulationIntervalMs = 750; | 41 const int kSimulationIntervalMs = 750; |
42 | 42 |
43 // Minimum and maximum bounds for randomly generated RSSI values. | 43 // Minimum and maximum bounds for randomly generated RSSI values. |
44 const int kMinRSSI = -90; | 44 const int kMinRSSI = -90; |
45 const int kMaxRSSI = -30; | 45 const int kMaxRSSI = -30; |
46 | 46 |
| 47 // The default value of connection info properties from GetConnInfo(). |
| 48 const int kUnkownPower = 127; |
| 49 |
47 | 50 |
48 void SimulatedProfileSocket(int fd) { | 51 void SimulatedProfileSocket(int fd) { |
49 // Simulate a server-side socket of a profile; read data from the socket, | 52 // Simulate a server-side socket of a profile; read data from the socket, |
50 // write it back, and then close. | 53 // write it back, and then close. |
51 char buf[1024]; | 54 char buf[1024]; |
52 ssize_t len; | 55 ssize_t len; |
53 ssize_t count; | 56 ssize_t count; |
54 | 57 |
55 len = read(fd, buf, sizeof buf); | 58 len = read(fd, buf, sizeof buf); |
56 if (len < 0) { | 59 if (len < 0) { |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 } else { | 217 } else { |
215 callback.Run(false); | 218 callback.Run(false); |
216 } | 219 } |
217 } | 220 } |
218 | 221 |
219 FakeBluetoothDeviceClient::FakeBluetoothDeviceClient() | 222 FakeBluetoothDeviceClient::FakeBluetoothDeviceClient() |
220 : simulation_interval_ms_(kSimulationIntervalMs), | 223 : simulation_interval_ms_(kSimulationIntervalMs), |
221 discovery_simulation_step_(0), | 224 discovery_simulation_step_(0), |
222 incoming_pairing_simulation_step_(0), | 225 incoming_pairing_simulation_step_(0), |
223 pairing_cancelled_(false), | 226 pairing_cancelled_(false), |
224 connection_monitor_started_(false) { | 227 connection_rssi_(kUnkownPower), |
| 228 transmit_power_(kUnkownPower), |
| 229 max_transmit_power_(kUnkownPower) { |
225 Properties* properties = new Properties(base::Bind( | 230 Properties* properties = new Properties(base::Bind( |
226 &FakeBluetoothDeviceClient::OnPropertyChanged, | 231 &FakeBluetoothDeviceClient::OnPropertyChanged, |
227 base::Unretained(this), | 232 base::Unretained(this), |
228 dbus::ObjectPath(kPairedDevicePath))); | 233 dbus::ObjectPath(kPairedDevicePath))); |
229 properties->address.ReplaceValue(kPairedDeviceAddress); | 234 properties->address.ReplaceValue(kPairedDeviceAddress); |
230 properties->bluetooth_class.ReplaceValue(kPairedDeviceClass); | 235 properties->bluetooth_class.ReplaceValue(kPairedDeviceClass); |
231 properties->name.ReplaceValue("Fake Device (Name)"); | 236 properties->name.ReplaceValue("Fake Device (Name)"); |
232 properties->alias.ReplaceValue(kPairedDeviceName); | 237 properties->alias.ReplaceValue(kPairedDeviceName); |
233 properties->paired.ReplaceValue(true); | 238 properties->paired.ReplaceValue(true); |
234 properties->trusted.ReplaceValue(true); | 239 properties->trusted.ReplaceValue(true); |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 | 459 |
455 void FakeBluetoothDeviceClient::CancelPairing( | 460 void FakeBluetoothDeviceClient::CancelPairing( |
456 const dbus::ObjectPath& object_path, | 461 const dbus::ObjectPath& object_path, |
457 const base::Closure& callback, | 462 const base::Closure& callback, |
458 const ErrorCallback& error_callback) { | 463 const ErrorCallback& error_callback) { |
459 VLOG(1) << "CancelPairing: " << object_path.value(); | 464 VLOG(1) << "CancelPairing: " << object_path.value(); |
460 pairing_cancelled_ = true; | 465 pairing_cancelled_ = true; |
461 callback.Run(); | 466 callback.Run(); |
462 } | 467 } |
463 | 468 |
464 void FakeBluetoothDeviceClient::StartConnectionMonitor( | 469 void FakeBluetoothDeviceClient::GetConnInfo( |
465 const dbus::ObjectPath& object_path, | 470 const dbus::ObjectPath& object_path, |
466 const base::Closure& callback, | 471 const ConnInfoCallback& callback, |
467 const ErrorCallback& error_callback) { | 472 const ErrorCallback& error_callback) { |
468 VLOG(1) << "StartConnectionMonitor: " << object_path.value(); | 473 Properties* properties = GetProperties(object_path); |
469 connection_monitor_started_ = true; | 474 if (!properties->connected.value()) { |
470 callback.Run(); | 475 error_callback.Run("org.bluez.Error.NotConnected", "Not Connected"); |
471 } | 476 return; |
| 477 } |
472 | 478 |
473 void FakeBluetoothDeviceClient::StopConnectionMonitor( | 479 callback.Run(connection_rssi_, transmit_power_, max_transmit_power_); |
474 const dbus::ObjectPath& object_path, | |
475 const base::Closure& callback, | |
476 const ErrorCallback& error_callback) { | |
477 connection_monitor_started_ = false; | |
478 callback.Run(); | |
479 } | 480 } |
480 | 481 |
481 void FakeBluetoothDeviceClient::BeginDiscoverySimulation( | 482 void FakeBluetoothDeviceClient::BeginDiscoverySimulation( |
482 const dbus::ObjectPath& adapter_path) { | 483 const dbus::ObjectPath& adapter_path) { |
483 VLOG(1) << "starting discovery simulation"; | 484 VLOG(1) << "starting discovery simulation"; |
484 | 485 |
485 discovery_simulation_step_ = 1; | 486 discovery_simulation_step_ = 1; |
486 | 487 |
487 base::MessageLoop::current()->PostDelayedTask( | 488 base::MessageLoop::current()->PostDelayedTask( |
488 FROM_HERE, | 489 FROM_HERE, |
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1012 PropertiesMap::iterator iter = properties_map_.find(object_path); | 1013 PropertiesMap::iterator iter = properties_map_.find(object_path); |
1013 if (iter == properties_map_.end()) { | 1014 if (iter == properties_map_.end()) { |
1014 VLOG(2) << "Fake device does not exist: " << object_path.value(); | 1015 VLOG(2) << "Fake device does not exist: " << object_path.value(); |
1015 return; | 1016 return; |
1016 } | 1017 } |
1017 Properties* properties = iter->second; | 1018 Properties* properties = iter->second; |
1018 DCHECK(properties); | 1019 DCHECK(properties); |
1019 properties->rssi.ReplaceValue(rssi); | 1020 properties->rssi.ReplaceValue(rssi); |
1020 } | 1021 } |
1021 | 1022 |
| 1023 void FakeBluetoothDeviceClient::UpdateConnectionInfo( |
| 1024 uint16 connection_rssi, |
| 1025 uint16 transmit_power, |
| 1026 uint16 max_transmit_power) { |
| 1027 connection_rssi_ = connection_rssi; |
| 1028 transmit_power_ = transmit_power; |
| 1029 max_transmit_power_ = max_transmit_power; |
| 1030 } |
| 1031 |
1022 void FakeBluetoothDeviceClient::PinCodeCallback( | 1032 void FakeBluetoothDeviceClient::PinCodeCallback( |
1023 const dbus::ObjectPath& object_path, | 1033 const dbus::ObjectPath& object_path, |
1024 const base::Closure& callback, | 1034 const base::Closure& callback, |
1025 const ErrorCallback& error_callback, | 1035 const ErrorCallback& error_callback, |
1026 BluetoothAgentServiceProvider::Delegate::Status status, | 1036 BluetoothAgentServiceProvider::Delegate::Status status, |
1027 const std::string& pincode) { | 1037 const std::string& pincode) { |
1028 VLOG(1) << "PinCodeCallback: " << object_path.value(); | 1038 VLOG(1) << "PinCodeCallback: " << object_path.value(); |
1029 | 1039 |
1030 if (status == BluetoothAgentServiceProvider::Delegate::SUCCESS) { | 1040 if (status == BluetoothAgentServiceProvider::Delegate::SUCCESS) { |
1031 base::MessageLoop::current()->PostDelayedTask( | 1041 base::MessageLoop::current()->PostDelayedTask( |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1191 // TODO(keybuk): tear down this side of the connection | 1201 // TODO(keybuk): tear down this side of the connection |
1192 callback.Run(); | 1202 callback.Run(); |
1193 } else if (status == BluetoothProfileServiceProvider::Delegate::CANCELLED) { | 1203 } else if (status == BluetoothProfileServiceProvider::Delegate::CANCELLED) { |
1194 error_callback.Run(bluetooth_device::kErrorFailed, "Canceled"); | 1204 error_callback.Run(bluetooth_device::kErrorFailed, "Canceled"); |
1195 } else if (status == BluetoothProfileServiceProvider::Delegate::REJECTED) { | 1205 } else if (status == BluetoothProfileServiceProvider::Delegate::REJECTED) { |
1196 error_callback.Run(bluetooth_device::kErrorFailed, "Rejected"); | 1206 error_callback.Run(bluetooth_device::kErrorFailed, "Rejected"); |
1197 } | 1207 } |
1198 } | 1208 } |
1199 | 1209 |
1200 } // namespace chromeos | 1210 } // namespace chromeos |
OLD | NEW |