OLD | NEW |
1 // Copyright (c) 2012 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 "chromeos/dbus/bluetooth_device_client.h" | 5 #include "chromeos/dbus/bluetooth_device_client.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
13 #include "chromeos/dbus/bluetooth_adapter_client.h" | 13 #include "chromeos/dbus/bluetooth_adapter_client.h" |
14 #include "chromeos/dbus/bluetooth_property.h" | 14 #include "chromeos/dbus/bluetooth_property.h" |
| 15 #include "chromeos/dbus/fake_old_bluetooth_device_client.h" |
15 #include "dbus/bus.h" | 16 #include "dbus/bus.h" |
16 #include "dbus/message.h" | 17 #include "dbus/message.h" |
17 #include "dbus/object_path.h" | 18 #include "dbus/object_path.h" |
18 #include "dbus/object_proxy.h" | 19 #include "dbus/object_proxy.h" |
19 #include "third_party/cros_system_api/dbus/service_constants.h" | 20 #include "third_party/cros_system_api/dbus/service_constants.h" |
20 | 21 |
21 namespace chromeos { | 22 namespace chromeos { |
22 | 23 |
23 BluetoothDeviceClient::Properties::Properties( | 24 BluetoothDeviceClient::Properties::Properties( |
24 dbus::ObjectProxy* object_proxy, | 25 dbus::ObjectProxy* object_proxy, |
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
456 | 457 |
457 // Weak pointer factory for generating 'this' pointers that might live longer | 458 // Weak pointer factory for generating 'this' pointers that might live longer |
458 // than we do. | 459 // than we do. |
459 // Note: This should remain the last member so it'll be destroyed and | 460 // Note: This should remain the last member so it'll be destroyed and |
460 // invalidate its weak pointers before any other members are destroyed. | 461 // invalidate its weak pointers before any other members are destroyed. |
461 base::WeakPtrFactory<BluetoothDeviceClientImpl> weak_ptr_factory_; | 462 base::WeakPtrFactory<BluetoothDeviceClientImpl> weak_ptr_factory_; |
462 | 463 |
463 DISALLOW_COPY_AND_ASSIGN(BluetoothDeviceClientImpl); | 464 DISALLOW_COPY_AND_ASSIGN(BluetoothDeviceClientImpl); |
464 }; | 465 }; |
465 | 466 |
466 // The BluetoothDeviceClient implementation used on Linux desktop, which does | |
467 // nothing. | |
468 class BluetoothDeviceClientStubImpl : public BluetoothDeviceClient { | |
469 public: | |
470 struct Properties : public BluetoothDeviceClient::Properties { | |
471 explicit Properties(const PropertyChangedCallback& callback) | |
472 : BluetoothDeviceClient::Properties(NULL, callback) { | |
473 } | |
474 | |
475 virtual ~Properties() { | |
476 } | |
477 | |
478 virtual void Get(dbus::PropertyBase* property, | |
479 dbus::PropertySet::GetCallback callback) OVERRIDE { | |
480 VLOG(1) << "Get " << property->name(); | |
481 callback.Run(false); | |
482 } | |
483 | |
484 virtual void GetAll() OVERRIDE { | |
485 VLOG(1) << "GetAll"; | |
486 } | |
487 | |
488 virtual void Set(dbus::PropertyBase *property, | |
489 dbus::PropertySet::SetCallback callback) OVERRIDE { | |
490 VLOG(1) << "Set " << property->name(); | |
491 callback.Run(false); | |
492 } | |
493 }; | |
494 | |
495 BluetoothDeviceClientStubImpl() { | |
496 dbus::ObjectPath dev0("/fake/hci0/dev0"); | |
497 | |
498 Properties* properties = new Properties(base::Bind( | |
499 &BluetoothDeviceClientStubImpl::OnPropertyChanged, | |
500 base::Unretained(this), | |
501 dev0)); | |
502 properties->address.ReplaceValue("00:11:22:33:44:55"); | |
503 properties->name.ReplaceValue("Fake Device"); | |
504 properties->paired.ReplaceValue(true); | |
505 properties->trusted.ReplaceValue(true); | |
506 | |
507 properties_map_[dev0] = properties; | |
508 } | |
509 | |
510 virtual ~BluetoothDeviceClientStubImpl() { | |
511 // Clean up Properties structures | |
512 STLDeleteValues(&properties_map_); | |
513 } | |
514 | |
515 // BluetoothDeviceClient override. | |
516 virtual void AddObserver(Observer* observer) OVERRIDE { | |
517 observers_.AddObserver(observer); | |
518 } | |
519 | |
520 // BluetoothDeviceClient override. | |
521 virtual void RemoveObserver(Observer* observer) OVERRIDE { | |
522 observers_.RemoveObserver(observer); | |
523 } | |
524 | |
525 // BluetoothDeviceClient override. | |
526 virtual Properties* GetProperties(const dbus::ObjectPath& object_path) | |
527 OVERRIDE { | |
528 VLOG(1) << "GetProperties: " << object_path.value(); | |
529 PropertiesMap::iterator iter = properties_map_.find(object_path); | |
530 if (iter != properties_map_.end()) | |
531 return iter->second; | |
532 return NULL; | |
533 } | |
534 | |
535 // BluetoothDeviceClient override. | |
536 virtual void DiscoverServices(const dbus::ObjectPath& object_path, | |
537 const std::string& pattern, | |
538 const ServicesCallback& callback) OVERRIDE { | |
539 VLOG(1) << "DiscoverServices: " << object_path.value() << " " << pattern; | |
540 | |
541 ServiceMap services; | |
542 callback.Run(object_path, services, false); | |
543 } | |
544 | |
545 // BluetoothDeviceClient override. | |
546 virtual void CancelDiscovery(const dbus::ObjectPath& object_path, | |
547 const DeviceCallback& callback) OVERRIDE { | |
548 VLOG(1) << "CancelDiscovery: " << object_path.value(); | |
549 callback.Run(object_path, false); | |
550 } | |
551 | |
552 // BluetoothDeviceClient override. | |
553 virtual void Disconnect(const dbus::ObjectPath& object_path, | |
554 const DeviceCallback& callback) OVERRIDE { | |
555 VLOG(1) << "Disconnect: " << object_path.value(); | |
556 callback.Run(object_path, false); | |
557 } | |
558 | |
559 // BluetoothDeviceClient override. | |
560 virtual void CreateNode(const dbus::ObjectPath& object_path, | |
561 const std::string& uuid, | |
562 const NodeCallback& callback) OVERRIDE { | |
563 VLOG(1) << "CreateNode: " << object_path.value() << " " << uuid; | |
564 callback.Run(dbus::ObjectPath(), false); | |
565 } | |
566 | |
567 // BluetoothDeviceClient override. | |
568 virtual void RemoveNode(const dbus::ObjectPath& object_path, | |
569 const dbus::ObjectPath& node_path, | |
570 const DeviceCallback& callback) OVERRIDE { | |
571 VLOG(1) << "RemoveNode: " << object_path.value() | |
572 << " " << node_path.value(); | |
573 callback.Run(object_path, false); | |
574 } | |
575 | |
576 private: | |
577 void OnPropertyChanged(dbus::ObjectPath object_path, | |
578 const std::string& property_name) { | |
579 FOR_EACH_OBSERVER(BluetoothDeviceClient::Observer, observers_, | |
580 DevicePropertyChanged(object_path, property_name)); | |
581 } | |
582 | |
583 // List of observers interested in event notifications from us. | |
584 ObserverList<Observer> observers_; | |
585 | |
586 // Static properties we typedef. | |
587 typedef std::map<const dbus::ObjectPath, Properties *> PropertiesMap; | |
588 PropertiesMap properties_map_; | |
589 }; | |
590 | |
591 BluetoothDeviceClient::BluetoothDeviceClient() { | 467 BluetoothDeviceClient::BluetoothDeviceClient() { |
592 } | 468 } |
593 | 469 |
594 BluetoothDeviceClient::~BluetoothDeviceClient() { | 470 BluetoothDeviceClient::~BluetoothDeviceClient() { |
595 } | 471 } |
596 | 472 |
597 BluetoothDeviceClient* BluetoothDeviceClient::Create( | 473 BluetoothDeviceClient* BluetoothDeviceClient::Create( |
598 DBusClientImplementationType type, | 474 DBusClientImplementationType type, |
599 dbus::Bus* bus, | 475 dbus::Bus* bus, |
600 BluetoothAdapterClient* adapter_client) { | 476 BluetoothAdapterClient* adapter_client) { |
601 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 477 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
602 return new BluetoothDeviceClientImpl(bus, adapter_client); | 478 return new BluetoothDeviceClientImpl(bus, adapter_client); |
603 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); | 479 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); |
604 return new BluetoothDeviceClientStubImpl(); | 480 return new FakeOldBluetoothDeviceClient(); |
605 } | 481 } |
606 | 482 |
607 } // namespace chromeos | 483 } // namespace chromeos |
OLD | NEW |