Fix a type mismatch on Windows caused by r201738.
[chromium-blink-merge.git] / chromeos / dbus / shill_device_client.cc
blob69dde4f023b32218876e5f0b1d01aab4a2e7cc89
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_device_client.h"
7 #include "base/bind.h"
8 #include "base/message_loop.h"
9 #include "base/stl_util.h"
10 #include "base/values.h"
11 #include "chromeos/dbus/shill_device_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"
20 namespace chromeos {
22 namespace {
24 // The ShillDeviceClient implementation.
25 class ShillDeviceClientImpl : public ShillDeviceClient {
26 public:
27 explicit ShillDeviceClientImpl(dbus::Bus* bus)
28 : bus_(bus) {
31 virtual ~ShillDeviceClientImpl() {
32 for (HelperMap::iterator iter = helpers_.begin();
33 iter != helpers_.end(); ++iter) {
34 // This *should* never happen, yet we're getting crash reports that
35 // seem to imply that it does happen sometimes. Adding CHECKs here
36 // so we can determine more accurately where the problem lies.
37 // See: http://crbug.com/170541
38 CHECK(iter->second) << "NULL Helper found in helper list.";
39 delete iter->second;
41 helpers_.clear();
44 ///////////////////////////////////////
45 // ShillDeviceClient overrides.
46 virtual void AddPropertyChangedObserver(
47 const dbus::ObjectPath& device_path,
48 ShillPropertyChangedObserver* observer) OVERRIDE {
49 GetHelper(device_path)->AddPropertyChangedObserver(observer);
52 virtual void RemovePropertyChangedObserver(
53 const dbus::ObjectPath& device_path,
54 ShillPropertyChangedObserver* observer) OVERRIDE {
55 GetHelper(device_path)->RemovePropertyChangedObserver(observer);
58 virtual void GetProperties(const dbus::ObjectPath& device_path,
59 const DictionaryValueCallback& callback) OVERRIDE {
60 dbus::MethodCall method_call(flimflam::kFlimflamDeviceInterface,
61 flimflam::kGetPropertiesFunction);
62 GetHelper(device_path)->CallDictionaryValueMethod(&method_call, callback);
65 virtual base::DictionaryValue* CallGetPropertiesAndBlock(
66 const dbus::ObjectPath& device_path) OVERRIDE {
67 dbus::MethodCall method_call(flimflam::kFlimflamDeviceInterface,
68 flimflam::kGetPropertiesFunction);
69 return GetHelper(device_path)->CallDictionaryValueMethodAndBlock(
70 &method_call);
73 virtual void ProposeScan(const dbus::ObjectPath& device_path,
74 const VoidDBusMethodCallback& callback) OVERRIDE {
75 dbus::MethodCall method_call(flimflam::kFlimflamDeviceInterface,
76 flimflam::kProposeScanFunction);
77 GetHelper(device_path)->CallVoidMethod(&method_call, callback);
80 virtual void SetProperty(const dbus::ObjectPath& device_path,
81 const std::string& name,
82 const base::Value& value,
83 const base::Closure& callback,
84 const ErrorCallback& error_callback) OVERRIDE {
85 dbus::MethodCall method_call(flimflam::kFlimflamDeviceInterface,
86 flimflam::kSetPropertyFunction);
87 dbus::MessageWriter writer(&method_call);
88 writer.AppendString(name);
89 ShillClientHelper::AppendValueDataAsVariant(&writer, value);
90 GetHelper(device_path)->CallVoidMethodWithErrorCallback(&method_call,
91 callback,
92 error_callback);
95 virtual void ClearProperty(const dbus::ObjectPath& device_path,
96 const std::string& name,
97 const VoidDBusMethodCallback& callback) OVERRIDE {
98 dbus::MethodCall method_call(flimflam::kFlimflamDeviceInterface,
99 flimflam::kClearPropertyFunction);
100 dbus::MessageWriter writer(&method_call);
101 writer.AppendString(name);
102 GetHelper(device_path)->CallVoidMethod(&method_call, callback);
105 virtual void AddIPConfig(
106 const dbus::ObjectPath& device_path,
107 const std::string& method,
108 const ObjectPathDBusMethodCallback& callback) OVERRIDE {
109 dbus::MethodCall method_call(flimflam::kFlimflamDeviceInterface,
110 flimflam::kAddIPConfigFunction);
111 dbus::MessageWriter writer(&method_call);
112 writer.AppendString(method);
113 GetHelper(device_path)->CallObjectPathMethod(&method_call, callback);
116 virtual void RequirePin(const dbus::ObjectPath& device_path,
117 const std::string& pin,
118 bool require,
119 const base::Closure& callback,
120 const ErrorCallback& error_callback) OVERRIDE {
121 dbus::MethodCall method_call(flimflam::kFlimflamDeviceInterface,
122 flimflam::kRequirePinFunction);
123 dbus::MessageWriter writer(&method_call);
124 writer.AppendString(pin);
125 writer.AppendBool(require);
126 GetHelper(device_path)->CallVoidMethodWithErrorCallback(
127 &method_call, callback, error_callback);
130 virtual void EnterPin(const dbus::ObjectPath& device_path,
131 const std::string& pin,
132 const base::Closure& callback,
133 const ErrorCallback& error_callback) OVERRIDE {
134 dbus::MethodCall method_call(flimflam::kFlimflamDeviceInterface,
135 flimflam::kEnterPinFunction);
136 dbus::MessageWriter writer(&method_call);
137 writer.AppendString(pin);
138 GetHelper(device_path)->CallVoidMethodWithErrorCallback(
139 &method_call, callback, error_callback);
142 virtual void UnblockPin(const dbus::ObjectPath& device_path,
143 const std::string& puk,
144 const std::string& pin,
145 const base::Closure& callback,
146 const ErrorCallback& error_callback) OVERRIDE {
147 dbus::MethodCall method_call(flimflam::kFlimflamDeviceInterface,
148 flimflam::kUnblockPinFunction);
149 dbus::MessageWriter writer(&method_call);
150 writer.AppendString(puk);
151 writer.AppendString(pin);
152 GetHelper(device_path)->CallVoidMethodWithErrorCallback(
153 &method_call, callback, error_callback);
156 virtual void ChangePin(const dbus::ObjectPath& device_path,
157 const std::string& old_pin,
158 const std::string& new_pin,
159 const base::Closure& callback,
160 const ErrorCallback& error_callback) OVERRIDE {
161 dbus::MethodCall method_call(flimflam::kFlimflamDeviceInterface,
162 flimflam::kChangePinFunction);
163 dbus::MessageWriter writer(&method_call);
164 writer.AppendString(old_pin);
165 writer.AppendString(new_pin);
166 GetHelper(device_path)->CallVoidMethodWithErrorCallback(
167 &method_call, callback, error_callback);
170 virtual void Register(const dbus::ObjectPath& device_path,
171 const std::string& network_id,
172 const base::Closure& callback,
173 const ErrorCallback& error_callback) OVERRIDE {
174 dbus::MethodCall method_call(flimflam::kFlimflamDeviceInterface,
175 flimflam::kRegisterFunction);
176 dbus::MessageWriter writer(&method_call);
177 writer.AppendString(network_id);
178 GetHelper(device_path)->CallVoidMethodWithErrorCallback(
179 &method_call, callback, error_callback);
182 virtual void SetCarrier(const dbus::ObjectPath& device_path,
183 const std::string& carrier,
184 const base::Closure& callback,
185 const ErrorCallback& error_callback) OVERRIDE {
186 dbus::MethodCall method_call(flimflam::kFlimflamDeviceInterface,
187 shill::kSetCarrierFunction);
188 dbus::MessageWriter writer(&method_call);
189 writer.AppendString(carrier);
190 GetHelper(device_path)->CallVoidMethodWithErrorCallback(
191 &method_call, callback, error_callback);
194 virtual void Reset(const dbus::ObjectPath& device_path,
195 const base::Closure& callback,
196 const ErrorCallback& error_callback) OVERRIDE {
197 dbus::MethodCall method_call(flimflam::kFlimflamDeviceInterface,
198 shill::kResetFunction);
199 GetHelper(device_path)->CallVoidMethodWithErrorCallback(
200 &method_call, callback, error_callback);
203 virtual TestInterface* GetTestInterface() OVERRIDE {
204 return NULL;
207 private:
208 typedef std::map<std::string, ShillClientHelper*> HelperMap;
210 // Returns the corresponding ShillClientHelper for the profile.
211 ShillClientHelper* GetHelper(const dbus::ObjectPath& device_path) {
212 HelperMap::iterator it = helpers_.find(device_path.value());
213 if (it != helpers_.end()) {
214 CHECK(it->second) << "Found a NULL helper in the list.";
215 return it->second;
218 // There is no helper for the profile, create it.
219 dbus::ObjectProxy* object_proxy =
220 bus_->GetObjectProxy(flimflam::kFlimflamServiceName, device_path);
221 ShillClientHelper* helper = new ShillClientHelper(bus_, object_proxy);
222 CHECK(helper) << "Unable to create Shill client helper.";
223 helper->MonitorPropertyChanged(flimflam::kFlimflamDeviceInterface);
224 helpers_.insert(HelperMap::value_type(device_path.value(), helper));
225 return helper;
228 dbus::Bus* bus_;
229 HelperMap helpers_;
231 DISALLOW_COPY_AND_ASSIGN(ShillDeviceClientImpl);
234 } // namespace
236 ShillDeviceClient::ShillDeviceClient() {}
238 ShillDeviceClient::~ShillDeviceClient() {}
240 // static
241 ShillDeviceClient* ShillDeviceClient::Create(
242 DBusClientImplementationType type,
243 dbus::Bus* bus) {
244 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION)
245 return new ShillDeviceClientImpl(bus);
246 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type);
247 return new ShillDeviceClientStub();
250 } // namespace chromeos