Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(163)

Side by Side Diff: chromeos/dbus/fake_bluetooth_device_client.cc

Issue 735893002: Add GetConnectionInfo function for BluetoothDevice, replacing the existing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixes Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 } else { 214 } else {
215 callback.Run(false); 215 callback.Run(false);
216 } 216 }
217 } 217 }
218 218
219 FakeBluetoothDeviceClient::FakeBluetoothDeviceClient() 219 FakeBluetoothDeviceClient::FakeBluetoothDeviceClient()
220 : simulation_interval_ms_(kSimulationIntervalMs), 220 : simulation_interval_ms_(kSimulationIntervalMs),
221 discovery_simulation_step_(0), 221 discovery_simulation_step_(0),
222 incoming_pairing_simulation_step_(0), 222 incoming_pairing_simulation_step_(0),
223 pairing_cancelled_(false), 223 pairing_cancelled_(false),
224 connection_monitor_started_(false) { 224 connection_rssi_(0),
225 transmit_power_(0),
226 max_transmit_power_(0) {
armansito 2015/01/06 20:36:07 Want to set these to 127 by default?
Tim Song 2015/01/06 22:30:50 Done.
225 Properties* properties = new Properties(base::Bind( 227 Properties* properties = new Properties(base::Bind(
226 &FakeBluetoothDeviceClient::OnPropertyChanged, 228 &FakeBluetoothDeviceClient::OnPropertyChanged,
227 base::Unretained(this), 229 base::Unretained(this),
228 dbus::ObjectPath(kPairedDevicePath))); 230 dbus::ObjectPath(kPairedDevicePath)));
229 properties->address.ReplaceValue(kPairedDeviceAddress); 231 properties->address.ReplaceValue(kPairedDeviceAddress);
230 properties->bluetooth_class.ReplaceValue(kPairedDeviceClass); 232 properties->bluetooth_class.ReplaceValue(kPairedDeviceClass);
231 properties->name.ReplaceValue("Fake Device (Name)"); 233 properties->name.ReplaceValue("Fake Device (Name)");
232 properties->alias.ReplaceValue(kPairedDeviceName); 234 properties->alias.ReplaceValue(kPairedDeviceName);
233 properties->paired.ReplaceValue(true); 235 properties->paired.ReplaceValue(true);
234 properties->trusted.ReplaceValue(true); 236 properties->trusted.ReplaceValue(true);
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 456
455 void FakeBluetoothDeviceClient::CancelPairing( 457 void FakeBluetoothDeviceClient::CancelPairing(
456 const dbus::ObjectPath& object_path, 458 const dbus::ObjectPath& object_path,
457 const base::Closure& callback, 459 const base::Closure& callback,
458 const ErrorCallback& error_callback) { 460 const ErrorCallback& error_callback) {
459 VLOG(1) << "CancelPairing: " << object_path.value(); 461 VLOG(1) << "CancelPairing: " << object_path.value();
460 pairing_cancelled_ = true; 462 pairing_cancelled_ = true;
461 callback.Run(); 463 callback.Run();
462 } 464 }
463 465
464 void FakeBluetoothDeviceClient::StartConnectionMonitor( 466 void FakeBluetoothDeviceClient::GetConnInfo(
465 const dbus::ObjectPath& object_path, 467 const dbus::ObjectPath& object_path,
466 const base::Closure& callback, 468 const ConnInfoCallback& callback,
467 const ErrorCallback& error_callback) { 469 const ErrorCallback& error_callback) {
468 VLOG(1) << "StartConnectionMonitor: " << object_path.value(); 470 Properties* properties = GetProperties(object_path);
469 connection_monitor_started_ = true; 471 if (!properties->connected.value()) {
470 callback.Run(); 472 error_callback.Run("org.bluez.Error.NotConnected", "Not Connected");
471 } 473 return;
474 }
472 475
473 void FakeBluetoothDeviceClient::StopConnectionMonitor( 476 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 } 477 }
480 478
481 void FakeBluetoothDeviceClient::BeginDiscoverySimulation( 479 void FakeBluetoothDeviceClient::BeginDiscoverySimulation(
482 const dbus::ObjectPath& adapter_path) { 480 const dbus::ObjectPath& adapter_path) {
483 VLOG(1) << "starting discovery simulation"; 481 VLOG(1) << "starting discovery simulation";
484 482
485 discovery_simulation_step_ = 1; 483 discovery_simulation_step_ = 1;
486 484
487 base::MessageLoop::current()->PostDelayedTask( 485 base::MessageLoop::current()->PostDelayedTask(
488 FROM_HERE, 486 FROM_HERE,
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after
1012 PropertiesMap::iterator iter = properties_map_.find(object_path); 1010 PropertiesMap::iterator iter = properties_map_.find(object_path);
1013 if (iter == properties_map_.end()) { 1011 if (iter == properties_map_.end()) {
1014 VLOG(2) << "Fake device does not exist: " << object_path.value(); 1012 VLOG(2) << "Fake device does not exist: " << object_path.value();
1015 return; 1013 return;
1016 } 1014 }
1017 Properties* properties = iter->second; 1015 Properties* properties = iter->second;
1018 DCHECK(properties); 1016 DCHECK(properties);
1019 properties->rssi.ReplaceValue(rssi); 1017 properties->rssi.ReplaceValue(rssi);
1020 } 1018 }
1021 1019
1020 void FakeBluetoothDeviceClient::UpdateConnectionInfo(
1021 uint16 connection_rssi,
1022 uint16 transmit_power,
1023 uint16 max_transmit_power) {
1024 connection_rssi_ = connection_rssi;
1025 transmit_power_ = transmit_power;
1026 max_transmit_power_ = max_transmit_power;
1027 }
1028
1022 void FakeBluetoothDeviceClient::PinCodeCallback( 1029 void FakeBluetoothDeviceClient::PinCodeCallback(
1023 const dbus::ObjectPath& object_path, 1030 const dbus::ObjectPath& object_path,
1024 const base::Closure& callback, 1031 const base::Closure& callback,
1025 const ErrorCallback& error_callback, 1032 const ErrorCallback& error_callback,
1026 BluetoothAgentServiceProvider::Delegate::Status status, 1033 BluetoothAgentServiceProvider::Delegate::Status status,
1027 const std::string& pincode) { 1034 const std::string& pincode) {
1028 VLOG(1) << "PinCodeCallback: " << object_path.value(); 1035 VLOG(1) << "PinCodeCallback: " << object_path.value();
1029 1036
1030 if (status == BluetoothAgentServiceProvider::Delegate::SUCCESS) { 1037 if (status == BluetoothAgentServiceProvider::Delegate::SUCCESS) {
1031 base::MessageLoop::current()->PostDelayedTask( 1038 base::MessageLoop::current()->PostDelayedTask(
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
1191 // TODO(keybuk): tear down this side of the connection 1198 // TODO(keybuk): tear down this side of the connection
1192 callback.Run(); 1199 callback.Run();
1193 } else if (status == BluetoothProfileServiceProvider::Delegate::CANCELLED) { 1200 } else if (status == BluetoothProfileServiceProvider::Delegate::CANCELLED) {
1194 error_callback.Run(bluetooth_device::kErrorFailed, "Canceled"); 1201 error_callback.Run(bluetooth_device::kErrorFailed, "Canceled");
1195 } else if (status == BluetoothProfileServiceProvider::Delegate::REJECTED) { 1202 } else if (status == BluetoothProfileServiceProvider::Delegate::REJECTED) {
1196 error_callback.Run(bluetooth_device::kErrorFailed, "Rejected"); 1203 error_callback.Run(bluetooth_device::kErrorFailed, "Rejected");
1197 } 1204 }
1198 } 1205 }
1199 1206
1200 } // namespace chromeos 1207 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698