1 // Copyright (c) 2012 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_SHILL_DEVICE_CLIENT_H_ 6 #define CHROMEOS_DBUS_SHILL_DEVICE_CLIENT_H_ 7 8 #include <string> 9 10 #include "base/basictypes.h" 11 #include "base/callback.h" 12 #include "chromeos/chromeos_export.h" 13 #include "chromeos/dbus/dbus_client.h" 14 #include "chromeos/dbus/shill_client_helper.h" 15 16 namespace base { 17 18 class Value; 19 class DictionaryValue; 20 21 } // namespace base 22 23 namespace dbus { 24 25 class ObjectPath; 26 27 } // namespace dbus 28 29 namespace chromeos { 30 31 class ShillPropertyChangedObserver; 32 33 // ShillDeviceClient is used to communicate with the Shill Device service. 34 // All methods should be called from the origin thread which initializes the 35 // DBusThreadManager instance. 36 class CHROMEOS_EXPORT ShillDeviceClient : public DBusClient { 37 public: 38 typedef ShillClientHelper::PropertyChangedHandler PropertyChangedHandler; 39 typedef ShillClientHelper::DictionaryValueCallback DictionaryValueCallback; 40 typedef ShillClientHelper::StringCallback StringCallback; 41 typedef ShillClientHelper::ErrorCallback ErrorCallback; 42 43 // Interface for setting up devices for testing. 44 // Accessed through GetTestInterface(), only implemented in the Stub Impl. 45 class TestInterface { 46 public: 47 virtual void AddDevice(const std::string& device_path, 48 const std::string& type, 49 const std::string& name) = 0; 50 virtual void RemoveDevice(const std::string& device_path) = 0; 51 virtual void ClearDevices() = 0; 52 virtual void SetDeviceProperty(const std::string& device_path, 53 const std::string& name, 54 const base::Value& value) = 0; 55 virtual std::string GetDevicePathForType(const std::string& type) = 0; 56 57 protected: 58 virtual ~TestInterface() {} 59 }; 60 61 virtual ~ShillDeviceClient(); 62 63 // Factory function, creates a new instance which is owned by the caller. 64 // For normal usage, access the singleton via DBusThreadManager::Get(). 65 static ShillDeviceClient* Create(); 66 67 // Adds a property changed |observer| for the device at |device_path|. 68 virtual void AddPropertyChangedObserver( 69 const dbus::ObjectPath& device_path, 70 ShillPropertyChangedObserver* observer) = 0; 71 72 // Removes a property changed |observer| for the device at |device_path|. 73 virtual void RemovePropertyChangedObserver( 74 const dbus::ObjectPath& device_path, 75 ShillPropertyChangedObserver* observer) = 0; 76 77 // Calls GetProperties method. 78 // |callback| is called after the method call finishes. 79 virtual void GetProperties(const dbus::ObjectPath& device_path, 80 const DictionaryValueCallback& callback) = 0; 81 82 // Calls ProposeScan method. 83 // |callback| is called after the method call finishes. 84 virtual void ProposeScan(const dbus::ObjectPath& device_path, 85 const VoidDBusMethodCallback& callback) = 0; 86 87 // Calls SetProperty method. 88 // |callback| is called after the method call finishes. 89 virtual void SetProperty(const dbus::ObjectPath& device_path, 90 const std::string& name, 91 const base::Value& value, 92 const base::Closure& callback, 93 const ErrorCallback& error_callback) = 0; 94 95 // Calls ClearProperty method. 96 // |callback| is called after the method call finishes. 97 virtual void ClearProperty(const dbus::ObjectPath& device_path, 98 const std::string& name, 99 const VoidDBusMethodCallback& callback) = 0; 100 101 // Calls AddIPConfig method. 102 // |callback| is called after the method call finishes. 103 virtual void AddIPConfig(const dbus::ObjectPath& device_path, 104 const std::string& method, 105 const ObjectPathDBusMethodCallback& callback) = 0; 106 107 // Calls the RequirePin method. 108 // |callback| is called after the method call finishes. 109 virtual void RequirePin(const dbus::ObjectPath& device_path, 110 const std::string& pin, 111 bool require, 112 const base::Closure& callback, 113 const ErrorCallback& error_callback) = 0; 114 115 // Calls the EnterPin method. 116 // |callback| is called after the method call finishes. 117 virtual void EnterPin(const dbus::ObjectPath& device_path, 118 const std::string& pin, 119 const base::Closure& callback, 120 const ErrorCallback& error_callback) = 0; 121 122 // Calls the UnblockPin method. 123 // |callback| is called after the method call finishes. 124 virtual void UnblockPin(const dbus::ObjectPath& device_path, 125 const std::string& puk, 126 const std::string& pin, 127 const base::Closure& callback, 128 const ErrorCallback& error_callback) = 0; 129 130 // Calls the ChangePin method. 131 // |callback| is called after the method call finishes. 132 virtual void ChangePin(const dbus::ObjectPath& device_path, 133 const std::string& old_pin, 134 const std::string& new_pin, 135 const base::Closure& callback, 136 const ErrorCallback& error_callback) = 0; 137 138 // Calls the Register method. 139 // |callback| is called after the method call finishes. 140 virtual void Register(const dbus::ObjectPath& device_path, 141 const std::string& network_id, 142 const base::Closure& callback, 143 const ErrorCallback& error_callback) = 0; 144 145 // Calls the SetCarrier method. 146 // |callback| is called after the method call finishes. 147 virtual void SetCarrier(const dbus::ObjectPath& device_path, 148 const std::string& carrier, 149 const base::Closure& callback, 150 const ErrorCallback& error_callback) = 0; 151 152 // Calls the Reset method. 153 // |callback| is called after the method call finishes. 154 virtual void Reset(const dbus::ObjectPath& device_path, 155 const base::Closure& callback, 156 const ErrorCallback& error_callback) = 0; 157 158 // Calls the PerformTDLSOperation method. 159 // |callback| is called after the method call finishes. 160 virtual void PerformTDLSOperation(const dbus::ObjectPath& device_path, 161 const std::string& operation, 162 const std::string& peer, 163 const StringCallback& callback, 164 const ErrorCallback& error_callback) = 0; 165 166 // Returns an interface for testing (stub only), or returns NULL. 167 virtual TestInterface* GetTestInterface() = 0; 168 169 protected: 170 friend class ShillDeviceClientTest; 171 172 // Create() should be used instead. 173 ShillDeviceClient(); 174 175 private: 176 DISALLOW_COPY_AND_ASSIGN(ShillDeviceClient); 177 }; 178 179 } // namespace chromeos 180 181 #endif // CHROMEOS_DBUS_SHILL_DEVICE_CLIENT_H_ 182