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