OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/chromeos/dbus/bluetooth_manager_client.h" | 5 #include "chrome/browser/chromeos/dbus/bluetooth_manager_client.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "chrome/browser/chromeos/system/runtime_environment.h" | 9 #include "chrome/browser/chromeos/system/runtime_environment.h" |
10 #include "dbus/bus.h" | 10 #include "dbus/bus.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 VLOG(1) << "Creating BluetoothManagerClientImpl"; | 23 VLOG(1) << "Creating BluetoothManagerClientImpl"; |
24 | 24 |
25 DCHECK(bus); | 25 DCHECK(bus); |
26 | 26 |
27 bluetooth_manager_proxy_ = bus->GetObjectProxy( | 27 bluetooth_manager_proxy_ = bus->GetObjectProxy( |
28 bluetooth_manager::kBluetoothManagerServiceName, | 28 bluetooth_manager::kBluetoothManagerServiceName, |
29 bluetooth_manager::kBluetoothManagerServicePath); | 29 bluetooth_manager::kBluetoothManagerServicePath); |
30 | 30 |
31 bluetooth_manager_proxy_->ConnectToSignal( | 31 bluetooth_manager_proxy_->ConnectToSignal( |
32 bluetooth_manager::kBluetoothManagerInterface, | 32 bluetooth_manager::kBluetoothManagerInterface, |
| 33 bluetooth_manager::kAdapterAddedSignal, |
| 34 base::Bind(&BluetoothManagerClientImpl::AdapterAddedReceived, |
| 35 weak_ptr_factory_.GetWeakPtr()), |
| 36 base::Bind(&BluetoothManagerClientImpl::AdapterAddedConnected, |
| 37 weak_ptr_factory_.GetWeakPtr())); |
| 38 |
| 39 bluetooth_manager_proxy_->ConnectToSignal( |
| 40 bluetooth_manager::kBluetoothManagerInterface, |
33 bluetooth_manager::kAdapterRemovedSignal, | 41 bluetooth_manager::kAdapterRemovedSignal, |
34 base::Bind(&BluetoothManagerClientImpl::AdapterRemovedReceived, | 42 base::Bind(&BluetoothManagerClientImpl::AdapterRemovedReceived, |
35 weak_ptr_factory_.GetWeakPtr()), | 43 weak_ptr_factory_.GetWeakPtr()), |
36 base::Bind(&BluetoothManagerClientImpl::AdapterRemovedConnected, | 44 base::Bind(&BluetoothManagerClientImpl::AdapterRemovedConnected, |
37 weak_ptr_factory_.GetWeakPtr())); | 45 weak_ptr_factory_.GetWeakPtr())); |
38 | 46 |
39 bluetooth_manager_proxy_->ConnectToSignal( | 47 bluetooth_manager_proxy_->ConnectToSignal( |
40 bluetooth_manager::kBluetoothManagerInterface, | 48 bluetooth_manager::kBluetoothManagerInterface, |
41 bluetooth_manager::kDefaultAdapterChangedSignal, | 49 bluetooth_manager::kDefaultAdapterChangedSignal, |
42 base::Bind(&BluetoothManagerClientImpl::DefaultAdapterChangedReceived, | 50 base::Bind(&BluetoothManagerClientImpl::DefaultAdapterChangedReceived, |
(...skipping 29 matching lines...) Expand all Loading... |
72 | 80 |
73 DCHECK(bluetooth_manager_proxy_); | 81 DCHECK(bluetooth_manager_proxy_); |
74 bluetooth_manager_proxy_->CallMethod( | 82 bluetooth_manager_proxy_->CallMethod( |
75 &method_call, | 83 &method_call, |
76 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 84 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
77 base::Bind(&BluetoothManagerClientImpl::OnDefaultAdapter, | 85 base::Bind(&BluetoothManagerClientImpl::OnDefaultAdapter, |
78 weak_ptr_factory_.GetWeakPtr(), callback)); | 86 weak_ptr_factory_.GetWeakPtr(), callback)); |
79 } | 87 } |
80 | 88 |
81 private: | 89 private: |
| 90 // Called by dbus:: when an AdapterAdded signal is received. |
| 91 void AdapterAddedReceived(dbus::Signal* signal) { |
| 92 DCHECK(signal); |
| 93 dbus::MessageReader reader(signal); |
| 94 std::string object_path; |
| 95 if (!reader.PopObjectPath(&object_path)) { |
| 96 LOG(ERROR) << "AdapterAdded signal has incorrect parameters: " |
| 97 << signal->ToString(); |
| 98 return; |
| 99 } |
| 100 VLOG(1) << "Adapter added: " << object_path; |
| 101 FOR_EACH_OBSERVER(Observer, observers_, AdapterAdded(object_path)); |
| 102 } |
| 103 |
| 104 // Called by dbus:: when the AdapterAdded signal is initially connected. |
| 105 void AdapterAddedConnected(const std::string& interface_name, |
| 106 const std::string& signal_name, |
| 107 bool success) { |
| 108 LOG_IF(WARNING, !success) << "Failed to connect to AdapterAdded signal."; |
| 109 } |
| 110 |
82 // Called by dbus:: when an AdapterRemoved signal is received. | 111 // Called by dbus:: when an AdapterRemoved signal is received. |
83 void AdapterRemovedReceived(dbus::Signal* signal) { | 112 void AdapterRemovedReceived(dbus::Signal* signal) { |
84 DCHECK(signal); | 113 DCHECK(signal); |
85 dbus::MessageReader reader(signal); | 114 dbus::MessageReader reader(signal); |
86 std::string adapter; | 115 std::string object_path; |
87 if (!reader.PopObjectPath(&adapter)) { | 116 if (!reader.PopObjectPath(&object_path)) { |
88 LOG(ERROR) << "AdapterRemoved signal has incorrect parameters: " | 117 LOG(ERROR) << "AdapterRemoved signal has incorrect parameters: " |
89 << signal->ToString(); | 118 << signal->ToString(); |
90 return; | 119 return; |
91 } | 120 } |
92 VLOG(1) << "Adapter removed: " << adapter; | 121 VLOG(1) << "Adapter removed: " << object_path; |
93 FOR_EACH_OBSERVER(Observer, observers_, AdapterRemoved(adapter)); | 122 FOR_EACH_OBSERVER(Observer, observers_, AdapterRemoved(object_path)); |
94 } | 123 } |
95 | 124 |
96 // Called by dbus:: when the AdapterRemoved signal is initially connected. | 125 // Called by dbus:: when the AdapterRemoved signal is initially connected. |
97 void AdapterRemovedConnected(const std::string& interface_name, | 126 void AdapterRemovedConnected(const std::string& interface_name, |
98 const std::string& signal_name, | 127 const std::string& signal_name, |
99 bool success) { | 128 bool success) { |
100 LOG_IF(WARNING, !success) << "Failed to connect to AdapterRemoved signal."; | 129 LOG_IF(WARNING, !success) << "Failed to connect to AdapterRemoved signal."; |
101 } | 130 } |
102 | 131 |
103 // Called by dbus:: when a DefaultAdapterChanged signal is received. | 132 // Called by dbus:: when a DefaultAdapterChanged signal is received. |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 | 214 |
186 BluetoothManagerClient* BluetoothManagerClient::Create(dbus::Bus* bus) { | 215 BluetoothManagerClient* BluetoothManagerClient::Create(dbus::Bus* bus) { |
187 if (system::runtime_environment::IsRunningOnChromeOS()) { | 216 if (system::runtime_environment::IsRunningOnChromeOS()) { |
188 return new BluetoothManagerClientImpl(bus); | 217 return new BluetoothManagerClientImpl(bus); |
189 } else { | 218 } else { |
190 return new BluetoothManagerClientStubImpl(); | 219 return new BluetoothManagerClientStubImpl(); |
191 } | 220 } |
192 } | 221 } |
193 | 222 |
194 } // namespace chromeos | 223 } // namespace chromeos |
OLD | NEW |