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