blob: f42c98c490dca38eb9fab027d1305fd147c11ced [file] [log] [blame]
Jason Glasgow74f5ef22012-03-29 16:15:04 -04001// 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 Chanfad4a0b2012-04-18 15:49:59 -07009#include "shill/cellular_error.h"
10#include "shill/scope_logger.h"
Jason Glasgow74f5ef22012-03-29 16:15:04 -040011
12using std::string;
13
14namespace shill {
15namespace mm1 {
16
17SimProxy::SimProxy(DBus::Connection *connection,
18 const string &path,
19 const string &service)
20 : proxy_(connection, path, service) {}
21
22SimProxy::~SimProxy() {}
23
24
25void SimProxy::SendPin(const string &pin,
26 Error *error,
27 const ResultCallback &callback,
28 int timeout) {
29 // pin is intentionally not logged.
Ben Chanfad4a0b2012-04-18 15:49:59 -070030 SLOG(Modem, 2) << __func__ << "( XXX, " << timeout << ")";
Jason Glasgow74f5ef22012-03-29 16:15:04 -040031 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
41void 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 Chanfad4a0b2012-04-18 15:49:59 -070047 SLOG(Modem, 2) << __func__ << "( XXX, XXX, " << timeout << ")";
Jason Glasgow74f5ef22012-03-29 16:15:04 -040048 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
58void 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 Chanfad4a0b2012-04-18 15:49:59 -070064 SLOG(Modem, 2) << __func__ << "( XXX, " << enabled << ", " << timeout << ")";
Jason Glasgow74f5ef22012-03-29 16:15:04 -040065 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
75void 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 Chanfad4a0b2012-04-18 15:49:59 -070081 SLOG(Modem, 2) << __func__ << "( XXX, XXX, " << timeout << ")";
Jason Glasgow74f5ef22012-03-29 16:15:04 -040082 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.
93const string SimProxy::SimIdentifier() {
94 return proxy_.SimIdentifier();
95}
96
97const string SimProxy::Imsi() {
98 return proxy_.Imsi();
99}
100
101const string SimProxy::OperatorIdentifier() {
102 return proxy_.OperatorIdentifier();
103}
104
105const string SimProxy::OperatorName() {
106 return proxy_.OperatorName();
107}
108
109SimProxy::Proxy::Proxy(DBus::Connection *connection,
110 const string &path,
111 const string &service)
112 : DBus::ObjectProxy(*connection, path, service.c_str()) {}
113
114SimProxy::Proxy::~Proxy() {}
115
116
117// Method callbacks inherited from
118// org::freedesktop::ModemManager1::SimProxy
119void 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
127void 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
135void 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
143void 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