blob: e1b57bf4501f00ff09afeb3e238251973bb0381d [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
7#include <base/logging.h>
8
mukesh agrawal06175d72012-04-23 16:46:01 -07009#include "shill/cellular_error.h"
10#include "shill/scope_logger.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 -050017ModemModemCdmaProxy::ModemModemCdmaProxy(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
22ModemModemCdmaProxy::~ModemModemCdmaProxy() {}
23
24void ModemModemCdmaProxy::Activate(const std::string &carrier,
Eric Shienbrood9a245532012-03-07 14:20:39 -050025 Error *error,
26 const ResultCallback &callback,
27 int timeout) {
28 scoped_ptr<ResultCallback> cb(new ResultCallback(callback));
29 try {
mukesh agrawal06175d72012-04-23 16:46:01 -070030 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -050031 proxy_.Activate(carrier, cb.get(), timeout);
32 cb.release();
Ben Chan80326f32012-05-04 17:51:32 -070033 } catch (const DBus::Error &e) {
Eric Shienbrood9a245532012-03-07 14:20:39 -050034 if (error)
35 CellularError::FromDBusError(e, error);
36 }
Jason Glasgowee1081c2012-03-06 15:14:53 -050037}
38
39void ModemModemCdmaProxy::ActivateManual(
40 const DBusPropertiesMap &properties,
Eric Shienbrood9a245532012-03-07 14:20:39 -050041 Error *error,
42 const ResultCallback &callback,
Jason Glasgowee1081c2012-03-06 15:14:53 -050043 int timeout) {
Eric Shienbrood9a245532012-03-07 14:20:39 -050044 scoped_ptr<ResultCallback> cb(new ResultCallback(callback));
45 try {
mukesh agrawal06175d72012-04-23 16:46:01 -070046 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -050047 proxy_.ActivateManual(properties, cb.get(), timeout);
48 cb.release();
Ben Chan80326f32012-05-04 17:51:32 -070049 } catch (const DBus::Error &e) {
Eric Shienbrood9a245532012-03-07 14:20:39 -050050 if (error)
51 CellularError::FromDBusError(e, error);
52 }
53}
54
55void ModemModemCdmaProxy::set_activation_state_callback(
56 const ActivationStateSignalCallback &callback) {
57 proxy_.set_activation_state_callback(callback);
Jason Glasgowee1081c2012-03-06 15:14:53 -050058}
59
60// Inherited properties from ModemModemCdmaProxyInterface.
61std::string ModemModemCdmaProxy::Meid() {
mukesh agrawal06175d72012-04-23 16:46:01 -070062 SLOG(DBus, 2) << __func__;
Gary Morain610977f2012-05-04 16:03:52 -070063 try {
64 return proxy_.Meid();
65 } catch (const DBus::Error &e) {
66 LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what();
67 return std::string(); // Make the compiler happy.
68 }
Jason Glasgowee1081c2012-03-06 15:14:53 -050069};
70std::string ModemModemCdmaProxy::Esn() {
mukesh agrawal06175d72012-04-23 16:46:01 -070071 SLOG(DBus, 2) << __func__;
Gary Morain610977f2012-05-04 16:03:52 -070072 try {
73 return proxy_.Esn();
74 } catch (const DBus::Error &e) {
75 LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what();
76 return std::string(); // Make the compiler happy.
77 }
Jason Glasgowee1081c2012-03-06 15:14:53 -050078};
79uint32_t ModemModemCdmaProxy::Sid() {
mukesh agrawal06175d72012-04-23 16:46:01 -070080 SLOG(DBus, 2) << __func__;
Gary Morain610977f2012-05-04 16:03:52 -070081 try {
82 return proxy_.Sid();
83 } catch (const DBus::Error &e) {
84 LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what();
85 return 0; // Make the compiler happy.
86 }
Jason Glasgowee1081c2012-03-06 15:14:53 -050087};
88uint32_t ModemModemCdmaProxy::Nid() {
mukesh agrawal06175d72012-04-23 16:46:01 -070089 SLOG(DBus, 2) << __func__;
Gary Morain610977f2012-05-04 16:03:52 -070090 try {
91 return proxy_.Nid();
92 } catch (const DBus::Error &e) {
93 LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what();
94 return 0; // Make the compiler happy.
95 }
Jason Glasgowee1081c2012-03-06 15:14:53 -050096};
97uint32_t ModemModemCdmaProxy::Cdma1xRegistrationState() {
mukesh agrawal06175d72012-04-23 16:46:01 -070098 SLOG(DBus, 2) << __func__;
Gary Morain610977f2012-05-04 16:03:52 -070099 try {
100 return proxy_.Cdma1xRegistrationState();
101 } catch (const DBus::Error &e) {
102 LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what();
103 return 0; // Make the compiler happy.
104 }
Jason Glasgowee1081c2012-03-06 15:14:53 -0500105};
106uint32_t ModemModemCdmaProxy::EvdoRegistrationState() {
mukesh agrawal06175d72012-04-23 16:46:01 -0700107 SLOG(DBus, 2) << __func__;
Gary Morain610977f2012-05-04 16:03:52 -0700108 try {
109 return proxy_.EvdoRegistrationState();
110 } catch (const DBus::Error &e) {
111 LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what();
112 return 0; // Make the compiler happy.
113 }
Jason Glasgowee1081c2012-03-06 15:14:53 -0500114};
115
116// ModemModemCdmaProxy::Proxy
Eric Shienbrood9a245532012-03-07 14:20:39 -0500117ModemModemCdmaProxy::Proxy::Proxy(DBus::Connection *connection,
Jason Glasgowee1081c2012-03-06 15:14:53 -0500118 const std::string &path,
119 const std::string &service)
Eric Shienbrood9a245532012-03-07 14:20:39 -0500120 : DBus::ObjectProxy(*connection, path, service.c_str()) {}
Jason Glasgowee1081c2012-03-06 15:14:53 -0500121
122ModemModemCdmaProxy::Proxy::~Proxy() {}
123
Eric Shienbrood9a245532012-03-07 14:20:39 -0500124void ModemModemCdmaProxy::Proxy::set_activation_state_callback(
125 const ActivationStateSignalCallback &callback) {
126 activation_state_callback_ = callback;
127}
128
Jason Glasgowee1081c2012-03-06 15:14:53 -0500129// Signal callbacks inherited from Proxy
130void ModemModemCdmaProxy::Proxy::ActivationStateChanged(
131 const uint32_t &activation_state,
132 const uint32_t &activation_error,
133 const DBusPropertiesMap &status_changes) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700134 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500135 activation_state_callback_.Run(activation_state,
136 activation_error,
137 status_changes);
Jason Glasgowee1081c2012-03-06 15:14:53 -0500138}
139
140// Method callbacks inherited from
141// org::freedesktop::ModemManager1::Modem::ModemModemCdmaProxy
142void ModemModemCdmaProxy::Proxy::ActivateCallback(const ::DBus::Error& dberror,
143 void *data) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700144 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500145 scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data));
Jason Glasgowee1081c2012-03-06 15:14:53 -0500146 Error error;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500147 CellularError::FromDBusError(dberror, &error);
148 callback->Run(error);
Jason Glasgowee1081c2012-03-06 15:14:53 -0500149}
150
151void ModemModemCdmaProxy::Proxy::ActivateManualCallback(
152 const ::DBus::Error& dberror,
153 void *data) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700154 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500155 scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data));
Jason Glasgowee1081c2012-03-06 15:14:53 -0500156 Error error;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500157 CellularError::FromDBusError(dberror, &error);
158 callback->Run(error);
Jason Glasgowee1081c2012-03-06 15:14:53 -0500159}
160
161} // namespace mm1
162} // namespace shill