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 | |
| 9 | #include "cellular_error.h" |
| 10 | |
| 11 | using std::string; |
| 12 | |
| 13 | namespace shill { |
| 14 | namespace mm1 { |
| 15 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 16 | ModemModemCdmaProxy::ModemModemCdmaProxy(DBus::Connection *connection, |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [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) {} |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 20 | |
| 21 | ModemModemCdmaProxy::~ModemModemCdmaProxy() {} |
| 22 | |
| 23 | void ModemModemCdmaProxy::Activate(const std::string &carrier, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 24 | Error *error, |
| 25 | const ResultCallback &callback, |
| 26 | int timeout) { |
| 27 | scoped_ptr<ResultCallback> cb(new ResultCallback(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 | } |
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 { |
| 44 | proxy_.ActivateManual(properties, cb.get(), timeout); |
| 45 | cb.release(); |
| 46 | } catch (DBus::Error e) { |
| 47 | if (error) |
| 48 | CellularError::FromDBusError(e, error); |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | void ModemModemCdmaProxy::set_activation_state_callback( |
| 53 | const ActivationStateSignalCallback &callback) { |
| 54 | proxy_.set_activation_state_callback(callback); |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | // Inherited properties from ModemModemCdmaProxyInterface. |
| 58 | std::string ModemModemCdmaProxy::Meid() { |
| 59 | return proxy_.Meid(); |
| 60 | }; |
| 61 | std::string ModemModemCdmaProxy::Esn() { |
| 62 | return proxy_.Esn(); |
| 63 | }; |
| 64 | uint32_t ModemModemCdmaProxy::Sid() { |
| 65 | return proxy_.Sid(); |
| 66 | }; |
| 67 | uint32_t ModemModemCdmaProxy::Nid() { |
| 68 | return proxy_.Nid(); |
| 69 | }; |
| 70 | uint32_t ModemModemCdmaProxy::Cdma1xRegistrationState() { |
| 71 | return proxy_.Cdma1xRegistrationState(); |
| 72 | }; |
| 73 | uint32_t ModemModemCdmaProxy::EvdoRegistrationState() { |
| 74 | return proxy_.EvdoRegistrationState(); |
| 75 | }; |
| 76 | |
| 77 | // ModemModemCdmaProxy::Proxy |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 78 | ModemModemCdmaProxy::Proxy::Proxy(DBus::Connection *connection, |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 79 | const std::string &path, |
| 80 | const std::string &service) |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 81 | : DBus::ObjectProxy(*connection, path, service.c_str()) {} |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 82 | |
| 83 | ModemModemCdmaProxy::Proxy::~Proxy() {} |
| 84 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 85 | void ModemModemCdmaProxy::Proxy::set_activation_state_callback( |
| 86 | const ActivationStateSignalCallback &callback) { |
| 87 | activation_state_callback_ = callback; |
| 88 | } |
| 89 | |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 90 | // Signal callbacks inherited from Proxy |
| 91 | void ModemModemCdmaProxy::Proxy::ActivationStateChanged( |
| 92 | const uint32_t &activation_state, |
| 93 | const uint32_t &activation_error, |
| 94 | const DBusPropertiesMap &status_changes) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 95 | activation_state_callback_.Run(activation_state, |
| 96 | activation_error, |
| 97 | status_changes); |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | // Method callbacks inherited from |
| 101 | // org::freedesktop::ModemManager1::Modem::ModemModemCdmaProxy |
| 102 | void ModemModemCdmaProxy::Proxy::ActivateCallback(const ::DBus::Error& dberror, |
| 103 | void *data) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 104 | scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data)); |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 105 | Error error; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 106 | CellularError::FromDBusError(dberror, &error); |
| 107 | callback->Run(error); |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | void ModemModemCdmaProxy::Proxy::ActivateManualCallback( |
| 111 | const ::DBus::Error& dberror, |
| 112 | void *data) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 113 | scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data)); |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 114 | Error error; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 115 | CellularError::FromDBusError(dberror, &error); |
| 116 | callback->Run(error); |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | } // namespace mm1 |
| 120 | } // namespace shill |