OLD | NEW |
(Empty) | |
| 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 |
| 5 #ifndef CHROMEOS_DBUS_FAKE_BLUETOOTH_DEVICE_CLIENT_H_ |
| 6 #define CHROMEOS_DBUS_FAKE_BLUETOOTH_DEVICE_CLIENT_H_ |
| 7 |
| 8 #include <map> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/bind.h" |
| 12 #include "base/callback.h" |
| 13 #include "base/observer_list.h" |
| 14 #include "chromeos/chromeos_export.h" |
| 15 #include "chromeos/dbus/dbus_client_implementation_type.h" |
| 16 #include "chromeos/dbus/experimental_bluetooth_device_client.h" |
| 17 #include "dbus/object_path.h" |
| 18 #include "dbus/property.h" |
| 19 |
| 20 namespace chromeos { |
| 21 |
| 22 // FakeBluetoothDeviceClient simulates the behavior of the Bluetooth Daemon |
| 23 // device objects and is used both in test cases in place of a mock and on |
| 24 // the Linux desktop. |
| 25 class CHROMEOS_EXPORT FakeBluetoothDeviceClient |
| 26 : public ExperimentalBluetoothDeviceClient { |
| 27 public: |
| 28 struct Properties : public ExperimentalBluetoothDeviceClient::Properties { |
| 29 explicit Properties(const PropertyChangedCallback & callback); |
| 30 virtual ~Properties(); |
| 31 |
| 32 // dbus::PropertySet override |
| 33 virtual void Get(dbus::PropertyBase* property, |
| 34 dbus::PropertySet::GetCallback callback) OVERRIDE; |
| 35 virtual void GetAll() OVERRIDE; |
| 36 virtual void Set(dbus::PropertyBase* property, |
| 37 dbus::PropertySet::SetCallback callback) OVERRIDE; |
| 38 }; |
| 39 |
| 40 FakeBluetoothDeviceClient(); |
| 41 virtual ~FakeBluetoothDeviceClient(); |
| 42 |
| 43 // ExperimentalBluetoothDeviceClient override |
| 44 virtual void AddObserver(Observer* observer) OVERRIDE; |
| 45 virtual void RemoveObserver(Observer* observer) OVERRIDE; |
| 46 virtual std::vector<dbus::ObjectPath> GetDevicesForAdapter( |
| 47 const dbus::ObjectPath& adapter_path) OVERRIDE; |
| 48 virtual Properties* GetProperties(const dbus::ObjectPath& object_path) |
| 49 OVERRIDE; |
| 50 virtual void Connect(const dbus::ObjectPath& object_path, |
| 51 const base::Closure& callback, |
| 52 const ErrorCallback& error_callback) OVERRIDE; |
| 53 virtual void Disconnect(const dbus::ObjectPath& object_path, |
| 54 const base::Closure& callback, |
| 55 const ErrorCallback& error_callback) OVERRIDE; |
| 56 virtual void ConnectProfile(const dbus::ObjectPath& object_path, |
| 57 const std::string& uuid, |
| 58 const base::Closure& callback, |
| 59 const ErrorCallback& error_callback) OVERRIDE; |
| 60 virtual void DisconnectProfile(const dbus::ObjectPath& object_path, |
| 61 const std::string& uuid, |
| 62 const base::Closure& callback, |
| 63 const ErrorCallback& error_callback) OVERRIDE; |
| 64 virtual void Pair(const dbus::ObjectPath& object_path, |
| 65 const base::Closure& callback, |
| 66 const ErrorCallback& error_callback) OVERRIDE; |
| 67 virtual void CancelPairing(const dbus::ObjectPath& object_path, |
| 68 const base::Closure& callback, |
| 69 const ErrorCallback& error_callback) OVERRIDE; |
| 70 |
| 71 // Simulate discovery of devices for the given adapter. |
| 72 void BeginDiscoverySimulation(const dbus::ObjectPath& adapter_path); |
| 73 void EndDiscoverySimulation(const dbus::ObjectPath& adapter_path); |
| 74 |
| 75 void SetDiscoverySimulationIntervalMs(int interval_ms); |
| 76 |
| 77 // Remove a device from the set we return for the given adapter. |
| 78 void RemoveDevice(const dbus::ObjectPath& adapter_path, |
| 79 const dbus::ObjectPath& device_path); |
| 80 |
| 81 // Object paths, names, addresses and bluetooth classes of the devices |
| 82 // we can emulate. |
| 83 static const dbus::ObjectPath kPairedDevicePath; |
| 84 static const char kPairedDeviceName[]; |
| 85 static const char kPairedDeviceAddress[]; |
| 86 static const uint32 kPairedDeviceClass; |
| 87 |
| 88 static const dbus::ObjectPath kAppleMousePath; |
| 89 static const char kAppleMouseName[]; |
| 90 static const char kAppleMouseAddress[]; |
| 91 static const uint32 kAppleMouseClass; |
| 92 |
| 93 static const dbus::ObjectPath kAppleKeyboardPath; |
| 94 static const char kAppleKeyboardName[]; |
| 95 static const char kAppleKeyboardAddress[]; |
| 96 static const uint32 kAppleKeyboardClass; |
| 97 |
| 98 static const dbus::ObjectPath kVanishingDevicePath; |
| 99 static const char kVanishingDeviceName[]; |
| 100 static const char kVanishingDeviceAddress[]; |
| 101 static const uint32 kVanishingDeviceClass; |
| 102 |
| 103 static const dbus::ObjectPath kMicrosoftMousePath; |
| 104 static const char kMicrosoftMouseName[]; |
| 105 static const char kMicrosoftMouseAddress[]; |
| 106 static const uint32 kMicrosoftMouseClass; |
| 107 |
| 108 static const dbus::ObjectPath kMotorolaKeyboardPath; |
| 109 static const char kMotorolaKeyboardName[]; |
| 110 static const char kMotorolaKeyboardAddress[]; |
| 111 static const uint32 kMotorolaKeyboardClass; |
| 112 |
| 113 static const dbus::ObjectPath kPhonePath; |
| 114 static const char kPhoneName[]; |
| 115 static const char kPhoneAddress[]; |
| 116 static const uint32 kPhoneClass; |
| 117 |
| 118 private: |
| 119 // Property callback passed when we create Properties* structures. |
| 120 void OnPropertyChanged(const dbus::ObjectPath& object_path, |
| 121 const std::string& property_name); |
| 122 |
| 123 void DiscoverySimulationTimer(); |
| 124 |
| 125 // List of observers interested in event notifications from us. |
| 126 ObserverList<Observer> observers_; |
| 127 |
| 128 // Static properties we return. |
| 129 typedef std::map<const dbus::ObjectPath, Properties *> PropertiesMap; |
| 130 PropertiesMap properties_map_; |
| 131 std::vector<dbus::ObjectPath> device_list_; |
| 132 |
| 133 int discovery_simulation_interval_ms_; |
| 134 uint32_t discovery_simulation_step_; |
| 135 }; |
| 136 |
| 137 } // namespace chromeos |
| 138 |
| 139 #endif /* CHROMEOS_DBUS_FAKE_BLUETOOTH_DEVICE_CLIENT_H_ */ |
OLD | NEW |