Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
| 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/mm1_modem_modemcdma_proxy.h" |
| 6 | |
| 7 | #include <base/logging.h> |
| 8 | |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 9 | #include "shill/cellular_error.h" |
| 10 | #include "shill/scope_logger.h" |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 11 | |
| 12 | using std::string; |
| 13 | |
| 14 | namespace shill { |
| 15 | namespace mm1 { |
| 16 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 17 | ModemModemCdmaProxy::ModemModemCdmaProxy(DBus::Connection *connection, |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 18 | const string &path, |
| 19 | const string &service) |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 20 | : proxy_(connection, path, service) {} |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 21 | |
| 22 | ModemModemCdmaProxy::~ModemModemCdmaProxy() {} |
| 23 | |
| 24 | void ModemModemCdmaProxy::Activate(const std::string &carrier, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 25 | Error *error, |
| 26 | const ResultCallback &callback, |
| 27 | int timeout) { |
| 28 | scoped_ptr<ResultCallback> cb(new ResultCallback(callback)); |
| 29 | try { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 30 | SLOG(DBus, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 31 | proxy_.Activate(carrier, cb.get(), timeout); |
| 32 | cb.release(); |
Ben Chan | 80326f3 | 2012-05-04 17:51:32 -0700 | [diff] [blame] | 33 | } catch (const DBus::Error &e) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 34 | if (error) |
| 35 | CellularError::FromDBusError(e, error); |
| 36 | } |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | void ModemModemCdmaProxy::ActivateManual( |
| 40 | const DBusPropertiesMap &properties, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 41 | Error *error, |
| 42 | const ResultCallback &callback, |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 43 | int timeout) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 44 | scoped_ptr<ResultCallback> cb(new ResultCallback(callback)); |
| 45 | try { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 46 | SLOG(DBus, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 47 | proxy_.ActivateManual(properties, cb.get(), timeout); |
| 48 | cb.release(); |
Ben Chan | 80326f3 | 2012-05-04 17:51:32 -0700 | [diff] [blame] | 49 | } catch (const DBus::Error &e) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 50 | if (error) |
| 51 | CellularError::FromDBusError(e, error); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | void ModemModemCdmaProxy::set_activation_state_callback( |
| 56 | const ActivationStateSignalCallback &callback) { |
| 57 | proxy_.set_activation_state_callback(callback); |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | // Inherited properties from ModemModemCdmaProxyInterface. |
| 61 | std::string ModemModemCdmaProxy::Meid() { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 62 | SLOG(DBus, 2) << __func__; |
Gary Morain | 610977f | 2012-05-04 16:03:52 -0700 | [diff] [blame] | 63 | try { |
| 64 | return proxy_.Meid(); |
| 65 | } catch (const DBus::Error &e) { |
| 66 | LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what(); |
| 67 | return std::string(); // Make the compiler happy. |
| 68 | } |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 69 | }; |
| 70 | std::string ModemModemCdmaProxy::Esn() { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 71 | SLOG(DBus, 2) << __func__; |
Gary Morain | 610977f | 2012-05-04 16:03:52 -0700 | [diff] [blame] | 72 | try { |
| 73 | return proxy_.Esn(); |
| 74 | } catch (const DBus::Error &e) { |
| 75 | LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what(); |
| 76 | return std::string(); // Make the compiler happy. |
| 77 | } |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 78 | }; |
| 79 | uint32_t ModemModemCdmaProxy::Sid() { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 80 | SLOG(DBus, 2) << __func__; |
Gary Morain | 610977f | 2012-05-04 16:03:52 -0700 | [diff] [blame] | 81 | try { |
| 82 | return proxy_.Sid(); |
| 83 | } catch (const DBus::Error &e) { |
| 84 | LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what(); |
| 85 | return 0; // Make the compiler happy. |
| 86 | } |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 87 | }; |
| 88 | uint32_t ModemModemCdmaProxy::Nid() { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 89 | SLOG(DBus, 2) << __func__; |
Gary Morain | 610977f | 2012-05-04 16:03:52 -0700 | [diff] [blame] | 90 | try { |
| 91 | return proxy_.Nid(); |
| 92 | } catch (const DBus::Error &e) { |
| 93 | LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what(); |
| 94 | return 0; // Make the compiler happy. |
| 95 | } |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 96 | }; |
| 97 | uint32_t ModemModemCdmaProxy::Cdma1xRegistrationState() { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 98 | SLOG(DBus, 2) << __func__; |
Gary Morain | 610977f | 2012-05-04 16:03:52 -0700 | [diff] [blame] | 99 | try { |
| 100 | return proxy_.Cdma1xRegistrationState(); |
| 101 | } catch (const DBus::Error &e) { |
| 102 | LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what(); |
| 103 | return 0; // Make the compiler happy. |
| 104 | } |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 105 | }; |
| 106 | uint32_t ModemModemCdmaProxy::EvdoRegistrationState() { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 107 | SLOG(DBus, 2) << __func__; |
Gary Morain | 610977f | 2012-05-04 16:03:52 -0700 | [diff] [blame] | 108 | try { |
| 109 | return proxy_.EvdoRegistrationState(); |
| 110 | } catch (const DBus::Error &e) { |
| 111 | LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what(); |
| 112 | return 0; // Make the compiler happy. |
| 113 | } |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 114 | }; |
| 115 | |
| 116 | // ModemModemCdmaProxy::Proxy |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 117 | ModemModemCdmaProxy::Proxy::Proxy(DBus::Connection *connection, |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 118 | const std::string &path, |
| 119 | const std::string &service) |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 120 | : DBus::ObjectProxy(*connection, path, service.c_str()) {} |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 121 | |
| 122 | ModemModemCdmaProxy::Proxy::~Proxy() {} |
| 123 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 124 | void ModemModemCdmaProxy::Proxy::set_activation_state_callback( |
| 125 | const ActivationStateSignalCallback &callback) { |
| 126 | activation_state_callback_ = callback; |
| 127 | } |
| 128 | |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 129 | // Signal callbacks inherited from Proxy |
| 130 | void ModemModemCdmaProxy::Proxy::ActivationStateChanged( |
| 131 | const uint32_t &activation_state, |
| 132 | const uint32_t &activation_error, |
| 133 | const DBusPropertiesMap &status_changes) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 134 | SLOG(DBus, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 135 | activation_state_callback_.Run(activation_state, |
| 136 | activation_error, |
| 137 | status_changes); |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | // Method callbacks inherited from |
| 141 | // org::freedesktop::ModemManager1::Modem::ModemModemCdmaProxy |
| 142 | void ModemModemCdmaProxy::Proxy::ActivateCallback(const ::DBus::Error& dberror, |
| 143 | void *data) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 144 | SLOG(DBus, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 145 | scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data)); |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 146 | Error error; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 147 | CellularError::FromDBusError(dberror, &error); |
| 148 | callback->Run(error); |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | void ModemModemCdmaProxy::Proxy::ActivateManualCallback( |
| 152 | const ::DBus::Error& dberror, |
| 153 | void *data) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 154 | SLOG(DBus, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 155 | scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data)); |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 156 | Error error; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 157 | CellularError::FromDBusError(dberror, &error); |
| 158 | callback->Run(error); |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | } // namespace mm1 |
| 162 | } // namespace shill |