blob: 8544467574c219cd76e99e8f9cf4b8cb0d08c4a9 [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
Ben Chanc20ed132014-10-16 12:25:03 -07007#include <memory>
8
Eric Shienbrood9a245532012-03-07 14:20:39 -05009#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"
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050012
Darin Petkovbec79a22011-08-01 14:47:17 -070013using std::string;
Ben Chanc20ed132014-10-16 12:25:03 -070014using std::unique_ptr;
Darin Petkovbec79a22011-08-01 14:47:17 -070015
16namespace shill {
17
Eric Shienbrood9a245532012-03-07 14:20:39 -050018ModemCDMAProxy::ModemCDMAProxy(
Darin Petkovd9661952011-08-03 16:25:42 -070019 DBus::Connection *connection,
Darin Petkovbec79a22011-08-01 14:47:17 -070020 const string &path,
21 const string &service)
Eric Shienbrood9a245532012-03-07 14:20:39 -050022 : proxy_(connection, path, service) {}
Darin Petkovbec79a22011-08-01 14:47:17 -070023
24ModemCDMAProxy::~ModemCDMAProxy() {}
25
Eric Shienbrood9a245532012-03-07 14:20:39 -050026void ModemCDMAProxy::Activate(const string &carrier, Error *error,
27 const ActivationResultCallback &callback,
28 int timeout) {
mukesh agrawal0e9e9d12014-04-18 16:09:58 -070029 BeginAsyncDBusCall(__func__, proxy_, &Proxy::ActivateAsync, callback,
30 error, &CellularError::FromDBusError, timeout,
31 carrier);
Darin Petkovc408e692011-08-17 13:47:15 -070032}
33
Eric Shienbrood9a245532012-03-07 14:20:39 -050034void ModemCDMAProxy::GetRegistrationState(
35 Error *error,
36 const RegistrationStateCallback &callback,
37 int timeout) {
mukesh agrawal0e9e9d12014-04-18 16:09:58 -070038 BeginAsyncDBusCall(__func__, proxy_, &Proxy::GetRegistrationStateAsync,
39 callback, error, &CellularError::FromDBusError, timeout);
Darin Petkovbec79a22011-08-01 14:47:17 -070040}
41
Eric Shienbrood9a245532012-03-07 14:20:39 -050042void ModemCDMAProxy::GetSignalQuality(Error *error,
43 const SignalQualityCallback &callback,
44 int timeout) {
mukesh agrawal0e9e9d12014-04-18 16:09:58 -070045 BeginAsyncDBusCall(__func__, proxy_, &Proxy::GetSignalQualityAsync, callback,
46 error, &CellularError::FromDBusError, timeout);
Darin Petkovd9661952011-08-03 16:25:42 -070047}
48
Darin Petkov975b5e72011-08-30 11:48:08 -070049const string ModemCDMAProxy::MEID() {
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050050 LOG(INFO) << "ModemCDMAProxy::" << __func__;
mukesh agrawal06175d72012-04-23 16:46:01 -070051 SLOG(DBus, 2) << __func__;
Gary Morain610977f2012-05-04 16:03:52 -070052 try {
53 return proxy_.Meid();
54 } catch (const DBus::Error &e) {
55 LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what();
56 return string(); // Make the compiler happy.
57 }
Darin Petkov975b5e72011-08-30 11:48:08 -070058}
59
Eric Shienbrood9a245532012-03-07 14:20:39 -050060void ModemCDMAProxy::set_activation_state_callback(
61 const ActivationStateSignalCallback &callback) {
62 proxy_.set_activation_state_callback(callback);
63}
64
65void ModemCDMAProxy::set_signal_quality_callback(
66 const SignalQualitySignalCallback &callback) {
67 proxy_.set_signal_quality_callback(callback);
68}
69
70void ModemCDMAProxy::set_registration_state_callback(
71 const RegistrationStateSignalCallback &callback) {
72 proxy_.set_registration_state_callback(callback);
73}
74
75ModemCDMAProxy::Proxy::Proxy(DBus::Connection *connection,
Darin Petkovbec79a22011-08-01 14:47:17 -070076 const string &path,
77 const string &service)
Eric Shienbrood9a245532012-03-07 14:20:39 -050078 : DBus::ObjectProxy(*connection, path, service.c_str()) {}
Darin Petkovbec79a22011-08-01 14:47:17 -070079
80ModemCDMAProxy::Proxy::~Proxy() {}
81
Eric Shienbrood9a245532012-03-07 14:20:39 -050082void ModemCDMAProxy::Proxy::set_activation_state_callback(
83 const ActivationStateSignalCallback &callback) {
84 activation_state_callback_ = callback;
85}
86
87void ModemCDMAProxy::Proxy::set_signal_quality_callback(
88 const SignalQualitySignalCallback &callback) {
89 signal_quality_callback_ = callback;
90}
91
92void ModemCDMAProxy::Proxy::set_registration_state_callback(
93 const RegistrationStateSignalCallback &callback) {
94 registration_state_callback_ = callback;
95}
96
Darin Petkovbec79a22011-08-01 14:47:17 -070097void ModemCDMAProxy::Proxy::ActivationStateChanged(
Ben Chan7fab8972014-08-10 17:14:46 -070098 const uint32_t &activation_state,
99 const uint32_t &activation_error,
Darin Petkovbec79a22011-08-01 14:47:17 -0700100 const DBusPropertiesMap &status_changes) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700101 SLOG(DBus, 2) << __func__ << "(" << activation_state << ", "
102 << activation_error << ")";
Eric Shienbrood9a245532012-03-07 14:20:39 -0500103 activation_state_callback_.Run(activation_state,
104 activation_error,
105 status_changes);
Darin Petkovbec79a22011-08-01 14:47:17 -0700106}
107
Ben Chan7fab8972014-08-10 17:14:46 -0700108void ModemCDMAProxy::Proxy::SignalQuality(const uint32_t &quality) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700109 SLOG(DBus, 2) << __func__ << "(" << quality << ")";
Eric Shienbrood9a245532012-03-07 14:20:39 -0500110 signal_quality_callback_.Run(quality);
Darin Petkovbec79a22011-08-01 14:47:17 -0700111}
112
113void ModemCDMAProxy::Proxy::RegistrationStateChanged(
Ben Chan7fab8972014-08-10 17:14:46 -0700114 const uint32_t &cdma_1x_state,
115 const uint32_t &evdo_state) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700116 SLOG(DBus, 2) << __func__ << "(" << cdma_1x_state << ", "
117 << evdo_state << ")";
Eric Shienbrood9a245532012-03-07 14:20:39 -0500118 registration_state_callback_.Run(cdma_1x_state, evdo_state);
Darin Petkovbec79a22011-08-01 14:47:17 -0700119}
120
Eric Shienbrood9a245532012-03-07 14:20:39 -0500121void ModemCDMAProxy::Proxy::ActivateCallback(const uint32_t &status,
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500122 const DBus::Error &dberror,
123 void *data) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700124 SLOG(DBus, 2) << __func__ << "(" << status << ")";
Ben Chanc20ed132014-10-16 12:25:03 -0700125 unique_ptr<ActivationResultCallback> callback(
Eric Shienbrood9a245532012-03-07 14:20:39 -0500126 reinterpret_cast<ActivationResultCallback *>(data));
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500127 Error error;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500128 CellularError::FromDBusError(dberror, &error);
129 callback->Run(status, error);
130}
131
132void ModemCDMAProxy::Proxy::GetRegistrationStateCallback(
Ben Chan7fab8972014-08-10 17:14:46 -0700133 const uint32_t &state_1x, const uint32_t &state_evdo,
Eric Shienbrood9a245532012-03-07 14:20:39 -0500134 const DBus::Error &dberror, void *data) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700135 SLOG(DBus, 2) << __func__ << "(" << state_1x << ", " << state_evdo << ")";
Ben Chanc20ed132014-10-16 12:25:03 -0700136 unique_ptr<RegistrationStateCallback> callback(
Eric Shienbrood9a245532012-03-07 14:20:39 -0500137 reinterpret_cast<RegistrationStateCallback *>(data));
138 Error error;
139 CellularError::FromDBusError(dberror, &error);
140 callback->Run(state_1x, state_evdo, error);
141}
142
143
Ben Chan7fab8972014-08-10 17:14:46 -0700144void ModemCDMAProxy::Proxy::GetSignalQualityCallback(const uint32_t &quality,
Eric Shienbrood9a245532012-03-07 14:20:39 -0500145 const DBus::Error &dberror,
146 void *data) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700147 SLOG(DBus, 2) << __func__ << "(" << quality << ")";
Ben Chanc20ed132014-10-16 12:25:03 -0700148 unique_ptr<SignalQualityCallback> callback(
Eric Shienbrood9a245532012-03-07 14:20:39 -0500149 reinterpret_cast<SignalQualityCallback *>(data));
150 Error error;
151 CellularError::FromDBusError(dberror, &error);
152 callback->Run(quality, error);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500153}
154
Darin Petkovbec79a22011-08-01 14:47:17 -0700155} // namespace shill