OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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/bluetooth_device_chromeos.h" | 5 #include "device/bluetooth/bluetooth_device_chromeos.h" |
6 | 6 |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
121 namespace chromeos { | 121 namespace chromeos { |
122 | 122 |
123 BluetoothDeviceChromeOS::BluetoothDeviceChromeOS( | 123 BluetoothDeviceChromeOS::BluetoothDeviceChromeOS( |
124 BluetoothAdapterChromeOS* adapter, | 124 BluetoothAdapterChromeOS* adapter, |
125 const dbus::ObjectPath& object_path, | 125 const dbus::ObjectPath& object_path, |
126 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, | 126 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, |
127 scoped_refptr<device::BluetoothSocketThread> socket_thread) | 127 scoped_refptr<device::BluetoothSocketThread> socket_thread) |
128 : adapter_(adapter), | 128 : adapter_(adapter), |
129 object_path_(object_path), | 129 object_path_(object_path), |
130 num_connecting_calls_(0), | 130 num_connecting_calls_(0), |
131 connection_monitor_started_(false), | |
131 ui_task_runner_(ui_task_runner), | 132 ui_task_runner_(ui_task_runner), |
132 socket_thread_(socket_thread), | 133 socket_thread_(socket_thread), |
133 weak_ptr_factory_(this) { | 134 weak_ptr_factory_(this) { |
134 DBusThreadManager::Get()->GetBluetoothGattServiceClient()->AddObserver(this); | 135 DBusThreadManager::Get()->GetBluetoothGattServiceClient()->AddObserver(this); |
135 | 136 |
136 // Add all known GATT services. | 137 // Add all known GATT services. |
137 const std::vector<dbus::ObjectPath> gatt_services = | 138 const std::vector<dbus::ObjectPath> gatt_services = |
138 DBusThreadManager::Get()->GetBluetoothGattServiceClient()->GetServices(); | 139 DBusThreadManager::Get()->GetBluetoothGattServiceClient()->GetServices(); |
139 for (std::vector<dbus::ObjectPath>::const_iterator it = gatt_services.begin(); | 140 for (std::vector<dbus::ObjectPath>::const_iterator it = gatt_services.begin(); |
140 it != gatt_services.end(); ++it) { | 141 it != gatt_services.end(); ++it) { |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
216 return product_id; | 217 return product_id; |
217 } | 218 } |
218 | 219 |
219 uint16 BluetoothDeviceChromeOS::GetDeviceID() const { | 220 uint16 BluetoothDeviceChromeOS::GetDeviceID() const { |
220 uint16 device_id = 0; | 221 uint16 device_id = 0; |
221 ParseModalias(object_path_, NULL, NULL, NULL, &device_id); | 222 ParseModalias(object_path_, NULL, NULL, NULL, &device_id); |
222 return device_id; | 223 return device_id; |
223 } | 224 } |
224 | 225 |
225 int BluetoothDeviceChromeOS::GetRSSI() const { | 226 int BluetoothDeviceChromeOS::GetRSSI() const { |
226 NOTIMPLEMENTED(); | 227 BluetoothDeviceClient::Properties* properties = |
227 return kUnknownPower; | 228 DBusThreadManager::Get()->GetBluetoothDeviceClient()->GetProperties( |
229 object_path_); | |
230 DCHECK(properties); | |
231 | |
232 if (!IsConnected()) { | |
233 NOTIMPLEMENTED(); | |
234 return kUnknownPower; | |
235 } | |
236 | |
237 return connection_monitor_started_ ? properties->connection_rssi.value() | |
238 : kUnknownPower; | |
228 } | 239 } |
229 | 240 |
230 int BluetoothDeviceChromeOS::GetCurrentHostTransmitPower() const { | 241 int BluetoothDeviceChromeOS::GetCurrentHostTransmitPower() const { |
231 NOTIMPLEMENTED(); | 242 BluetoothDeviceClient::Properties* properties = |
232 return kUnknownPower; | 243 DBusThreadManager::Get()->GetBluetoothDeviceClient()->GetProperties( |
244 object_path_); | |
245 DCHECK(properties); | |
246 | |
247 return IsConnected() ? properties->connection_tx_power.value() | |
keybuk
2014/05/09 19:06:38
shouldn't this also be connection monitor?
Tim Song
2014/05/09 20:08:01
Done.
| |
248 : kUnknownPower; | |
233 } | 249 } |
234 | 250 |
235 int BluetoothDeviceChromeOS::GetMaximumHostTransmitPower() const { | 251 int BluetoothDeviceChromeOS::GetMaximumHostTransmitPower() const { |
236 NOTIMPLEMENTED(); | 252 BluetoothDeviceClient::Properties* properties = |
237 return kUnknownPower; | 253 DBusThreadManager::Get()->GetBluetoothDeviceClient()->GetProperties( |
254 object_path_); | |
255 DCHECK(properties); | |
256 | |
257 return IsConnected() ? properties->connection_tx_power_max.value() | |
keybuk
2014/05/09 19:06:38
ditto
Tim Song
2014/05/09 20:08:01
The maximum TX power doesn't need to be tracked, a
| |
258 : kUnknownPower; | |
238 } | 259 } |
239 | 260 |
240 bool BluetoothDeviceChromeOS::IsPaired() const { | 261 bool BluetoothDeviceChromeOS::IsPaired() const { |
241 BluetoothDeviceClient::Properties* properties = | 262 BluetoothDeviceClient::Properties* properties = |
242 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> | 263 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> |
243 GetProperties(object_path_); | 264 GetProperties(object_path_); |
244 DCHECK(properties); | 265 DCHECK(properties); |
245 | 266 |
246 // Trusted devices are devices that don't support pairing but that the | 267 // Trusted devices are devices that don't support pairing but that the |
247 // user has explicitly connected; it makes no sense for UI purposes to | 268 // user has explicitly connected; it makes no sense for UI purposes to |
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
648 true, | 669 true, |
649 base::Bind(&BluetoothDeviceChromeOS::OnSetTrusted, | 670 base::Bind(&BluetoothDeviceChromeOS::OnSetTrusted, |
650 weak_ptr_factory_.GetWeakPtr())); | 671 weak_ptr_factory_.GetWeakPtr())); |
651 } | 672 } |
652 | 673 |
653 void BluetoothDeviceChromeOS::OnSetTrusted(bool success) { | 674 void BluetoothDeviceChromeOS::OnSetTrusted(bool success) { |
654 LOG_IF(WARNING, !success) << object_path_.value() | 675 LOG_IF(WARNING, !success) << object_path_.value() |
655 << ": Failed to set device as trusted"; | 676 << ": Failed to set device as trusted"; |
656 } | 677 } |
657 | 678 |
679 void BluetoothDeviceChromeOS::StartConnectionMonitor() { | |
680 if (connection_monitor_started_) | |
681 return; | |
682 | |
683 DBusThreadManager::Get()->GetBluetoothDeviceClient()->StartConnectionMonitor( | |
684 object_path_, | |
685 base::Bind(&base::DoNothing), | |
686 base::Bind(&BluetoothDeviceChromeOS::OnStartConnectionMonitorError, | |
687 weak_ptr_factory_.GetWeakPtr())); | |
688 } | |
689 | |
690 void BluetoothDeviceChromeOS::OnStartConnectionMonitor() { | |
691 connection_monitor_started_ = true; | |
692 } | |
693 | |
694 void BluetoothDeviceChromeOS::OnStartConnectionMonitorError( | |
695 const std::string& error_name, | |
696 const std::string& error_message) { | |
697 connection_monitor_started_ = false; | |
698 LOG(WARNING) << object_path_.value() | |
699 << ": Failed to start connection monitor: " << error_name << ": " | |
700 << error_message; | |
701 } | |
702 | |
658 void BluetoothDeviceChromeOS::OnDisconnect(const base::Closure& callback) { | 703 void BluetoothDeviceChromeOS::OnDisconnect(const base::Closure& callback) { |
659 VLOG(1) << object_path_.value() << ": Disconnected"; | 704 VLOG(1) << object_path_.value() << ": Disconnected"; |
660 callback.Run(); | 705 callback.Run(); |
661 } | 706 } |
662 | 707 |
663 void BluetoothDeviceChromeOS::OnDisconnectError( | 708 void BluetoothDeviceChromeOS::OnDisconnectError( |
664 const ErrorCallback& error_callback, | 709 const ErrorCallback& error_callback, |
665 const std::string& error_name, | 710 const std::string& error_name, |
666 const std::string& error_message) { | 711 const std::string& error_message) { |
667 LOG(WARNING) << object_path_.value() << ": Failed to disconnect device: " | 712 LOG(WARNING) << object_path_.value() << ": Failed to disconnect device: " |
(...skipping 27 matching lines...) Expand all Loading... | |
695 const std::string& error_message) { | 740 const std::string& error_message) { |
696 BluetoothProfileChromeOS* profile_chromeos = | 741 BluetoothProfileChromeOS* profile_chromeos = |
697 static_cast<BluetoothProfileChromeOS*>(profile); | 742 static_cast<BluetoothProfileChromeOS*>(profile); |
698 VLOG(1) << object_path_.value() << ": Profile connection failed: " | 743 VLOG(1) << object_path_.value() << ": Profile connection failed: " |
699 << profile_chromeos->uuid().canonical_value() << ": " | 744 << profile_chromeos->uuid().canonical_value() << ": " |
700 << error_name << ": " << error_message; | 745 << error_name << ": " << error_message; |
701 error_callback.Run(error_message); | 746 error_callback.Run(error_message); |
702 } | 747 } |
703 | 748 |
704 } // namespace chromeos | 749 } // namespace chromeos |
OLD | NEW |