OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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_CHROMEOS_H_ | 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_CHROMEOS_H_ |
6 #define DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_CHROMEOS_H_ | 6 #define DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_CHROMEOS_H_ |
7 | 7 |
| 8 #include <map> |
8 #include <queue> | 9 #include <queue> |
9 #include <string> | 10 #include <string> |
10 #include <utility> | 11 #include <utility> |
11 #include <vector> | 12 #include <vector> |
12 | 13 |
13 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
14 #include "base/sequenced_task_runner.h" | 15 #include "base/sequenced_task_runner.h" |
15 #include "chromeos/dbus/bluetooth_adapter_client.h" | 16 #include "chromeos/dbus/bluetooth_adapter_client.h" |
16 #include "chromeos/dbus/bluetooth_agent_service_provider.h" | 17 #include "chromeos/dbus/bluetooth_agent_service_provider.h" |
17 #include "chromeos/dbus/bluetooth_device_client.h" | 18 #include "chromeos/dbus/bluetooth_device_client.h" |
18 #include "chromeos/dbus/bluetooth_input_client.h" | 19 #include "chromeos/dbus/bluetooth_input_client.h" |
| 20 #include "chromeos/dbus/bluetooth_profile_manager_client.h" |
| 21 #include "chromeos/dbus/bluetooth_profile_service_provider.h" |
19 #include "dbus/object_path.h" | 22 #include "dbus/object_path.h" |
20 #include "device/bluetooth/bluetooth_adapter.h" | 23 #include "device/bluetooth/bluetooth_adapter.h" |
21 #include "device/bluetooth/bluetooth_audio_sink.h" | 24 #include "device/bluetooth/bluetooth_audio_sink.h" |
22 #include "device/bluetooth/bluetooth_device.h" | 25 #include "device/bluetooth/bluetooth_device.h" |
23 #include "device/bluetooth/bluetooth_export.h" | 26 #include "device/bluetooth/bluetooth_export.h" |
24 | 27 |
25 namespace device { | 28 namespace device { |
26 class BluetoothSocketThread; | 29 class BluetoothSocketThread; |
27 } // namespace device | 30 } // namespace device |
28 | 31 |
29 namespace chromeos { | 32 namespace chromeos { |
30 | 33 |
31 class BluetoothChromeOSTest; | 34 class BluetoothChromeOSTest; |
| 35 class BluetoothAdapterProfileChromeOS; |
32 class BluetoothDeviceChromeOS; | 36 class BluetoothDeviceChromeOS; |
33 class BluetoothPairingChromeOS; | 37 class BluetoothPairingChromeOS; |
34 class BluetoothRemoteGattCharacteristicChromeOS; | 38 class BluetoothRemoteGattCharacteristicChromeOS; |
35 class BluetoothRemoteGattDescriptorChromeOS; | 39 class BluetoothRemoteGattDescriptorChromeOS; |
36 class BluetoothRemoteGattServiceChromeOS; | 40 class BluetoothRemoteGattServiceChromeOS; |
37 | 41 |
38 // The BluetoothAdapterChromeOS class implements BluetoothAdapter for the | 42 // The BluetoothAdapterChromeOS class implements BluetoothAdapter for the |
39 // Chrome OS platform. | 43 // Chrome OS platform. |
40 class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterChromeOS | 44 class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterChromeOS |
41 : public device::BluetoothAdapter, | 45 : public device::BluetoothAdapter, |
42 public chromeos::BluetoothAdapterClient::Observer, | 46 public chromeos::BluetoothAdapterClient::Observer, |
43 public chromeos::BluetoothDeviceClient::Observer, | 47 public chromeos::BluetoothDeviceClient::Observer, |
44 public chromeos::BluetoothInputClient::Observer, | 48 public chromeos::BluetoothInputClient::Observer, |
45 public chromeos::BluetoothAgentServiceProvider::Delegate { | 49 public chromeos::BluetoothAgentServiceProvider::Delegate { |
46 public: | 50 public: |
| 51 typedef base::Callback<void(const std::string& error_message)> |
| 52 ErrorCompletionCallback; |
| 53 typedef base::Callback<void(BluetoothAdapterProfileChromeOS* profile)> |
| 54 ProfileRegisteredCallback; |
| 55 |
47 static base::WeakPtr<BluetoothAdapter> CreateAdapter(); | 56 static base::WeakPtr<BluetoothAdapter> CreateAdapter(); |
48 | 57 |
49 // BluetoothAdapter: | 58 // BluetoothAdapter: |
50 void Shutdown() override; | 59 void Shutdown() override; |
51 void DeleteOnCorrectThread() const override; | 60 void DeleteOnCorrectThread() const override; |
52 void AddObserver(device::BluetoothAdapter::Observer* observer) override; | 61 void AddObserver(device::BluetoothAdapter::Observer* observer) override; |
53 void RemoveObserver(device::BluetoothAdapter::Observer* observer) override; | 62 void RemoveObserver(device::BluetoothAdapter::Observer* observer) override; |
54 std::string GetAddress() const override; | 63 std::string GetAddress() const override; |
55 std::string GetName() const override; | 64 std::string GetName() const override; |
56 void SetName(const std::string& name, | 65 void SetName(const std::string& name, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 void NotifyGattCharacteristicValueChanged( | 117 void NotifyGattCharacteristicValueChanged( |
109 BluetoothRemoteGattCharacteristicChromeOS* characteristic, | 118 BluetoothRemoteGattCharacteristicChromeOS* characteristic, |
110 const std::vector<uint8>& value); | 119 const std::vector<uint8>& value); |
111 void NotifyGattDescriptorValueChanged( | 120 void NotifyGattDescriptorValueChanged( |
112 BluetoothRemoteGattDescriptorChromeOS* descriptor, | 121 BluetoothRemoteGattDescriptorChromeOS* descriptor, |
113 const std::vector<uint8>& value); | 122 const std::vector<uint8>& value); |
114 | 123 |
115 // Returns the object path of the adapter. | 124 // Returns the object path of the adapter. |
116 const dbus::ObjectPath& object_path() const { return object_path_; } | 125 const dbus::ObjectPath& object_path() const { return object_path_; } |
117 | 126 |
| 127 // Request a profile on the adapter for a custom service with a |
| 128 // specific UUID for the device at |device_path| to be sent to |delegate|. |
| 129 // If |device_path| is the empty string, incoming connections will be |
| 130 // assigned to |delegate|. When the profile is |
| 131 // successfully registered, |success_callback| will be called with a pointer |
| 132 // to the profile which is managed by BluetoothAdapterChromeOS. On failure, |
| 133 // |error_callback| will be called. |
| 134 void UseProfile(const device::BluetoothUUID& uuid, |
| 135 const dbus::ObjectPath& device_path, |
| 136 const BluetoothProfileManagerClient::Options& options, |
| 137 BluetoothProfileServiceProvider::Delegate* delegate, |
| 138 const ProfileRegisteredCallback& success_callback, |
| 139 const ErrorCompletionCallback& error_callback); |
| 140 |
| 141 // Releases the profile associated with |uuid| |
| 142 void ReleaseProfile(const device::BluetoothUUID& uuid); |
| 143 |
118 protected: | 144 protected: |
119 // BluetoothAdapter: | 145 // BluetoothAdapter: |
120 void RemovePairingDelegateInternal( | 146 void RemovePairingDelegateInternal( |
121 device::BluetoothDevice::PairingDelegate* pairing_delegate) override; | 147 device::BluetoothDevice::PairingDelegate* pairing_delegate) override; |
122 | 148 |
123 private: | 149 private: |
124 friend class base::DeleteHelper<BluetoothAdapterChromeOS>; | 150 friend class base::DeleteHelper<BluetoothAdapterChromeOS>; |
125 friend class BluetoothChromeOSTest; | 151 friend class BluetoothChromeOSTest; |
126 | 152 |
127 // typedef for callback parameters that are passed to AddDiscoverySession | 153 // typedef for callback parameters that are passed to AddDiscoverySession |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 const ErrorCallback& error_callback, | 254 const ErrorCallback& error_callback, |
229 const std::string& error_name, | 255 const std::string& error_name, |
230 const std::string& error_message); | 256 const std::string& error_message); |
231 | 257 |
232 // Called by dbus:: on completion of the D-Bus method call to stop discovery. | 258 // Called by dbus:: on completion of the D-Bus method call to stop discovery. |
233 void OnStopDiscovery(const base::Closure& callback); | 259 void OnStopDiscovery(const base::Closure& callback); |
234 void OnStopDiscoveryError(const ErrorCallback& error_callback, | 260 void OnStopDiscoveryError(const ErrorCallback& error_callback, |
235 const std::string& error_name, | 261 const std::string& error_name, |
236 const std::string& error_message); | 262 const std::string& error_message); |
237 | 263 |
| 264 // Called by dbus:: on completion of the D-Bus method to register a profile. |
| 265 void OnRegisterProfile(const device::BluetoothUUID& uuid, |
| 266 const dbus::ObjectPath& device_path, |
| 267 BluetoothProfileServiceProvider::Delegate* delegate, |
| 268 const ProfileRegisteredCallback& success_callback, |
| 269 const ErrorCompletionCallback& error_callback); |
| 270 bool SetProfileDelegate(const device::BluetoothUUID& uuid, |
| 271 const dbus::ObjectPath& device_path, |
| 272 BluetoothProfileServiceProvider::Delegate* delegate, |
| 273 const ProfileRegisteredCallback& success_callback, |
| 274 const ErrorCompletionCallback& error_callback); |
| 275 void OnRegisterProfileError(const device::BluetoothUUID& uuid, |
| 276 const ErrorCompletionCallback& error_callback, |
| 277 const std::string& error_name, |
| 278 const std::string& error_message); |
| 279 |
238 // Processes the queued discovery requests. For each DiscoveryCallbackPair in | 280 // Processes the queued discovery requests. For each DiscoveryCallbackPair in |
239 // the queue, this method will try to add a new discovery session. This method | 281 // the queue, this method will try to add a new discovery session. This method |
240 // is called whenever a pending D-Bus call to start or stop discovery has | 282 // is called whenever a pending D-Bus call to start or stop discovery has |
241 // ended (with either success or failure). | 283 // ended (with either success or failure). |
242 void ProcessQueuedDiscoveryRequests(); | 284 void ProcessQueuedDiscoveryRequests(); |
243 | 285 |
244 // Set in |Shutdown()|, makes IsPresent()| return false. | 286 // Set in |Shutdown()|, makes IsPresent()| return false. |
245 bool dbus_is_shutdown_; | 287 bool dbus_is_shutdown_; |
246 | 288 |
247 // Number of discovery sessions that have been added. | 289 // Number of discovery sessions that have been added. |
(...skipping 20 matching lines...) Expand all Loading... |
268 ObserverList<device::BluetoothAdapter::Observer> observers_; | 310 ObserverList<device::BluetoothAdapter::Observer> observers_; |
269 | 311 |
270 // Instance of the D-Bus agent object used for pairing, initialized with | 312 // Instance of the D-Bus agent object used for pairing, initialized with |
271 // our own class as its delegate. | 313 // our own class as its delegate. |
272 scoped_ptr<BluetoothAgentServiceProvider> agent_; | 314 scoped_ptr<BluetoothAgentServiceProvider> agent_; |
273 | 315 |
274 // UI thread task runner and socket thread object used to create sockets. | 316 // UI thread task runner and socket thread object used to create sockets. |
275 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_; | 317 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_; |
276 scoped_refptr<device::BluetoothSocketThread> socket_thread_; | 318 scoped_refptr<device::BluetoothSocketThread> socket_thread_; |
277 | 319 |
| 320 // The profiles we have registered with the bluetooth daemon. |
| 321 std::map<device::BluetoothUUID, BluetoothAdapterProfileChromeOS*> profiles_; |
| 322 |
278 // Note: This should remain the last member so it'll be destroyed and | 323 // Note: This should remain the last member so it'll be destroyed and |
279 // invalidate its weak pointers before any other members are destroyed. | 324 // invalidate its weak pointers before any other members are destroyed. |
280 base::WeakPtrFactory<BluetoothAdapterChromeOS> weak_ptr_factory_; | 325 base::WeakPtrFactory<BluetoothAdapterChromeOS> weak_ptr_factory_; |
281 | 326 |
282 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterChromeOS); | 327 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterChromeOS); |
283 }; | 328 }; |
284 | 329 |
285 } // namespace chromeos | 330 } // namespace chromeos |
286 | 331 |
287 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_CHROMEOS_H_ | 332 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_CHROMEOS_H_ |
OLD | NEW |