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