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_CHROMEOS_H_ |
6 #define DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_PROFILE_CHROMEOS_H_ | 6 #define DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_PROFILE_CHROMEOS_H_ |
7 | 7 |
8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
9 #include "chromeos/dbus/bluetooth_profile_manager_client.h" | 9 #include "chromeos/dbus/bluetooth_profile_manager_client.h" |
10 #include "chromeos/dbus/bluetooth_profile_service_provider.h" | 10 #include "chromeos/dbus/bluetooth_profile_service_provider.h" |
11 #include "device/bluetooth/bluetooth_adapter_chromeos.h" | 11 #include "device/bluetooth/bluetooth_adapter_chromeos.h" |
12 #include "device/bluetooth/bluetooth_export.h" | 12 #include "device/bluetooth/bluetooth_export.h" |
13 | 13 |
14 namespace device { | 14 namespace device { |
15 class BluetoothUUID; | 15 class BluetoothUUID; |
16 } // namespace device | 16 } // namespace device |
17 | 17 |
18 namespace chromeos { | 18 namespace chromeos { |
19 | 19 |
20 // The BluetoothAdapterProfileChromeOS class implements a multiplexing | 20 // The BluetoothAdapterProfileChromeOS class implements a multiplexing |
21 // profile for custom Bluetooth services managed by a BluetoothAdapter. | 21 // profile for custom Bluetooth services managed by a BluetoothAdapter. |
22 // Maintains a list of delegates which may serve the profile. | 22 // Maintains a list of delegates which may serve the profile. |
23 // One delegate is allowed for each device. | 23 // One delegate is allowed for each device. |
24 // | |
25 // BluetoothAdapterProfileChromeOS objects are owned by the | |
26 // BluetoothAdapterChromeOS and allocated through Register() | |
27 class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterProfileChromeOS | 24 class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterProfileChromeOS |
28 : public chromeos::BluetoothProfileServiceProvider::Delegate { | 25 : public chromeos::BluetoothProfileServiceProvider::Delegate { |
29 public: | 26 public: |
30 typedef base::Callback<void(BluetoothAdapterProfileChromeOS* profile)> | |
31 ProfileRegisteredCallback; | |
32 | |
33 // Registers a profile with the BlueZ server for |uuid| with the | 27 // Registers a profile with the BlueZ server for |uuid| with the |
34 // options |options|. Returns a newly allocated pointer, or nullptr | 28 // options |options|. Returns a newly allocated pointer, or nullptr |
35 // if there was a problem. | 29 // if there was a problem. |
36 static BluetoothAdapterProfileChromeOS* Register( | 30 static BluetoothAdapterProfileChromeOS* Register( |
| 31 BluetoothAdapterChromeOS* adapter, |
37 const device::BluetoothUUID& uuid, | 32 const device::BluetoothUUID& uuid, |
38 const BluetoothProfileManagerClient::Options& options, | 33 const BluetoothProfileManagerClient::Options& options, |
39 const ProfileRegisteredCallback& success_callback, | 34 const base::Closure& success_callback, |
40 const BluetoothProfileManagerClient::ErrorCallback& error_callback); | 35 const BluetoothProfileManagerClient::ErrorCallback& error_callback); |
41 | 36 |
42 ~BluetoothAdapterProfileChromeOS() override; | 37 ~BluetoothAdapterProfileChromeOS() override; |
43 | 38 |
44 // The object path of the profile. | 39 // The object path of the profile. |
45 const dbus::ObjectPath& object_path() const { return object_path_; } | 40 const dbus::ObjectPath& object_path() const { return object_path_; } |
46 | 41 |
47 // Returns the UUID of the profile | |
48 const device::BluetoothUUID& uuid() const { return uuid_; } | |
49 | |
50 // Add a delegate for a device associated with this profile. | 42 // Add a delegate for a device associated with this profile. |
51 // An empty |device_path| indicates a local listening service. | 43 // An empty |device_path| indicates a local listening service. |
52 // Returns true if the delegate was set, and false if the |device_path| | 44 // Returns true if the delegate was set, and false if the |device_path| |
53 // already had a delegate set. | 45 // already had a delegate set. |
54 bool SetDelegate(const dbus::ObjectPath& device_path, | 46 bool SetDelegate(const dbus::ObjectPath& device_path, |
55 BluetoothProfileServiceProvider::Delegate* delegate); | 47 BluetoothProfileServiceProvider::Delegate* delegate); |
56 | 48 |
57 // Remove the delegate for a device. |unregistered_callback| will be called | 49 // Remove the delegate for a device. |unregistered_callback| will be called |
58 // if this unregisters the profile. | 50 // if this unregisters the profile. |
59 void RemoveDelegate(const dbus::ObjectPath& device_path, | 51 void RemoveDelegate(const dbus::ObjectPath& device_path, |
60 const base::Closure& unregistered_callback); | 52 const base::Closure& unregistered_callback); |
61 | 53 |
62 // Returns the number of delegates for this profile. | 54 // Returns the number of delegates for this profile. |
63 size_t DelegateCount() const { return delegates_.size(); } | 55 size_t DelegateCount() const { return delegates_.size(); } |
64 | 56 |
65 private: | 57 private: |
66 BluetoothAdapterProfileChromeOS(const device::BluetoothUUID& uuid); | 58 BluetoothAdapterProfileChromeOS(BluetoothAdapterChromeOS* adapter, |
| 59 const device::BluetoothUUID& uuid); |
67 | 60 |
68 // BluetoothProfileServiceProvider::Delegate: | 61 // BluetoothProfileServiceProvider::Delegate: |
69 void Released() override; | 62 void Released() override; |
70 void NewConnection( | 63 void NewConnection( |
71 const dbus::ObjectPath& device_path, | 64 const dbus::ObjectPath& device_path, |
72 scoped_ptr<dbus::FileDescriptor> fd, | 65 scoped_ptr<dbus::FileDescriptor> fd, |
73 const BluetoothProfileServiceProvider::Delegate::Options& options, | 66 const BluetoothProfileServiceProvider::Delegate::Options& options, |
74 const ConfirmationCallback& callback) override; | 67 const ConfirmationCallback& callback) override; |
75 void RequestDisconnection(const dbus::ObjectPath& device_path, | 68 void RequestDisconnection(const dbus::ObjectPath& device_path, |
76 const ConfirmationCallback& callback) override; | 69 const ConfirmationCallback& callback) override; |
77 void Cancel() override; | 70 void Cancel() override; |
78 | 71 |
79 // Called by dbus:: on completion of the D-Bus method to unregister a profile. | 72 // Called by dbus:: on completion of the D-Bus method to unregister a profile. |
80 void OnUnregisterProfileError(const base::Closure& unregistered_callback, | 73 void OnUnregisterProfileError(const base::Closure& unregistered_callback, |
81 const std::string& error_name, | 74 const std::string& error_name, |
82 const std::string& error_message); | 75 const std::string& error_message); |
83 | 76 |
84 // List of delegates which this profile is multiplexing to. | 77 // List of delegates which this profile is multiplexing to. |
85 std::map<std::string, BluetoothProfileServiceProvider::Delegate*> delegates_; | 78 std::map<std::string, BluetoothProfileServiceProvider::Delegate*> delegates_; |
86 | 79 |
87 // The UUID that this profile represents. | 80 // The UUID that this profile represents. |
88 const device::BluetoothUUID& uuid_; | 81 const device::BluetoothUUID& uuid_; |
89 | 82 |
90 // Registered dbus object path for this profile. | 83 // Registered dbus object path for this profile. |
91 dbus::ObjectPath object_path_; | 84 dbus::ObjectPath object_path_; |
92 | 85 |
93 // Profile dbus object for receiving profile method calls from BlueZ | 86 // Profile dbus object for receiving profile method calls from BlueZ |
94 scoped_ptr<BluetoothProfileServiceProvider> profile_; | 87 scoped_ptr<BluetoothProfileServiceProvider> profile_; |
95 | 88 |
| 89 // Adapter that owns this profile. |
| 90 BluetoothAdapterChromeOS* adapter_; |
| 91 |
96 // Note: This should remain the last member so it'll be destroyed and | 92 // Note: This should remain the last member so it'll be destroyed and |
97 // invalidate its weak pointers before any other members are destroyed. | 93 // invalidate its weak pointers before any other members are destroyed. |
98 base::WeakPtrFactory<BluetoothAdapterProfileChromeOS> weak_ptr_factory_; | 94 base::WeakPtrFactory<BluetoothAdapterProfileChromeOS> weak_ptr_factory_; |
99 | 95 |
100 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterProfileChromeOS); | 96 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterProfileChromeOS); |
101 }; | 97 }; |
102 | 98 |
103 } // namespace chromeos | 99 } // namespace chromeos |
104 | 100 |
105 #endif | 101 #endif |
OLD | NEW |