blob: def4fe1c688716bc5bbd8f40756a0b5ed59040e5 [file] [log] [blame]
Jason Glasgowee1081c2012-03-06 15:14:53 -05001// Copyright (c) 2012 The Chromium OS 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 "shill/mm1_modem_proxy.h"
6
7#include <base/logging.h>
8
9#include "cellular_error.h"
10
11using std::string;
12
13namespace shill {
14namespace mm1 {
15
Eric Shienbrood9a245532012-03-07 14:20:39 -050016ModemProxy::ModemProxy(DBus::Connection *connection,
Jason Glasgowee1081c2012-03-06 15:14:53 -050017 const string &path,
18 const string &service)
Eric Shienbrood9a245532012-03-07 14:20:39 -050019 : proxy_(connection, path, service) {}
Jason Glasgowee1081c2012-03-06 15:14:53 -050020
21ModemProxy::~ModemProxy() {}
22
Eric Shienbrood9a245532012-03-07 14:20:39 -050023void ModemProxy::set_state_changed_callback(
24 const ModemStateChangedSignalCallback &callback) {
25 proxy_.set_state_changed_callback(callback);
Jason Glasgowee1081c2012-03-06 15:14:53 -050026}
27
Eric Shienbrood9a245532012-03-07 14:20:39 -050028void ModemProxy::Enable(bool enable,
29 Error *error,
30 const ResultCallback &callback,
31 int timeout) {
32 VLOG(2) << __func__ << "(" << enable << ", " << timeout << ")";
33 scoped_ptr<ResultCallback> cb(new ResultCallback(callback));
34 try {
35 proxy_.Enable(enable, cb.get(), timeout);
36 cb.release();
37 } catch (DBus::Error e) {
38 if (error)
39 CellularError::FromDBusError(e, error);
40 }
41}
42
43void ModemProxy::ListBearers(Error *error,
44 const DBusPathsCallback &callback,
Jason Glasgowee1081c2012-03-06 15:14:53 -050045 int timeout) {
Eric Shienbrood9a245532012-03-07 14:20:39 -050046 scoped_ptr<DBusPathsCallback> cb(new DBusPathsCallback(callback));
47 try {
48 proxy_.ListBearers(cb.get(), timeout);
49 cb.release();
50 } catch (DBus::Error e) {
51 if (error)
52 CellularError::FromDBusError(e, error);
53 }
Jason Glasgowee1081c2012-03-06 15:14:53 -050054}
55
56void ModemProxy::CreateBearer(
57 const DBusPropertiesMap &properties,
Eric Shienbrood9a245532012-03-07 14:20:39 -050058 Error *error,
59 const DBusPathCallback &callback,
Jason Glasgowee1081c2012-03-06 15:14:53 -050060 int timeout) {
Eric Shienbrood9a245532012-03-07 14:20:39 -050061 scoped_ptr<DBusPathCallback> cb(new DBusPathCallback(callback));
62 try {
63 proxy_.CreateBearer(properties, cb.get(), timeout);
64 cb.release();
65 } catch (DBus::Error e) {
66 if (error)
67 CellularError::FromDBusError(e, error);
68 }
Jason Glasgowee1081c2012-03-06 15:14:53 -050069}
70
71void ModemProxy::DeleteBearer(const ::DBus::Path &bearer,
Eric Shienbrood9a245532012-03-07 14:20:39 -050072 Error *error,
73 const ResultCallback &callback,
Jason Glasgowee1081c2012-03-06 15:14:53 -050074 int timeout) {
Eric Shienbrood9a245532012-03-07 14:20:39 -050075 scoped_ptr<ResultCallback> cb(new ResultCallback(callback));
76 try {
77 proxy_.DeleteBearer(bearer, cb.get(), timeout);
78 cb.release();
79 } catch (DBus::Error e) {
80 if (error)
81 CellularError::FromDBusError(e, error);
82 }
Jason Glasgowee1081c2012-03-06 15:14:53 -050083}
84
Eric Shienbrood9a245532012-03-07 14:20:39 -050085void ModemProxy::Reset(Error *error,
86 const ResultCallback &callback,
87 int timeout) {
88 scoped_ptr<ResultCallback> cb(new ResultCallback(callback));
89 try {
90 proxy_.Reset(cb.get(), timeout);
91 cb.release();
92 } catch (DBus::Error e) {
93 if (error)
94 CellularError::FromDBusError(e, error);
95 }
Jason Glasgowee1081c2012-03-06 15:14:53 -050096}
97
98void ModemProxy::FactoryReset(const std::string &code,
Eric Shienbrood9a245532012-03-07 14:20:39 -050099 Error *error,
100 const ResultCallback &callback,
Jason Glasgowee1081c2012-03-06 15:14:53 -0500101 int timeout) {
Eric Shienbrood9a245532012-03-07 14:20:39 -0500102 scoped_ptr<ResultCallback> cb(new ResultCallback(callback));
103 try {
104 proxy_.FactoryReset(code, cb.get(), timeout);
105 cb.release();
106 } catch (DBus::Error e) {
107 if (error)
108 CellularError::FromDBusError(e, error);
109 }
Jason Glasgowee1081c2012-03-06 15:14:53 -0500110}
111
112void ModemProxy::SetAllowedModes(const uint32_t &modes,
113 const uint32_t &preferred,
Eric Shienbrood9a245532012-03-07 14:20:39 -0500114 Error *error,
115 const ResultCallback &callback,
Jason Glasgowee1081c2012-03-06 15:14:53 -0500116 int timeout) {
Eric Shienbrood9a245532012-03-07 14:20:39 -0500117 scoped_ptr<ResultCallback> cb(new ResultCallback(callback));
118 try {
119 proxy_.SetAllowedModes(modes, preferred, cb.get(), timeout);
120 cb.release();
121 } catch (DBus::Error e) {
122 if (error)
123 CellularError::FromDBusError(e, error);
124 }
Jason Glasgowee1081c2012-03-06 15:14:53 -0500125}
126
127void ModemProxy::SetBands(const std::vector< uint32_t > &bands,
Eric Shienbrood9a245532012-03-07 14:20:39 -0500128 Error *error,
129 const ResultCallback &callback,
Jason Glasgowee1081c2012-03-06 15:14:53 -0500130 int timeout) {
Eric Shienbrood9a245532012-03-07 14:20:39 -0500131 scoped_ptr<ResultCallback> cb(new ResultCallback(callback));
132 try {
133 proxy_.SetBands(bands, cb.get(), timeout);
134 cb.release();
135 } catch (DBus::Error e) {
136 if (error)
137 CellularError::FromDBusError(e, error);
138 }
Jason Glasgowee1081c2012-03-06 15:14:53 -0500139}
140
141void ModemProxy::Command(const std::string &cmd,
142 const uint32_t &user_timeout,
Eric Shienbrood9a245532012-03-07 14:20:39 -0500143 Error *error,
144 const StringCallback &callback,
Jason Glasgowee1081c2012-03-06 15:14:53 -0500145 int timeout) {
Eric Shienbrood9a245532012-03-07 14:20:39 -0500146 scoped_ptr<StringCallback> cb(new StringCallback(callback));
147 try {
148 proxy_.Command(cmd, user_timeout, cb.get(), timeout);
149 cb.release();
150 } catch (DBus::Error e) {
151 if (error)
152 CellularError::FromDBusError(e, error);
153 }
Jason Glasgowee1081c2012-03-06 15:14:53 -0500154}
155
156// Inherited properties from ModemProxyInterface.
157const ::DBus::Path ModemProxy::Sim() {
158 return proxy_.Sim();
Jason Glasgow90d216d2012-04-04 15:57:14 -0400159}
Jason Glasgowee1081c2012-03-06 15:14:53 -0500160uint32_t ModemProxy::ModemCapabilities() {
161 return proxy_.ModemCapabilities();
Jason Glasgow90d216d2012-04-04 15:57:14 -0400162}
Jason Glasgowee1081c2012-03-06 15:14:53 -0500163uint32_t ModemProxy::CurrentCapabilities() {
164 return proxy_.CurrentCapabilities();
Jason Glasgow90d216d2012-04-04 15:57:14 -0400165}
Jason Glasgowee1081c2012-03-06 15:14:53 -0500166uint32_t ModemProxy::MaxBearers() {
167 return proxy_.MaxBearers();
Jason Glasgow90d216d2012-04-04 15:57:14 -0400168}
Jason Glasgowee1081c2012-03-06 15:14:53 -0500169uint32_t ModemProxy::MaxActiveBearers() {
170 return proxy_.MaxActiveBearers();
Jason Glasgow90d216d2012-04-04 15:57:14 -0400171}
Jason Glasgowee1081c2012-03-06 15:14:53 -0500172const std::string ModemProxy::Manufacturer() {
173 return proxy_.Manufacturer();
Jason Glasgow90d216d2012-04-04 15:57:14 -0400174}
Jason Glasgowee1081c2012-03-06 15:14:53 -0500175const std::string ModemProxy::Model() {
176 return proxy_.Model();
Jason Glasgow90d216d2012-04-04 15:57:14 -0400177}
Jason Glasgowee1081c2012-03-06 15:14:53 -0500178const std::string ModemProxy::Revision() {
179 return proxy_.Revision();
Jason Glasgow90d216d2012-04-04 15:57:14 -0400180}
Jason Glasgowee1081c2012-03-06 15:14:53 -0500181const std::string ModemProxy::DeviceIdentifier() {
182 return proxy_.DeviceIdentifier();
Jason Glasgow90d216d2012-04-04 15:57:14 -0400183}
Jason Glasgowee1081c2012-03-06 15:14:53 -0500184const std::string ModemProxy::Device() {
185 return proxy_.Device();
Jason Glasgow90d216d2012-04-04 15:57:14 -0400186}
Jason Glasgowee1081c2012-03-06 15:14:53 -0500187const std::string ModemProxy::Driver() {
188 return proxy_.Driver();
Jason Glasgow90d216d2012-04-04 15:57:14 -0400189}
Jason Glasgowee1081c2012-03-06 15:14:53 -0500190const std::string ModemProxy::Plugin() {
191 return proxy_.Plugin();
Jason Glasgow90d216d2012-04-04 15:57:14 -0400192}
Jason Glasgowee1081c2012-03-06 15:14:53 -0500193const std::string ModemProxy::EquipmentIdentifier() {
194 return proxy_.EquipmentIdentifier();
Jason Glasgow90d216d2012-04-04 15:57:14 -0400195}
Jason Glasgowee1081c2012-03-06 15:14:53 -0500196uint32_t ModemProxy::UnlockRequired() {
197 return proxy_.UnlockRequired();
Jason Glasgow90d216d2012-04-04 15:57:14 -0400198}
Jason Glasgowee1081c2012-03-06 15:14:53 -0500199const std::map< uint32_t, uint32_t > ModemProxy::UnlockRetries() {
200 return proxy_.UnlockRetries();
Jason Glasgow90d216d2012-04-04 15:57:14 -0400201}
Jason Glasgowee1081c2012-03-06 15:14:53 -0500202uint32_t ModemProxy::State() {
203 return proxy_.State();
Jason Glasgow90d216d2012-04-04 15:57:14 -0400204}
Jason Glasgowee1081c2012-03-06 15:14:53 -0500205uint32_t ModemProxy::AccessTechnologies() {
206 return proxy_.AccessTechnologies();
Jason Glasgow90d216d2012-04-04 15:57:14 -0400207}
Jason Glasgowee1081c2012-03-06 15:14:53 -0500208const ::DBus::Struct< uint32_t, bool > ModemProxy::SignalQuality() {
209 return proxy_.SignalQuality();
Jason Glasgow90d216d2012-04-04 15:57:14 -0400210}
211const std::vector<string> ModemProxy::OwnNumbers() {
212 return proxy_.OwnNumbers();
213}
Jason Glasgowee1081c2012-03-06 15:14:53 -0500214uint32_t ModemProxy::SupportedModes() {
215 return proxy_.SupportedModes();
Jason Glasgow90d216d2012-04-04 15:57:14 -0400216}
Jason Glasgowee1081c2012-03-06 15:14:53 -0500217uint32_t ModemProxy::AllowedModes() {
218 return proxy_.AllowedModes();
Jason Glasgow90d216d2012-04-04 15:57:14 -0400219}
Jason Glasgowee1081c2012-03-06 15:14:53 -0500220uint32_t ModemProxy::PreferredMode() {
221 return proxy_.PreferredMode();
Jason Glasgow90d216d2012-04-04 15:57:14 -0400222}
Jason Glasgowee1081c2012-03-06 15:14:53 -0500223const std::vector< uint32_t > ModemProxy::SupportedBands() {
224 return proxy_.SupportedBands();
Jason Glasgow90d216d2012-04-04 15:57:14 -0400225}
Jason Glasgowee1081c2012-03-06 15:14:53 -0500226const std::vector< uint32_t > ModemProxy::Bands() {
227 return proxy_.Bands();
Jason Glasgow90d216d2012-04-04 15:57:14 -0400228}
Jason Glasgowee1081c2012-03-06 15:14:53 -0500229
Eric Shienbrood9a245532012-03-07 14:20:39 -0500230ModemProxy::Proxy::Proxy(DBus::Connection *connection,
Jason Glasgowee1081c2012-03-06 15:14:53 -0500231 const std::string &path,
232 const std::string &service)
Eric Shienbrood9a245532012-03-07 14:20:39 -0500233 : DBus::ObjectProxy(*connection, path, service.c_str()) {}
Jason Glasgowee1081c2012-03-06 15:14:53 -0500234
235ModemProxy::Proxy::~Proxy() {}
236
Eric Shienbrood9a245532012-03-07 14:20:39 -0500237void ModemProxy::Proxy::set_state_changed_callback(
238 const ModemStateChangedSignalCallback &callback) {
239 state_changed_callback_ = callback;
240}
241
Jason Glasgowee1081c2012-03-06 15:14:53 -0500242// Signal callbacks inherited from Proxy
Nathan Williamsa31e79c2012-03-30 15:07:00 -0400243void ModemProxy::Proxy::StateChanged(const int32_t &old,
244 const int32_t &_new,
Jason Glasgowee1081c2012-03-06 15:14:53 -0500245 const uint32_t &reason) {
Eric Shienbrood9a245532012-03-07 14:20:39 -0500246 state_changed_callback_.Run(old, _new, reason);
Jason Glasgowee1081c2012-03-06 15:14:53 -0500247}
248
249// Method callbacks inherited from
250// org::freedesktop::ModemManager1::ModemProxy
251void ModemProxy::Proxy::EnableCallback(const ::DBus::Error& dberror,
252 void *data) {
Eric Shienbrood9a245532012-03-07 14:20:39 -0500253 scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data));
Jason Glasgowee1081c2012-03-06 15:14:53 -0500254 Error error;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500255 CellularError::FromDBusError(dberror, &error);
256 callback->Run(error);
Jason Glasgowee1081c2012-03-06 15:14:53 -0500257}
258
259void ModemProxy::Proxy::ListBearersCallback(
260 const std::vector< ::DBus::Path > &bearers,
261 const ::DBus::Error& dberror,
262 void *data) {
Eric Shienbrood9a245532012-03-07 14:20:39 -0500263 scoped_ptr<DBusPathsCallback> callback(
264 reinterpret_cast<DBusPathsCallback *>(data));
Jason Glasgowee1081c2012-03-06 15:14:53 -0500265 Error error;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500266 CellularError::FromDBusError(dberror, &error);
267 callback->Run(bearers, error);
Jason Glasgowee1081c2012-03-06 15:14:53 -0500268}
269
270void ModemProxy::Proxy::CreateBearerCallback(const ::DBus::Path &path,
271 const ::DBus::Error& dberror,
272 void *data) {
Eric Shienbrood9a245532012-03-07 14:20:39 -0500273 scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data));
Jason Glasgowee1081c2012-03-06 15:14:53 -0500274 Error error;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500275 CellularError::FromDBusError(dberror, &error);
276 callback->Run(error);
Jason Glasgowee1081c2012-03-06 15:14:53 -0500277}
278
279void ModemProxy::Proxy::DeleteBearerCallback(const ::DBus::Error& dberror,
280 void *data) {
Eric Shienbrood9a245532012-03-07 14:20:39 -0500281 scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data));
Jason Glasgowee1081c2012-03-06 15:14:53 -0500282 Error error;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500283 CellularError::FromDBusError(dberror, &error);
284 callback->Run(error);
Jason Glasgowee1081c2012-03-06 15:14:53 -0500285}
286
287void ModemProxy::Proxy::ResetCallback(const ::DBus::Error& dberror,
288 void *data) {
Eric Shienbrood9a245532012-03-07 14:20:39 -0500289 scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data));
Jason Glasgowee1081c2012-03-06 15:14:53 -0500290 Error error;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500291 CellularError::FromDBusError(dberror, &error);
292 callback->Run(error);
Jason Glasgowee1081c2012-03-06 15:14:53 -0500293}
294
295void ModemProxy::Proxy::FactoryResetCallback(const ::DBus::Error& dberror,
296 void *data) {
Eric Shienbrood9a245532012-03-07 14:20:39 -0500297 scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data));
Jason Glasgowee1081c2012-03-06 15:14:53 -0500298 Error error;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500299 CellularError::FromDBusError(dberror, &error);
300 callback->Run(error);
Jason Glasgowee1081c2012-03-06 15:14:53 -0500301}
302
303void ModemProxy::Proxy::SetAllowedModesCallback(
304 const ::DBus::Error& dberror,
305 void *data) {
Eric Shienbrood9a245532012-03-07 14:20:39 -0500306 scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data));
Jason Glasgowee1081c2012-03-06 15:14:53 -0500307 Error error;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500308 CellularError::FromDBusError(dberror, &error);
309 callback->Run(error);
Jason Glasgowee1081c2012-03-06 15:14:53 -0500310}
311
312void ModemProxy::Proxy::SetBandsCallback(const ::DBus::Error& dberror,
313 void *data) {
Eric Shienbrood9a245532012-03-07 14:20:39 -0500314 scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data));
Jason Glasgowee1081c2012-03-06 15:14:53 -0500315 Error error;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500316 CellularError::FromDBusError(dberror, &error);
317 callback->Run(error);
Jason Glasgowee1081c2012-03-06 15:14:53 -0500318}
319
320void ModemProxy::Proxy::CommandCallback(const std::string &response,
321 const ::DBus::Error& dberror,
322 void *data) {
Eric Shienbrood9a245532012-03-07 14:20:39 -0500323 scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data));
Jason Glasgowee1081c2012-03-06 15:14:53 -0500324 Error error;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500325 CellularError::FromDBusError(dberror, &error);
326 callback->Run(error);
Jason Glasgowee1081c2012-03-06 15:14:53 -0500327}
328
329} // namespace mm1
330} // namespace shill