Jason Glasgow | 74f5ef2 | 2012-03-29 16:15:04 -0400 | [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_sim_proxy.h" |
| 6 | |
| 7 | #include <base/logging.h> |
| 8 | |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 9 | #include "shill/cellular_error.h" |
| 10 | #include "shill/scope_logger.h" |
Jason Glasgow | 74f5ef2 | 2012-03-29 16:15:04 -0400 | [diff] [blame] | 11 | |
| 12 | using std::string; |
| 13 | |
| 14 | namespace shill { |
| 15 | namespace mm1 { |
| 16 | |
| 17 | SimProxy::SimProxy(DBus::Connection *connection, |
| 18 | const string &path, |
| 19 | const string &service) |
| 20 | : proxy_(connection, path, service) {} |
| 21 | |
| 22 | SimProxy::~SimProxy() {} |
| 23 | |
| 24 | |
| 25 | void SimProxy::SendPin(const string &pin, |
| 26 | Error *error, |
| 27 | const ResultCallback &callback, |
| 28 | int timeout) { |
| 29 | // pin is intentionally not logged. |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 30 | SLOG(Modem, 2) << __func__ << "( XXX, " << timeout << ")"; |
Jason Glasgow | 74f5ef2 | 2012-03-29 16:15:04 -0400 | [diff] [blame] | 31 | scoped_ptr<ResultCallback> cb(new ResultCallback(callback)); |
| 32 | try { |
| 33 | proxy_.SendPin(pin, cb.get(), timeout); |
| 34 | cb.release(); |
| 35 | } catch (DBus::Error e) { |
| 36 | if (error) |
| 37 | CellularError::FromDBusError(e, error); |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | void SimProxy::SendPuk(const string &puk, |
| 42 | const string &pin, |
| 43 | Error *error, |
| 44 | const ResultCallback &callback, |
| 45 | int timeout) { |
| 46 | // pin and puk are intentionally not logged. |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 47 | SLOG(Modem, 2) << __func__ << "( XXX, XXX, " << timeout << ")"; |
Jason Glasgow | 74f5ef2 | 2012-03-29 16:15:04 -0400 | [diff] [blame] | 48 | scoped_ptr<ResultCallback> cb(new ResultCallback(callback)); |
| 49 | try { |
| 50 | proxy_.SendPuk(puk, pin, cb.get(), timeout); |
| 51 | cb.release(); |
| 52 | } catch (DBus::Error e) { |
| 53 | if (error) |
| 54 | CellularError::FromDBusError(e, error); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | void SimProxy::EnablePin(const string &pin, |
| 59 | const bool enabled, |
| 60 | Error *error, |
| 61 | const ResultCallback &callback, |
| 62 | int timeout) { |
| 63 | // pin is intentionally not logged. |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 64 | SLOG(Modem, 2) << __func__ << "( XXX, " << enabled << ", " << timeout << ")"; |
Jason Glasgow | 74f5ef2 | 2012-03-29 16:15:04 -0400 | [diff] [blame] | 65 | scoped_ptr<ResultCallback> cb(new ResultCallback(callback)); |
| 66 | try { |
| 67 | proxy_.EnablePin(pin, enabled, cb.get(), timeout); |
| 68 | cb.release(); |
| 69 | } catch (DBus::Error e) { |
| 70 | if (error) |
| 71 | CellularError::FromDBusError(e, error); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | void SimProxy::ChangePin(const string &old_pin, |
| 76 | const string &new_pin, |
| 77 | Error *error, |
| 78 | const ResultCallback &callback, |
| 79 | int timeout) { |
| 80 | // old_pin and new_pin are intentionally not logged. |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 81 | SLOG(Modem, 2) << __func__ << "( XXX, XXX, " << timeout << ")"; |
Jason Glasgow | 74f5ef2 | 2012-03-29 16:15:04 -0400 | [diff] [blame] | 82 | scoped_ptr<ResultCallback> cb(new ResultCallback(callback)); |
| 83 | try { |
| 84 | proxy_.ChangePin(old_pin, new_pin, cb.get(), timeout); |
| 85 | cb.release(); |
| 86 | } catch (DBus::Error e) { |
| 87 | if (error) |
| 88 | CellularError::FromDBusError(e, error); |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | // Inherited properties from SimProxyInterface. |
| 93 | const string SimProxy::SimIdentifier() { |
| 94 | return proxy_.SimIdentifier(); |
| 95 | } |
| 96 | |
| 97 | const string SimProxy::Imsi() { |
| 98 | return proxy_.Imsi(); |
| 99 | } |
| 100 | |
| 101 | const string SimProxy::OperatorIdentifier() { |
| 102 | return proxy_.OperatorIdentifier(); |
| 103 | } |
| 104 | |
| 105 | const string SimProxy::OperatorName() { |
| 106 | return proxy_.OperatorName(); |
| 107 | } |
| 108 | |
| 109 | SimProxy::Proxy::Proxy(DBus::Connection *connection, |
| 110 | const string &path, |
| 111 | const string &service) |
| 112 | : DBus::ObjectProxy(*connection, path, service.c_str()) {} |
| 113 | |
| 114 | SimProxy::Proxy::~Proxy() {} |
| 115 | |
| 116 | |
| 117 | // Method callbacks inherited from |
| 118 | // org::freedesktop::ModemManager1::SimProxy |
| 119 | void SimProxy::Proxy::SendPinCallback(const ::DBus::Error &dberror, |
| 120 | void *data) { |
| 121 | scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data)); |
| 122 | Error error; |
| 123 | CellularError::FromDBusError(dberror, &error); |
| 124 | callback->Run(error); |
| 125 | } |
| 126 | |
| 127 | void SimProxy::Proxy::SendPukCallback(const ::DBus::Error &dberror, |
| 128 | void *data) { |
| 129 | scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data)); |
| 130 | Error error; |
| 131 | CellularError::FromDBusError(dberror, &error); |
| 132 | callback->Run(error); |
| 133 | } |
| 134 | |
| 135 | void SimProxy::Proxy::EnableCallback(const ::DBus::Error &dberror, |
| 136 | void *data) { |
| 137 | scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data)); |
| 138 | Error error; |
| 139 | CellularError::FromDBusError(dberror, &error); |
| 140 | callback->Run(error); |
| 141 | } |
| 142 | |
| 143 | void SimProxy::Proxy::ChangeCallback(const ::DBus::Error &dberror, |
| 144 | void *data) { |
| 145 | scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data)); |
| 146 | Error error; |
| 147 | CellularError::FromDBusError(dberror, &error); |
| 148 | callback->Run(error); |
| 149 | } |
| 150 | |
| 151 | } // namespace mm1 |
| 152 | } // namespace shill |