| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROMEOS_DBUS_FAKE_BLUETOOTH_DEVICE_CLIENT_H_ | 5 #ifndef CHROMEOS_DBUS_FAKE_BLUETOOTH_DEVICE_CLIENT_H_ |
| 6 #define CHROMEOS_DBUS_FAKE_BLUETOOTH_DEVICE_CLIENT_H_ | 6 #define CHROMEOS_DBUS_FAKE_BLUETOOTH_DEVICE_CLIENT_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/containers/scoped_ptr_map.h" |
| 13 #include "base/observer_list.h" | 14 #include "base/observer_list.h" |
| 14 #include "chromeos/chromeos_export.h" | 15 #include "chromeos/chromeos_export.h" |
| 15 #include "chromeos/dbus/bluetooth_agent_service_provider.h" | 16 #include "chromeos/dbus/bluetooth_agent_service_provider.h" |
| 16 #include "chromeos/dbus/bluetooth_device_client.h" | 17 #include "chromeos/dbus/bluetooth_device_client.h" |
| 17 #include "chromeos/dbus/bluetooth_profile_service_provider.h" | 18 #include "chromeos/dbus/bluetooth_profile_service_provider.h" |
| 18 #include "dbus/object_path.h" | 19 #include "dbus/object_path.h" |
| 19 #include "dbus/property.h" | 20 #include "dbus/property.h" |
| 20 | 21 |
| 21 namespace chromeos { | 22 namespace chromeos { |
| 22 | 23 |
| 23 // FakeBluetoothDeviceClient simulates the behavior of the Bluetooth Daemon | 24 // 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 // device objects and is used both in test cases in place of a mock and on |
| 25 // the Linux desktop. | 26 // the Linux desktop. |
| 26 class CHROMEOS_EXPORT FakeBluetoothDeviceClient | 27 class CHROMEOS_EXPORT FakeBluetoothDeviceClient |
| 27 : public BluetoothDeviceClient { | 28 : public BluetoothDeviceClient { |
| 28 public: | 29 public: |
| 29 struct Properties : public BluetoothDeviceClient::Properties { | 30 struct Properties : public BluetoothDeviceClient::Properties { |
| 30 explicit Properties(const PropertyChangedCallback & callback); | 31 explicit Properties(const PropertyChangedCallback & callback); |
| 31 ~Properties() override; | 32 ~Properties() override; |
| 32 | 33 |
| 33 // dbus::PropertySet override | 34 // dbus::PropertySet override |
| 34 void Get(dbus::PropertyBase* property, | 35 void Get(dbus::PropertyBase* property, |
| 35 dbus::PropertySet::GetCallback callback) override; | 36 dbus::PropertySet::GetCallback callback) override; |
| 36 void GetAll() override; | 37 void GetAll() override; |
| 37 void Set(dbus::PropertyBase* property, | 38 void Set(dbus::PropertyBase* property, |
| 38 dbus::PropertySet::SetCallback callback) override; | 39 dbus::PropertySet::SetCallback callback) override; |
| 39 }; | 40 }; |
| 40 | 41 |
| 42 struct SimulatedPairingOptions { |
| 43 std::string pairing_method; |
| 44 std::string pairing_auth_token; |
| 45 }; |
| 46 |
| 47 // Stores properties of a device that is about to be created. |
| 48 struct IncomingDeviceProperties { |
| 49 IncomingDeviceProperties(); |
| 50 ~IncomingDeviceProperties(); |
| 51 |
| 52 std::string device_name; |
| 53 std::string device_alias; |
| 54 std::string device_address; |
| 55 std::string device_path; |
| 56 std::string pairing_method; |
| 57 std::string pairing_auth_token; |
| 58 int device_class = 0; |
| 59 bool is_trusted = true; |
| 60 }; |
| 61 |
| 41 FakeBluetoothDeviceClient(); | 62 FakeBluetoothDeviceClient(); |
| 42 ~FakeBluetoothDeviceClient() override; | 63 ~FakeBluetoothDeviceClient() override; |
| 43 | 64 |
| 44 // BluetoothDeviceClient overrides | 65 // BluetoothDeviceClient overrides |
| 45 void Init(dbus::Bus* bus) override; | 66 void Init(dbus::Bus* bus) override; |
| 46 void AddObserver(Observer* observer) override; | 67 void AddObserver(Observer* observer) override; |
| 47 void RemoveObserver(Observer* observer) override; | 68 void RemoveObserver(Observer* observer) override; |
| 48 std::vector<dbus::ObjectPath> GetDevicesForAdapter( | 69 std::vector<dbus::ObjectPath> GetDevicesForAdapter( |
| 49 const dbus::ObjectPath& adapter_path) override; | 70 const dbus::ObjectPath& adapter_path) override; |
| 50 Properties* GetProperties(const dbus::ObjectPath& object_path) override; | 71 Properties* GetProperties(const dbus::ObjectPath& object_path) override; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 79 void EndDiscoverySimulation(const dbus::ObjectPath& adapter_path); | 100 void EndDiscoverySimulation(const dbus::ObjectPath& adapter_path); |
| 80 | 101 |
| 81 // Simulates incoming pairing of devices for the given adapter. | 102 // Simulates incoming pairing of devices for the given adapter. |
| 82 void BeginIncomingPairingSimulation(const dbus::ObjectPath& adapter_path); | 103 void BeginIncomingPairingSimulation(const dbus::ObjectPath& adapter_path); |
| 83 void EndIncomingPairingSimulation(const dbus::ObjectPath& adapter_path); | 104 void EndIncomingPairingSimulation(const dbus::ObjectPath& adapter_path); |
| 84 | 105 |
| 85 // Creates a device from the set we return for the given adapter. | 106 // Creates a device from the set we return for the given adapter. |
| 86 void CreateDevice(const dbus::ObjectPath& adapter_path, | 107 void CreateDevice(const dbus::ObjectPath& adapter_path, |
| 87 const dbus::ObjectPath& device_path); | 108 const dbus::ObjectPath& device_path); |
| 88 | 109 |
| 110 // Creates a device with the given properties. |
| 111 void CreateDeviceWithProperties(const dbus::ObjectPath& adapter_path, |
| 112 const IncomingDeviceProperties& props); |
| 113 |
| 114 SimulatedPairingOptions* GetPairingOptions( |
| 115 const dbus::ObjectPath& object_path); |
| 116 |
| 89 // Removes a device from the set we return for the given adapter. | 117 // Removes a device from the set we return for the given adapter. |
| 90 void RemoveDevice(const dbus::ObjectPath& adapter_path, | 118 void RemoveDevice(const dbus::ObjectPath& adapter_path, |
| 91 const dbus::ObjectPath& device_path); | 119 const dbus::ObjectPath& device_path); |
| 92 | 120 |
| 93 // Simulates a pairing for the device with the given D-Bus object path, | 121 // Simulates a pairing for the device with the given D-Bus object path, |
| 94 // |object_path|. Set |incoming_request| to true if simulating an incoming | 122 // |object_path|. Set |incoming_request| to true if simulating an incoming |
| 95 // pairing request, false for an outgoing one. On successful completion | 123 // pairing request, false for an outgoing one. On successful completion |
| 96 // |callback| will be called, on failure, |error_callback| is called. | 124 // |callback| will be called, on failure, |error_callback| is called. |
| 97 void SimulatePairing(const dbus::ObjectPath& object_path, | 125 void SimulatePairing(const dbus::ObjectPath& object_path, |
| 98 bool incoming_request, | 126 bool incoming_request, |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 BluetoothProfileServiceProvider::Delegate::Status status); | 267 BluetoothProfileServiceProvider::Delegate::Status status); |
| 240 void DisconnectionCallback( | 268 void DisconnectionCallback( |
| 241 const dbus::ObjectPath& object_path, | 269 const dbus::ObjectPath& object_path, |
| 242 const base::Closure& callback, | 270 const base::Closure& callback, |
| 243 const ErrorCallback& error_callback, | 271 const ErrorCallback& error_callback, |
| 244 BluetoothProfileServiceProvider::Delegate::Status status); | 272 BluetoothProfileServiceProvider::Delegate::Status status); |
| 245 | 273 |
| 246 // List of observers interested in event notifications from us. | 274 // List of observers interested in event notifications from us. |
| 247 base::ObserverList<Observer> observers_; | 275 base::ObserverList<Observer> observers_; |
| 248 | 276 |
| 249 // Static properties we return. | 277 using PropertiesMap = |
| 250 typedef std::map<const dbus::ObjectPath, Properties *> PropertiesMap; | 278 base::ScopedPtrMap<const dbus::ObjectPath, scoped_ptr<Properties>>; |
| 251 PropertiesMap properties_map_; | 279 PropertiesMap properties_map_; |
| 252 std::vector<dbus::ObjectPath> device_list_; | 280 std::vector<dbus::ObjectPath> device_list_; |
| 253 | 281 |
| 282 // Properties which are used to decied which method of pairing should |
| 283 // be done on request. |
| 284 using PairingOptionsMap = |
| 285 base::ScopedPtrMap<const dbus::ObjectPath, |
| 286 scoped_ptr<SimulatedPairingOptions>>; |
| 287 PairingOptionsMap pairing_options_map_; |
| 288 |
| 254 int simulation_interval_ms_; | 289 int simulation_interval_ms_; |
| 255 uint32_t discovery_simulation_step_; | 290 uint32_t discovery_simulation_step_; |
| 256 uint32_t incoming_pairing_simulation_step_; | 291 uint32_t incoming_pairing_simulation_step_; |
| 257 bool pairing_cancelled_; | 292 bool pairing_cancelled_; |
| 258 | 293 |
| 259 int16 connection_rssi_; | 294 int16 connection_rssi_; |
| 260 int16 transmit_power_; | 295 int16 transmit_power_; |
| 261 int16 max_transmit_power_; | 296 int16 max_transmit_power_; |
| 262 }; | 297 }; |
| 263 | 298 |
| 264 } // namespace chromeos | 299 } // namespace chromeos |
| 265 | 300 |
| 266 #endif // CHROMEOS_DBUS_FAKE_BLUETOOTH_DEVICE_CLIENT_H_ | 301 #endif // CHROMEOS_DBUS_FAKE_BLUETOOTH_DEVICE_CLIENT_H_ |
| OLD | NEW |