shill: reduce some copy-paste in dbus proxies
When making asynchronous D-Bus calls, we have to take
care not to leak Callback objects. This code occurs
in many places, but differs only in types.
Factor this code out into a template, to remove code
duplication.
CQ-DEPEND=CL:195761
BUG=chromium:365390
TEST=unit tests
Change-Id: Ica63045a00b9bbd70b3e12cb0939f0d7f1af0e1d
Reviewed-on: https://chromium-review.googlesource.com/195762
Tested-by: mukesh agrawal <quiche@chromium.org>
Reviewed-by: Ben Chan <benchan@chromium.org>
Commit-Queue: mukesh agrawal <quiche@chromium.org>
diff --git a/mm1_modem_location_proxy.cc b/mm1_modem_location_proxy.cc
index ddfa3d3..b3ca0c1 100644
--- a/mm1_modem_location_proxy.cc
+++ b/mm1_modem_location_proxy.cc
@@ -5,6 +5,7 @@
#include "mm1_modem_location_proxy.h"
#include "shill/cellular_error.h"
+#include "shill/dbus_async_call_helper.h"
#include "shill/logging.h"
using std::string;
@@ -25,31 +26,17 @@
const ResultCallback &callback,
int timeout) {
SLOG(Modem, 2) << __func__;
- scoped_ptr<ResultCallback> cb(new ResultCallback(callback));
- try {
- SLOG(DBus, 2) << __func__;
- proxy_.Setup(sources, signal_location, cb.get(), timeout);
- cb.release();
- } catch (const DBus::Error &e) {
- if (error)
- CellularError::FromMM1DBusError(e, error);
- }
+ BeginAsyncDBusCall(__func__, proxy_, &Proxy::SetupAsync, callback,
+ error, &CellularError::FromMM1DBusError, timeout,
+ sources, signal_location);
}
void ModemLocationProxy::GetLocation(Error *error,
const DBusEnumValueMapCallback &callback,
int timeout) {
SLOG(Modem, 2) << __func__;
- scoped_ptr<DBusEnumValueMapCallback> cb(
- new DBusEnumValueMapCallback(callback));
- try {
- SLOG(DBus, 2) << __func__;
- proxy_.GetLocation(cb.get(), timeout);
- cb.release();
- } catch (const DBus::Error &e) {
- if (error)
- CellularError::FromMM1DBusError(e, error);
- }
+ BeginAsyncDBusCall(__func__, proxy_, &Proxy::GetLocationAsync, callback,
+ error, &CellularError::FromMM1DBusError, timeout);
}
ModemLocationProxy::Proxy::Proxy(DBus::Connection *connection,