fake_bluetooth_profile_service_provider.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright (c) 2013 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. #ifndef DEVICE_BLUETOOTH_DBUS_FAKE_BLUETOOTH_PROFILE_SERVICE_PROVIDER_H_
  5. #define DEVICE_BLUETOOTH_DBUS_FAKE_BLUETOOTH_PROFILE_SERVICE_PROVIDER_H_
  6. #include "base/bind.h"
  7. #include "base/callback.h"
  8. #include "base/memory/raw_ptr.h"
  9. #include "dbus/object_path.h"
  10. #include "device/bluetooth/bluetooth_export.h"
  11. #include "device/bluetooth/dbus/bluetooth_profile_service_provider.h"
  12. namespace bluez {
  13. // FakeBluetoothProfileServiceProvider simulates the behavior of a local
  14. // Bluetooth agent object and is used both in test cases in place of a
  15. // mock and on the Linux desktop.
  16. //
  17. // This class is only called from the dbus origin thread and is not thread-safe.
  18. class DEVICE_BLUETOOTH_EXPORT FakeBluetoothProfileServiceProvider
  19. : public BluetoothProfileServiceProvider {
  20. public:
  21. FakeBluetoothProfileServiceProvider(const dbus::ObjectPath& object_path,
  22. Delegate* delegate);
  23. FakeBluetoothProfileServiceProvider(
  24. const FakeBluetoothProfileServiceProvider&) = delete;
  25. FakeBluetoothProfileServiceProvider& operator=(
  26. const FakeBluetoothProfileServiceProvider&) = delete;
  27. ~FakeBluetoothProfileServiceProvider() override;
  28. // Each of these calls the equivalent
  29. // BluetoothProfileServiceProvider::Delegate method on the object passed on
  30. // construction.
  31. void Released();
  32. void NewConnection(const dbus::ObjectPath& device_path,
  33. base::ScopedFD fd,
  34. const Delegate::Options& options,
  35. Delegate::ConfirmationCallback callback);
  36. void RequestDisconnection(const dbus::ObjectPath& device_path,
  37. Delegate::ConfirmationCallback callback);
  38. void Cancel();
  39. const dbus::ObjectPath& object_path() const { return object_path_; }
  40. private:
  41. friend class FakeBluetoothProfileManagerClient;
  42. // D-Bus object path we are faking.
  43. dbus::ObjectPath object_path_;
  44. // All incoming method calls are passed on to the Delegate and a callback
  45. // passed to generate the reply. |delegate_| is generally the object that
  46. // owns this one, and must outlive it.
  47. raw_ptr<Delegate> delegate_;
  48. };
  49. } // namespace bluez
  50. #endif // DEVICE_BLUETOOTH_DBUS_FAKE_BLUETOOTH_PROFILE_SERVICE_PROVIDER_H_