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

Side by Side Diff: chrome/browser/chromeos/dbus/bluetooth_adapter_client.cc

Issue 9317012: chrome: bluetooth: hook up DeviceCreated/Removed signals (Closed) Base URL: http://git.chromium.org/git/chromium/src.git@master
Patch Set: fix the object/device path confusion Created 8 years, 10 months 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/chromeos/dbus/bluetooth_adapter_client.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_adapter_client.h" 5 #include "chrome/browser/chromeos/dbus/bluetooth_adapter_client.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/stl_util.h" 11 #include "base/stl_util.h"
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 VLOG(1) << "AddObjectProxyForPath: " << object_path; 255 VLOG(1) << "AddObjectProxyForPath: " << object_path;
256 256
257 DCHECK(bus_); 257 DCHECK(bus_);
258 dbus::ObjectProxy* adapter_proxy = bus_->GetObjectProxy( 258 dbus::ObjectProxy* adapter_proxy = bus_->GetObjectProxy(
259 bluetooth_adapter::kBluetoothAdapterServiceName, object_path); 259 bluetooth_adapter::kBluetoothAdapterServiceName, object_path);
260 260
261 proxy_map_[object_path] = adapter_proxy; 261 proxy_map_[object_path] = adapter_proxy;
262 262
263 adapter_proxy->ConnectToSignal( 263 adapter_proxy->ConnectToSignal(
264 bluetooth_adapter::kBluetoothAdapterInterface, 264 bluetooth_adapter::kBluetoothAdapterInterface,
265 bluetooth_adapter::kDeviceCreatedSignal,
266 base::Bind(&BluetoothAdapterClientImpl::DeviceCreatedReceived,
267 weak_ptr_factory_.GetWeakPtr(), object_path),
268 base::Bind(&BluetoothAdapterClientImpl::DeviceCreatedConnected,
269 weak_ptr_factory_.GetWeakPtr(), object_path));
270
271 adapter_proxy->ConnectToSignal(
272 bluetooth_adapter::kBluetoothAdapterInterface,
273 bluetooth_adapter::kDeviceRemovedSignal,
274 base::Bind(&BluetoothAdapterClientImpl::DeviceRemovedReceived,
275 weak_ptr_factory_.GetWeakPtr(), object_path),
276 base::Bind(&BluetoothAdapterClientImpl::DeviceRemovedConnected,
277 weak_ptr_factory_.GetWeakPtr(), object_path));
278
279 adapter_proxy->ConnectToSignal(
280 bluetooth_adapter::kBluetoothAdapterInterface,
265 bluetooth_adapter::kPropertyChangedSignal, 281 bluetooth_adapter::kPropertyChangedSignal,
266 base::Bind(&BluetoothAdapterClientImpl::PropertyChangedReceived, 282 base::Bind(&BluetoothAdapterClientImpl::PropertyChangedReceived,
267 weak_ptr_factory_.GetWeakPtr(), object_path), 283 weak_ptr_factory_.GetWeakPtr(), object_path),
268 base::Bind(&BluetoothAdapterClientImpl::PropertyChangedConnected, 284 base::Bind(&BluetoothAdapterClientImpl::PropertyChangedConnected,
269 weak_ptr_factory_.GetWeakPtr(), object_path)); 285 weak_ptr_factory_.GetWeakPtr(), object_path));
270 286
271 adapter_proxy->ConnectToSignal( 287 adapter_proxy->ConnectToSignal(
272 bluetooth_adapter::kBluetoothAdapterInterface, 288 bluetooth_adapter::kBluetoothAdapterInterface,
273 bluetooth_adapter::kDeviceFoundSignal, 289 bluetooth_adapter::kDeviceFoundSignal,
274 base::Bind(&BluetoothAdapterClientImpl::DeviceFoundReceived, 290 base::Bind(&BluetoothAdapterClientImpl::DeviceFoundReceived,
(...skipping 10 matching lines...) Expand all
285 weak_ptr_factory_.GetWeakPtr(), object_path)); 301 weak_ptr_factory_.GetWeakPtr(), object_path));
286 } 302 }
287 303
288 // Removes the dbus object proxy for the adapter with dbus object path 304 // Removes the dbus object proxy for the adapter with dbus object path
289 // |object_path| from our |proxy_map_| map. 305 // |object_path| from our |proxy_map_| map.
290 void RemoveObjectProxyForPath(const std::string& object_path) { 306 void RemoveObjectProxyForPath(const std::string& object_path) {
291 VLOG(1) << "RemoveObjectProxyForPath: " << object_path; 307 VLOG(1) << "RemoveObjectProxyForPath: " << object_path;
292 proxy_map_.erase(object_path); 308 proxy_map_.erase(object_path);
293 } 309 }
294 310
311 // Called by dbus:: when a DeviceCreated signal is received.
312 void DeviceCreatedReceived(const std::string& object_path,
313 dbus::Signal* signal) {
314 DCHECK(signal);
315 dbus::MessageReader reader(signal);
316 std::string device_path;
317 if (!reader.PopString(&device_path)) {
318 LOG(ERROR) << object_path
319 << ": DeviceCreated signal has incorrect parameters: "
320 << signal->ToString();
321 return;
322 }
323 VLOG(1) << object_path << ": Device created: " << device_path;
324
325 FOR_EACH_OBSERVER(BluetoothAdapterClient::Observer, observers_,
326 DeviceCreated(object_path, device_path));
327 }
328
329 // Called by dbus:: when the DeviceCreated signal is initially connected.
330 void DeviceCreatedConnected(const std::string& object_path,
331 const std::string& interface_name,
332 const std::string& signal_name,
333 bool success) {
334 LOG_IF(WARNING, !success) << object_path
335 << ": Failed to connect to DeviceCreated signal.";
336 }
337
338 // Called by dbus:: when a DeviceRemoved signal is received.
339 void DeviceRemovedReceived(const std::string& object_path,
340 dbus::Signal* signal) {
341 DCHECK(signal);
342 dbus::MessageReader reader(signal);
343 std::string device_path;
344 if (!reader.PopString(&device_path)) {
345 LOG(ERROR) << object_path
346 << ": DeviceRemoved signal has incorrect parameters: "
347 << signal->ToString();
348 return;
349 }
350 VLOG(1) << object_path << ": Device created: " << device_path;
351
352 FOR_EACH_OBSERVER(BluetoothAdapterClient::Observer, observers_,
353 DeviceRemoved(object_path, device_path));
354 }
355
356 // Called by dbus:: when the DeviceRemoved signal is initially connected.
357 void DeviceRemovedConnected(const std::string& object_path,
358 const std::string& interface_name,
359 const std::string& signal_name,
360 bool success) {
361 LOG_IF(WARNING, !success) << object_path
362 << ": Failed to connect to DeviceRemoved signal.";
363 }
364
295 // Called by dbus:: when a PropertyChanged signal is received. 365 // Called by dbus:: when a PropertyChanged signal is received.
296 void PropertyChangedReceived(const std::string& object_path, 366 void PropertyChangedReceived(const std::string& object_path,
297 dbus::Signal* signal) { 367 dbus::Signal* signal) {
298 DCHECK(signal); 368 DCHECK(signal);
299 dbus::MessageReader reader(signal); 369 dbus::MessageReader reader(signal);
300 std::string property_name; 370 std::string property_name;
301 if (!reader.PopString(&property_name)) { 371 if (!reader.PopString(&property_name)) {
302 LOG(ERROR) << object_path 372 LOG(ERROR) << object_path
303 << ": PropertyChanged signal has incorrect parameters: " 373 << ": PropertyChanged signal has incorrect parameters: "
304 << signal->ToString(); 374 << signal->ToString();
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 529
460 BluetoothAdapterClient* BluetoothAdapterClient::Create(dbus::Bus* bus) { 530 BluetoothAdapterClient* BluetoothAdapterClient::Create(dbus::Bus* bus) {
461 if (system::runtime_environment::IsRunningOnChromeOS()) { 531 if (system::runtime_environment::IsRunningOnChromeOS()) {
462 return new BluetoothAdapterClientImpl(bus); 532 return new BluetoothAdapterClientImpl(bus);
463 } else { 533 } else {
464 return new BluetoothAdapterClientStubImpl(); 534 return new BluetoothAdapterClientStubImpl();
465 } 535 }
466 } 536 }
467 537
468 } // namespace chromeos 538 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/dbus/bluetooth_adapter_client.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698