blob: 3e4563f6d6a154e6e67cffa7b0f82c2da2f937b6 [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"
mukesh agrawal0e9e9d12014-04-18 16:09:58 -070010#include "shill/dbus_async_call_helper.h"
Christopher Wileyb691efd2012-08-09 13:51:51 -070011#include "shill/logging.h"
Jason Glasgowee1081c2012-03-06 15:14:53 -050012
13using std::string;
14
15namespace shill {
16namespace mm1 {
17
mukesh agrawal0e9e9d12014-04-18 16:09:58 -070018template<typename TraceMsgT, typename CallT, typename CallbackT,
19 typename... ArgTypes>
20void ModemProxy::BeginCall(
Alex Vakulenko8a532292014-06-16 17:18:44 -070021 const TraceMsgT &trace_msg, const CallT &call, const CallbackT &callback,
mukesh agrawal0e9e9d12014-04-18 16:09:58 -070022 Error *error, int timeout, ArgTypes... rest) {
23 BeginAsyncDBusCall(trace_msg, proxy_, call, callback, error,
24 &CellularError::FromMM1DBusError, timeout, rest...);
25}
26
Eric Shienbrood9a245532012-03-07 14:20:39 -050027ModemProxy::ModemProxy(DBus::Connection *connection,
Jason Glasgowee1081c2012-03-06 15:14:53 -050028 const string &path,
29 const string &service)
Eric Shienbrood9a245532012-03-07 14:20:39 -050030 : proxy_(connection, path, service) {}
Jason Glasgowee1081c2012-03-06 15:14:53 -050031
32ModemProxy::~ModemProxy() {}
33
Eric Shienbrood9a245532012-03-07 14:20:39 -050034void ModemProxy::set_state_changed_callback(
Ben Chan74924d82013-06-15 17:52:55 -070035 const ModemStateChangedSignalCallback &callback) {
Eric Shienbrood9a245532012-03-07 14:20:39 -050036 proxy_.set_state_changed_callback(callback);
Jason Glasgowee1081c2012-03-06 15:14:53 -050037}
38
Eric Shienbrood9a245532012-03-07 14:20:39 -050039void ModemProxy::Enable(bool enable,
40 Error *error,
41 const ResultCallback &callback,
42 int timeout) {
Ben Chanfad4a0b2012-04-18 15:49:59 -070043 SLOG(Modem, 2) << __func__ << "(" << enable << ", " << timeout << ")";
mukesh agrawal0e9e9d12014-04-18 16:09:58 -070044 BeginCall(__func__, &Proxy::EnableAsync, callback, error, timeout,
45 enable);
Eric Shienbrood9a245532012-03-07 14:20:39 -050046}
47
Jason Glasgowee1081c2012-03-06 15:14:53 -050048void ModemProxy::CreateBearer(
49 const DBusPropertiesMap &properties,
Eric Shienbrood9a245532012-03-07 14:20:39 -050050 Error *error,
51 const DBusPathCallback &callback,
Jason Glasgowee1081c2012-03-06 15:14:53 -050052 int timeout) {
mukesh agrawal0e9e9d12014-04-18 16:09:58 -070053 BeginCall(__func__, &Proxy::CreateBearerAsync, callback, error, timeout,
54 properties);
Jason Glasgowee1081c2012-03-06 15:14:53 -050055}
56
57void ModemProxy::DeleteBearer(const ::DBus::Path &bearer,
Eric Shienbrood9a245532012-03-07 14:20:39 -050058 Error *error,
59 const ResultCallback &callback,
Jason Glasgowee1081c2012-03-06 15:14:53 -050060 int timeout) {
mukesh agrawal0e9e9d12014-04-18 16:09:58 -070061 BeginCall(__func__, &Proxy::DeleteBearerAsync, callback, error, timeout,
62 bearer);
Jason Glasgowee1081c2012-03-06 15:14:53 -050063}
64
Eric Shienbrood9a245532012-03-07 14:20:39 -050065void ModemProxy::Reset(Error *error,
66 const ResultCallback &callback,
67 int timeout) {
mukesh agrawal0e9e9d12014-04-18 16:09:58 -070068 BeginCall(__func__, &Proxy::ResetAsync, callback, error, timeout);
Jason Glasgowee1081c2012-03-06 15:14:53 -050069}
70
71void ModemProxy::FactoryReset(const std::string &code,
Eric Shienbrood9a245532012-03-07 14:20:39 -050072 Error *error,
73 const ResultCallback &callback,
Jason Glasgowee1081c2012-03-06 15:14:53 -050074 int timeout) {
mukesh agrawal0e9e9d12014-04-18 16:09:58 -070075 BeginCall(__func__, &Proxy::FactoryResetAsync, callback, error, timeout,
76 code);
Jason Glasgowee1081c2012-03-06 15:14:53 -050077}
78
Ben Chan74924d82013-06-15 17:52:55 -070079void ModemProxy::SetCurrentCapabilities(const uint32_t &capabilities,
80 Error *error,
81 const ResultCallback &callback,
82 int timeout) {
mukesh agrawal0e9e9d12014-04-18 16:09:58 -070083 BeginCall(__func__, &Proxy::SetCurrentCapabilitiesAsync, callback, error,
84 timeout, capabilities);
Ben Chan74924d82013-06-15 17:52:55 -070085}
86
87void ModemProxy::SetCurrentModes(
88 const ::DBus::Struct<uint32_t, uint32_t> &modes,
89 Error *error,
90 const ResultCallback &callback,
91 int timeout) {
mukesh agrawal0e9e9d12014-04-18 16:09:58 -070092 BeginCall(__func__, &Proxy::SetCurrentModesAsync, callback, error, timeout,
93 modes);
Ben Chan74924d82013-06-15 17:52:55 -070094}
95
96void ModemProxy::SetCurrentBands(const std::vector<uint32_t> &bands,
97 Error *error,
98 const ResultCallback &callback,
99 int timeout) {
mukesh agrawal0e9e9d12014-04-18 16:09:58 -0700100 BeginCall(__func__, &Proxy::SetCurrentBandsAsync, callback, error, timeout,
101 bands);
Ben Chan74924d82013-06-15 17:52:55 -0700102}
103
Jason Glasgowee1081c2012-03-06 15:14:53 -0500104void ModemProxy::Command(const std::string &cmd,
105 const uint32_t &user_timeout,
Eric Shienbrood9a245532012-03-07 14:20:39 -0500106 Error *error,
107 const StringCallback &callback,
Jason Glasgowee1081c2012-03-06 15:14:53 -0500108 int timeout) {
mukesh agrawal0e9e9d12014-04-18 16:09:58 -0700109 BeginCall(__func__, &Proxy::CommandAsync, callback, error, timeout,
110 cmd, user_timeout);
Jason Glasgowee1081c2012-03-06 15:14:53 -0500111}
112
Arman Ugurayee464d32013-02-13 17:14:36 -0800113void ModemProxy::SetPowerState(const uint32_t &power_state,
114 Error *error,
115 const ResultCallback &callback,
116 int timeout) {
mukesh agrawal0e9e9d12014-04-18 16:09:58 -0700117 BeginCall(__func__, &Proxy::SetPowerStateAsync, callback, error, timeout,
118 power_state);
Arman Ugurayee464d32013-02-13 17:14:36 -0800119}
120
Eric Shienbrood9a245532012-03-07 14:20:39 -0500121ModemProxy::Proxy::Proxy(DBus::Connection *connection,
Jason Glasgowee1081c2012-03-06 15:14:53 -0500122 const std::string &path,
123 const std::string &service)
Eric Shienbrood9a245532012-03-07 14:20:39 -0500124 : DBus::ObjectProxy(*connection, path, service.c_str()) {}
Jason Glasgowee1081c2012-03-06 15:14:53 -0500125
126ModemProxy::Proxy::~Proxy() {}
127
Eric Shienbrood9a245532012-03-07 14:20:39 -0500128void ModemProxy::Proxy::set_state_changed_callback(
129 const ModemStateChangedSignalCallback &callback) {
130 state_changed_callback_ = callback;
131}
132
Jason Glasgowee1081c2012-03-06 15:14:53 -0500133// Signal callbacks inherited from Proxy
Nathan Williamsa31e79c2012-03-30 15:07:00 -0400134void ModemProxy::Proxy::StateChanged(const int32_t &old,
135 const int32_t &_new,
Jason Glasgowee1081c2012-03-06 15:14:53 -0500136 const uint32_t &reason) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700137 SLOG(DBus, 2) << __func__;
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400138 if (!state_changed_callback_.is_null())
139 state_changed_callback_.Run(old, _new, reason);
Jason Glasgowee1081c2012-03-06 15:14:53 -0500140}
141
142// Method callbacks inherited from
143// org::freedesktop::ModemManager1::ModemProxy
Ben Chan74924d82013-06-15 17:52:55 -0700144void ModemProxy::Proxy::EnableCallback(const ::DBus::Error &dberror,
Jason Glasgowee1081c2012-03-06 15:14:53 -0500145 void *data) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700146 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500147 scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data));
Jason Glasgowee1081c2012-03-06 15:14:53 -0500148 Error error;
Arman Uguray763df862013-07-02 12:49:10 -0700149 CellularError::FromMM1DBusError(dberror, &error);
Eric Shienbrood9a245532012-03-07 14:20:39 -0500150 callback->Run(error);
Jason Glasgowee1081c2012-03-06 15:14:53 -0500151}
152
Jason Glasgowee1081c2012-03-06 15:14:53 -0500153void ModemProxy::Proxy::CreateBearerCallback(const ::DBus::Path &path,
Ben Chan74924d82013-06-15 17:52:55 -0700154 const ::DBus::Error &dberror,
Jason Glasgowee1081c2012-03-06 15:14:53 -0500155 void *data) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700156 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500157 scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data));
Jason Glasgowee1081c2012-03-06 15:14:53 -0500158 Error error;
Arman Uguray763df862013-07-02 12:49:10 -0700159 CellularError::FromMM1DBusError(dberror, &error);
Eric Shienbrood9a245532012-03-07 14:20:39 -0500160 callback->Run(error);
Jason Glasgowee1081c2012-03-06 15:14:53 -0500161}
162
Ben Chan74924d82013-06-15 17:52:55 -0700163void ModemProxy::Proxy::DeleteBearerCallback(const ::DBus::Error &dberror,
Jason Glasgowee1081c2012-03-06 15:14:53 -0500164 void *data) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700165 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500166 scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data));
Jason Glasgowee1081c2012-03-06 15:14:53 -0500167 Error error;
Arman Uguray763df862013-07-02 12:49:10 -0700168 CellularError::FromMM1DBusError(dberror, &error);
Eric Shienbrood9a245532012-03-07 14:20:39 -0500169 callback->Run(error);
Jason Glasgowee1081c2012-03-06 15:14:53 -0500170}
171
Ben Chan74924d82013-06-15 17:52:55 -0700172void ModemProxy::Proxy::ResetCallback(const ::DBus::Error &dberror,
Jason Glasgowee1081c2012-03-06 15:14:53 -0500173 void *data) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700174 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500175 scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data));
Jason Glasgowee1081c2012-03-06 15:14:53 -0500176 Error error;
Arman Uguray763df862013-07-02 12:49:10 -0700177 CellularError::FromMM1DBusError(dberror, &error);
Eric Shienbrood9a245532012-03-07 14:20:39 -0500178 callback->Run(error);
Jason Glasgowee1081c2012-03-06 15:14:53 -0500179}
180
Ben Chan74924d82013-06-15 17:52:55 -0700181void ModemProxy::Proxy::FactoryResetCallback(const ::DBus::Error &dberror,
Jason Glasgowee1081c2012-03-06 15:14:53 -0500182 void *data) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700183 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500184 scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data));
Jason Glasgowee1081c2012-03-06 15:14:53 -0500185 Error error;
Arman Uguray763df862013-07-02 12:49:10 -0700186 CellularError::FromMM1DBusError(dberror, &error);
Eric Shienbrood9a245532012-03-07 14:20:39 -0500187 callback->Run(error);
Jason Glasgowee1081c2012-03-06 15:14:53 -0500188}
189
Ben Chan74924d82013-06-15 17:52:55 -0700190void ModemProxy::Proxy::SetCurrentCapabilitesCallback(
191 const ::DBus::Error &dberror,
192 void *data) {
193 SLOG(DBus, 2) << __func__;
194 scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data));
195 Error error;
Arman Uguray763df862013-07-02 12:49:10 -0700196 CellularError::FromMM1DBusError(dberror, &error);
Ben Chan74924d82013-06-15 17:52:55 -0700197 callback->Run(error);
198}
199
200void ModemProxy::Proxy::SetCurrentModesCallback(const ::DBus::Error &dberror,
201 void *data) {
202 SLOG(DBus, 2) << __func__;
203 scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data));
204 Error error;
Arman Uguray763df862013-07-02 12:49:10 -0700205 CellularError::FromMM1DBusError(dberror, &error);
Ben Chan74924d82013-06-15 17:52:55 -0700206 callback->Run(error);
207}
208
209void ModemProxy::Proxy::SetCurrentBandsCallback(const ::DBus::Error &dberror,
210 void *data) {
211 SLOG(DBus, 2) << __func__;
212 scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data));
213 Error error;
Arman Uguray763df862013-07-02 12:49:10 -0700214 CellularError::FromMM1DBusError(dberror, &error);
Ben Chan74924d82013-06-15 17:52:55 -0700215 callback->Run(error);
216}
217
Jason Glasgowee1081c2012-03-06 15:14:53 -0500218void ModemProxy::Proxy::CommandCallback(const std::string &response,
Ben Chan74924d82013-06-15 17:52:55 -0700219 const ::DBus::Error &dberror,
Jason Glasgowee1081c2012-03-06 15:14:53 -0500220 void *data) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700221 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500222 scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data));
Jason Glasgowee1081c2012-03-06 15:14:53 -0500223 Error error;
Arman Uguray763df862013-07-02 12:49:10 -0700224 CellularError::FromMM1DBusError(dberror, &error);
Eric Shienbrood9a245532012-03-07 14:20:39 -0500225 callback->Run(error);
Jason Glasgowee1081c2012-03-06 15:14:53 -0500226}
227
Arman Ugurayee464d32013-02-13 17:14:36 -0800228void ModemProxy::Proxy::SetPowerStateCallback(const ::DBus::Error &dberror,
229 void *data) {
230 SLOG(DBus, 2) << __func__;
231 scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data));
232 Error error;
Arman Uguray763df862013-07-02 12:49:10 -0700233 CellularError::FromMM1DBusError(dberror, &error);
Arman Ugurayee464d32013-02-13 17:14:36 -0800234 callback->Run(error);
235}
236
Jason Glasgowee1081c2012-03-06 15:14:53 -0500237} // namespace mm1
238} // namespace shill