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> |
(...skipping 13 matching lines...) Expand all Loading... |
24 | 24 |
25 // The BluetoothAdapter class represents a local Bluetooth adapter which | 25 // The BluetoothAdapter class represents a local Bluetooth adapter which |
26 // may be used to interact with remote Bluetooth devices. As well as | 26 // may be used to interact with remote Bluetooth devices. As well as |
27 // providing support for determining whether an adapter is present, and | 27 // providing support for determining whether an adapter is present, and |
28 // whether the radio is powered, this class also provides support for | 28 // whether the radio is powered, this class also provides support for |
29 // obtaining the list of remote devices known to the adapter, discovering | 29 // obtaining the list of remote devices known to the adapter, discovering |
30 // new devices, and providing notification of updates to device information. | 30 // new devices, and providing notification of updates to device information. |
31 // | 31 // |
32 // The class may be instantiated for either a specific adapter, or for the | 32 // The class may be instantiated for either a specific adapter, or for the |
33 // generic "default adapter" which may change depending on availability. | 33 // generic "default adapter" which may change depending on availability. |
34 class BluetoothAdapter : public BluetoothManagerClient::Observer, | 34 class BluetoothAdapter : private BluetoothManagerClient::Observer, |
35 public BluetoothAdapterClient::Observer, | 35 private BluetoothAdapterClient::Observer, |
36 public BluetoothDeviceClient::Observer { | 36 private BluetoothDeviceClient::Observer { |
37 public: | 37 public: |
38 // Interface for observing changes from bluetooth adapters. | 38 // Interface for observing changes from bluetooth adapters. |
39 class Observer { | 39 class Observer { |
40 public: | 40 public: |
41 virtual ~Observer() {} | 41 virtual ~Observer() {} |
42 | 42 |
43 // Called when the presence of the adapter |adapter| changes, when | 43 // Called when the presence of the adapter |adapter| changes, when |
44 // |present| is true the adapter is now present, false means the adapter | 44 // |present| is true the adapter is now present, false means the adapter |
45 // has been removed from the system. | 45 // has been removed from the system. |
46 virtual void AdapterPresentChanged(BluetoothAdapter* adapter, | 46 virtual void AdapterPresentChanged(BluetoothAdapter* adapter, |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 // will only be called if the request fails. | 114 // will only be called if the request fails. |
115 void SetDiscovering(bool discovering, ErrorCallback callback); | 115 void SetDiscovering(bool discovering, ErrorCallback callback); |
116 | 116 |
117 // Requests the list of devices from the adapter, all are returned | 117 // Requests the list of devices from the adapter, all are returned |
118 // including those currently connected, those that have been connected or | 118 // including those currently connected, those that have been connected or |
119 // paired in the past and those that have only been discovered. Use the | 119 // paired in the past and those that have only been discovered. Use the |
120 // returned device pointers to determine which they are. | 120 // returned device pointers to determine which they are. |
121 typedef std::vector<BluetoothDevice*> DeviceList; | 121 typedef std::vector<BluetoothDevice*> DeviceList; |
122 DeviceList GetDevices(); | 122 DeviceList GetDevices(); |
123 | 123 |
| 124 // Returns a pointer to the device with the given address |address| or |
| 125 // NULL if no such device is known. |
| 126 BluetoothDevice* GetDevice(const std::string& address); |
| 127 |
124 // Creates the instance for the default adapter, whichever that may | 128 // Creates the instance for the default adapter, whichever that may |
125 // be at the time. Use IsPresent() and the AdapterPresentChanged() observer | 129 // be at the time. Use IsPresent() and the AdapterPresentChanged() observer |
126 // method to determine whether an adapter is actually available or not. | 130 // method to determine whether an adapter is actually available or not. |
127 static BluetoothAdapter* CreateDefaultAdapter(); | 131 static BluetoothAdapter* CreateDefaultAdapter(); |
128 | 132 |
129 // Creates an instance for a specific adapter named by |address|, which | 133 // Creates an instance for a specific adapter named by |address|, which |
130 // may be the bluetooth address of the adapter or a device name such as | 134 // may be the bluetooth address of the adapter or a device name such as |
131 // "hci0". | 135 // "hci0". |
132 static BluetoothAdapter* Create(const std::string& address); | 136 static BluetoothAdapter* Create(const std::string& address); |
133 | 137 |
134 private: | 138 private: |
| 139 friend class BluetoothDevice; |
| 140 |
135 BluetoothAdapter(); | 141 BluetoothAdapter(); |
136 | 142 |
137 // Obtains the default adapter object path from the Bluetooth Daemon | 143 // Obtains the default adapter object path from the Bluetooth Daemon |
138 // and tracks future changes to it. | 144 // and tracks future changes to it. |
139 void DefaultAdapter(); | 145 void DefaultAdapter(); |
140 | 146 |
141 // Obtains the object paht for the adapter named by |address| from the | 147 // Obtains the object paht for the adapter named by |address| from the |
142 // Bluetooth Daemon. | 148 // Bluetooth Daemon. |
143 void FindAdapter(const std::string& address); | 149 void FindAdapter(const std::string& address); |
144 | 150 |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 // by the adapter instance. | 286 // by the adapter instance. |
281 typedef std::map<const std::string, BluetoothDevice*> DevicesMap; | 287 typedef std::map<const std::string, BluetoothDevice*> DevicesMap; |
282 DevicesMap devices_; | 288 DevicesMap devices_; |
283 | 289 |
284 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapter); | 290 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapter); |
285 }; | 291 }; |
286 | 292 |
287 } // namespace chromeos | 293 } // namespace chromeos |
288 | 294 |
289 #endif // CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_ADAPTER_H_ | 295 #endif // CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_ADAPTER_H_ |
OLD | NEW |