fake_bluetooth_input_client.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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_INPUT_CLIENT_H_
  5. #define DEVICE_BLUETOOTH_DBUS_FAKE_BLUETOOTH_INPUT_CLIENT_H_
  6. #include <memory>
  7. #include "base/callback.h"
  8. #include "base/observer_list.h"
  9. #include "dbus/object_path.h"
  10. #include "dbus/property.h"
  11. #include "device/bluetooth/bluetooth_export.h"
  12. #include "device/bluetooth/dbus/bluetooth_input_client.h"
  13. namespace bluez {
  14. // FakeBluetoothInputClient simulates the behavior of the Bluetooth Daemon
  15. // input device objects and is used both in test cases in place of a mock and on
  16. // the Linux desktop.
  17. class DEVICE_BLUETOOTH_EXPORT FakeBluetoothInputClient
  18. : public BluetoothInputClient {
  19. public:
  20. struct Properties : public BluetoothInputClient::Properties {
  21. explicit Properties(const PropertyChangedCallback& callback);
  22. ~Properties() override;
  23. // dbus::PropertySet override
  24. void Get(dbus::PropertyBase* property,
  25. dbus::PropertySet::GetCallback callback) override;
  26. void GetAll() override;
  27. void Set(dbus::PropertyBase* property,
  28. dbus::PropertySet::SetCallback callback) override;
  29. };
  30. FakeBluetoothInputClient();
  31. FakeBluetoothInputClient(const FakeBluetoothInputClient&) = delete;
  32. FakeBluetoothInputClient& operator=(const FakeBluetoothInputClient&) = delete;
  33. ~FakeBluetoothInputClient() override;
  34. // BluetoothInputClient overrides
  35. void Init(dbus::Bus* bus, const std::string& bluetooth_service_name) override;
  36. void AddObserver(Observer* observer) override;
  37. void RemoveObserver(Observer* observer) override;
  38. Properties* GetProperties(const dbus::ObjectPath& object_path) override;
  39. // Simulate device addition/removal
  40. void AddInputDevice(const dbus::ObjectPath& object_path);
  41. void RemoveInputDevice(const dbus::ObjectPath& object_path);
  42. private:
  43. // Property callback passed when we create Properties* structures.
  44. void OnPropertyChanged(const dbus::ObjectPath& object_path,
  45. const std::string& property_name);
  46. // Static properties we return.
  47. std::map<const dbus::ObjectPath, std::unique_ptr<Properties>> properties_map_;
  48. // List of observers interested in event notifications from us.
  49. base::ObserverList<Observer>::Unchecked observers_;
  50. };
  51. } // namespace bluez
  52. #endif // DEVICE_BLUETOOTH_DBUS_FAKE_BLUETOOTH_INPUT_CLIENT_H_