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