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_SERVICE_CLIENT_H_ 6#define CHROMEOS_DBUS_SHILL_SERVICE_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 16namespace base { 17 18class Value; 19class DictionaryValue; 20 21} // namespace base 22 23namespace dbus { 24 25class ObjectPath; 26 27} // namespace dbus 28 29namespace chromeos { 30 31// ShillServiceClient is used to communicate with the Shill Service 32// service. 33// All methods should be called from the origin thread which initializes the 34// DBusThreadManager instance. 35class CHROMEOS_EXPORT ShillServiceClient : public DBusClient { 36 public: 37 typedef ShillClientHelper::PropertyChangedHandler PropertyChangedHandler; 38 typedef ShillClientHelper::DictionaryValueCallback DictionaryValueCallback; 39 typedef ShillClientHelper::ListValueCallback ListValueCallback; 40 typedef ShillClientHelper::ErrorCallback ErrorCallback; 41 42 // Interface for setting up services for testing. Accessed through 43 // GetTestInterface(), only implemented in the stub implementation. 44 class TestInterface { 45 public: 46 // Adds a Service to the Manager and Service stubs. 47 virtual void AddService(const std::string& service_path, 48 const std::string& guid, 49 const std::string& name, 50 const std::string& type, 51 const std::string& state, 52 bool visible) = 0; 53 virtual void AddServiceWithIPConfig(const std::string& service_path, 54 const std::string& guid, 55 const std::string& name, 56 const std::string& type, 57 const std::string& state, 58 const std::string& ipconfig_path, 59 bool visible) = 0; 60 // Sets the properties for a service but does not add it to the Manager 61 // or Profile. Returns the properties for the service. 62 virtual base::DictionaryValue* SetServiceProperties( 63 const std::string& service_path, 64 const std::string& guid, 65 const std::string& name, 66 const std::string& type, 67 const std::string& state, 68 bool visible) = 0; 69 70 // Removes a Service to the Manager and Service stubs. 71 virtual void RemoveService(const std::string& service_path) = 0; 72 73 // Returns false if a Service matching |service_path| does not exist. 74 virtual bool SetServiceProperty(const std::string& service_path, 75 const std::string& property, 76 const base::Value& value) = 0; 77 78 // Returns properties for |service_path| or NULL if no Service matches. 79 virtual const base::DictionaryValue* GetServiceProperties( 80 const std::string& service_path) const = 0; 81 82 // Clears all Services from the Manager and Service stubs. 83 virtual void ClearServices() = 0; 84 85 virtual void SetConnectBehavior(const std::string& service_path, 86 const base::Closure& behavior) = 0; 87 88 protected: 89 virtual ~TestInterface() {} 90 }; 91 virtual ~ShillServiceClient(); 92 93 // Factory function, creates a new instance which is owned by the caller. 94 // For normal usage, access the singleton via DBusThreadManager::Get(). 95 static ShillServiceClient* Create(); 96 97 // Adds a property changed |observer| to the service at |service_path|. 98 virtual void AddPropertyChangedObserver( 99 const dbus::ObjectPath& service_path, 100 ShillPropertyChangedObserver* observer) = 0; 101 102 // Removes a property changed |observer| to the service at |service_path|. 103 virtual void RemovePropertyChangedObserver( 104 const dbus::ObjectPath& service_path, 105 ShillPropertyChangedObserver* observer) = 0; 106 107 // Calls GetProperties method. 108 // |callback| is called after the method call succeeds. 109 virtual void GetProperties(const dbus::ObjectPath& service_path, 110 const DictionaryValueCallback& callback) = 0; 111 112 // Calls SetProperty method. 113 // |callback| is called after the method call succeeds. 114 virtual void SetProperty(const dbus::ObjectPath& service_path, 115 const std::string& name, 116 const base::Value& value, 117 const base::Closure& callback, 118 const ErrorCallback& error_callback) = 0; 119 120 // Calls SetProperties method. 121 // |callback| is called after the method call succeeds. 122 virtual void SetProperties(const dbus::ObjectPath& service_path, 123 const base::DictionaryValue& properties, 124 const base::Closure& callback, 125 const ErrorCallback& error_callback) = 0; 126 127 // Calls ClearProperty method. 128 // |callback| is called after the method call succeeds. 129 virtual void ClearProperty(const dbus::ObjectPath& service_path, 130 const std::string& name, 131 const base::Closure& callback, 132 const ErrorCallback& error_callback) = 0; 133 134 // Calls ClearProperties method. 135 // |callback| is called after the method call succeeds. 136 virtual void ClearProperties(const dbus::ObjectPath& service_path, 137 const std::vector<std::string>& names, 138 const ListValueCallback& callback, 139 const ErrorCallback& error_callback) = 0; 140 141 // Calls Connect method. 142 // |callback| is called after the method call succeeds. 143 virtual void Connect(const dbus::ObjectPath& service_path, 144 const base::Closure& callback, 145 const ErrorCallback& error_callback) = 0; 146 147 // Calls Disconnect method. 148 // |callback| is called after the method call succeeds. 149 virtual void Disconnect(const dbus::ObjectPath& service_path, 150 const base::Closure& callback, 151 const ErrorCallback& error_callback) = 0; 152 153 // Calls Remove method. 154 // |callback| is called after the method call succeeds. 155 virtual void Remove(const dbus::ObjectPath& service_path, 156 const base::Closure& callback, 157 const ErrorCallback& error_callback) = 0; 158 159 // Calls ActivateCellularModem method. 160 // |callback| is called after the method call succeeds. 161 virtual void ActivateCellularModem( 162 const dbus::ObjectPath& service_path, 163 const std::string& carrier, 164 const base::Closure& callback, 165 const ErrorCallback& error_callback) = 0; 166 167 // Calls the CompleteCellularActivation method. 168 // |callback| is called after the method call succeeds. 169 virtual void CompleteCellularActivation( 170 const dbus::ObjectPath& service_path, 171 const base::Closure& callback, 172 const ErrorCallback& error_callback) = 0; 173 174 // Calls the GetLoadableProfileEntries method. 175 // |callback| is called after the method call succeeds. 176 virtual void GetLoadableProfileEntries( 177 const dbus::ObjectPath& service_path, 178 const DictionaryValueCallback& callback) = 0; 179 180 // Returns an interface for testing (stub only), or returns NULL. 181 virtual TestInterface* GetTestInterface() = 0; 182 183 protected: 184 friend class ShillServiceClientTest; 185 186 // Create() should be used instead. 187 ShillServiceClient(); 188 189 private: 190 DISALLOW_COPY_AND_ASSIGN(ShillServiceClient); 191}; 192 193} // namespace chromeos 194 195#endif // CHROMEOS_DBUS_SHILL_SERVICE_CLIENT_H_ 196