Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 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/modem_cdma_proxy.h" |
| 6 | |
Ben Chan | c20ed13 | 2014-10-16 12:25:03 -0700 | [diff] [blame] | 7 | #include <memory> |
| 8 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 9 | #include "shill/cellular_error.h" |
mukesh agrawal | 0e9e9d1 | 2014-04-18 16:09:58 -0700 | [diff] [blame] | 10 | #include "shill/dbus_async_call_helper.h" |
Christopher Wiley | b691efd | 2012-08-09 13:51:51 -0700 | [diff] [blame] | 11 | #include "shill/logging.h" |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 12 | |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 13 | using std::string; |
Ben Chan | c20ed13 | 2014-10-16 12:25:03 -0700 | [diff] [blame] | 14 | using std::unique_ptr; |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 15 | |
| 16 | namespace shill { |
| 17 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 18 | ModemCDMAProxy::ModemCDMAProxy( |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 19 | DBus::Connection *connection, |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 20 | const string &path, |
| 21 | const string &service) |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 22 | : proxy_(connection, path, service) {} |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 23 | |
| 24 | ModemCDMAProxy::~ModemCDMAProxy() {} |
| 25 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 26 | void ModemCDMAProxy::Activate(const string &carrier, Error *error, |
| 27 | const ActivationResultCallback &callback, |
| 28 | int timeout) { |
mukesh agrawal | 0e9e9d1 | 2014-04-18 16:09:58 -0700 | [diff] [blame] | 29 | BeginAsyncDBusCall(__func__, proxy_, &Proxy::ActivateAsync, callback, |
| 30 | error, &CellularError::FromDBusError, timeout, |
| 31 | carrier); |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 32 | } |
| 33 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 34 | void ModemCDMAProxy::GetRegistrationState( |
| 35 | Error *error, |
| 36 | const RegistrationStateCallback &callback, |
| 37 | int timeout) { |
mukesh agrawal | 0e9e9d1 | 2014-04-18 16:09:58 -0700 | [diff] [blame] | 38 | BeginAsyncDBusCall(__func__, proxy_, &Proxy::GetRegistrationStateAsync, |
| 39 | callback, error, &CellularError::FromDBusError, timeout); |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 40 | } |
| 41 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 42 | void ModemCDMAProxy::GetSignalQuality(Error *error, |
| 43 | const SignalQualityCallback &callback, |
| 44 | int timeout) { |
mukesh agrawal | 0e9e9d1 | 2014-04-18 16:09:58 -0700 | [diff] [blame] | 45 | BeginAsyncDBusCall(__func__, proxy_, &Proxy::GetSignalQualityAsync, callback, |
| 46 | error, &CellularError::FromDBusError, timeout); |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 47 | } |
| 48 | |
Darin Petkov | 975b5e7 | 2011-08-30 11:48:08 -0700 | [diff] [blame] | 49 | const string ModemCDMAProxy::MEID() { |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 50 | LOG(INFO) << "ModemCDMAProxy::" << __func__; |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 51 | SLOG(DBus, 2) << __func__; |
Gary Morain | 610977f | 2012-05-04 16:03:52 -0700 | [diff] [blame] | 52 | 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 Petkov | 975b5e7 | 2011-08-30 11:48:08 -0700 | [diff] [blame] | 58 | } |
| 59 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 60 | void ModemCDMAProxy::set_activation_state_callback( |
| 61 | const ActivationStateSignalCallback &callback) { |
| 62 | proxy_.set_activation_state_callback(callback); |
| 63 | } |
| 64 | |
| 65 | void ModemCDMAProxy::set_signal_quality_callback( |
| 66 | const SignalQualitySignalCallback &callback) { |
| 67 | proxy_.set_signal_quality_callback(callback); |
| 68 | } |
| 69 | |
| 70 | void ModemCDMAProxy::set_registration_state_callback( |
| 71 | const RegistrationStateSignalCallback &callback) { |
| 72 | proxy_.set_registration_state_callback(callback); |
| 73 | } |
| 74 | |
| 75 | ModemCDMAProxy::Proxy::Proxy(DBus::Connection *connection, |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 76 | const string &path, |
| 77 | const string &service) |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 78 | : DBus::ObjectProxy(*connection, path, service.c_str()) {} |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 79 | |
| 80 | ModemCDMAProxy::Proxy::~Proxy() {} |
| 81 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 82 | void ModemCDMAProxy::Proxy::set_activation_state_callback( |
| 83 | const ActivationStateSignalCallback &callback) { |
| 84 | activation_state_callback_ = callback; |
| 85 | } |
| 86 | |
| 87 | void ModemCDMAProxy::Proxy::set_signal_quality_callback( |
| 88 | const SignalQualitySignalCallback &callback) { |
| 89 | signal_quality_callback_ = callback; |
| 90 | } |
| 91 | |
| 92 | void ModemCDMAProxy::Proxy::set_registration_state_callback( |
| 93 | const RegistrationStateSignalCallback &callback) { |
| 94 | registration_state_callback_ = callback; |
| 95 | } |
| 96 | |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 97 | void ModemCDMAProxy::Proxy::ActivationStateChanged( |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 98 | const uint32_t &activation_state, |
| 99 | const uint32_t &activation_error, |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 100 | const DBusPropertiesMap &status_changes) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 101 | SLOG(DBus, 2) << __func__ << "(" << activation_state << ", " |
| 102 | << activation_error << ")"; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 103 | activation_state_callback_.Run(activation_state, |
| 104 | activation_error, |
| 105 | status_changes); |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 106 | } |
| 107 | |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 108 | void ModemCDMAProxy::Proxy::SignalQuality(const uint32_t &quality) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 109 | SLOG(DBus, 2) << __func__ << "(" << quality << ")"; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 110 | signal_quality_callback_.Run(quality); |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | void ModemCDMAProxy::Proxy::RegistrationStateChanged( |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 114 | const uint32_t &cdma_1x_state, |
| 115 | const uint32_t &evdo_state) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 116 | SLOG(DBus, 2) << __func__ << "(" << cdma_1x_state << ", " |
| 117 | << evdo_state << ")"; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 118 | registration_state_callback_.Run(cdma_1x_state, evdo_state); |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 119 | } |
| 120 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 121 | void ModemCDMAProxy::Proxy::ActivateCallback(const uint32_t &status, |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 122 | const DBus::Error &dberror, |
| 123 | void *data) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 124 | SLOG(DBus, 2) << __func__ << "(" << status << ")"; |
Ben Chan | c20ed13 | 2014-10-16 12:25:03 -0700 | [diff] [blame] | 125 | unique_ptr<ActivationResultCallback> callback( |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 126 | reinterpret_cast<ActivationResultCallback *>(data)); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 127 | Error error; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 128 | CellularError::FromDBusError(dberror, &error); |
| 129 | callback->Run(status, error); |
| 130 | } |
| 131 | |
| 132 | void ModemCDMAProxy::Proxy::GetRegistrationStateCallback( |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 133 | const uint32_t &state_1x, const uint32_t &state_evdo, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 134 | const DBus::Error &dberror, void *data) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 135 | SLOG(DBus, 2) << __func__ << "(" << state_1x << ", " << state_evdo << ")"; |
Ben Chan | c20ed13 | 2014-10-16 12:25:03 -0700 | [diff] [blame] | 136 | unique_ptr<RegistrationStateCallback> callback( |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 137 | reinterpret_cast<RegistrationStateCallback *>(data)); |
| 138 | Error error; |
| 139 | CellularError::FromDBusError(dberror, &error); |
| 140 | callback->Run(state_1x, state_evdo, error); |
| 141 | } |
| 142 | |
| 143 | |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 144 | void ModemCDMAProxy::Proxy::GetSignalQualityCallback(const uint32_t &quality, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 145 | const DBus::Error &dberror, |
| 146 | void *data) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 147 | SLOG(DBus, 2) << __func__ << "(" << quality << ")"; |
Ben Chan | c20ed13 | 2014-10-16 12:25:03 -0700 | [diff] [blame] | 148 | unique_ptr<SignalQualityCallback> callback( |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 149 | reinterpret_cast<SignalQualityCallback *>(data)); |
| 150 | Error error; |
| 151 | CellularError::FromDBusError(dberror, &error); |
| 152 | callback->Run(quality, error); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 153 | } |
| 154 | |
Darin Petkov | bec79a2 | 2011-08-01 14:47:17 -0700 | [diff] [blame] | 155 | } // namespace shill |