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(); |
| 33 | } catch (DBus::Error e) { |
| 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(); |
| 49 | } catch (DBus::Error e) { |
| 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__; |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 63 | return proxy_.Meid(); |
| 64 | }; |
| 65 | std::string ModemModemCdmaProxy::Esn() { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 66 | SLOG(DBus, 2) << __func__; |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 67 | return proxy_.Esn(); |
| 68 | }; |
| 69 | uint32_t ModemModemCdmaProxy::Sid() { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 70 | SLOG(DBus, 2) << __func__; |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 71 | return proxy_.Sid(); |
| 72 | }; |
| 73 | uint32_t ModemModemCdmaProxy::Nid() { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 74 | SLOG(DBus, 2) << __func__; |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 75 | return proxy_.Nid(); |
| 76 | }; |
| 77 | uint32_t ModemModemCdmaProxy::Cdma1xRegistrationState() { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 78 | SLOG(DBus, 2) << __func__; |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 79 | return proxy_.Cdma1xRegistrationState(); |
| 80 | }; |
| 81 | uint32_t ModemModemCdmaProxy::EvdoRegistrationState() { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 82 | SLOG(DBus, 2) << __func__; |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 83 | return proxy_.EvdoRegistrationState(); |
| 84 | }; |
| 85 | |
| 86 | // ModemModemCdmaProxy::Proxy |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 87 | ModemModemCdmaProxy::Proxy::Proxy(DBus::Connection *connection, |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 88 | const std::string &path, |
| 89 | const std::string &service) |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 90 | : DBus::ObjectProxy(*connection, path, service.c_str()) {} |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 91 | |
| 92 | ModemModemCdmaProxy::Proxy::~Proxy() {} |
| 93 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 94 | void ModemModemCdmaProxy::Proxy::set_activation_state_callback( |
| 95 | const ActivationStateSignalCallback &callback) { |
| 96 | activation_state_callback_ = callback; |
| 97 | } |
| 98 | |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 99 | // Signal callbacks inherited from Proxy |
| 100 | void ModemModemCdmaProxy::Proxy::ActivationStateChanged( |
| 101 | const uint32_t &activation_state, |
| 102 | const uint32_t &activation_error, |
| 103 | const DBusPropertiesMap &status_changes) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 104 | SLOG(DBus, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 105 | activation_state_callback_.Run(activation_state, |
| 106 | activation_error, |
| 107 | status_changes); |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | // Method callbacks inherited from |
| 111 | // org::freedesktop::ModemManager1::Modem::ModemModemCdmaProxy |
| 112 | void ModemModemCdmaProxy::Proxy::ActivateCallback(const ::DBus::Error& dberror, |
| 113 | void *data) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 114 | SLOG(DBus, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 115 | scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data)); |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 116 | Error error; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 117 | CellularError::FromDBusError(dberror, &error); |
| 118 | callback->Run(error); |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | void ModemModemCdmaProxy::Proxy::ActivateManualCallback( |
| 122 | const ::DBus::Error& dberror, |
| 123 | void *data) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 124 | SLOG(DBus, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 125 | scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data)); |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 126 | Error error; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 127 | CellularError::FromDBusError(dberror, &error); |
| 128 | callback->Run(error); |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | } // namespace mm1 |
| 132 | } // namespace shill |