diff options
author | tengs <tengs@chromium.org> | 2015-01-07 13:31:30 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-01-07 21:32:08 +0000 |
commit | d060690f69581b758adb9b477ebe5e08acbccfa7 (patch) | |
tree | 6dfd27e6130f8c961ffa84b628edc017e16e6173 /chromeos/dbus/bluetooth_device_client.cc | |
parent | 574fc997fce7f47ee223764f02ac1c423265ff0a (diff) | |
download | chromium_src-d060690f69581b758adb9b477ebe5e08acbccfa7.zip chromium_src-d060690f69581b758adb9b477ebe5e08acbccfa7.tar.gz chromium_src-d060690f69581b758adb9b477ebe5e08acbccfa7.tar.bz2 |
Add GetConnectionInfo function for BluetoothDevice, replacing the existing
GetRSSI, GetHostTransmitPower, and GetMaximumHostTransmitPower functions.
On Mac, this function uses IOBluetooth APIs.
On ChromeOS, this function is a wrapper for the GetConnInfo() DBus plugin API.
On Windows, this function is unimplemented.
BUG=382683
Review URL: https://codereview.chromium.org/735893002
Cr-Commit-Position: refs/heads/master@{#310372}
Diffstat (limited to 'chromeos/dbus/bluetooth_device_client.cc')
-rw-r--r-- | chromeos/dbus/bluetooth_device_client.cc | 80 |
1 files changed, 38 insertions, 42 deletions
diff --git a/chromeos/dbus/bluetooth_device_client.cc b/chromeos/dbus/bluetooth_device_client.cc index 777b1aa..e2eae7d 100644 --- a/chromeos/dbus/bluetooth_device_client.cc +++ b/chromeos/dbus/bluetooth_device_client.cc @@ -16,6 +16,13 @@ namespace chromeos { +namespace { + +// Value returned for the the RSSI or TX power if it cannot be read. +const int kUnknownPower = 127; + +} // namespace + const char BluetoothDeviceClient::kNoResponseError[] = "org.chromium.Error.NoResponse"; const char BluetoothDeviceClient::kUnknownDeviceError[] = @@ -41,10 +48,6 @@ BluetoothDeviceClient::Properties::Properties( RegisterProperty(bluetooth_device::kLegacyPairingProperty, &legacy_pairing); RegisterProperty(bluetooth_device::kModaliasProperty, &modalias); RegisterProperty(bluetooth_device::kRSSIProperty, &rssi); - RegisterProperty(bluetooth_device::kConnectionRSSI, &connection_rssi); - RegisterProperty(bluetooth_device::kConnectionTXPower, &connection_tx_power); - RegisterProperty(bluetooth_device::kConnectionTXPowerMax, - &connection_tx_power_max); } BluetoothDeviceClient::Properties::~Properties() { @@ -273,37 +276,12 @@ class BluetoothDeviceClientImpl } // BluetoothDeviceClient override. - virtual void StartConnectionMonitor( - const dbus::ObjectPath& object_path, - const base::Closure& callback, - const ErrorCallback& error_callback) override { - dbus::MethodCall method_call(bluetooth_device::kBluetoothDeviceInterface, - bluetooth_device::kStartConnectionMonitor); - - dbus::ObjectProxy* object_proxy = - object_manager_->GetObjectProxy(object_path); - if (!object_proxy) { - error_callback.Run(kUnknownDeviceError, ""); - return; - } - object_proxy->CallMethodWithErrorCallback( - &method_call, - dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, - base::Bind(&BluetoothDeviceClientImpl::OnSuccess, - weak_ptr_factory_.GetWeakPtr(), - callback), - base::Bind(&BluetoothDeviceClientImpl::OnError, - weak_ptr_factory_.GetWeakPtr(), - error_callback)); - } - - // BluetoothDeviceClient override. - virtual void StopConnectionMonitor( - const dbus::ObjectPath& object_path, - const base::Closure& callback, - const ErrorCallback& error_callback) override { - dbus::MethodCall method_call(bluetooth_device::kBluetoothDeviceInterface, - bluetooth_device::kStopConnectionMonitor); + void GetConnInfo(const dbus::ObjectPath& object_path, + const ConnInfoCallback& callback, + const ErrorCallback& error_callback) override { + dbus::MethodCall method_call( + bluetooth_plugin_device::kBluetoothPluginInterface, + bluetooth_plugin_device::kGetConnInfo); dbus::ObjectProxy* object_proxy = object_manager_->GetObjectProxy(object_path); @@ -312,14 +290,11 @@ class BluetoothDeviceClientImpl return; } object_proxy->CallMethodWithErrorCallback( - &method_call, - dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, - base::Bind(&BluetoothDeviceClientImpl::OnSuccess, - weak_ptr_factory_.GetWeakPtr(), - callback), + &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, + base::Bind(&BluetoothDeviceClientImpl::OnGetConnInfoSuccess, + weak_ptr_factory_.GetWeakPtr(), callback), base::Bind(&BluetoothDeviceClientImpl::OnError, - weak_ptr_factory_.GetWeakPtr(), - error_callback)); + weak_ptr_factory_.GetWeakPtr(), error_callback)); } protected: @@ -365,6 +340,27 @@ class BluetoothDeviceClientImpl callback.Run(); } + // Called when a response for the GetConnInfo method is received. + void OnGetConnInfoSuccess(const ConnInfoCallback& callback, + dbus::Response* response) { + int16 rssi = kUnknownPower; + int16 transmit_power = kUnknownPower; + int16 max_transmit_power = kUnknownPower; + + if (!response) { + LOG(ERROR) << "GetConnInfo succeeded, but no response received."; + callback.Run(rssi, transmit_power, max_transmit_power); + return; + } + + dbus::MessageReader reader(response); + if (!reader.PopInt16(&rssi) || !reader.PopInt16(&transmit_power) || + !reader.PopInt16(&max_transmit_power)) { + LOG(ERROR) << "Arguments for GetConnInfo invalid."; + } + callback.Run(rssi, transmit_power, max_transmit_power); + } + // Called when a response for a failed method call is received. void OnError(const ErrorCallback& error_callback, dbus::ErrorResponse* response) { |