1 // Copyright 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_SHILL_DEVICE_CLIENT_H_ 6 #define CHROMEOS_DBUS_FAKE_SHILL_DEVICE_CLIENT_H_ 7 8 #include <string> 9 10 #include "base/basictypes.h" 11 #include "chromeos/chromeos_export.h" 12 #include "chromeos/dbus/shill_device_client.h" 13 14 namespace chromeos { 15 16 // A fake implementation of ShillDeviceClient. 17 // Implemented: Stub cellular device for SMS testing. 18 class CHROMEOS_EXPORT FakeShillDeviceClient 19 : public ShillDeviceClient, 20 public ShillDeviceClient::TestInterface { 21 public: 22 FakeShillDeviceClient(); 23 virtual ~FakeShillDeviceClient(); 24 25 // ShillDeviceClient overrides 26 virtual void Init(dbus::Bus* bus) OVERRIDE; 27 virtual void AddPropertyChangedObserver( 28 const dbus::ObjectPath& device_path, 29 ShillPropertyChangedObserver* observer) OVERRIDE; 30 virtual void RemovePropertyChangedObserver( 31 const dbus::ObjectPath& device_path, 32 ShillPropertyChangedObserver* observer) OVERRIDE; 33 virtual void GetProperties(const dbus::ObjectPath& device_path, 34 const DictionaryValueCallback& callback) OVERRIDE; 35 virtual void ProposeScan(const dbus::ObjectPath& device_path, 36 const VoidDBusMethodCallback& callback) OVERRIDE; 37 virtual void SetProperty(const dbus::ObjectPath& device_path, 38 const std::string& name, 39 const base::Value& value, 40 const base::Closure& callback, 41 const ErrorCallback& error_callback) OVERRIDE; 42 virtual void ClearProperty(const dbus::ObjectPath& device_path, 43 const std::string& name, 44 const VoidDBusMethodCallback& callback) OVERRIDE; 45 virtual void AddIPConfig( 46 const dbus::ObjectPath& device_path, 47 const std::string& method, 48 const ObjectPathDBusMethodCallback& callback) OVERRIDE; 49 virtual void RequirePin(const dbus::ObjectPath& device_path, 50 const std::string& pin, 51 bool require, 52 const base::Closure& callback, 53 const ErrorCallback& error_callback) OVERRIDE; 54 virtual void EnterPin(const dbus::ObjectPath& device_path, 55 const std::string& pin, 56 const base::Closure& callback, 57 const ErrorCallback& error_callback) OVERRIDE; 58 virtual void UnblockPin(const dbus::ObjectPath& device_path, 59 const std::string& puk, 60 const std::string& pin, 61 const base::Closure& callback, 62 const ErrorCallback& error_callback) OVERRIDE; 63 virtual void ChangePin(const dbus::ObjectPath& device_path, 64 const std::string& old_pin, 65 const std::string& new_pin, 66 const base::Closure& callback, 67 const ErrorCallback& error_callback) OVERRIDE; 68 virtual void Register(const dbus::ObjectPath& device_path, 69 const std::string& network_id, 70 const base::Closure& callback, 71 const ErrorCallback& error_callback) OVERRIDE; 72 virtual void SetCarrier(const dbus::ObjectPath& device_path, 73 const std::string& carrier, 74 const base::Closure& callback, 75 const ErrorCallback& error_callback) OVERRIDE; 76 virtual void Reset(const dbus::ObjectPath& device_path, 77 const base::Closure& callback, 78 const ErrorCallback& error_callback) OVERRIDE; 79 virtual ShillDeviceClient::TestInterface* GetTestInterface() OVERRIDE; 80 81 // ShillDeviceClient::TestInterface overrides. 82 virtual void AddDevice(const std::string& device_path, 83 const std::string& type, 84 const std::string& object_path) OVERRIDE; 85 virtual void RemoveDevice(const std::string& device_path) OVERRIDE; 86 virtual void ClearDevices() OVERRIDE; 87 virtual void SetDeviceProperty(const std::string& device_path, 88 const std::string& name, 89 const base::Value& value) OVERRIDE; 90 virtual std::string GetDevicePathForType(const std::string& type) OVERRIDE; 91 92 private: 93 typedef ObserverList<ShillPropertyChangedObserver> PropertyObserverList; 94 95 void SetDefaultProperties(); 96 void PassStubDeviceProperties(const dbus::ObjectPath& device_path, 97 const DictionaryValueCallback& callback) const; 98 99 // Posts a task to run a void callback with status code |status|. 100 void PostVoidCallback(const VoidDBusMethodCallback& callback, 101 DBusMethodCallStatus status); 102 103 void NotifyObserversPropertyChanged(const dbus::ObjectPath& device_path, 104 const std::string& property); 105 base::DictionaryValue* GetDeviceProperties(const std::string& device_path); 106 PropertyObserverList& GetObserverList(const dbus::ObjectPath& device_path); 107 108 // Dictionary of <device_name, Dictionary>. 109 base::DictionaryValue stub_devices_; 110 // Observer list for each device. 111 std::map<dbus::ObjectPath, PropertyObserverList*> observer_list_; 112 113 // Note: This should remain the last member so it'll be destroyed and 114 // invalidate its weak pointers before any other members are destroyed. 115 base::WeakPtrFactory<FakeShillDeviceClient> weak_ptr_factory_; 116 117 DISALLOW_COPY_AND_ASSIGN(FakeShillDeviceClient); 118 }; 119 120 } // namespace chromeos 121 122 #endif // CHROMEOS_DBUS_FAKE_SHILL_DEVICE_CLIENT_H_ 123