blob: 94bb1d60e9f7f7a01fb1b0b231c45c0ad85892a7 [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_modemcdma_proxy.h"
6
mukesh agrawal06175d72012-04-23 16:46:01 -07007#include "shill/cellular_error.h"
Christopher Wileyb691efd2012-08-09 13:51:51 -07008#include "shill/logging.h"
Jason Glasgowee1081c2012-03-06 15:14:53 -05009
10using std::string;
11
12namespace shill {
13namespace mm1 {
14
Eric Shienbrood9a245532012-03-07 14:20:39 -050015ModemModemCdmaProxy::ModemModemCdmaProxy(DBus::Connection *connection,
Jason Glasgowee1081c2012-03-06 15:14:53 -050016 const string &path,
17 const string &service)
Eric Shienbrood9a245532012-03-07 14:20:39 -050018 : proxy_(connection, path, service) {}
Jason Glasgowee1081c2012-03-06 15:14:53 -050019
20ModemModemCdmaProxy::~ModemModemCdmaProxy() {}
21
22void ModemModemCdmaProxy::Activate(const std::string &carrier,
Eric Shienbrood9a245532012-03-07 14:20:39 -050023 Error *error,
24 const ResultCallback &callback,
25 int timeout) {
26 scoped_ptr<ResultCallback> cb(new ResultCallback(callback));
27 try {
mukesh agrawal06175d72012-04-23 16:46:01 -070028 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -050029 proxy_.Activate(carrier, cb.get(), timeout);
30 cb.release();
Ben Chan80326f32012-05-04 17:51:32 -070031 } catch (const DBus::Error &e) {
Eric Shienbrood9a245532012-03-07 14:20:39 -050032 if (error)
33 CellularError::FromDBusError(e, error);
34 }
Jason Glasgowee1081c2012-03-06 15:14:53 -050035}
36
37void ModemModemCdmaProxy::ActivateManual(
38 const DBusPropertiesMap &properties,
Eric Shienbrood9a245532012-03-07 14:20:39 -050039 Error *error,
40 const ResultCallback &callback,
Jason Glasgowee1081c2012-03-06 15:14:53 -050041 int timeout) {
Eric Shienbrood9a245532012-03-07 14:20:39 -050042 scoped_ptr<ResultCallback> cb(new ResultCallback(callback));
43 try {
mukesh agrawal06175d72012-04-23 16:46:01 -070044 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -050045 proxy_.ActivateManual(properties, cb.get(), timeout);
46 cb.release();
Ben Chan80326f32012-05-04 17:51:32 -070047 } catch (const DBus::Error &e) {
Eric Shienbrood9a245532012-03-07 14:20:39 -050048 if (error)
49 CellularError::FromDBusError(e, error);
50 }
51}
52
53void ModemModemCdmaProxy::set_activation_state_callback(
54 const ActivationStateSignalCallback &callback) {
55 proxy_.set_activation_state_callback(callback);
Jason Glasgowee1081c2012-03-06 15:14:53 -050056}
57
58// Inherited properties from ModemModemCdmaProxyInterface.
59std::string ModemModemCdmaProxy::Meid() {
mukesh agrawal06175d72012-04-23 16:46:01 -070060 SLOG(DBus, 2) << __func__;
Gary Morain610977f2012-05-04 16:03:52 -070061 try {
62 return proxy_.Meid();
63 } catch (const DBus::Error &e) {
64 LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what();
65 return std::string(); // Make the compiler happy.
66 }
Jason Glasgowee1081c2012-03-06 15:14:53 -050067};
68std::string ModemModemCdmaProxy::Esn() {
mukesh agrawal06175d72012-04-23 16:46:01 -070069 SLOG(DBus, 2) << __func__;
Gary Morain610977f2012-05-04 16:03:52 -070070 try {
71 return proxy_.Esn();
72 } catch (const DBus::Error &e) {
73 LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what();
74 return std::string(); // Make the compiler happy.
75 }
Jason Glasgowee1081c2012-03-06 15:14:53 -050076};
Arman Uguraycf4c0072013-03-05 17:27:18 -080077uint32_t ModemModemCdmaProxy::ActivationState() {
78 SLOG(DBus, 2) << __func__;
79 try {
80 return proxy_.ActivationState();
81 } catch (const DBus::Error &e) {
82 LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what();
83 return 0; // Make the compiler happy.
84 }
85};
Jason Glasgowee1081c2012-03-06 15:14:53 -050086uint32_t ModemModemCdmaProxy::Sid() {
mukesh agrawal06175d72012-04-23 16:46:01 -070087 SLOG(DBus, 2) << __func__;
Gary Morain610977f2012-05-04 16:03:52 -070088 try {
89 return proxy_.Sid();
90 } catch (const DBus::Error &e) {
91 LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what();
92 return 0; // Make the compiler happy.
93 }
Jason Glasgowee1081c2012-03-06 15:14:53 -050094};
95uint32_t ModemModemCdmaProxy::Nid() {
mukesh agrawal06175d72012-04-23 16:46:01 -070096 SLOG(DBus, 2) << __func__;
Gary Morain610977f2012-05-04 16:03:52 -070097 try {
98 return proxy_.Nid();
99 } catch (const DBus::Error &e) {
100 LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what();
101 return 0; // Make the compiler happy.
102 }
Jason Glasgowee1081c2012-03-06 15:14:53 -0500103};
104uint32_t ModemModemCdmaProxy::Cdma1xRegistrationState() {
mukesh agrawal06175d72012-04-23 16:46:01 -0700105 SLOG(DBus, 2) << __func__;
Gary Morain610977f2012-05-04 16:03:52 -0700106 try {
107 return proxy_.Cdma1xRegistrationState();
108 } catch (const DBus::Error &e) {
109 LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what();
110 return 0; // Make the compiler happy.
111 }
Jason Glasgowee1081c2012-03-06 15:14:53 -0500112};
113uint32_t ModemModemCdmaProxy::EvdoRegistrationState() {
mukesh agrawal06175d72012-04-23 16:46:01 -0700114 SLOG(DBus, 2) << __func__;
Gary Morain610977f2012-05-04 16:03:52 -0700115 try {
116 return proxy_.EvdoRegistrationState();
117 } catch (const DBus::Error &e) {
118 LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what();
119 return 0; // Make the compiler happy.
120 }
Jason Glasgowee1081c2012-03-06 15:14:53 -0500121};
122
123// ModemModemCdmaProxy::Proxy
Eric Shienbrood9a245532012-03-07 14:20:39 -0500124ModemModemCdmaProxy::Proxy::Proxy(DBus::Connection *connection,
Jason Glasgowee1081c2012-03-06 15:14:53 -0500125 const std::string &path,
126 const std::string &service)
Eric Shienbrood9a245532012-03-07 14:20:39 -0500127 : DBus::ObjectProxy(*connection, path, service.c_str()) {}
Jason Glasgowee1081c2012-03-06 15:14:53 -0500128
129ModemModemCdmaProxy::Proxy::~Proxy() {}
130
Eric Shienbrood9a245532012-03-07 14:20:39 -0500131void ModemModemCdmaProxy::Proxy::set_activation_state_callback(
132 const ActivationStateSignalCallback &callback) {
133 activation_state_callback_ = callback;
134}
135
Jason Glasgowee1081c2012-03-06 15:14:53 -0500136// Signal callbacks inherited from Proxy
137void ModemModemCdmaProxy::Proxy::ActivationStateChanged(
138 const uint32_t &activation_state,
139 const uint32_t &activation_error,
140 const DBusPropertiesMap &status_changes) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700141 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500142 activation_state_callback_.Run(activation_state,
143 activation_error,
144 status_changes);
Jason Glasgowee1081c2012-03-06 15:14:53 -0500145}
146
147// Method callbacks inherited from
148// org::freedesktop::ModemManager1::Modem::ModemModemCdmaProxy
149void ModemModemCdmaProxy::Proxy::ActivateCallback(const ::DBus::Error& dberror,
150 void *data) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700151 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500152 scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data));
Jason Glasgowee1081c2012-03-06 15:14:53 -0500153 Error error;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500154 CellularError::FromDBusError(dberror, &error);
155 callback->Run(error);
Jason Glasgowee1081c2012-03-06 15:14:53 -0500156}
157
158void ModemModemCdmaProxy::Proxy::ActivateManualCallback(
159 const ::DBus::Error& dberror,
160 void *data) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700161 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500162 scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data));
Jason Glasgowee1081c2012-03-06 15:14:53 -0500163 Error error;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500164 CellularError::FromDBusError(dberror, &error);
165 callback->Run(error);
Jason Glasgowee1081c2012-03-06 15:14:53 -0500166}
167
168} // namespace mm1
169} // namespace shill