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.
5 #include "chromeos/dbus/shill_manager_client.h"
8 #include "base/logging.h"
9 #include "base/message_loop/message_loop.h"
10 #include "base/values.h"
11 #include "chromeos/dbus/shill_property_changed_observer.h"
13 #include "dbus/message.h"
14 #include "dbus/object_path.h"
15 #include "dbus/object_proxy.h"
16 #include "dbus/values_util.h"
17 #include "net/base/ip_endpoint.h"
18 #include "third_party/cros_system_api/dbus/service_constants.h"
24 // The ShillManagerClient implementation.
25 class ShillManagerClientImpl
: public ShillManagerClient
{
27 ShillManagerClientImpl() : proxy_(NULL
) {}
29 ////////////////////////////////////
30 // ShillManagerClient overrides.
31 virtual void AddPropertyChangedObserver(
32 ShillPropertyChangedObserver
* observer
) override
{
33 helper_
->AddPropertyChangedObserver(observer
);
36 virtual void RemovePropertyChangedObserver(
37 ShillPropertyChangedObserver
* observer
) override
{
38 helper_
->RemovePropertyChangedObserver(observer
);
41 virtual void GetProperties(const DictionaryValueCallback
& callback
) override
{
42 dbus::MethodCall
method_call(shill::kFlimflamManagerInterface
,
43 shill::kGetPropertiesFunction
);
44 helper_
->CallDictionaryValueMethod(&method_call
, callback
);
47 virtual void GetNetworksForGeolocation(
48 const DictionaryValueCallback
& callback
) override
{
49 dbus::MethodCall
method_call(shill::kFlimflamManagerInterface
,
50 shill::kGetNetworksForGeolocation
);
51 helper_
->CallDictionaryValueMethod(&method_call
, callback
);
54 virtual void SetProperty(const std::string
& name
,
55 const base::Value
& value
,
56 const base::Closure
& callback
,
57 const ErrorCallback
& error_callback
) override
{
58 dbus::MethodCall
method_call(shill::kFlimflamManagerInterface
,
59 shill::kSetPropertyFunction
);
60 dbus::MessageWriter
writer(&method_call
);
61 writer
.AppendString(name
);
62 ShillClientHelper::AppendValueDataAsVariant(&writer
, value
);
63 helper_
->CallVoidMethodWithErrorCallback(&method_call
,
68 virtual void RequestScan(const std::string
& type
,
69 const base::Closure
& callback
,
70 const ErrorCallback
& error_callback
) override
{
71 dbus::MethodCall
method_call(shill::kFlimflamManagerInterface
,
72 shill::kRequestScanFunction
);
73 dbus::MessageWriter
writer(&method_call
);
74 writer
.AppendString(type
);
75 helper_
->CallVoidMethodWithErrorCallback(&method_call
,
80 virtual void EnableTechnology(
81 const std::string
& type
,
82 const base::Closure
& callback
,
83 const ErrorCallback
& error_callback
) override
{
84 dbus::MethodCall
method_call(shill::kFlimflamManagerInterface
,
85 shill::kEnableTechnologyFunction
);
86 dbus::MessageWriter
writer(&method_call
);
87 writer
.AppendString(type
);
88 helper_
->CallVoidMethodWithErrorCallback(&method_call
,
93 virtual void DisableTechnology(
94 const std::string
& type
,
95 const base::Closure
& callback
,
96 const ErrorCallback
& error_callback
) override
{
97 dbus::MethodCall
method_call(shill::kFlimflamManagerInterface
,
98 shill::kDisableTechnologyFunction
);
99 dbus::MessageWriter
writer(&method_call
);
100 writer
.AppendString(type
);
101 helper_
->CallVoidMethodWithErrorCallback(&method_call
,
106 virtual void ConfigureService(
107 const base::DictionaryValue
& properties
,
108 const ObjectPathCallback
& callback
,
109 const ErrorCallback
& error_callback
) override
{
110 dbus::MethodCall
method_call(shill::kFlimflamManagerInterface
,
111 shill::kConfigureServiceFunction
);
112 dbus::MessageWriter
writer(&method_call
);
113 ShillClientHelper::AppendServicePropertiesDictionary(&writer
, properties
);
114 helper_
->CallObjectPathMethodWithErrorCallback(&method_call
,
119 virtual void ConfigureServiceForProfile(
120 const dbus::ObjectPath
& profile_path
,
121 const base::DictionaryValue
& properties
,
122 const ObjectPathCallback
& callback
,
123 const ErrorCallback
& error_callback
) override
{
124 dbus::MethodCall
method_call(shill::kFlimflamManagerInterface
,
125 shill::kConfigureServiceForProfileFunction
);
126 dbus::MessageWriter
writer(&method_call
);
127 writer
.AppendObjectPath(dbus::ObjectPath(profile_path
));
128 ShillClientHelper::AppendServicePropertiesDictionary(&writer
, properties
);
129 helper_
->CallObjectPathMethodWithErrorCallback(&method_call
,
134 virtual void GetService(
135 const base::DictionaryValue
& properties
,
136 const ObjectPathCallback
& callback
,
137 const ErrorCallback
& error_callback
) override
{
138 dbus::MethodCall
method_call(shill::kFlimflamManagerInterface
,
139 shill::kGetServiceFunction
);
140 dbus::MessageWriter
writer(&method_call
);
141 ShillClientHelper::AppendServicePropertiesDictionary(&writer
, properties
);
142 helper_
->CallObjectPathMethodWithErrorCallback(&method_call
,
147 virtual void VerifyDestination(const VerificationProperties
& properties
,
148 const BooleanCallback
& callback
,
149 const ErrorCallback
& error_callback
) override
{
150 dbus::MethodCall
method_call(shill::kFlimflamManagerInterface
,
151 shill::kVerifyDestinationFunction
);
152 dbus::MessageWriter
writer(&method_call
);
153 writer
.AppendString(properties
.certificate
);
154 writer
.AppendString(properties
.public_key
);
155 writer
.AppendString(properties
.nonce
);
156 writer
.AppendString(properties
.signed_data
);
157 writer
.AppendString(properties
.device_serial
);
158 writer
.AppendString(properties
.device_ssid
);
159 writer
.AppendString(properties
.device_bssid
);
160 helper_
->CallBooleanMethodWithErrorCallback(
161 &method_call
, callback
, error_callback
);
164 virtual void VerifyAndEncryptCredentials(
165 const VerificationProperties
& properties
,
166 const std::string
& service_path
,
167 const StringCallback
& callback
,
168 const ErrorCallback
& error_callback
) override
{
169 dbus::MethodCall
method_call(shill::kFlimflamManagerInterface
,
170 shill::kVerifyAndEncryptCredentialsFunction
);
171 dbus::MessageWriter
writer(&method_call
);
172 writer
.AppendString(properties
.certificate
);
173 writer
.AppendString(properties
.public_key
);
174 writer
.AppendString(properties
.nonce
);
175 writer
.AppendString(properties
.signed_data
);
176 writer
.AppendString(properties
.device_serial
);
177 writer
.AppendString(properties
.device_ssid
);
178 writer
.AppendString(properties
.device_bssid
);
179 writer
.AppendObjectPath(dbus::ObjectPath(service_path
));
180 helper_
->CallStringMethodWithErrorCallback(
181 &method_call
, callback
, error_callback
);
184 virtual void VerifyAndEncryptData(
185 const VerificationProperties
& properties
,
186 const std::string
& data
,
187 const StringCallback
& callback
,
188 const ErrorCallback
& error_callback
) override
{
189 dbus::MethodCall
method_call(shill::kFlimflamManagerInterface
,
190 shill::kVerifyAndEncryptDataFunction
);
191 dbus::MessageWriter
writer(&method_call
);
192 writer
.AppendString(properties
.certificate
);
193 writer
.AppendString(properties
.public_key
);
194 writer
.AppendString(properties
.nonce
);
195 writer
.AppendString(properties
.signed_data
);
196 writer
.AppendString(properties
.device_serial
);
197 writer
.AppendString(properties
.device_ssid
);
198 writer
.AppendString(properties
.device_bssid
);
199 writer
.AppendString(data
);
200 helper_
->CallStringMethodWithErrorCallback(
201 &method_call
, callback
, error_callback
);
204 virtual void ConnectToBestServices(
205 const base::Closure
& callback
,
206 const ErrorCallback
& error_callback
) override
{
207 dbus::MethodCall
method_call(shill::kFlimflamManagerInterface
,
208 shill::kConnectToBestServicesFunction
);
209 helper_
->CallVoidMethodWithErrorCallback(&method_call
,
214 virtual TestInterface
* GetTestInterface() override
{
219 virtual void Init(dbus::Bus
* bus
) override
{
220 proxy_
= bus
->GetObjectProxy(shill::kFlimflamServiceName
,
221 dbus::ObjectPath(shill::kFlimflamServicePath
));
222 helper_
.reset(new ShillClientHelper(proxy_
));
223 helper_
->MonitorPropertyChanged(shill::kFlimflamManagerInterface
);
227 dbus::ObjectProxy
* proxy_
;
228 scoped_ptr
<ShillClientHelper
> helper_
;
230 DISALLOW_COPY_AND_ASSIGN(ShillManagerClientImpl
);
235 ShillManagerClient::ShillManagerClient() {}
237 ShillManagerClient::~ShillManagerClient() {}
240 ShillManagerClient
* ShillManagerClient::Create() {
241 return new ShillManagerClientImpl();
244 // ShillManagerClient::VerificationProperties implementation.
245 ShillManagerClient::VerificationProperties::VerificationProperties() {
248 ShillManagerClient::VerificationProperties::~VerificationProperties() {
251 } // namespace chromeos