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