OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_PROFILE_CHROMEOS_H_ | 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_PROFILE_BLUEZ_H_ |
6 #define DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_PROFILE_CHROMEOS_H_ | 6 #define DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_PROFILE_BLUEZ_H_ |
7 | 7 |
| 8 #include "base/macros.h" |
8 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
9 #include "device/bluetooth/bluetooth_adapter_chromeos.h" | 10 #include "device/bluetooth/bluetooth_adapter_bluez.h" |
10 #include "device/bluetooth/bluetooth_export.h" | 11 #include "device/bluetooth/bluetooth_export.h" |
11 #include "device/bluetooth/dbus/bluetooth_profile_manager_client.h" | 12 #include "device/bluetooth/dbus/bluetooth_profile_manager_client.h" |
12 #include "device/bluetooth/dbus/bluetooth_profile_service_provider.h" | 13 #include "device/bluetooth/dbus/bluetooth_profile_service_provider.h" |
13 | 14 |
14 namespace device { | 15 namespace device { |
15 class BluetoothUUID; | 16 class BluetoothUUID; |
16 } // namespace device | 17 } // namespace device |
17 | 18 |
18 namespace chromeos { | 19 namespace bluez { |
19 | 20 |
20 // The BluetoothAdapterProfileChromeOS class implements a multiplexing | 21 // The BluetoothAdapterProfileBlueZ class implements a multiplexing |
21 // profile for custom Bluetooth services managed by a BluetoothAdapter. | 22 // profile for custom Bluetooth services managed by a BluetoothAdapter. |
22 // Maintains a list of delegates which may serve the profile. | 23 // Maintains a list of delegates which may serve the profile. |
23 // One delegate is allowed for each device. | 24 // One delegate is allowed for each device. |
24 // | 25 // |
25 // This class is not thread-safe, but is only called from the dbus origin | 26 // This class is not thread-safe, but is only called from the dbus origin |
26 // thread. | 27 // thread. |
27 // | 28 // |
28 // BluetoothAdapterProfileChromeOS objects are owned by the | 29 // BluetoothAdapterProfileBlueZ objects are owned by the |
29 // BluetoothAdapterChromeOS and allocated through Register() | 30 // BluetoothAdapterBlueZ and allocated through Register() |
30 class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterProfileChromeOS | 31 class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterProfileBlueZ |
31 : public bluez::BluetoothProfileServiceProvider::Delegate { | 32 : public bluez::BluetoothProfileServiceProvider::Delegate { |
32 public: | 33 public: |
33 typedef base::Callback<void(scoped_ptr<BluetoothAdapterProfileChromeOS> | 34 typedef base::Callback<void(scoped_ptr<BluetoothAdapterProfileBlueZ> profile)> |
34 profile)> ProfileRegisteredCallback; | 35 ProfileRegisteredCallback; |
35 | 36 |
36 // Registers a profile with the BlueZ server for |uuid| with the | 37 // Registers a profile with the BlueZ server for |uuid| with the |
37 // options |options|. |success_callback| is provided with a newly | 38 // options |options|. |success_callback| is provided with a newly |
38 // allocated profile if registration is successful, otherwise |error_callback| | 39 // allocated profile if registration is successful, otherwise |error_callback| |
39 // will be called. | 40 // will be called. |
40 static void Register( | 41 static void Register( |
41 const device::BluetoothUUID& uuid, | 42 const device::BluetoothUUID& uuid, |
42 const bluez::BluetoothProfileManagerClient::Options& options, | 43 const bluez::BluetoothProfileManagerClient::Options& options, |
43 const ProfileRegisteredCallback& success_callback, | 44 const ProfileRegisteredCallback& success_callback, |
44 const bluez::BluetoothProfileManagerClient::ErrorCallback& | 45 const bluez::BluetoothProfileManagerClient::ErrorCallback& |
45 error_callback); | 46 error_callback); |
46 | 47 |
47 ~BluetoothAdapterProfileChromeOS() override; | 48 ~BluetoothAdapterProfileBlueZ() override; |
48 | 49 |
49 // The object path of the profile. | 50 // The object path of the profile. |
50 const dbus::ObjectPath& object_path() const { return object_path_; } | 51 const dbus::ObjectPath& object_path() const { return object_path_; } |
51 | 52 |
52 // Returns the UUID of the profile | 53 // Returns the UUID of the profile |
53 const device::BluetoothUUID& uuid() const { return uuid_; } | 54 const device::BluetoothUUID& uuid() const { return uuid_; } |
54 | 55 |
55 // Add a delegate for a device associated with this profile. | 56 // Add a delegate for a device associated with this profile. |
56 // An empty |device_path| indicates a local listening service. | 57 // An empty |device_path| indicates a local listening service. |
57 // Returns true if the delegate was set, and false if the |device_path| | 58 // Returns true if the delegate was set, and false if the |device_path| |
58 // already had a delegate set. | 59 // already had a delegate set. |
59 bool SetDelegate(const dbus::ObjectPath& device_path, | 60 bool SetDelegate(const dbus::ObjectPath& device_path, |
60 bluez::BluetoothProfileServiceProvider::Delegate* delegate); | 61 bluez::BluetoothProfileServiceProvider::Delegate* delegate); |
61 | 62 |
62 // Remove the delegate for a device. |unregistered_callback| will be called | 63 // Remove the delegate for a device. |unregistered_callback| will be called |
63 // if this unregisters the profile. | 64 // if this unregisters the profile. |
64 void RemoveDelegate(const dbus::ObjectPath& device_path, | 65 void RemoveDelegate(const dbus::ObjectPath& device_path, |
65 const base::Closure& unregistered_callback); | 66 const base::Closure& unregistered_callback); |
66 | 67 |
67 // Returns the number of delegates for this profile. | 68 // Returns the number of delegates for this profile. |
68 size_t DelegateCount() const { return delegates_.size(); } | 69 size_t DelegateCount() const { return delegates_.size(); } |
69 | 70 |
70 private: | 71 private: |
71 BluetoothAdapterProfileChromeOS(const device::BluetoothUUID& uuid); | 72 BluetoothAdapterProfileBlueZ(const device::BluetoothUUID& uuid); |
72 | 73 |
73 // bluez::BluetoothProfileServiceProvider::Delegate: | 74 // bluez::BluetoothProfileServiceProvider::Delegate: |
74 void Released() override; | 75 void Released() override; |
75 void NewConnection( | 76 void NewConnection( |
76 const dbus::ObjectPath& device_path, | 77 const dbus::ObjectPath& device_path, |
77 scoped_ptr<dbus::FileDescriptor> fd, | 78 scoped_ptr<dbus::FileDescriptor> fd, |
78 const bluez::BluetoothProfileServiceProvider::Delegate::Options& options, | 79 const bluez::BluetoothProfileServiceProvider::Delegate::Options& options, |
79 const ConfirmationCallback& callback) override; | 80 const ConfirmationCallback& callback) override; |
80 void RequestDisconnection(const dbus::ObjectPath& device_path, | 81 void RequestDisconnection(const dbus::ObjectPath& device_path, |
81 const ConfirmationCallback& callback) override; | 82 const ConfirmationCallback& callback) override; |
(...skipping 12 matching lines...) Expand all Loading... |
94 const device::BluetoothUUID& uuid_; | 95 const device::BluetoothUUID& uuid_; |
95 | 96 |
96 // Registered dbus object path for this profile. | 97 // Registered dbus object path for this profile. |
97 dbus::ObjectPath object_path_; | 98 dbus::ObjectPath object_path_; |
98 | 99 |
99 // Profile dbus object for receiving profile method calls from BlueZ | 100 // Profile dbus object for receiving profile method calls from BlueZ |
100 scoped_ptr<bluez::BluetoothProfileServiceProvider> profile_; | 101 scoped_ptr<bluez::BluetoothProfileServiceProvider> profile_; |
101 | 102 |
102 // Note: This should remain the last member so it'll be destroyed and | 103 // Note: This should remain the last member so it'll be destroyed and |
103 // invalidate its weak pointers before any other members are destroyed. | 104 // invalidate its weak pointers before any other members are destroyed. |
104 base::WeakPtrFactory<BluetoothAdapterProfileChromeOS> weak_ptr_factory_; | 105 base::WeakPtrFactory<BluetoothAdapterProfileBlueZ> weak_ptr_factory_; |
105 | 106 |
106 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterProfileChromeOS); | 107 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterProfileBlueZ); |
107 }; | 108 }; |
108 | 109 |
109 } // namespace chromeos | 110 } // namespace bluez |
110 | 111 |
111 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_PROFILE_CHROMEOS_H_ | 112 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_PROFILE_BLUEZ_H_ |
OLD | NEW |