shill: Add ModemManager1.Sim proxy interface and class
Add ModemManager1.Sim proxy interface and class
BUG=chromium-os:27531
TEST=run unit tests, will be tested when MM1 capabilities object is ready
Change-Id: I69d4a089d295cb26c0a528ebdda03b658d29ae0e
Reviewed-on: https://gerrit.chromium.org/gerrit/19317
Commit-Ready: Jason Glasgow <jglasgow@chromium.org>
Reviewed-by: Jason Glasgow <jglasgow@chromium.org>
Tested-by: Jason Glasgow <jglasgow@chromium.org>
diff --git a/Makefile b/Makefile
index 243bde9..95eb0fc 100644
--- a/Makefile
+++ b/Makefile
@@ -60,7 +60,8 @@
org.freedesktop.ModemManager1.Modem>mm1-modem \
org.freedesktop.ModemManager1.Modem.Modem3gpp>mm1-modem-modem3gpp \
org.freedesktop.ModemManager1.Modem.ModemCdma>mm1-modem-modemcdma \
- org.freedesktop.ModemManager1.Modem.Simple>mm1-modem-simple
+ org.freedesktop.ModemManager1.Modem.Simple>mm1-modem-simple \
+ org.freedesktop.ModemManager1.Sim>mm1-sim
# Rename local XML files with the names required by DBus to XML files with the
# names required by the style guide, which will then be turned into generated
@@ -148,6 +149,7 @@
mm1_modem_modemcdma_proxy.o \
mm1_modem_proxy.o \
mm1_modem_simple_proxy.o \
+ mm1_sim_proxy.o \
modem.o \
modem_cdma_proxy.o \
modem_gsm_card_proxy.o \
diff --git a/mm1_sim_proxy.cc b/mm1_sim_proxy.cc
new file mode 100644
index 0000000..b7f34fd
--- /dev/null
+++ b/mm1_sim_proxy.cc
@@ -0,0 +1,151 @@
+// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "shill/mm1_sim_proxy.h"
+
+#include <base/logging.h>
+
+#include "cellular_error.h"
+
+using std::string;
+
+namespace shill {
+namespace mm1 {
+
+SimProxy::SimProxy(DBus::Connection *connection,
+ const string &path,
+ const string &service)
+ : proxy_(connection, path, service) {}
+
+SimProxy::~SimProxy() {}
+
+
+void SimProxy::SendPin(const string &pin,
+ Error *error,
+ const ResultCallback &callback,
+ int timeout) {
+ // pin is intentionally not logged.
+ VLOG(2) << __func__ << "( XXX, " << timeout << ")";
+ scoped_ptr<ResultCallback> cb(new ResultCallback(callback));
+ try {
+ proxy_.SendPin(pin, cb.get(), timeout);
+ cb.release();
+ } catch (DBus::Error e) {
+ if (error)
+ CellularError::FromDBusError(e, error);
+ }
+}
+
+void SimProxy::SendPuk(const string &puk,
+ const string &pin,
+ Error *error,
+ const ResultCallback &callback,
+ int timeout) {
+ // pin and puk are intentionally not logged.
+ VLOG(2) << __func__ << "( XXX, XXX, " << timeout << ")";
+ scoped_ptr<ResultCallback> cb(new ResultCallback(callback));
+ try {
+ proxy_.SendPuk(puk, pin, cb.get(), timeout);
+ cb.release();
+ } catch (DBus::Error e) {
+ if (error)
+ CellularError::FromDBusError(e, error);
+ }
+}
+
+void SimProxy::EnablePin(const string &pin,
+ const bool enabled,
+ Error *error,
+ const ResultCallback &callback,
+ int timeout) {
+ // pin is intentionally not logged.
+ VLOG(2) << __func__ << "( XXX, " << enabled << ", " << timeout << ")";
+ scoped_ptr<ResultCallback> cb(new ResultCallback(callback));
+ try {
+ proxy_.EnablePin(pin, enabled, cb.get(), timeout);
+ cb.release();
+ } catch (DBus::Error e) {
+ if (error)
+ CellularError::FromDBusError(e, error);
+ }
+}
+
+void SimProxy::ChangePin(const string &old_pin,
+ const string &new_pin,
+ Error *error,
+ const ResultCallback &callback,
+ int timeout) {
+ // old_pin and new_pin are intentionally not logged.
+ VLOG(2) << __func__ << "( XXX, XXX, " << timeout << ")";
+ scoped_ptr<ResultCallback> cb(new ResultCallback(callback));
+ try {
+ proxy_.ChangePin(old_pin, new_pin, cb.get(), timeout);
+ cb.release();
+ } catch (DBus::Error e) {
+ if (error)
+ CellularError::FromDBusError(e, error);
+ }
+}
+
+// Inherited properties from SimProxyInterface.
+const string SimProxy::SimIdentifier() {
+ return proxy_.SimIdentifier();
+}
+
+const string SimProxy::Imsi() {
+ return proxy_.Imsi();
+}
+
+const string SimProxy::OperatorIdentifier() {
+ return proxy_.OperatorIdentifier();
+}
+
+const string SimProxy::OperatorName() {
+ return proxy_.OperatorName();
+}
+
+SimProxy::Proxy::Proxy(DBus::Connection *connection,
+ const string &path,
+ const string &service)
+ : DBus::ObjectProxy(*connection, path, service.c_str()) {}
+
+SimProxy::Proxy::~Proxy() {}
+
+
+// Method callbacks inherited from
+// org::freedesktop::ModemManager1::SimProxy
+void SimProxy::Proxy::SendPinCallback(const ::DBus::Error &dberror,
+ void *data) {
+ scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data));
+ Error error;
+ CellularError::FromDBusError(dberror, &error);
+ callback->Run(error);
+}
+
+void SimProxy::Proxy::SendPukCallback(const ::DBus::Error &dberror,
+ void *data) {
+ scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data));
+ Error error;
+ CellularError::FromDBusError(dberror, &error);
+ callback->Run(error);
+}
+
+void SimProxy::Proxy::EnableCallback(const ::DBus::Error &dberror,
+ void *data) {
+ scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data));
+ Error error;
+ CellularError::FromDBusError(dberror, &error);
+ callback->Run(error);
+}
+
+void SimProxy::Proxy::ChangeCallback(const ::DBus::Error &dberror,
+ void *data) {
+ scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data));
+ Error error;
+ CellularError::FromDBusError(dberror, &error);
+ callback->Run(error);
+}
+
+} // namespace mm1
+} // namespace shill
diff --git a/mm1_sim_proxy.h b/mm1_sim_proxy.h
new file mode 100644
index 0000000..1b98ecd
--- /dev/null
+++ b/mm1_sim_proxy.h
@@ -0,0 +1,85 @@
+// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef SHILL_MM1_SIM_PROXY_
+#define SHILL_MM1_SIM_PROXY_
+
+#include <string>
+
+#include "shill/dbus_bindings/mm1-sim.h"
+#include "shill/dbus_properties.h"
+#include "shill/mm1_sim_proxy_interface.h"
+
+namespace shill {
+namespace mm1 {
+
+class SimProxy : public SimProxyInterface {
+ public:
+ // Constructs a org.freedesktop.ModemManager1.Modem DBus object
+ // proxy at |path| owned by |service|.
+ SimProxy(DBus::Connection *connection,
+ const std::string &path,
+ const std::string &service);
+ virtual ~SimProxy();
+
+ // Inherited methods from SimProxyInterface.
+ virtual void SendPin(const std::string &pin,
+ Error *error,
+ const ResultCallback &callback,
+ int timeout);
+ virtual void SendPuk(const std::string &puk,
+ const std::string &pin,
+ Error *error,
+ const ResultCallback &callback,
+ int timeout);
+ virtual void EnablePin(const std::string &pin,
+ const bool enabled,
+ Error *error,
+ const ResultCallback &callback,
+ int timeout);
+ virtual void ChangePin(const std::string &old_pin,
+ const std::string &new_pin,
+ Error *error,
+ const ResultCallback &callback,
+ int timeout);
+
+ // Inherited properties from SimProxyInterface.
+ virtual const std::string SimIdentifier();
+ virtual const std::string Imsi();
+ virtual const std::string OperatorIdentifier();
+ virtual const std::string OperatorName();
+
+ private:
+ class Proxy : public org::freedesktop::ModemManager1::Sim_proxy,
+ public DBus::ObjectProxy {
+ public:
+ Proxy(DBus::Connection *connection,
+ const std::string &path,
+ const std::string &service);
+ virtual ~Proxy();
+
+ private:
+ // Method callbacks inherited from
+ // org::freedesktop::ModemManager1::SimProxy
+ virtual void SendPinCallback(const ::DBus::Error &dberror,
+ void *data);
+ virtual void SendPukCallback(const ::DBus::Error &dberror,
+ void *data);
+ virtual void EnableCallback(const ::DBus::Error &dberror,
+ void *data);
+ virtual void ChangeCallback(const ::DBus::Error &dberror,
+ void *data);
+
+ DISALLOW_COPY_AND_ASSIGN(Proxy);
+ };
+
+ Proxy proxy_;
+
+ DISALLOW_COPY_AND_ASSIGN(SimProxy);
+};
+
+} // namespace mm1
+} // namespace shill
+
+#endif // SHILL_MM1_SIM_PROXY_
diff --git a/mm1_sim_proxy_interface.h b/mm1_sim_proxy_interface.h
new file mode 100644
index 0000000..cf7517c
--- /dev/null
+++ b/mm1_sim_proxy_interface.h
@@ -0,0 +1,58 @@
+// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef SHILL_MM1_SIM_PROXY_INTERFACE_
+#define SHILL_MM1_SIM_PROXY_INTERFACE_
+
+#include <string>
+
+#include <base/basictypes.h>
+
+#include "shill/callbacks.h"
+
+namespace shill {
+
+class Error;
+
+namespace mm1 {
+
+// These are the methods that a org.freedesktop.ModemManager1.Sim
+// proxy must support. The interface is provided so that it can be
+// mocked in tests. All calls are made asynchronously. Call completion
+// is signalled via the callbacks passed to the methods.
+class SimProxyInterface {
+ public:
+ virtual ~SimProxyInterface() {}
+
+ virtual void SendPin(const std::string &pin,
+ Error *error,
+ const ResultCallback &callback,
+ int timeout) = 0;
+ virtual void SendPuk(const std::string &puk,
+ const std::string &pin,
+ Error *error,
+ const ResultCallback &callback,
+ int timeout) = 0;
+ virtual void EnablePin(const std::string &pin,
+ const bool enabled,
+ Error *error,
+ const ResultCallback &callback,
+ int timeout) = 0;
+ virtual void ChangePin(const std::string &old_pin,
+ const std::string &new_pin,
+ Error *error,
+ const ResultCallback &callback,
+ int timeout) = 0;
+
+ // Properties.
+ virtual const std::string SimIdentifier() = 0;
+ virtual const std::string Imsi() = 0;
+ virtual const std::string OperatorIdentifier() = 0;
+ virtual const std::string OperatorName() = 0;
+};
+
+} // namespace mm1
+} // namespace shill
+
+#endif // SHILL_MM1_SIM_PROXY_INTERFACE_