| 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 #ifndef CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_ADAPTER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_ADAPTER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_ADAPTER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_ADAPTER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
| 14 #include "base/callback.h" | 14 #include "base/callback.h" |
| 15 #include "base/observer_list.h" | 15 #include "base/observer_list.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_pairing_data.h" |
| 19 #include "dbus/object_path.h" | 20 #include "dbus/object_path.h" |
| 20 | 21 |
| 21 namespace chromeos { | 22 namespace chromeos { |
| 22 | 23 |
| 23 class BluetoothDevice; | 24 class BluetoothDevice; |
| 24 | 25 |
| 25 // The BluetoothAdapter class represents a local Bluetooth adapter which | 26 // The BluetoothAdapter class represents a local Bluetooth adapter which |
| 26 // may be used to interact with remote Bluetooth devices. As well as | 27 // may be used to interact with remote Bluetooth devices. As well as |
| 27 // providing support for determining whether an adapter is present, and | 28 // providing support for determining whether an adapter is present, and |
| 28 // whether the radio is powered, this class also provides support for | 29 // whether the radio is powered, this class also provides support for |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 // Adds and removes observers for events on this bluetooth adapter, | 85 // Adds and removes observers for events on this bluetooth adapter, |
| 85 // if monitoring multiple adapters check the |adapter| parameter of | 86 // if monitoring multiple adapters check the |adapter| parameter of |
| 86 // observer methods to determine which adapter is issuing the event. | 87 // observer methods to determine which adapter is issuing the event. |
| 87 void AddObserver(Observer* observer); | 88 void AddObserver(Observer* observer); |
| 88 void RemoveObserver(Observer* observer); | 89 void RemoveObserver(Observer* observer); |
| 89 | 90 |
| 90 // The ErrorCallback is used for methods that can fail in which case it | 91 // 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 // is called, in the success case the callback is simply not called. |
| 92 typedef base::Callback<void()> ErrorCallback; | 93 typedef base::Callback<void()> ErrorCallback; |
| 93 | 94 |
| 95 // The ResultCallback is used for methods that return a boolean value |
| 96 // indicating success (true) or failure (false). |
| 97 typedef base::Callback<void(bool result)> ResultCallback; |
| 98 |
| 94 // The address of this adapter. The address format is "XX:XX:XX:XX:XX:XX", | 99 // The address of this adapter. The address format is "XX:XX:XX:XX:XX:XX", |
| 95 // where each XX is a hexadecimal number. | 100 // where each XX is a hexadecimal number. |
| 96 const std::string& address() const { return address_; } | 101 const std::string& address() const { return address_; } |
| 97 | 102 |
| 98 // Indicates whether the adapter is actually present on the system, for | 103 // Indicates whether the adapter is actually present on the system, for |
| 99 // the default adapter this indicates whether any adapter is present. | 104 // the default adapter this indicates whether any adapter is present. |
| 100 virtual bool IsPresent() const; | 105 virtual bool IsPresent() const; |
| 101 | 106 |
| 102 // Indicates whether the adapter radio is powered. | 107 // Indicates whether the adapter radio is powered. |
| 103 virtual bool IsPowered() const; | 108 virtual bool IsPowered() const; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 124 typedef std::vector<BluetoothDevice*> DeviceList; | 129 typedef std::vector<BluetoothDevice*> DeviceList; |
| 125 virtual DeviceList GetDevices(); | 130 virtual DeviceList GetDevices(); |
| 126 typedef std::vector<const BluetoothDevice*> ConstDeviceList; | 131 typedef std::vector<const BluetoothDevice*> ConstDeviceList; |
| 127 virtual ConstDeviceList GetDevices() const; | 132 virtual ConstDeviceList GetDevices() const; |
| 128 | 133 |
| 129 // Returns a pointer to the device with the given address |address| or | 134 // Returns a pointer to the device with the given address |address| or |
| 130 // NULL if no such device is known. | 135 // NULL if no such device is known. |
| 131 BluetoothDevice* GetDevice(const std::string& address); | 136 BluetoothDevice* GetDevice(const std::string& address); |
| 132 const BluetoothDevice* GetDevice(const std::string& address) const; | 137 const BluetoothDevice* GetDevice(const std::string& address) const; |
| 133 | 138 |
| 139 // Requests the local Out Of Band pairing data. |
| 140 virtual void ReadLocalOutOfBandPairingData( |
| 141 const OutOfBandPairingDataCallback& callback) const; |
| 142 |
| 143 // Sets the Out Of Band pairing data for the device at |address| to |data|. |
| 144 void SetOutOfBandPairingData(const std::string& address, |
| 145 const chromeos::OutOfBandPairingData& data, |
| 146 const ResultCallback& callback); |
| 147 |
| 148 // Clears the Out Of Band pairing data for the device at |address|. |
| 149 virtual void ClearOutOfBandPairingData(const std::string& address, |
| 150 const ResultCallback& callback); |
| 151 |
| 134 // Creates the instance for the default adapter, whichever that may | 152 // Creates the instance for the default adapter, whichever that may |
| 135 // be at the time. Use IsPresent() and the AdapterPresentChanged() observer | 153 // be at the time. Use IsPresent() and the AdapterPresentChanged() observer |
| 136 // method to determine whether an adapter is actually available or not. | 154 // method to determine whether an adapter is actually available or not. |
| 137 static BluetoothAdapter* CreateDefaultAdapter(); | 155 static BluetoothAdapter* CreateDefaultAdapter(); |
| 138 | 156 |
| 139 // Creates an instance for a specific adapter named by |address|, which | 157 // Creates an instance for a specific adapter named by |address|, which |
| 140 // may be the bluetooth address of the adapter or a device name such as | 158 // may be the bluetooth address of the adapter or a device name such as |
| 141 // "hci0". | 159 // "hci0". |
| 142 static BluetoothAdapter* Create(const std::string& address); | 160 static BluetoothAdapter* Create(const std::string& address); |
| 143 | 161 |
| 144 private: | 162 private: |
| 145 friend class BluetoothDevice; | 163 friend class BluetoothDevice; |
| 146 friend class MockBluetoothAdapter; | 164 friend class MockBluetoothAdapter; |
| 147 | 165 |
| 148 BluetoothAdapter(); | 166 BluetoothAdapter(); |
| 149 | 167 |
| 150 // Obtains the default adapter object path from the Bluetooth Daemon | 168 // Obtains the default adapter object path from the Bluetooth Daemon |
| 151 // and tracks future changes to it. | 169 // and tracks future changes to it. |
| 152 void DefaultAdapter(); | 170 void DefaultAdapter(); |
| 153 | 171 |
| 154 // Obtains the object paht for the adapter named by |address| from the | 172 // Obtains the object paht for the adapter named by |address| from the |
| 155 // Bluetooth Daemon. | 173 // Bluetooth Daemon. |
| 156 void FindAdapter(const std::string& address); | 174 void FindAdapter(const std::string& address); |
| 157 | 175 |
| 158 // Called by dbus:: in response to the method call sent by both | 176 // Called by dbus:: in response to the method call sent by both |
| 159 // DefaultAdapter() and FindAdapter(), |object_path| will contain the | 177 // DefaultAdapter() and FindAdapter(), |object_path| will contain the |
| 160 // dbus object path of the requested adapter when |success| is true. | 178 // dbus object path of the requested adapter when |success| is true. |
| 161 void AdapterCallback(const dbus::ObjectPath& adapter_path, bool success); | 179 void AdapterCallback(const dbus::ObjectPath& adapter_path, bool success); |
| 162 | 180 |
| 181 // Translates from an AdapterCallback to a ResultCallback, by ignoring the |
| 182 // |adapter_path| and passing |success| on to |callback|. |
| 183 void AdapterCallbackToResultCallback( |
| 184 const ResultCallback& callback, |
| 185 const dbus::ObjectPath& adapter_path, |
| 186 bool success); |
| 187 |
| 163 // BluetoothManagerClient::Observer override. | 188 // BluetoothManagerClient::Observer override. |
| 164 // | 189 // |
| 165 // Called when the default local bluetooth adapter changes. | 190 // Called when the default local bluetooth adapter changes. |
| 166 // |object_path| is the dbus object path of the new default adapter. | 191 // |object_path| is the dbus object path of the new default adapter. |
| 167 // Not called if all adapters are removed. | 192 // Not called if all adapters are removed. |
| 168 virtual void DefaultAdapterChanged(const dbus::ObjectPath& adapter_path) | 193 virtual void DefaultAdapterChanged(const dbus::ObjectPath& adapter_path) |
| 169 OVERRIDE; | 194 OVERRIDE; |
| 170 | 195 |
| 171 // BluetoothManagerClient::Observer override. | 196 // BluetoothManagerClient::Observer override. |
| 172 // | 197 // |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 // instance. | 321 // instance. |
| 297 typedef std::map<const std::string, BluetoothDevice*> DevicesMap; | 322 typedef std::map<const std::string, BluetoothDevice*> DevicesMap; |
| 298 DevicesMap devices_; | 323 DevicesMap devices_; |
| 299 | 324 |
| 300 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapter); | 325 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapter); |
| 301 }; | 326 }; |
| 302 | 327 |
| 303 } // namespace chromeos | 328 } // namespace chromeos |
| 304 | 329 |
| 305 #endif // CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_ADAPTER_H_ | 330 #endif // CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_ADAPTER_H_ |
| OLD | NEW |