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 { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 33 | SLOG(DBus, 2) << __func__; |
Jason Glasgow | 74f5ef2 | 2012-03-29 16:15:04 -0400 | [diff] [blame] | 34 | proxy_.SendPin(pin, cb.get(), timeout); |
| 35 | cb.release(); |
Ben Chan | 80326f3 | 2012-05-04 17:51:32 -0700 | [diff] [blame] | 36 | } catch (const DBus::Error &e) { |
Jason Glasgow | 74f5ef2 | 2012-03-29 16:15:04 -0400 | [diff] [blame] | 37 | if (error) |
| 38 | CellularError::FromDBusError(e, error); |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | void SimProxy::SendPuk(const string &puk, |
| 43 | const string &pin, |
| 44 | Error *error, |
| 45 | const ResultCallback &callback, |
| 46 | int timeout) { |
| 47 | // pin and puk are intentionally not logged. |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 48 | SLOG(Modem, 2) << __func__ << "( XXX, XXX, " << timeout << ")"; |
Jason Glasgow | 74f5ef2 | 2012-03-29 16:15:04 -0400 | [diff] [blame] | 49 | scoped_ptr<ResultCallback> cb(new ResultCallback(callback)); |
| 50 | try { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 51 | SLOG(DBus, 2) << __func__; |
Jason Glasgow | 74f5ef2 | 2012-03-29 16:15:04 -0400 | [diff] [blame] | 52 | proxy_.SendPuk(puk, pin, cb.get(), timeout); |
| 53 | cb.release(); |
Ben Chan | 80326f3 | 2012-05-04 17:51:32 -0700 | [diff] [blame] | 54 | } catch (const DBus::Error &e) { |
Jason Glasgow | 74f5ef2 | 2012-03-29 16:15:04 -0400 | [diff] [blame] | 55 | if (error) |
| 56 | CellularError::FromDBusError(e, error); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | void SimProxy::EnablePin(const string &pin, |
| 61 | const bool enabled, |
| 62 | Error *error, |
| 63 | const ResultCallback &callback, |
| 64 | int timeout) { |
| 65 | // pin is intentionally not logged. |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 66 | SLOG(Modem, 2) << __func__ << "( XXX, " << enabled << ", " << timeout << ")"; |
Jason Glasgow | 74f5ef2 | 2012-03-29 16:15:04 -0400 | [diff] [blame] | 67 | scoped_ptr<ResultCallback> cb(new ResultCallback(callback)); |
| 68 | try { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 69 | SLOG(DBus, 2) << __func__; |
Jason Glasgow | 74f5ef2 | 2012-03-29 16:15:04 -0400 | [diff] [blame] | 70 | proxy_.EnablePin(pin, enabled, cb.get(), timeout); |
| 71 | cb.release(); |
Ben Chan | 80326f3 | 2012-05-04 17:51:32 -0700 | [diff] [blame] | 72 | } catch (const DBus::Error &e) { |
Jason Glasgow | 74f5ef2 | 2012-03-29 16:15:04 -0400 | [diff] [blame] | 73 | if (error) |
| 74 | CellularError::FromDBusError(e, error); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | void SimProxy::ChangePin(const string &old_pin, |
| 79 | const string &new_pin, |
| 80 | Error *error, |
| 81 | const ResultCallback &callback, |
| 82 | int timeout) { |
| 83 | // old_pin and new_pin are intentionally not logged. |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 84 | SLOG(Modem, 2) << __func__ << "( XXX, XXX, " << timeout << ")"; |
Jason Glasgow | 74f5ef2 | 2012-03-29 16:15:04 -0400 | [diff] [blame] | 85 | scoped_ptr<ResultCallback> cb(new ResultCallback(callback)); |
| 86 | try { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 87 | SLOG(DBus, 2) << __func__; |
Jason Glasgow | 74f5ef2 | 2012-03-29 16:15:04 -0400 | [diff] [blame] | 88 | proxy_.ChangePin(old_pin, new_pin, cb.get(), timeout); |
| 89 | cb.release(); |
Ben Chan | 80326f3 | 2012-05-04 17:51:32 -0700 | [diff] [blame] | 90 | } catch (const DBus::Error &e) { |
Jason Glasgow | 74f5ef2 | 2012-03-29 16:15:04 -0400 | [diff] [blame] | 91 | if (error) |
| 92 | CellularError::FromDBusError(e, error); |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | // Inherited properties from SimProxyInterface. |
| 97 | const string SimProxy::SimIdentifier() { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 98 | SLOG(DBus, 2) << __func__; |
Gary Morain | 610977f | 2012-05-04 16:03:52 -0700 | [diff] [blame] | 99 | try { |
| 100 | return proxy_.SimIdentifier(); |
| 101 | } catch (const DBus::Error &e) { |
| 102 | LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what(); |
| 103 | return string(); // Make the compiler happy. |
| 104 | } |
Jason Glasgow | 74f5ef2 | 2012-03-29 16:15:04 -0400 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | const string SimProxy::Imsi() { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 108 | SLOG(DBus, 2) << __func__; |
Gary Morain | 610977f | 2012-05-04 16:03:52 -0700 | [diff] [blame] | 109 | try { |
| 110 | return proxy_.Imsi(); |
| 111 | } catch (const DBus::Error &e) { |
| 112 | LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what(); |
| 113 | return string(); // Make the compiler happy. |
| 114 | } |
Jason Glasgow | 74f5ef2 | 2012-03-29 16:15:04 -0400 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | const string SimProxy::OperatorIdentifier() { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 118 | SLOG(DBus, 2) << __func__; |
Gary Morain | 610977f | 2012-05-04 16:03:52 -0700 | [diff] [blame] | 119 | try { |
| 120 | return proxy_.OperatorIdentifier(); |
| 121 | } catch (const DBus::Error &e) { |
| 122 | LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what(); |
| 123 | return string(); // Make the compiler happy. |
| 124 | } |
Jason Glasgow | 74f5ef2 | 2012-03-29 16:15:04 -0400 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | const string SimProxy::OperatorName() { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 128 | SLOG(DBus, 2) << __func__; |
Gary Morain | 610977f | 2012-05-04 16:03:52 -0700 | [diff] [blame] | 129 | try { |
| 130 | return proxy_.OperatorName(); |
| 131 | } catch (const DBus::Error &e) { |
| 132 | LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what(); |
| 133 | return string(); // Make the compiler happy. |
| 134 | } |
Jason Glasgow | 74f5ef2 | 2012-03-29 16:15:04 -0400 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | SimProxy::Proxy::Proxy(DBus::Connection *connection, |
| 138 | const string &path, |
| 139 | const string &service) |
| 140 | : DBus::ObjectProxy(*connection, path, service.c_str()) {} |
| 141 | |
| 142 | SimProxy::Proxy::~Proxy() {} |
| 143 | |
| 144 | |
| 145 | // Method callbacks inherited from |
| 146 | // org::freedesktop::ModemManager1::SimProxy |
| 147 | void SimProxy::Proxy::SendPinCallback(const ::DBus::Error &dberror, |
| 148 | void *data) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 149 | SLOG(DBus, 2) << __func__; |
Jason Glasgow | 74f5ef2 | 2012-03-29 16:15:04 -0400 | [diff] [blame] | 150 | scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data)); |
| 151 | Error error; |
| 152 | CellularError::FromDBusError(dberror, &error); |
| 153 | callback->Run(error); |
| 154 | } |
| 155 | |
| 156 | void SimProxy::Proxy::SendPukCallback(const ::DBus::Error &dberror, |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 157 | void *data) { |
| 158 | SLOG(DBus, 2) << __func__; |
Jason Glasgow | 74f5ef2 | 2012-03-29 16:15:04 -0400 | [diff] [blame] | 159 | scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data)); |
| 160 | Error error; |
| 161 | CellularError::FromDBusError(dberror, &error); |
| 162 | callback->Run(error); |
| 163 | } |
| 164 | |
Gary Morain | abb30da | 2012-05-08 16:59:59 -0700 | [diff] [blame] | 165 | void SimProxy::Proxy::EnablePinCallback(const ::DBus::Error &dberror, |
| 166 | void *data) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 167 | SLOG(DBus, 2) << __func__; |
Jason Glasgow | 74f5ef2 | 2012-03-29 16:15:04 -0400 | [diff] [blame] | 168 | scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data)); |
| 169 | Error error; |
| 170 | CellularError::FromDBusError(dberror, &error); |
| 171 | callback->Run(error); |
| 172 | } |
| 173 | |
Gary Morain | abb30da | 2012-05-08 16:59:59 -0700 | [diff] [blame] | 174 | void SimProxy::Proxy::ChangePinCallback(const ::DBus::Error &dberror, |
| 175 | void *data) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 176 | SLOG(DBus, 2) << __func__; |
Jason Glasgow | 74f5ef2 | 2012-03-29 16:15:04 -0400 | [diff] [blame] | 177 | scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data)); |
| 178 | Error error; |
| 179 | CellularError::FromDBusError(dberror, &error); |
| 180 | callback->Run(error); |
| 181 | } |
| 182 | |
| 183 | } // namespace mm1 |
| 184 | } // namespace shill |