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 #include "chromeos/dbus/shill_manager_client.h" 6 7 #include "base/bind.h" 8 #include "base/logging.h" 9 #include "base/message_loop/message_loop.h" 10 #include "base/values.h" 11 #include "chromeos/dbus/shill_manager_client_stub.h" 12 #include "chromeos/dbus/shill_property_changed_observer.h" 13 #include "dbus/bus.h" 14 #include "dbus/message.h" 15 #include "dbus/object_path.h" 16 #include "dbus/object_proxy.h" 17 #include "dbus/values_util.h" 18 #include "third_party/cros_system_api/dbus/service_constants.h" 19 20 namespace chromeos { 21 22 namespace { 23 24 // The ShillManagerClient implementation. 25 class ShillManagerClientImpl : public ShillManagerClient { 26 public: 27 explicit ShillManagerClientImpl(dbus::Bus* bus) 28 : proxy_(bus->GetObjectProxy( 29 flimflam::kFlimflamServiceName, 30 dbus::ObjectPath(flimflam::kFlimflamServicePath))), 31 helper_(bus, proxy_) { 32 helper_.MonitorPropertyChanged(flimflam::kFlimflamManagerInterface); 33 } 34 35 //////////////////////////////////// 36 // ShillManagerClient overrides. 37 virtual void AddPropertyChangedObserver( 38 ShillPropertyChangedObserver* observer) OVERRIDE { 39 helper_.AddPropertyChangedObserver(observer); 40 } 41 42 virtual void RemovePropertyChangedObserver( 43 ShillPropertyChangedObserver* observer) OVERRIDE { 44 helper_.RemovePropertyChangedObserver(observer); 45 } 46 47 virtual void GetProperties(const DictionaryValueCallback& callback) OVERRIDE { 48 dbus::MethodCall method_call(flimflam::kFlimflamManagerInterface, 49 flimflam::kGetPropertiesFunction); 50 helper_.CallDictionaryValueMethod(&method_call, callback); 51 } 52 53 virtual void GetNetworksForGeolocation( 54 const DictionaryValueCallback& callback) OVERRIDE { 55 dbus::MethodCall method_call(flimflam::kFlimflamManagerInterface, 56 shill::kGetNetworksForGeolocation); 57 helper_.CallDictionaryValueMethod(&method_call, callback); 58 } 59 60 virtual void SetProperty(const std::string& name, 61 const base::Value& value, 62 const base::Closure& callback, 63 const ErrorCallback& error_callback) OVERRIDE { 64 dbus::MethodCall method_call(flimflam::kFlimflamManagerInterface, 65 flimflam::kSetPropertyFunction); 66 dbus::MessageWriter writer(&method_call); 67 writer.AppendString(name); 68 ShillClientHelper::AppendValueDataAsVariant(&writer, value); 69 helper_.CallVoidMethodWithErrorCallback(&method_call, 70 callback, 71 error_callback); 72 } 73 74 virtual void RequestScan(const std::string& type, 75 const base::Closure& callback, 76 const ErrorCallback& error_callback) OVERRIDE { 77 dbus::MethodCall method_call(flimflam::kFlimflamManagerInterface, 78 flimflam::kRequestScanFunction); 79 dbus::MessageWriter writer(&method_call); 80 writer.AppendString(type); 81 helper_.CallVoidMethodWithErrorCallback(&method_call, 82 callback, 83 error_callback); 84 } 85 86 virtual void EnableTechnology( 87 const std::string& type, 88 const base::Closure& callback, 89 const ErrorCallback& error_callback) OVERRIDE { 90 dbus::MethodCall method_call(flimflam::kFlimflamManagerInterface, 91 flimflam::kEnableTechnologyFunction); 92 dbus::MessageWriter writer(&method_call); 93 writer.AppendString(type); 94 helper_.CallVoidMethodWithErrorCallback(&method_call, 95 callback, 96 error_callback); 97 } 98 99 virtual void DisableTechnology( 100 const std::string& type, 101 const base::Closure& callback, 102 const ErrorCallback& error_callback) OVERRIDE { 103 dbus::MethodCall method_call(flimflam::kFlimflamManagerInterface, 104 flimflam::kDisableTechnologyFunction); 105 dbus::MessageWriter writer(&method_call); 106 writer.AppendString(type); 107 helper_.CallVoidMethodWithErrorCallback(&method_call, 108 callback, 109 error_callback); 110 } 111 112 virtual void ConfigureService( 113 const base::DictionaryValue& properties, 114 const ObjectPathCallback& callback, 115 const ErrorCallback& error_callback) OVERRIDE { 116 dbus::MethodCall method_call(flimflam::kFlimflamManagerInterface, 117 flimflam::kConfigureServiceFunction); 118 dbus::MessageWriter writer(&method_call); 119 ShillClientHelper::AppendServicePropertiesDictionary(&writer, properties); 120 helper_.CallObjectPathMethodWithErrorCallback(&method_call, 121 callback, 122 error_callback); 123 } 124 125 virtual void ConfigureServiceForProfile( 126 const dbus::ObjectPath& profile_path, 127 const base::DictionaryValue& properties, 128 const ObjectPathCallback& callback, 129 const ErrorCallback& error_callback) OVERRIDE { 130 dbus::MethodCall method_call(flimflam::kFlimflamManagerInterface, 131 shill::kConfigureServiceForProfileFunction); 132 dbus::MessageWriter writer(&method_call); 133 writer.AppendObjectPath(dbus::ObjectPath(profile_path)); 134 ShillClientHelper::AppendServicePropertiesDictionary(&writer, properties); 135 helper_.CallObjectPathMethodWithErrorCallback(&method_call, 136 callback, 137 error_callback); 138 } 139 140 virtual void GetService( 141 const base::DictionaryValue& properties, 142 const ObjectPathCallback& callback, 143 const ErrorCallback& error_callback) OVERRIDE { 144 dbus::MethodCall method_call(flimflam::kFlimflamManagerInterface, 145 flimflam::kGetServiceFunction); 146 dbus::MessageWriter writer(&method_call); 147 ShillClientHelper::AppendServicePropertiesDictionary(&writer, properties); 148 helper_.CallObjectPathMethodWithErrorCallback(&method_call, 149 callback, 150 error_callback); 151 } 152 153 virtual void VerifyDestination(const VerificationProperties& properties, 154 const BooleanCallback& callback, 155 const ErrorCallback& error_callback) OVERRIDE { 156 dbus::MethodCall method_call(flimflam::kFlimflamManagerInterface, 157 shill::kVerifyDestinationFunction); 158 dbus::MessageWriter writer(&method_call); 159 writer.AppendString(properties.certificate); 160 writer.AppendString(properties.public_key); 161 writer.AppendString(properties.nonce); 162 writer.AppendString(properties.signed_data); 163 writer.AppendString(properties.device_serial); 164 writer.AppendString(properties.device_ssid); 165 writer.AppendString(properties.device_bssid); 166 helper_.CallBooleanMethodWithErrorCallback( 167 &method_call, callback, error_callback); 168 } 169 170 virtual void VerifyAndEncryptCredentials( 171 const VerificationProperties& properties, 172 const std::string& service_path, 173 const StringCallback& callback, 174 const ErrorCallback& error_callback) OVERRIDE { 175 dbus::MethodCall method_call(flimflam::kFlimflamManagerInterface, 176 shill::kVerifyAndEncryptCredentialsFunction); 177 dbus::MessageWriter writer(&method_call); 178 writer.AppendString(properties.certificate); 179 writer.AppendString(properties.public_key); 180 writer.AppendString(properties.nonce); 181 writer.AppendString(properties.signed_data); 182 writer.AppendString(properties.device_serial); 183 writer.AppendString(properties.device_ssid); 184 writer.AppendString(properties.device_bssid); 185 writer.AppendObjectPath(dbus::ObjectPath(service_path)); 186 helper_.CallStringMethodWithErrorCallback( 187 &method_call, callback, error_callback); 188 } 189 190 virtual void VerifyAndEncryptData( 191 const VerificationProperties& properties, 192 const std::string& data, 193 const StringCallback& callback, 194 const ErrorCallback& error_callback) OVERRIDE { 195 dbus::MethodCall method_call(flimflam::kFlimflamManagerInterface, 196 shill::kVerifyAndEncryptDataFunction); 197 dbus::MessageWriter writer(&method_call); 198 writer.AppendString(properties.certificate); 199 writer.AppendString(properties.public_key); 200 writer.AppendString(properties.nonce); 201 writer.AppendString(properties.signed_data); 202 writer.AppendString(properties.device_serial); 203 writer.AppendString(properties.device_ssid); 204 writer.AppendString(properties.device_bssid); 205 writer.AppendString(data); 206 helper_.CallStringMethodWithErrorCallback( 207 &method_call, callback, error_callback); 208 } 209 210 virtual void ConnectToBestServices( 211 const base::Closure& callback, 212 const ErrorCallback& error_callback) OVERRIDE { 213 dbus::MethodCall method_call(flimflam::kFlimflamManagerInterface, 214 shill::kConnectToBestServicesFunction); 215 helper_.CallVoidMethodWithErrorCallback(&method_call, 216 callback, 217 error_callback); 218 } 219 220 virtual TestInterface* GetTestInterface() OVERRIDE { 221 return NULL; 222 } 223 224 private: 225 dbus::ObjectProxy* proxy_; 226 ShillClientHelper helper_; 227 228 DISALLOW_COPY_AND_ASSIGN(ShillManagerClientImpl); 229 }; 230 231 } // namespace 232 233 ShillManagerClient::ShillManagerClient() {} 234 235 ShillManagerClient::~ShillManagerClient() {} 236 237 // static 238 ShillManagerClient* ShillManagerClient::Create( 239 DBusClientImplementationType type, 240 dbus::Bus* bus) { 241 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) 242 return new ShillManagerClientImpl(bus); 243 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); 244 return new ShillManagerClientStub(); 245 } 246 247 // ShillManagerClient::VerificationProperties implementation. 248 ShillManagerClient::VerificationProperties::VerificationProperties() { 249 } 250 251 ShillManagerClient::VerificationProperties::~VerificationProperties() { 252 } 253 254 } // namespace chromeos 255