blob: d9772bd81a6b6f4a69a1231e3a1d1cfd53b68d32 [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
Ben Chanfd1144d2013-09-06 09:10:16 -07007#include <ModemManager/ModemManager.h>
8
Ben Chanfad4a0b2012-04-18 15:49:59 -07009#include "shill/cellular_error.h"
Christopher Wileyb691efd2012-08-09 13:51:51 -070010#include "shill/logging.h"
Jason Glasgowee1081c2012-03-06 15:14:53 -050011
12using std::string;
13
14namespace shill {
15namespace mm1 {
16
Eric Shienbrood9a245532012-03-07 14:20:39 -050017ModemProxy::ModemProxy(DBus::Connection *connection,
Jason Glasgowee1081c2012-03-06 15:14:53 -050018 const string &path,
19 const string &service)
Eric Shienbrood9a245532012-03-07 14:20:39 -050020 : proxy_(connection, path, service) {}
Jason Glasgowee1081c2012-03-06 15:14:53 -050021
22ModemProxy::~ModemProxy() {}
23
Eric Shienbrood9a245532012-03-07 14:20:39 -050024void ModemProxy::set_state_changed_callback(
Ben Chan74924d82013-06-15 17:52:55 -070025 const ModemStateChangedSignalCallback &callback) {
Eric Shienbrood9a245532012-03-07 14:20:39 -050026 proxy_.set_state_changed_callback(callback);
Jason Glasgowee1081c2012-03-06 15:14:53 -050027}
28
Eric Shienbrood9a245532012-03-07 14:20:39 -050029void ModemProxy::Enable(bool enable,
30 Error *error,
31 const ResultCallback &callback,
32 int timeout) {
Ben Chanfad4a0b2012-04-18 15:49:59 -070033 SLOG(Modem, 2) << __func__ << "(" << enable << ", " << timeout << ")";
Eric Shienbrood9a245532012-03-07 14:20:39 -050034 scoped_ptr<ResultCallback> cb(new ResultCallback(callback));
35 try {
mukesh agrawal06175d72012-04-23 16:46:01 -070036 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -050037 proxy_.Enable(enable, cb.get(), timeout);
38 cb.release();
Ben Chan80326f32012-05-04 17:51:32 -070039 } catch (const DBus::Error &e) {
Eric Shienbrood9a245532012-03-07 14:20:39 -050040 if (error)
Arman Uguray763df862013-07-02 12:49:10 -070041 CellularError::FromMM1DBusError(e, error);
Eric Shienbrood9a245532012-03-07 14:20:39 -050042 }
43}
44
Jason Glasgowee1081c2012-03-06 15:14:53 -050045void ModemProxy::CreateBearer(
46 const DBusPropertiesMap &properties,
Eric Shienbrood9a245532012-03-07 14:20:39 -050047 Error *error,
48 const DBusPathCallback &callback,
Jason Glasgowee1081c2012-03-06 15:14:53 -050049 int timeout) {
Eric Shienbrood9a245532012-03-07 14:20:39 -050050 scoped_ptr<DBusPathCallback> cb(new DBusPathCallback(callback));
51 try {
mukesh agrawal06175d72012-04-23 16:46:01 -070052 SLOG(DBus, 2) << __func__;
53 proxy_.CreateBearer(properties, cb.get(), timeout);
Eric Shienbrood9a245532012-03-07 14:20:39 -050054 cb.release();
Ben Chan80326f32012-05-04 17:51:32 -070055 } catch (const DBus::Error &e) {
Eric Shienbrood9a245532012-03-07 14:20:39 -050056 if (error)
Arman Uguray763df862013-07-02 12:49:10 -070057 CellularError::FromMM1DBusError(e, error);
Eric Shienbrood9a245532012-03-07 14:20:39 -050058 }
Jason Glasgowee1081c2012-03-06 15:14:53 -050059}
60
61void ModemProxy::DeleteBearer(const ::DBus::Path &bearer,
Eric Shienbrood9a245532012-03-07 14:20:39 -050062 Error *error,
63 const ResultCallback &callback,
Jason Glasgowee1081c2012-03-06 15:14:53 -050064 int timeout) {
Eric Shienbrood9a245532012-03-07 14:20:39 -050065 scoped_ptr<ResultCallback> cb(new ResultCallback(callback));
66 try {
mukesh agrawal06175d72012-04-23 16:46:01 -070067 SLOG(DBus, 2) << __func__;
68 proxy_.DeleteBearer(bearer, cb.get(), timeout);
Eric Shienbrood9a245532012-03-07 14:20:39 -050069 cb.release();
Ben Chan80326f32012-05-04 17:51:32 -070070 } catch (const DBus::Error &e) {
Eric Shienbrood9a245532012-03-07 14:20:39 -050071 if (error)
Arman Uguray763df862013-07-02 12:49:10 -070072 CellularError::FromMM1DBusError(e, error);
Eric Shienbrood9a245532012-03-07 14:20:39 -050073 }
Jason Glasgowee1081c2012-03-06 15:14:53 -050074}
75
Eric Shienbrood9a245532012-03-07 14:20:39 -050076void ModemProxy::Reset(Error *error,
77 const ResultCallback &callback,
78 int timeout) {
79 scoped_ptr<ResultCallback> cb(new ResultCallback(callback));
80 try {
mukesh agrawal06175d72012-04-23 16:46:01 -070081 SLOG(DBus, 2) << __func__;
82 proxy_.Reset(cb.get(), timeout);
Eric Shienbrood9a245532012-03-07 14:20:39 -050083 cb.release();
Ben Chan80326f32012-05-04 17:51:32 -070084 } catch (const DBus::Error &e) {
Eric Shienbrood9a245532012-03-07 14:20:39 -050085 if (error)
Arman Uguray763df862013-07-02 12:49:10 -070086 CellularError::FromMM1DBusError(e, error);
Eric Shienbrood9a245532012-03-07 14:20:39 -050087 }
Jason Glasgowee1081c2012-03-06 15:14:53 -050088}
89
90void ModemProxy::FactoryReset(const std::string &code,
Eric Shienbrood9a245532012-03-07 14:20:39 -050091 Error *error,
92 const ResultCallback &callback,
Jason Glasgowee1081c2012-03-06 15:14:53 -050093 int timeout) {
Eric Shienbrood9a245532012-03-07 14:20:39 -050094 scoped_ptr<ResultCallback> cb(new ResultCallback(callback));
95 try {
mukesh agrawal06175d72012-04-23 16:46:01 -070096 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -050097 proxy_.FactoryReset(code, cb.get(), timeout);
98 cb.release();
Ben Chan80326f32012-05-04 17:51:32 -070099 } catch (const DBus::Error &e) {
Eric Shienbrood9a245532012-03-07 14:20:39 -0500100 if (error)
Arman Uguray763df862013-07-02 12:49:10 -0700101 CellularError::FromMM1DBusError(e, error);
Eric Shienbrood9a245532012-03-07 14:20:39 -0500102 }
Jason Glasgowee1081c2012-03-06 15:14:53 -0500103}
104
Ben Chan74924d82013-06-15 17:52:55 -0700105void ModemProxy::SetCurrentCapabilities(const uint32_t &capabilities,
106 Error *error,
107 const ResultCallback &callback,
108 int timeout) {
109 scoped_ptr<ResultCallback> cb(new ResultCallback(callback));
110 try {
111 SLOG(DBus, 2) << __func__;
112 proxy_.SetCurrentCapabilities(capabilities, cb.get(), timeout);
113 cb.release();
114 } catch (const DBus::Error &e) {
115 if (error)
Arman Uguray763df862013-07-02 12:49:10 -0700116 CellularError::FromMM1DBusError(e, error);
Ben Chan74924d82013-06-15 17:52:55 -0700117 }
118}
119
120void ModemProxy::SetCurrentModes(
121 const ::DBus::Struct<uint32_t, uint32_t> &modes,
122 Error *error,
123 const ResultCallback &callback,
124 int timeout) {
125 scoped_ptr<ResultCallback> cb(new ResultCallback(callback));
126 try {
127 SLOG(DBus, 2) << __func__;
128 proxy_.SetCurrentModes(modes, cb.get(), timeout);
129 cb.release();
130 } catch (const DBus::Error &e) {
131 if (error)
Arman Uguray763df862013-07-02 12:49:10 -0700132 CellularError::FromMM1DBusError(e, error);
Ben Chan74924d82013-06-15 17:52:55 -0700133 }
134}
135
136void ModemProxy::SetCurrentBands(const std::vector<uint32_t> &bands,
137 Error *error,
138 const ResultCallback &callback,
139 int timeout) {
140 scoped_ptr<ResultCallback> cb(new ResultCallback(callback));
141 try {
142 SLOG(DBus, 2) << __func__;
143 proxy_.SetCurrentBands(bands, cb.get(), timeout);
144 cb.release();
145 } catch (const DBus::Error &e) {
146 if (error)
Arman Uguray763df862013-07-02 12:49:10 -0700147 CellularError::FromMM1DBusError(e, error);
Ben Chan74924d82013-06-15 17:52:55 -0700148 }
149}
150
Jason Glasgowee1081c2012-03-06 15:14:53 -0500151void ModemProxy::Command(const std::string &cmd,
152 const uint32_t &user_timeout,
Eric Shienbrood9a245532012-03-07 14:20:39 -0500153 Error *error,
154 const StringCallback &callback,
Jason Glasgowee1081c2012-03-06 15:14:53 -0500155 int timeout) {
Eric Shienbrood9a245532012-03-07 14:20:39 -0500156 scoped_ptr<StringCallback> cb(new StringCallback(callback));
157 try {
mukesh agrawal06175d72012-04-23 16:46:01 -0700158 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500159 proxy_.Command(cmd, user_timeout, cb.get(), timeout);
160 cb.release();
Ben Chan80326f32012-05-04 17:51:32 -0700161 } catch (const DBus::Error &e) {
Eric Shienbrood9a245532012-03-07 14:20:39 -0500162 if (error)
Arman Uguray763df862013-07-02 12:49:10 -0700163 CellularError::FromMM1DBusError(e, error);
Eric Shienbrood9a245532012-03-07 14:20:39 -0500164 }
Jason Glasgowee1081c2012-03-06 15:14:53 -0500165}
166
Arman Ugurayee464d32013-02-13 17:14:36 -0800167void ModemProxy::SetPowerState(const uint32_t &power_state,
168 Error *error,
169 const ResultCallback &callback,
170 int timeout) {
171 scoped_ptr<ResultCallback> cb(new ResultCallback(callback));
172 try {
173 SLOG(DBus, 2) << __func__;
174 proxy_.SetPowerState(power_state, cb.get(), timeout);
175 cb.release();
176 } catch (const DBus::Error &e) {
177 if (error)
Arman Uguray763df862013-07-02 12:49:10 -0700178 CellularError::FromMM1DBusError(e, error);
Arman Ugurayee464d32013-02-13 17:14:36 -0800179 }
180}
181
Eric Shienbrood9a245532012-03-07 14:20:39 -0500182ModemProxy::Proxy::Proxy(DBus::Connection *connection,
Jason Glasgowee1081c2012-03-06 15:14:53 -0500183 const std::string &path,
184 const std::string &service)
Eric Shienbrood9a245532012-03-07 14:20:39 -0500185 : DBus::ObjectProxy(*connection, path, service.c_str()) {}
Jason Glasgowee1081c2012-03-06 15:14:53 -0500186
187ModemProxy::Proxy::~Proxy() {}
188
Eric Shienbrood9a245532012-03-07 14:20:39 -0500189void ModemProxy::Proxy::set_state_changed_callback(
190 const ModemStateChangedSignalCallback &callback) {
191 state_changed_callback_ = callback;
192}
193
Jason Glasgowee1081c2012-03-06 15:14:53 -0500194// Signal callbacks inherited from Proxy
Nathan Williamsa31e79c2012-03-30 15:07:00 -0400195void ModemProxy::Proxy::StateChanged(const int32_t &old,
196 const int32_t &_new,
Jason Glasgowee1081c2012-03-06 15:14:53 -0500197 const uint32_t &reason) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700198 SLOG(DBus, 2) << __func__;
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400199 if (!state_changed_callback_.is_null())
200 state_changed_callback_.Run(old, _new, reason);
Jason Glasgowee1081c2012-03-06 15:14:53 -0500201}
202
203// Method callbacks inherited from
204// org::freedesktop::ModemManager1::ModemProxy
Ben Chan74924d82013-06-15 17:52:55 -0700205void ModemProxy::Proxy::EnableCallback(const ::DBus::Error &dberror,
Jason Glasgowee1081c2012-03-06 15:14:53 -0500206 void *data) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700207 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500208 scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data));
Jason Glasgowee1081c2012-03-06 15:14:53 -0500209 Error error;
Arman Uguray763df862013-07-02 12:49:10 -0700210 CellularError::FromMM1DBusError(dberror, &error);
Eric Shienbrood9a245532012-03-07 14:20:39 -0500211 callback->Run(error);
Jason Glasgowee1081c2012-03-06 15:14:53 -0500212}
213
Jason Glasgowee1081c2012-03-06 15:14:53 -0500214void ModemProxy::Proxy::CreateBearerCallback(const ::DBus::Path &path,
Ben Chan74924d82013-06-15 17:52:55 -0700215 const ::DBus::Error &dberror,
Jason Glasgowee1081c2012-03-06 15:14:53 -0500216 void *data) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700217 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500218 scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data));
Jason Glasgowee1081c2012-03-06 15:14:53 -0500219 Error error;
Arman Uguray763df862013-07-02 12:49:10 -0700220 CellularError::FromMM1DBusError(dberror, &error);
Eric Shienbrood9a245532012-03-07 14:20:39 -0500221 callback->Run(error);
Jason Glasgowee1081c2012-03-06 15:14:53 -0500222}
223
Ben Chan74924d82013-06-15 17:52:55 -0700224void ModemProxy::Proxy::DeleteBearerCallback(const ::DBus::Error &dberror,
Jason Glasgowee1081c2012-03-06 15:14:53 -0500225 void *data) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700226 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500227 scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data));
Jason Glasgowee1081c2012-03-06 15:14:53 -0500228 Error error;
Arman Uguray763df862013-07-02 12:49:10 -0700229 CellularError::FromMM1DBusError(dberror, &error);
Eric Shienbrood9a245532012-03-07 14:20:39 -0500230 callback->Run(error);
Jason Glasgowee1081c2012-03-06 15:14:53 -0500231}
232
Ben Chan74924d82013-06-15 17:52:55 -0700233void ModemProxy::Proxy::ResetCallback(const ::DBus::Error &dberror,
Jason Glasgowee1081c2012-03-06 15:14:53 -0500234 void *data) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700235 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500236 scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data));
Jason Glasgowee1081c2012-03-06 15:14:53 -0500237 Error error;
Arman Uguray763df862013-07-02 12:49:10 -0700238 CellularError::FromMM1DBusError(dberror, &error);
Eric Shienbrood9a245532012-03-07 14:20:39 -0500239 callback->Run(error);
Jason Glasgowee1081c2012-03-06 15:14:53 -0500240}
241
Ben Chan74924d82013-06-15 17:52:55 -0700242void ModemProxy::Proxy::FactoryResetCallback(const ::DBus::Error &dberror,
Jason Glasgowee1081c2012-03-06 15:14:53 -0500243 void *data) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700244 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500245 scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data));
Jason Glasgowee1081c2012-03-06 15:14:53 -0500246 Error error;
Arman Uguray763df862013-07-02 12:49:10 -0700247 CellularError::FromMM1DBusError(dberror, &error);
Eric Shienbrood9a245532012-03-07 14:20:39 -0500248 callback->Run(error);
Jason Glasgowee1081c2012-03-06 15:14:53 -0500249}
250
Ben Chan74924d82013-06-15 17:52:55 -0700251void ModemProxy::Proxy::SetCurrentCapabilitesCallback(
252 const ::DBus::Error &dberror,
253 void *data) {
254 SLOG(DBus, 2) << __func__;
255 scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data));
256 Error error;
Arman Uguray763df862013-07-02 12:49:10 -0700257 CellularError::FromMM1DBusError(dberror, &error);
Ben Chan74924d82013-06-15 17:52:55 -0700258 callback->Run(error);
259}
260
261void ModemProxy::Proxy::SetCurrentModesCallback(const ::DBus::Error &dberror,
262 void *data) {
263 SLOG(DBus, 2) << __func__;
264 scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data));
265 Error error;
Arman Uguray763df862013-07-02 12:49:10 -0700266 CellularError::FromMM1DBusError(dberror, &error);
Ben Chan74924d82013-06-15 17:52:55 -0700267 callback->Run(error);
268}
269
270void ModemProxy::Proxy::SetCurrentBandsCallback(const ::DBus::Error &dberror,
271 void *data) {
272 SLOG(DBus, 2) << __func__;
273 scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data));
274 Error error;
Arman Uguray763df862013-07-02 12:49:10 -0700275 CellularError::FromMM1DBusError(dberror, &error);
Ben Chan74924d82013-06-15 17:52:55 -0700276 callback->Run(error);
277}
278
Jason Glasgowee1081c2012-03-06 15:14:53 -0500279void ModemProxy::Proxy::CommandCallback(const std::string &response,
Ben Chan74924d82013-06-15 17:52:55 -0700280 const ::DBus::Error &dberror,
Jason Glasgowee1081c2012-03-06 15:14:53 -0500281 void *data) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700282 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500283 scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data));
Jason Glasgowee1081c2012-03-06 15:14:53 -0500284 Error error;
Arman Uguray763df862013-07-02 12:49:10 -0700285 CellularError::FromMM1DBusError(dberror, &error);
Eric Shienbrood9a245532012-03-07 14:20:39 -0500286 callback->Run(error);
Jason Glasgowee1081c2012-03-06 15:14:53 -0500287}
288
Arman Ugurayee464d32013-02-13 17:14:36 -0800289void ModemProxy::Proxy::SetPowerStateCallback(const ::DBus::Error &dberror,
290 void *data) {
291 SLOG(DBus, 2) << __func__;
292 scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data));
293 Error error;
Arman Uguray763df862013-07-02 12:49:10 -0700294 CellularError::FromMM1DBusError(dberror, &error);
Arman Ugurayee464d32013-02-13 17:14:36 -0800295 callback->Run(error);
296}
297
Jason Glasgowee1081c2012-03-06 15:14:53 -0500298} // namespace mm1
299} // namespace shill