blob: f6c8cd3bc120a9944842821b77c8cde7ad483f83 [file] [log] [blame]
Eric Shienbrood5de44ab2011-12-05 10:46:27 -05001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Darin Petkov975b5e72011-08-30 11:48:08 -07002// 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/modem_gsm_card_proxy.h"
6
Eric Shienbrood9a245532012-03-07 14:20:39 -05007#include <base/bind.h>
8
Eric Shienbrood5de44ab2011-12-05 10:46:27 -05009#include "shill/cellular_error.h"
10#include "shill/error.h"
11
Eric Shienbrood9a245532012-03-07 14:20:39 -050012using base::Bind;
13using base::Callback;
Darin Petkov975b5e72011-08-30 11:48:08 -070014using std::string;
15
16namespace shill {
17
Eric Shienbrood9a245532012-03-07 14:20:39 -050018ModemGSMCardProxy::ModemGSMCardProxy(DBus::Connection *connection,
Darin Petkov975b5e72011-08-30 11:48:08 -070019 const string &path,
20 const string &service)
Eric Shienbrood9a245532012-03-07 14:20:39 -050021 : proxy_(connection, path, service) {}
Darin Petkov975b5e72011-08-30 11:48:08 -070022
23ModemGSMCardProxy::~ModemGSMCardProxy() {}
24
Eric Shienbrood9a245532012-03-07 14:20:39 -050025void ModemGSMCardProxy::GetIMEI(Error *error,
26 const GSMIdentifierCallback &callback,
27 int timeout) {
28 scoped_ptr<GSMIdentifierCallback> cb(new GSMIdentifierCallback(callback));
29 try {
30 proxy_.GetImei(cb.get(), timeout);
31 cb.release();
32 } catch (DBus::Error e) {
33 if (error)
34 CellularError::FromDBusError(e, error);
35 }
Darin Petkov975b5e72011-08-30 11:48:08 -070036}
37
Eric Shienbrood9a245532012-03-07 14:20:39 -050038void ModemGSMCardProxy::GetIMSI(Error *error,
39 const GSMIdentifierCallback &callback,
40 int timeout) {
41 scoped_ptr<GSMIdentifierCallback> cb(new GSMIdentifierCallback(callback));
42 try {
43 proxy_.GetImsi(cb.get(), timeout);
44 cb.release();
45 } catch (DBus::Error e) {
46 if (error)
47 CellularError::FromDBusError(e, error);
48 }
Darin Petkov975b5e72011-08-30 11:48:08 -070049}
50
Eric Shienbrood9a245532012-03-07 14:20:39 -050051void ModemGSMCardProxy::GetSPN(Error *error,
52 const GSMIdentifierCallback &callback,
53 int timeout) {
54 scoped_ptr<GSMIdentifierCallback> cb(new GSMIdentifierCallback(callback));
55 try {
56 proxy_.GetSpn(cb.get(), timeout);
57 cb.release();
58 } catch (DBus::Error e) {
59 if (error)
60 CellularError::FromDBusError(e, error);
61 }
Darin Petkov975b5e72011-08-30 11:48:08 -070062}
63
Eric Shienbrood9a245532012-03-07 14:20:39 -050064void ModemGSMCardProxy::GetMSISDN(Error *error,
65 const GSMIdentifierCallback &callback,
66 int timeout) {
67 scoped_ptr<GSMIdentifierCallback> cb(new GSMIdentifierCallback(callback));
68 try {
69 proxy_.GetMsIsdn(cb.get(), timeout);
70 cb.release();
71 } catch (DBus::Error e) {
72 if (error)
73 CellularError::FromDBusError(e, error);
74 }
Darin Petkov975b5e72011-08-30 11:48:08 -070075}
76
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050077void ModemGSMCardProxy::EnablePIN(const string &pin, bool enabled,
Eric Shienbrood9a245532012-03-07 14:20:39 -050078 Error *error,
79 const ResultCallback &callback,
80 int timeout) {
81 scoped_ptr<ResultCallback> cb(new ResultCallback(callback));
82 try {
83 proxy_.EnablePin(pin, enabled, cb.get(), timeout);
84 cb.release();
85 } catch (DBus::Error e) {
86 if (error)
87 CellularError::FromDBusError(e, error);
88 }
Darin Petkove42e1012011-08-31 12:35:04 -070089}
90
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050091void ModemGSMCardProxy::SendPIN(const string &pin,
Eric Shienbrood9a245532012-03-07 14:20:39 -050092 Error *error,
93 const ResultCallback &callback,
94 int timeout) {
95 scoped_ptr<ResultCallback> cb(new ResultCallback(callback));
96 try {
97 proxy_.SendPin(pin, cb.get(), timeout);
98 cb.release();
99 } catch (DBus::Error e) {
100 if (error)
101 CellularError::FromDBusError(e, error);
102 }
Darin Petkove42e1012011-08-31 12:35:04 -0700103}
104
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500105void ModemGSMCardProxy::SendPUK(const string &puk, const string &pin,
Eric Shienbrood9a245532012-03-07 14:20:39 -0500106 Error *error,
107 const ResultCallback &callback,
108 int timeout) {
109 scoped_ptr<ResultCallback> cb(new ResultCallback(callback));
110 try {
111 proxy_.SendPuk(puk, pin, cb.get(), timeout);
112 cb.release();
113 } catch (DBus::Error e) {
114 if (error)
115 CellularError::FromDBusError(e, error);
116 }
Darin Petkove42e1012011-08-31 12:35:04 -0700117}
118
119void ModemGSMCardProxy::ChangePIN(const string &old_pin,
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500120 const string &new_pin,
Eric Shienbrood9a245532012-03-07 14:20:39 -0500121 Error *error,
122 const ResultCallback &callback,
123 int timeout) {
124 scoped_ptr<ResultCallback> cb(new ResultCallback(callback));
125 try {
126 proxy_.ChangePin(old_pin, new_pin, cb.get(), timeout);
127 cb.release();
128 } catch (DBus::Error e) {
129 if (error)
130 CellularError::FromDBusError(e, error);
131 }
Darin Petkove42e1012011-08-31 12:35:04 -0700132}
133
Darin Petkov63138a92012-02-06 14:09:15 +0100134uint32 ModemGSMCardProxy::EnabledFacilityLocks() {
135 return proxy_.EnabledFacilityLocks();
136}
137
Eric Shienbrood9a245532012-03-07 14:20:39 -0500138ModemGSMCardProxy::Proxy::Proxy(DBus::Connection *connection,
Darin Petkov975b5e72011-08-30 11:48:08 -0700139 const string &path,
140 const string &service)
Eric Shienbrood9a245532012-03-07 14:20:39 -0500141 : DBus::ObjectProxy(*connection, path, service.c_str()) {}
142
143void ModemGSMCardProxy::Proxy::GetIdCallback(const string &id,
144 const DBus::Error &dberror,
145 void *data) {
146 scoped_ptr<GSMIdentifierCallback> callback(
147 reinterpret_cast<GSMIdentifierCallback *>(data));
148 Error error;
149 CellularError::FromDBusError(dberror, &error);
150 callback->Run(id, error);
151}
Darin Petkov975b5e72011-08-30 11:48:08 -0700152
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500153void ModemGSMCardProxy::Proxy::GetImeiCallback(const string &imei,
154 const DBus::Error &dberror,
155 void *data) {
Eric Shienbrood9a245532012-03-07 14:20:39 -0500156 GetIdCallback(imei, dberror, data);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500157}
158
159void ModemGSMCardProxy::Proxy::GetImsiCallback(const string &imsi,
160 const DBus::Error &dberror,
161 void *data) {
Eric Shienbrood9a245532012-03-07 14:20:39 -0500162 GetIdCallback(imsi, dberror, data);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500163}
164
165void ModemGSMCardProxy::Proxy::GetSpnCallback(const string &spn,
166 const DBus::Error &dberror,
167 void *data) {
Eric Shienbrood9a245532012-03-07 14:20:39 -0500168 GetIdCallback(spn, dberror, data);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500169}
170
Eric Shienbrood9a245532012-03-07 14:20:39 -0500171void ModemGSMCardProxy::Proxy::GetMsIsdnCallback(const string &msisdn,
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500172 const DBus::Error &dberror,
173 void *data) {
Eric Shienbrood9a245532012-03-07 14:20:39 -0500174 GetIdCallback(msisdn, dberror, data);
175}
176
177void ModemGSMCardProxy::Proxy::PinCallback(const DBus::Error &dberror,
178 void *data) {
179 scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data));
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500180 Error error;
181 CellularError::FromDBusError(dberror, &error);
Eric Shienbrood9a245532012-03-07 14:20:39 -0500182 callback->Run(error);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500183}
184
185void ModemGSMCardProxy::Proxy::EnablePinCallback(const DBus::Error &dberror,
186 void *data) {
Eric Shienbrood9a245532012-03-07 14:20:39 -0500187 PinCallback(dberror, data);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500188}
189
190void ModemGSMCardProxy::Proxy::SendPinCallback(const DBus::Error &dberror,
191 void *data) {
Eric Shienbrood9a245532012-03-07 14:20:39 -0500192 PinCallback(dberror, data);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500193}
194
195void ModemGSMCardProxy::Proxy::SendPukCallback(const DBus::Error &dberror,
196 void *data) {
Eric Shienbrood9a245532012-03-07 14:20:39 -0500197 PinCallback(dberror, data);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500198}
199
200void ModemGSMCardProxy::Proxy::ChangePinCallback(const DBus::Error &dberror,
201 void *data) {
Eric Shienbrood9a245532012-03-07 14:20:39 -0500202 PinCallback(dberror, data);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500203}
204
Darin Petkov975b5e72011-08-30 11:48:08 -0700205ModemGSMCardProxy::Proxy::~Proxy() {}
206
207} // namespace shill