OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_EXPERIMENTAL_CHROMEOS_H_ | 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_EXPERIMENTAL_CHROMEOS_H_ |
6 #define DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_EXPERIMENTAL_CHROMEOS_H_ | 6 #define DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_EXPERIMENTAL_CHROMEOS_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| 11 #include "chromeos/dbus/experimental_bluetooth_adapter_client.h" |
| 12 #include "chromeos/dbus/experimental_bluetooth_device_client.h" |
| 13 #include "dbus/object_path.h" |
11 #include "device/bluetooth/bluetooth_adapter.h" | 14 #include "device/bluetooth/bluetooth_adapter.h" |
12 | 15 |
13 namespace device { | 16 namespace device { |
14 | 17 |
15 class BluetoothAdapterFactory; | 18 class BluetoothAdapterFactory; |
16 | 19 |
17 } // namespace device | 20 } // namespace device |
18 | 21 |
19 namespace chromeos { | 22 namespace chromeos { |
20 | 23 |
| 24 class BluetoothDeviceExperimentalChromeOS; |
| 25 class BluetoothExperimentalChromeOSTest; |
| 26 |
21 // The BluetoothAdapterExperimentalChromeOS class is an alternate implementation | 27 // The BluetoothAdapterExperimentalChromeOS class is an alternate implementation |
22 // of BluetoothAdapter for the Chrome OS platform using the Bluetooth Smart | 28 // of BluetoothAdapter for the Chrome OS platform using the Bluetooth Smart |
23 // capable backend. It will become the sole implementation for Chrome OS, and | 29 // capable backend. It will become the sole implementation for Chrome OS, and |
24 // be renamed to BluetoothAdapterChromeOS, once the backend is switched, | 30 // be renamed to BluetoothAdapterChromeOS, once the backend is switched, |
25 class BluetoothAdapterExperimentalChromeOS | 31 class BluetoothAdapterExperimentalChromeOS |
26 : public device::BluetoothAdapter { | 32 : public device::BluetoothAdapter, |
| 33 private chromeos::ExperimentalBluetoothAdapterClient::Observer, |
| 34 private chromeos::ExperimentalBluetoothDeviceClient::Observer { |
27 public: | 35 public: |
28 // BluetoothAdapter override | 36 // BluetoothAdapter override |
29 virtual void AddObserver( | 37 virtual void AddObserver( |
30 device::BluetoothAdapter::Observer* observer) OVERRIDE; | 38 device::BluetoothAdapter::Observer* observer) OVERRIDE; |
31 virtual void RemoveObserver( | 39 virtual void RemoveObserver( |
32 device::BluetoothAdapter::Observer* observer) OVERRIDE; | 40 device::BluetoothAdapter::Observer* observer) OVERRIDE; |
33 virtual std::string GetAddress() const OVERRIDE; | 41 virtual std::string GetAddress() const OVERRIDE; |
34 virtual std::string GetName() const OVERRIDE; | 42 virtual std::string GetName() const OVERRIDE; |
35 virtual bool IsInitialized() const OVERRIDE; | 43 virtual bool IsInitialized() const OVERRIDE; |
36 virtual bool IsPresent() const OVERRIDE; | 44 virtual bool IsPresent() const OVERRIDE; |
37 virtual bool IsPowered() const OVERRIDE; | 45 virtual bool IsPowered() const OVERRIDE; |
38 virtual void SetPowered( | 46 virtual void SetPowered( |
39 bool powered, | 47 bool powered, |
40 const base::Closure& callback, | 48 const base::Closure& callback, |
41 const ErrorCallback& error_callback) OVERRIDE; | 49 const ErrorCallback& error_callback) OVERRIDE; |
42 virtual bool IsDiscovering() const OVERRIDE; | 50 virtual bool IsDiscovering() const OVERRIDE; |
43 virtual void StartDiscovering( | 51 virtual void StartDiscovering( |
44 const base::Closure& callback, | 52 const base::Closure& callback, |
45 const ErrorCallback& error_callback) OVERRIDE; | 53 const ErrorCallback& error_callback) OVERRIDE; |
46 virtual void StopDiscovering( | 54 virtual void StopDiscovering( |
47 const base::Closure& callback, | 55 const base::Closure& callback, |
48 const ErrorCallback& error_callback) OVERRIDE; | 56 const ErrorCallback& error_callback) OVERRIDE; |
49 virtual void ReadLocalOutOfBandPairingData( | 57 virtual void ReadLocalOutOfBandPairingData( |
50 const device::BluetoothAdapter::BluetoothOutOfBandPairingDataCallback& | 58 const device::BluetoothAdapter::BluetoothOutOfBandPairingDataCallback& |
51 callback, | 59 callback, |
52 const ErrorCallback& error_callback) OVERRIDE; | 60 const ErrorCallback& error_callback) OVERRIDE; |
53 | 61 |
54 private: | 62 private: |
55 friend class device::BluetoothAdapterFactory; | 63 friend class device::BluetoothAdapterFactory; |
| 64 friend class BluetoothDeviceExperimentalChromeOS; |
| 65 friend class BluetoothExperimentalChromeOSTest; |
56 | 66 |
57 BluetoothAdapterExperimentalChromeOS(); | 67 BluetoothAdapterExperimentalChromeOS(); |
58 virtual ~BluetoothAdapterExperimentalChromeOS(); | 68 virtual ~BluetoothAdapterExperimentalChromeOS(); |
59 | 69 |
| 70 // ExperimentalBluetoothAdapterClient::Observer override. |
| 71 virtual void AdapterAdded(const dbus::ObjectPath& object_path) OVERRIDE; |
| 72 virtual void AdapterRemoved(const dbus::ObjectPath& object_path) OVERRIDE; |
| 73 virtual void AdapterPropertyChanged( |
| 74 const dbus::ObjectPath& object_path, |
| 75 const std::string& property_name) OVERRIDE; |
| 76 |
| 77 // ExperimentalBluetoothDeviceClient::Observer override. |
| 78 virtual void DeviceAdded(const dbus::ObjectPath& object_path) OVERRIDE; |
| 79 virtual void DeviceRemoved(const dbus::ObjectPath& object_path) OVERRIDE; |
| 80 virtual void DevicePropertyChanged(const dbus::ObjectPath& object_path, |
| 81 const std::string& property_name) OVERRIDE; |
| 82 |
| 83 // Internal method used to locate the device object by object path |
| 84 // (the devices map and BluetoothDevice methods are by address) |
| 85 BluetoothDeviceExperimentalChromeOS* GetDeviceWithPath( |
| 86 const dbus::ObjectPath& object_path); |
| 87 |
| 88 // Set the tracked adapter to the one in |object_path|, this object will |
| 89 // subsequently operate on that adapter until it is removed. |
| 90 void SetAdapter(const dbus::ObjectPath& object_path); |
| 91 |
| 92 // Remove the currently tracked adapter. IsPresent() will return false after |
| 93 // this is called. |
| 94 void RemoveAdapter(); |
| 95 |
| 96 // Announce to observers a change in the adapter state. |
| 97 void PoweredChanged(bool powered); |
| 98 void DiscoveringChanged(bool discovering); |
| 99 void PresentChanged(bool present); |
| 100 |
| 101 // Called by dbus:: on completion of the powered property change. |
| 102 void OnSetPowered(const base::Closure& callback, |
| 103 const ErrorCallback& error_callback, |
| 104 bool success); |
| 105 |
| 106 // Called by dbus:: on completion of the D-Bus method call to start discovery. |
| 107 void OnStartDiscovery(const base::Closure& callback); |
| 108 void OnStartDiscoveryError(const ErrorCallback& error_callback, |
| 109 const std::string& error_name, |
| 110 const std::string& error_message); |
| 111 |
| 112 // Called by dbus:: on completion of the D-Bus method call to stop discovery. |
| 113 void OnStopDiscovery(const base::Closure& callback); |
| 114 void OnStopDiscoveryError(const ErrorCallback& error_callback, |
| 115 const std::string& error_name, |
| 116 const std::string& error_message); |
| 117 |
| 118 // Object path of the adapter we track. |
| 119 dbus::ObjectPath object_path_; |
| 120 |
| 121 // List of observers interested in event notifications from us. |
| 122 ObserverList<device::BluetoothAdapter::Observer> observers_; |
| 123 |
60 // Note: This should remain the last member so it'll be destroyed and | 124 // Note: This should remain the last member so it'll be destroyed and |
61 // invalidate its weak pointers before any other members are destroyed. | 125 // invalidate its weak pointers before any other members are destroyed. |
62 base::WeakPtrFactory<BluetoothAdapterExperimentalChromeOS> weak_ptr_factory_; | 126 base::WeakPtrFactory<BluetoothAdapterExperimentalChromeOS> weak_ptr_factory_; |
63 | 127 |
64 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterExperimentalChromeOS); | 128 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterExperimentalChromeOS); |
65 }; | 129 }; |
66 | 130 |
67 } // namespace chromeos | 131 } // namespace chromeos |
68 | 132 |
69 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_EXPERIMENTAL_CHROMEOS_H_ | 133 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_EXPERIMENTAL_CHROMEOS_H_ |
OLD | NEW |