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) |
| 33 | CellularError::FromDBusError(e, error); |
| 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) |
| 49 | CellularError::FromDBusError(e, error); |
| 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 | }; |
| 77 | uint32_t ModemModemCdmaProxy::Sid() { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 78 | SLOG(DBus, 2) << __func__; |
Gary Morain | 610977f | 2012-05-04 16:03:52 -0700 | [diff] [blame] | 79 | try { |
| 80 | return proxy_.Sid(); |
| 81 | } catch (const DBus::Error &e) { |
| 82 | LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what(); |
| 83 | return 0; // Make the compiler happy. |
| 84 | } |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 85 | }; |
| 86 | uint32_t ModemModemCdmaProxy::Nid() { |
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_.Nid(); |
| 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::Cdma1xRegistrationState() { |
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_.Cdma1xRegistrationState(); |
| 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::EvdoRegistrationState() { |
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_.EvdoRegistrationState(); |
| 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 | |
| 114 | // ModemModemCdmaProxy::Proxy |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 115 | ModemModemCdmaProxy::Proxy::Proxy(DBus::Connection *connection, |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 116 | const std::string &path, |
| 117 | const std::string &service) |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 118 | : DBus::ObjectProxy(*connection, path, service.c_str()) {} |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 119 | |
| 120 | ModemModemCdmaProxy::Proxy::~Proxy() {} |
| 121 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 122 | void ModemModemCdmaProxy::Proxy::set_activation_state_callback( |
| 123 | const ActivationStateSignalCallback &callback) { |
| 124 | activation_state_callback_ = callback; |
| 125 | } |
| 126 | |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 127 | // Signal callbacks inherited from Proxy |
| 128 | void ModemModemCdmaProxy::Proxy::ActivationStateChanged( |
| 129 | const uint32_t &activation_state, |
| 130 | const uint32_t &activation_error, |
| 131 | const DBusPropertiesMap &status_changes) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 132 | SLOG(DBus, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 133 | activation_state_callback_.Run(activation_state, |
| 134 | activation_error, |
| 135 | status_changes); |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | // Method callbacks inherited from |
| 139 | // org::freedesktop::ModemManager1::Modem::ModemModemCdmaProxy |
| 140 | void ModemModemCdmaProxy::Proxy::ActivateCallback(const ::DBus::Error& dberror, |
| 141 | void *data) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 142 | SLOG(DBus, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 143 | scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data)); |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 144 | Error error; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 145 | CellularError::FromDBusError(dberror, &error); |
| 146 | callback->Run(error); |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | void ModemModemCdmaProxy::Proxy::ActivateManualCallback( |
| 150 | const ::DBus::Error& dberror, |
| 151 | void *data) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 152 | SLOG(DBus, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 153 | scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data)); |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 154 | Error error; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 155 | CellularError::FromDBusError(dberror, &error); |
| 156 | callback->Run(error); |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | } // namespace mm1 |
| 160 | } // namespace shill |