Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
|
keybuk
2012/09/13 23:57:30
rename to bluetooth_adapter_chromeos.h
youngki
2012/09/17 21:53:02
Done.
| |
| 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 CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_ADAPTER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_ADAPTER_DBUS_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_ADAPTER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_ADAPTER_DBUS_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/memory/ref_counted.h" | |
| 15 #include "base/observer_list.h" | 14 #include "base/observer_list.h" |
| 15 #include "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h" | |
| 16 #include "chromeos/dbus/bluetooth_adapter_client.h" | 16 #include "chromeos/dbus/bluetooth_adapter_client.h" |
| 17 #include "chromeos/dbus/bluetooth_device_client.h" | 17 #include "chromeos/dbus/bluetooth_device_client.h" |
| 18 #include "chromeos/dbus/bluetooth_manager_client.h" | 18 #include "chromeos/dbus/bluetooth_manager_client.h" |
| 19 #include "chromeos/dbus/bluetooth_out_of_band_client.h" | 19 #include "chromeos/dbus/bluetooth_out_of_band_client.h" |
| 20 #include "dbus/object_path.h" | 20 #include "dbus/object_path.h" |
| 21 | 21 |
| 22 namespace chromeos { | 22 namespace chromeos { |
| 23 | 23 |
| 24 class BluetoothDevice; | 24 class BluetoothDeviceDBus; |
|
keybuk
2012/09/13 23:57:30
This class should not be named ...DBus, that's inc
bryeung
2012/09/14 12:00:21
Will this remain true even when we want to use the
keybuk
2012/09/14 17:13:17
Yes, even on Linux the implementation will likely
youngki
2012/09/17 21:53:02
Done.
| |
| 25 | 25 |
| 26 // The BluetoothAdapter class represents a local Bluetooth adapter which | 26 struct BluetoothOutOfBandPairingData; |
| 27 // may be used to interact with remote Bluetooth devices. As well as | 27 |
| 28 // providing support for determining whether an adapter is present, and | 28 // The BluetoothAdapterDBus class is an implementation of |
| 29 // whether the radio is powered, this class also provides support for | 29 // BluetoothAdapter using DBus for Linux/ChromeOS platform. |
|
keybuk
2012/09/13 23:57:30
Chrome OS only currently
youngki
2012/09/17 21:53:02
Done.
| |
| 30 // obtaining the list of remote devices known to the adapter, discovering | |
| 31 // new devices, and providing notification of updates to device information. | |
| 32 // | 30 // |
| 33 // The class may be instantiated for either a specific adapter, or for the | 31 // This class may be instantiated for either a specific adapter, or for the |
| 34 // generic "default adapter" which may change depending on availability. | 32 // generic "default adapter" which may change depending on availability. |
| 35 class BluetoothAdapter : public base::RefCounted<BluetoothAdapter>, | 33 class BluetoothAdapterDBus : public BluetoothAdapter, |
|
keybuk
2012/09/13 23:57:30
This class should not be named ...DBus, that's inc
youngki
2012/09/17 21:53:02
Done.
| |
| 36 public BluetoothManagerClient::Observer, | 34 public BluetoothManagerClient::Observer, |
| 37 public BluetoothAdapterClient::Observer, | 35 public BluetoothAdapterClient::Observer, |
| 38 public BluetoothDeviceClient::Observer { | 36 public BluetoothDeviceClient::Observer { |
| 39 public: | 37 public: |
| 40 // Interface for observing changes from bluetooth adapters. | |
| 41 class Observer { | |
| 42 public: | |
| 43 virtual ~Observer() {} | |
| 44 | |
| 45 // Called when the presence of the adapter |adapter| changes, when | |
| 46 // |present| is true the adapter is now present, false means the adapter | |
| 47 // has been removed from the system. | |
| 48 virtual void AdapterPresentChanged(BluetoothAdapter* adapter, | |
| 49 bool present) {} | |
| 50 | |
| 51 // Called when the radio power state of the adapter |adapter| changes, | |
| 52 // when |powered| is true the adapter radio is powered, false means the | |
| 53 // adapter radio is off. | |
| 54 virtual void AdapterPoweredChanged(BluetoothAdapter* adapter, | |
| 55 bool powered) {} | |
| 56 | |
| 57 // Called when the discovering state of the adapter |adapter| changes, | |
| 58 // when |discovering| is true the adapter is seeking new devices, false | |
| 59 // means it is not. Note that device discovery involves both states when | |
| 60 // the adapter is seeking new devices and states when it is not because | |
| 61 // it is interrogating the devices it found. | |
| 62 virtual void AdapterDiscoveringChanged(BluetoothAdapter* adapter, | |
| 63 bool discovering) {} | |
| 64 | |
| 65 // Called when a new device |device| is added to the adapter |adapter|, | |
| 66 // either because it has been discovered or a connection made. |device| | |
| 67 // should not be cached, instead copy its address. | |
| 68 virtual void DeviceAdded(BluetoothAdapter* adapter, | |
| 69 BluetoothDevice* device) {} | |
| 70 | |
| 71 // Called when properties of the device |device| known to the adapter | |
| 72 // |adapter| change. |device| should not be cached, instead copy its | |
| 73 // address. | |
| 74 virtual void DeviceChanged(BluetoothAdapter* adapter, | |
| 75 BluetoothDevice* device) {} | |
| 76 | |
| 77 // Called when the device |device| is removed from the adapter |adapter|, | |
| 78 // either as a result of a discovered device being lost between discovering | |
| 79 // phases or pairing information deleted. |device| should not be cached. | |
| 80 virtual void DeviceRemoved(BluetoothAdapter* adapter, | |
| 81 BluetoothDevice* device) {} | |
| 82 }; | |
| 83 | |
| 84 // Adds and removes observers for events on this bluetooth adapter, | 38 // Adds and removes observers for events on this bluetooth adapter, |
|
bryeung
2012/09/13 19:52:57
In many places blocks of methods will be marked wi
keybuk
2012/09/13 23:57:30
Chrome style says this should be
// BluetoothAdap
youngki
2012/09/17 21:53:02
Done.
| |
| 85 // if monitoring multiple adapters check the |adapter| parameter of | 39 // if monitoring multiple adapters check the |adapter| parameter of |
| 86 // observer methods to determine which adapter is issuing the event. | 40 // observer methods to determine which adapter is issuing the event. |
| 87 void AddObserver(Observer* observer); | 41 virtual void AddObserver(BluetoothAdapter::Observer* observer) OVERRIDE; |
| 88 void RemoveObserver(Observer* observer); | 42 virtual void RemoveObserver(BluetoothAdapter::Observer* observer) OVERRIDE; |
| 89 | |
| 90 // The ErrorCallback is used for methods that can fail in which case it | |
| 91 // is called, in the success case the callback is simply not called. | |
| 92 typedef base::Callback<void()> ErrorCallback; | |
| 93 | |
| 94 // The BluetoothOutOfBandPairingDataCallback is used to return | |
| 95 // BluetoothOutOfBandPairingData to the caller. | |
| 96 typedef base::Callback<void(const BluetoothOutOfBandPairingData& data)> | |
| 97 BluetoothOutOfBandPairingDataCallback; | |
| 98 | 43 |
| 99 // The address of this adapter. The address format is "XX:XX:XX:XX:XX:XX", | 44 // The address of this adapter. The address format is "XX:XX:XX:XX:XX:XX", |
| 100 // where each XX is a hexadecimal number. | 45 // where each XX is a hexadecimal number. |
| 101 const std::string& address() const { return address_; } | 46 virtual const std::string& address() const OVERRIDE; |
| 102 | 47 |
| 103 // The name of the adapter. | 48 // The name of the adapter. |
| 104 const std::string& name() const { return name_; } | 49 virtual const std::string& name() const OVERRIDE; |
| 105 | 50 |
| 106 // Indicates whether the adapter is actually present on the system, for | 51 // Indicates whether the adapter is actually present on the system, for |
| 107 // the default adapter this indicates whether any adapter is present. An | 52 // the default adapter this indicates whether any adapter is present. An |
| 108 // adapter is only considered present if the address has been obtained. | 53 // adapter is only considered present if the address has been obtained. |
| 109 virtual bool IsPresent() const; | 54 virtual bool IsPresent() const OVERRIDE; |
| 110 | 55 |
| 111 // Indicates whether the adapter radio is powered. | 56 // Indicates whether the adapter radio is powered. |
| 112 virtual bool IsPowered() const; | 57 virtual bool IsPowered() const OVERRIDE; |
| 113 | 58 |
| 114 // Requests a change to the adapter radio power, setting |powered| to true | 59 // Requests a change to the adapter radio power, setting |powered| to true |
| 115 // will turn on the radio and false will turn it off. On success, callback | 60 // will turn on the radio and false will turn it off. On success, callback |
| 116 // will be called. On failure, |error_callback| will be called. | 61 // will be called. On failure, |error_callback| will be called. |
| 117 void SetPowered(bool powered, | 62 virtual void SetPowered(bool powered, |
| 118 const base::Closure& callback, | 63 const base::Closure& callback, |
| 119 const ErrorCallback& error_callback); | 64 const ErrorCallback& error_callback) OVERRIDE; |
| 120 | 65 |
| 121 // Indicates whether the adapter is currently discovering new devices, | 66 // Indicates whether the adapter is currently discovering new devices, |
| 122 // note that a typical discovery process has phases of this being true | 67 // note that a typical discovery process has phases of this being true |
| 123 // followed by phases of being false when the adapter interrogates the | 68 // followed by phases of being false when the adapter interrogates the |
| 124 // devices found. | 69 // devices found. |
| 125 virtual bool IsDiscovering() const; | 70 virtual bool IsDiscovering() const OVERRIDE; |
| 126 | 71 |
| 127 // Requests that the adapter either begin discovering new devices when | 72 // Requests that the adapter either begin discovering new devices when |
| 128 // |discovering| is true, or cease any discovery when false. On success, | 73 // |discovering| is true, or cease any discovery when false. On success, |
| 129 // callback will be called. On failure, |error_callback| will be called. | 74 // callback will be called. On failure, |error_callback| will be called. |
| 130 virtual void SetDiscovering(bool discovering, | 75 virtual void SetDiscovering(bool discovering, |
| 131 const base::Closure& callback, | 76 const base::Closure& callback, |
| 132 const ErrorCallback& error_callback); | 77 const ErrorCallback& error_callback) OVERRIDE; |
| 133 | 78 |
| 134 // Requests the list of devices from the adapter, all are returned | 79 // Requests the list of devices from the adapter, all are returned |
| 135 // including those currently connected and those paired. Use the | 80 // including those currently connected and those paired. Use the |
| 136 // returned device pointers to determine which they are. | 81 // returned device pointers to determine which they are. |
| 137 typedef std::vector<BluetoothDevice*> DeviceList; | 82 virtual DeviceList GetDevices() OVERRIDE; |
| 138 virtual DeviceList GetDevices(); | 83 virtual ConstDeviceList GetDevices() const OVERRIDE; |
| 139 typedef std::vector<const BluetoothDevice*> ConstDeviceList; | |
| 140 virtual ConstDeviceList GetDevices() const; | |
| 141 | 84 |
| 142 // Returns a pointer to the device with the given address |address| or | 85 // Returns a pointer to the device with the given address |address| or |
| 143 // NULL if no such device is known. | 86 // NULL if no such device is known. |
| 144 virtual BluetoothDevice* GetDevice(const std::string& address); | 87 virtual BluetoothDevice* GetDevice(const std::string& address) OVERRIDE; |
| 145 virtual const BluetoothDevice* GetDevice(const std::string& address) const; | 88 virtual const BluetoothDevice* GetDevice( |
| 89 const std::string& address) const OVERRIDE; | |
| 146 | 90 |
| 147 // Requests the local Out Of Band pairing data. | 91 // Requests the local Out Of Band pairing data. |
| 148 virtual void ReadLocalOutOfBandPairingData( | 92 virtual void ReadLocalOutOfBandPairingData( |
| 149 const BluetoothOutOfBandPairingDataCallback& callback, | 93 const BluetoothOutOfBandPairingDataCallback& callback, |
| 150 const ErrorCallback& error_callback); | 94 const ErrorCallback& error_callback) OVERRIDE; |
| 151 | 95 |
| 152 // Returns the shared instance for the default adapter, whichever that may | 96 // Returns the shared instance for the default adapter, whichever that may |
| 153 // be at the time. Use IsPresent() and the AdapterPresentChanged() observer | 97 // be at the time. Use IsPresent() and the AdapterPresentChanged() observer |
| 154 // method to determine whether an adapter is actually available or not. | 98 // method to determine whether an adapter is actually available or not. |
| 155 static scoped_refptr<BluetoothAdapter> DefaultAdapter(); | 99 static scoped_refptr<BluetoothAdapter> DefaultAdapter(); |
| 156 | 100 |
| 157 // Creates an instance for a specific adapter named by |address|, which | 101 // Creates an instance for a specific adapter named by |address|, which |
| 158 // may be the bluetooth address of the adapter or a device name such as | 102 // may be the bluetooth address of the adapter or a device name such as |
| 159 // "hci0". | 103 // "hci0". |
| 160 static BluetoothAdapter* Create(const std::string& address); | 104 static BluetoothAdapterDBus* Create(const std::string& address); |
| 161 | 105 |
| 162 private: | 106 private: |
| 163 friend class base::RefCounted<BluetoothAdapter>; | 107 friend class base::RefCounted<BluetoothAdapterDBus>; |
| 164 friend class BluetoothDevice; | 108 friend class BluetoothDeviceDBus; |
| 165 friend class MockBluetoothAdapter; | 109 friend class MockBluetoothAdapter; |
| 166 | 110 |
| 167 BluetoothAdapter(); | 111 BluetoothAdapterDBus(); |
| 168 virtual ~BluetoothAdapter(); | 112 virtual ~BluetoothAdapterDBus(); |
| 169 | 113 |
| 170 // Obtains the default adapter object path from the Bluetooth Daemon | 114 // Obtains the default adapter object path from the Bluetooth Daemon |
| 171 // and tracks future changes to it. | 115 // and tracks future changes to it. |
| 172 void TrackDefaultAdapter(); | 116 void TrackDefaultAdapter(); |
| 173 | 117 |
| 174 // Obtains the object paht for the adapter named by |address| from the | 118 // Obtains the object paht for the adapter named by |address| from the |
| 175 // Bluetooth Daemon. | 119 // Bluetooth Daemon. |
| 176 void FindAdapter(const std::string& address); | 120 void FindAdapter(const std::string& address); |
| 177 | 121 |
| 178 // Called by dbus:: in response to the method call sent by both | 122 // Called by dbus:: in response to the method call sent by both |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 319 // Name of the adapter. | 263 // Name of the adapter. |
| 320 std::string name_; | 264 std::string name_; |
| 321 | 265 |
| 322 // Tracked adapter state, cached locally so we only send change notifications | 266 // Tracked adapter state, cached locally so we only send change notifications |
| 323 // to observers on a genuine change. | 267 // to observers on a genuine change. |
| 324 bool powered_; | 268 bool powered_; |
| 325 bool discovering_; | 269 bool discovering_; |
| 326 | 270 |
| 327 // Devices paired with, connected to, discovered by, or visible to the | 271 // Devices paired with, connected to, discovered by, or visible to the |
| 328 // adapter. The key is the Bluetooth address of the device and the value | 272 // adapter. The key is the Bluetooth address of the device and the value |
| 329 // is the BluetoothDevice object whose lifetime is managed by the adapter | 273 // is the BluetoothDeviceDBus object whose lifetime is managed by the adapter |
| 330 // instance. | 274 // instance. |
| 331 typedef std::map<const std::string, BluetoothDevice*> DevicesMap; | 275 typedef std::map<const std::string, BluetoothDeviceDBus*> DevicesMap; |
| 332 DevicesMap devices_; | 276 DevicesMap devices_; |
| 333 | 277 |
| 334 // Note: This should remain the last member so it'll be destroyed and | 278 // Note: This should remain the last member so it'll be destroyed and |
| 335 // invalidate its weak pointers before any other members are destroyed. | 279 // invalidate its weak pointers before any other members are destroyed. |
| 336 base::WeakPtrFactory<BluetoothAdapter> weak_ptr_factory_; | 280 base::WeakPtrFactory<BluetoothAdapterDBus> weak_ptr_factory_; |
| 337 | 281 |
| 338 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapter); | 282 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterDBus); |
| 339 }; | 283 }; |
| 340 | 284 |
| 341 } // namespace chromeos | 285 } // namespace chromeos |
| 342 | 286 |
| 343 #endif // CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_ADAPTER_H_ | 287 #endif // CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_ADAPTER_DBUS_H_ |
| OLD | NEW |