Chromium Code Reviews| 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_agent_service_provider.h" | |
| 17 #include "chromeos/dbus/experimental_bluetooth_device_client.h" | |
| 18 #include "dbus/object_path.h" | |
| 19 #include "dbus/property.h" | |
| 20 | |
| 21 namespace chromeos { | |
| 22 | |
| 23 // FakeBluetoothDeviceClient simulates the behavior of the Bluetooth Daemon | |
| 24 // device objects and is used both in test cases in place of a mock and on | |
| 25 // the Linux desktop. | |
| 26 class CHROMEOS_EXPORT FakeBluetoothDeviceClient | |
| 27 : public ExperimentalBluetoothDeviceClient { | |
| 28 public: | |
| 29 struct Properties : public ExperimentalBluetoothDeviceClient::Properties { | |
| 30 explicit Properties(const PropertyChangedCallback & callback); | |
| 31 virtual ~Properties(); | |
| 32 | |
| 33 // dbus::PropertySet override | |
| 34 virtual void Get(dbus::PropertyBase* property, | |
| 35 dbus::PropertySet::GetCallback callback) OVERRIDE; | |
| 36 virtual void GetAll() OVERRIDE; | |
| 37 virtual void Set(dbus::PropertyBase* property, | |
| 38 dbus::PropertySet::SetCallback callback) OVERRIDE; | |
| 39 }; | |
| 40 | |
| 41 FakeBluetoothDeviceClient(); | |
| 42 virtual ~FakeBluetoothDeviceClient(); | |
| 43 | |
| 44 // ExperimentalBluetoothDeviceClient override | |
| 45 virtual void AddObserver(Observer* observer) OVERRIDE; | |
| 46 virtual void RemoveObserver(Observer* observer) OVERRIDE; | |
| 47 virtual std::vector<dbus::ObjectPath> GetDevicesForAdapter( | |
| 48 const dbus::ObjectPath& adapter_path) OVERRIDE; | |
| 49 virtual Properties* GetProperties(const dbus::ObjectPath& object_path) | |
| 50 OVERRIDE; | |
| 51 virtual void Connect(const dbus::ObjectPath& object_path, | |
| 52 const base::Closure& callback, | |
| 53 const ErrorCallback& error_callback) OVERRIDE; | |
| 54 virtual void Disconnect(const dbus::ObjectPath& object_path, | |
| 55 const base::Closure& callback, | |
| 56 const ErrorCallback& error_callback) OVERRIDE; | |
| 57 virtual void ConnectProfile(const dbus::ObjectPath& object_path, | |
| 58 const std::string& uuid, | |
| 59 const base::Closure& callback, | |
| 60 const ErrorCallback& error_callback) OVERRIDE; | |
| 61 virtual void DisconnectProfile(const dbus::ObjectPath& object_path, | |
| 62 const std::string& uuid, | |
| 63 const base::Closure& callback, | |
| 64 const ErrorCallback& error_callback) OVERRIDE; | |
| 65 virtual void Pair(const dbus::ObjectPath& object_path, | |
| 66 const base::Closure& callback, | |
| 67 const ErrorCallback& error_callback) OVERRIDE; | |
| 68 virtual void CancelPairing(const dbus::ObjectPath& object_path, | |
| 69 const base::Closure& callback, | |
| 70 const ErrorCallback& error_callback) OVERRIDE; | |
| 71 | |
| 72 void SetSimulationIntervalMs(int interval_ms); | |
| 73 | |
| 74 // Simulate discovery of devices for the given adapter. | |
| 75 void BeginDiscoverySimulation(const dbus::ObjectPath& adapter_path); | |
| 76 void EndDiscoverySimulation(const dbus::ObjectPath& adapter_path); | |
| 77 | |
| 78 // Remove a device from the set we return for the given adapter. | |
| 79 void RemoveDevice(const dbus::ObjectPath& adapter_path, | |
| 80 const dbus::ObjectPath& device_path); | |
| 81 | |
| 82 // Object paths, names, addresses and bluetooth classes of the devices | |
| 83 // we can emulate. | |
| 84 static const dbus::ObjectPath kPairedDevicePath; | |
|
Haruki Sato
2013/04/16 04:59:45
Use const char[] ?
keybuk
2013/04/16 23:19:13
Done.
| |
| 85 static const char kPairedDeviceName[]; | |
| 86 static const char kPairedDeviceAddress[]; | |
| 87 static const uint32 kPairedDeviceClass; | |
| 88 | |
| 89 static const dbus::ObjectPath kAppleMousePath; | |
|
Haruki Sato
2013/04/16 04:59:45
ditto.
keybuk
2013/04/16 23:19:13
Done.
| |
| 90 static const char kAppleMouseName[]; | |
| 91 static const char kAppleMouseAddress[]; | |
| 92 static const uint32 kAppleMouseClass; | |
| 93 | |
| 94 static const dbus::ObjectPath kAppleKeyboardPath; | |
|
Haruki Sato
2013/04/16 04:59:45
ditto.
keybuk
2013/04/16 23:19:13
Done.
| |
| 95 static const char kAppleKeyboardName[]; | |
| 96 static const char kAppleKeyboardAddress[]; | |
| 97 static const uint32 kAppleKeyboardClass; | |
| 98 | |
| 99 static const dbus::ObjectPath kVanishingDevicePath; | |
|
Haruki Sato
2013/04/16 04:59:45
ditto.
keybuk
2013/04/16 23:19:13
Done.
| |
| 100 static const char kVanishingDeviceName[]; | |
| 101 static const char kVanishingDeviceAddress[]; | |
| 102 static const uint32 kVanishingDeviceClass; | |
| 103 | |
| 104 static const dbus::ObjectPath kMicrosoftMousePath; | |
|
Haruki Sato
2013/04/16 04:59:45
ditto.
keybuk
2013/04/16 23:19:13
Done.
| |
| 105 static const char kMicrosoftMouseName[]; | |
| 106 static const char kMicrosoftMouseAddress[]; | |
| 107 static const uint32 kMicrosoftMouseClass; | |
| 108 | |
| 109 static const dbus::ObjectPath kMotorolaKeyboardPath; | |
|
Haruki Sato
2013/04/16 04:59:45
ditto.
keybuk
2013/04/16 23:19:13
Done.
| |
| 110 static const char kMotorolaKeyboardName[]; | |
| 111 static const char kMotorolaKeyboardAddress[]; | |
| 112 static const uint32 kMotorolaKeyboardClass; | |
| 113 | |
| 114 static const dbus::ObjectPath kSonyHeadphonesPath; | |
|
Haruki Sato
2013/04/16 04:59:45
ditto.
keybuk
2013/04/16 23:19:13
Done.
| |
| 115 static const char kSonyHeadphonesName[]; | |
| 116 static const char kSonyHeadphonesAddress[]; | |
| 117 static const uint32 kSonyHeadphonesClass; | |
| 118 | |
| 119 static const dbus::ObjectPath kPhonePath; | |
|
Haruki Sato
2013/04/16 04:59:45
ditto.
keybuk
2013/04/16 23:19:13
Done.
| |
| 120 static const char kPhoneName[]; | |
| 121 static const char kPhoneAddress[]; | |
| 122 static const uint32 kPhoneClass; | |
| 123 | |
| 124 static const dbus::ObjectPath kWeirdDevicePath; | |
|
Haruki Sato
2013/04/16 04:59:45
ditto.
keybuk
2013/04/16 23:19:13
Done.
| |
| 125 static const char kWeirdDeviceName[]; | |
| 126 static const char kWeirdDeviceAddress[]; | |
| 127 static const uint32 kWeirdDeviceClass; | |
| 128 | |
| 129 private: | |
| 130 // Property callback passed when we create Properties* structures. | |
| 131 void OnPropertyChanged(const dbus::ObjectPath& object_path, | |
| 132 const std::string& property_name); | |
| 133 | |
| 134 void DiscoverySimulationTimer(); | |
| 135 | |
| 136 void CompleteSimulatedPairing( | |
| 137 const dbus::ObjectPath& object_path, | |
| 138 const base::Closure& callback, | |
| 139 const ErrorCallback& error_callback); | |
| 140 void TimeoutSimulatedPairing( | |
| 141 const dbus::ObjectPath& object_path, | |
| 142 const ErrorCallback& error_callback); | |
| 143 void CancelSimulatedPairing( | |
| 144 const dbus::ObjectPath& object_path, | |
| 145 const ErrorCallback& error_callback); | |
| 146 void RejectSimulatedPairing( | |
| 147 const dbus::ObjectPath& object_path, | |
| 148 const ErrorCallback& error_callback); | |
| 149 | |
| 150 void PinCodeCallback( | |
| 151 const dbus::ObjectPath& object_path, | |
| 152 const base::Closure& callback, | |
| 153 const ErrorCallback& error_callback, | |
| 154 ExperimentalBluetoothAgentServiceProvider::Delegate::Status status, | |
| 155 const std::string& pincode); | |
| 156 void PasskeyCallback( | |
| 157 const dbus::ObjectPath& object_path, | |
| 158 const base::Closure& callback, | |
| 159 const ErrorCallback& error_callback, | |
| 160 ExperimentalBluetoothAgentServiceProvider::Delegate::Status status, | |
| 161 uint32 passkey); | |
| 162 void ConfirmationCallback( | |
| 163 const dbus::ObjectPath& object_path, | |
| 164 const base::Closure& callback, | |
| 165 const ErrorCallback& error_callback, | |
| 166 ExperimentalBluetoothAgentServiceProvider::Delegate::Status status); | |
| 167 void SimulateKeypress( | |
| 168 int16 entered, | |
| 169 const dbus::ObjectPath& object_path, | |
| 170 const base::Closure& callback, | |
| 171 const ErrorCallback& error_callback); | |
| 172 | |
| 173 // List of observers interested in event notifications from us. | |
| 174 ObserverList<Observer> observers_; | |
| 175 | |
| 176 // Static properties we return. | |
| 177 typedef std::map<const dbus::ObjectPath, Properties *> PropertiesMap; | |
| 178 PropertiesMap properties_map_; | |
| 179 std::vector<dbus::ObjectPath> device_list_; | |
| 180 | |
| 181 int simulation_interval_ms_; | |
| 182 uint32_t discovery_simulation_step_; | |
| 183 bool pairing_cancelled_; | |
| 184 }; | |
| 185 | |
| 186 } // namespace chromeos | |
| 187 | |
| 188 #endif /* CHROMEOS_DBUS_FAKE_BLUETOOTH_DEVICE_CLIENT_H_ */ | |
| OLD | NEW |