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