blob: 0656474c02d9d726a4c2ba3f54d678982b3841fb [file] [log] [blame]
Eric Shienbrood5de44ab2011-12-05 10:46:27 -05001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Darin Petkovbec79a22011-08-01 14:47:17 -07002// 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/modem_cdma_proxy.h"
6
Eric Shienbrood9a245532012-03-07 14:20:39 -05007#include "shill/cellular_error.h"
Christopher Wileyb691efd2012-08-09 13:51:51 -07008#include "shill/logging.h"
Eric Shienbrood5de44ab2011-12-05 10:46:27 -05009
Darin Petkovbec79a22011-08-01 14:47:17 -070010using std::string;
11
12namespace shill {
13
Eric Shienbrood9a245532012-03-07 14:20:39 -050014ModemCDMAProxy::ModemCDMAProxy(
Darin Petkovd9661952011-08-03 16:25:42 -070015 DBus::Connection *connection,
Darin Petkovbec79a22011-08-01 14:47:17 -070016 const string &path,
17 const string &service)
Eric Shienbrood9a245532012-03-07 14:20:39 -050018 : proxy_(connection, path, service) {}
Darin Petkovbec79a22011-08-01 14:47:17 -070019
20ModemCDMAProxy::~ModemCDMAProxy() {}
21
Eric Shienbrood9a245532012-03-07 14:20:39 -050022void ModemCDMAProxy::Activate(const string &carrier, Error *error,
23 const ActivationResultCallback &callback,
24 int timeout) {
25 scoped_ptr<ActivationResultCallback>
26 cb(new ActivationResultCallback(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 }
Darin Petkovc408e692011-08-17 13:47:15 -070035}
36
Eric Shienbrood9a245532012-03-07 14:20:39 -050037void ModemCDMAProxy::GetRegistrationState(
38 Error *error,
39 const RegistrationStateCallback &callback,
40 int timeout) {
41 scoped_ptr<RegistrationStateCallback>
42 cb(new RegistrationStateCallback(callback));
43 try {
mukesh agrawal06175d72012-04-23 16:46:01 -070044 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -050045 proxy_.GetRegistrationState(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 }
Darin Petkovbec79a22011-08-01 14:47:17 -070051}
52
Eric Shienbrood9a245532012-03-07 14:20:39 -050053void ModemCDMAProxy::GetSignalQuality(Error *error,
54 const SignalQualityCallback &callback,
55 int timeout) {
56 scoped_ptr<SignalQualityCallback> cb(new SignalQualityCallback(callback));
57 try {
mukesh agrawal06175d72012-04-23 16:46:01 -070058 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -050059 proxy_.GetSignalQuality(cb.get(), timeout);
60 cb.release();
Ben Chan80326f32012-05-04 17:51:32 -070061 } catch (const DBus::Error &e) {
Eric Shienbrood9a245532012-03-07 14:20:39 -050062 if (error)
63 CellularError::FromDBusError(e, error);
64 }
Darin Petkovd9661952011-08-03 16:25:42 -070065}
66
Darin Petkov975b5e72011-08-30 11:48:08 -070067const string ModemCDMAProxy::MEID() {
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050068 LOG(INFO) << "ModemCDMAProxy::" << __func__;
mukesh agrawal06175d72012-04-23 16:46:01 -070069 SLOG(DBus, 2) << __func__;
Gary Morain610977f2012-05-04 16:03:52 -070070 try {
71 return proxy_.Meid();
72 } catch (const DBus::Error &e) {
73 LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what();
74 return string(); // Make the compiler happy.
75 }
Darin Petkov975b5e72011-08-30 11:48:08 -070076}
77
Eric Shienbrood9a245532012-03-07 14:20:39 -050078void ModemCDMAProxy::set_activation_state_callback(
79 const ActivationStateSignalCallback &callback) {
80 proxy_.set_activation_state_callback(callback);
81}
82
83void ModemCDMAProxy::set_signal_quality_callback(
84 const SignalQualitySignalCallback &callback) {
85 proxy_.set_signal_quality_callback(callback);
86}
87
88void ModemCDMAProxy::set_registration_state_callback(
89 const RegistrationStateSignalCallback &callback) {
90 proxy_.set_registration_state_callback(callback);
91}
92
93ModemCDMAProxy::Proxy::Proxy(DBus::Connection *connection,
Darin Petkovbec79a22011-08-01 14:47:17 -070094 const string &path,
95 const string &service)
Eric Shienbrood9a245532012-03-07 14:20:39 -050096 : DBus::ObjectProxy(*connection, path, service.c_str()) {}
Darin Petkovbec79a22011-08-01 14:47:17 -070097
98ModemCDMAProxy::Proxy::~Proxy() {}
99
Eric Shienbrood9a245532012-03-07 14:20:39 -0500100void ModemCDMAProxy::Proxy::set_activation_state_callback(
101 const ActivationStateSignalCallback &callback) {
102 activation_state_callback_ = callback;
103}
104
105void ModemCDMAProxy::Proxy::set_signal_quality_callback(
106 const SignalQualitySignalCallback &callback) {
107 signal_quality_callback_ = callback;
108}
109
110void ModemCDMAProxy::Proxy::set_registration_state_callback(
111 const RegistrationStateSignalCallback &callback) {
112 registration_state_callback_ = callback;
113}
114
Darin Petkovbec79a22011-08-01 14:47:17 -0700115void ModemCDMAProxy::Proxy::ActivationStateChanged(
116 const uint32 &activation_state,
117 const uint32 &activation_error,
118 const DBusPropertiesMap &status_changes) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700119 SLOG(DBus, 2) << __func__ << "(" << activation_state << ", "
120 << activation_error << ")";
Eric Shienbrood9a245532012-03-07 14:20:39 -0500121 activation_state_callback_.Run(activation_state,
122 activation_error,
123 status_changes);
Darin Petkovbec79a22011-08-01 14:47:17 -0700124}
125
126void ModemCDMAProxy::Proxy::SignalQuality(const uint32 &quality) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700127 SLOG(DBus, 2) << __func__ << "(" << quality << ")";
Eric Shienbrood9a245532012-03-07 14:20:39 -0500128 signal_quality_callback_.Run(quality);
Darin Petkovbec79a22011-08-01 14:47:17 -0700129}
130
131void ModemCDMAProxy::Proxy::RegistrationStateChanged(
Darin Petkovd9661952011-08-03 16:25:42 -0700132 const uint32 &cdma_1x_state,
133 const uint32 &evdo_state) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700134 SLOG(DBus, 2) << __func__ << "(" << cdma_1x_state << ", "
135 << evdo_state << ")";
Eric Shienbrood9a245532012-03-07 14:20:39 -0500136 registration_state_callback_.Run(cdma_1x_state, evdo_state);
Darin Petkovbec79a22011-08-01 14:47:17 -0700137}
138
Eric Shienbrood9a245532012-03-07 14:20:39 -0500139void ModemCDMAProxy::Proxy::ActivateCallback(const uint32_t &status,
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500140 const DBus::Error &dberror,
141 void *data) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700142 SLOG(DBus, 2) << __func__ << "(" << status << ")";
Eric Shienbrood9a245532012-03-07 14:20:39 -0500143 scoped_ptr<ActivationResultCallback> callback(
144 reinterpret_cast<ActivationResultCallback *>(data));
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500145 Error error;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500146 CellularError::FromDBusError(dberror, &error);
147 callback->Run(status, error);
148}
149
150void ModemCDMAProxy::Proxy::GetRegistrationStateCallback(
151 const uint32 &state_1x, const uint32 &state_evdo,
152 const DBus::Error &dberror, void *data) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700153 SLOG(DBus, 2) << __func__ << "(" << state_1x << ", " << state_evdo << ")";
Eric Shienbrood9a245532012-03-07 14:20:39 -0500154 scoped_ptr<RegistrationStateCallback> callback(
155 reinterpret_cast<RegistrationStateCallback *>(data));
156 Error error;
157 CellularError::FromDBusError(dberror, &error);
158 callback->Run(state_1x, state_evdo, error);
159}
160
161
162void ModemCDMAProxy::Proxy::GetSignalQualityCallback(const uint32 &quality,
163 const DBus::Error &dberror,
164 void *data) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700165 SLOG(DBus, 2) << __func__ << "(" << quality << ")";
Eric Shienbrood9a245532012-03-07 14:20:39 -0500166 scoped_ptr<SignalQualityCallback> callback(
167 reinterpret_cast<SignalQualityCallback *>(data));
168 Error error;
169 CellularError::FromDBusError(dberror, &error);
170 callback->Run(quality, error);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500171}
172
Darin Petkovbec79a22011-08-01 14:47:17 -0700173} // namespace shill