blob: 01bf8499741940ac97f938e4c0a3ea15c93b0a2c [file] [log] [blame]
Eric Shienbrood5de44ab2011-12-05 10:46:27 -05001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Darin Petkove604f702011-07-28 15:51:17 -07002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Ben Chanc54afe52014-11-05 10:28:08 -08005#include "shill/cellular/modem_simple_proxy.h"
Darin Petkove604f702011-07-28 15:51:17 -07006
Ben Chanc20ed132014-10-16 12:25:03 -07007#include <memory>
8
Eric Shienbrood9a245532012-03-07 14:20:39 -05009#include <base/bind.h>
10
Ben Chanc54afe52014-11-05 10:28:08 -080011#include "shill/cellular/cellular_error.h"
mukesh agrawal0e9e9d12014-04-18 16:09:58 -070012#include "shill/dbus_async_call_helper.h"
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050013#include "shill/error.h"
Christopher Wileyb691efd2012-08-09 13:51:51 -070014#include "shill/logging.h"
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050015
Eric Shienbrood9a245532012-03-07 14:20:39 -050016using base::Bind;
17using base::Callback;
Darin Petkove604f702011-07-28 15:51:17 -070018using std::string;
Ben Chanc20ed132014-10-16 12:25:03 -070019using std::unique_ptr;
Darin Petkove604f702011-07-28 15:51:17 -070020
21namespace shill {
22
Eric Shienbrood9a245532012-03-07 14:20:39 -050023typedef Callback<void(const DBusPropertiesMap &,
24 const Error &)> ModemStatusCallback;
25
26ModemSimpleProxy::ModemSimpleProxy(DBus::Connection *connection,
Darin Petkove604f702011-07-28 15:51:17 -070027 const string &path,
28 const string &service)
Eric Shienbrood9a245532012-03-07 14:20:39 -050029 : proxy_(connection, path, service) {}
Darin Petkove604f702011-07-28 15:51:17 -070030
31ModemSimpleProxy::~ModemSimpleProxy() {}
32
Eric Shienbrood9a245532012-03-07 14:20:39 -050033void ModemSimpleProxy::GetModemStatus(Error *error,
34 const DBusPropertyMapCallback &callback,
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050035 int timeout) {
mukesh agrawal0e9e9d12014-04-18 16:09:58 -070036 BeginAsyncDBusCall(__func__, proxy_, &Proxy::GetStatusAsync, callback,
37 error, &CellularError::FromDBusError, timeout);
Darin Petkove604f702011-07-28 15:51:17 -070038}
39
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050040void ModemSimpleProxy::Connect(const DBusPropertiesMap &properties,
Eric Shienbrood9a245532012-03-07 14:20:39 -050041 Error *error,
42 const ResultCallback &callback,
43 int timeout) {
mukesh agrawal0e9e9d12014-04-18 16:09:58 -070044 BeginAsyncDBusCall(__func__, proxy_, &Proxy::ConnectAsync, callback,
45 error, &CellularError::FromDBusError, timeout,
46 properties);
Darin Petkovc5f56562011-08-06 16:40:05 -070047}
48
Eric Shienbrood9a245532012-03-07 14:20:39 -050049ModemSimpleProxy::Proxy::Proxy(DBus::Connection *connection,
Darin Petkove604f702011-07-28 15:51:17 -070050 const string &path,
51 const string &service)
Eric Shienbrood9a245532012-03-07 14:20:39 -050052 : DBus::ObjectProxy(*connection, path, service.c_str()) {}
Darin Petkove604f702011-07-28 15:51:17 -070053
54ModemSimpleProxy::Proxy::~Proxy() {}
55
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050056void ModemSimpleProxy::Proxy::GetStatusCallback(const DBusPropertiesMap &props,
57 const DBus::Error &dberror,
58 void *data) {
Rebecca Silbersteinc9c31d82014-10-21 15:01:00 -070059 SLOG(&path(), 2) << __func__;
Ben Chanc20ed132014-10-16 12:25:03 -070060 unique_ptr<DBusPropertyMapCallback> callback(
Eric Shienbrood9a245532012-03-07 14:20:39 -050061 reinterpret_cast<DBusPropertyMapCallback *>(data));
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050062 Error error;
63 CellularError::FromDBusError(dberror, &error);
Eric Shienbrood9a245532012-03-07 14:20:39 -050064 callback->Run(props, error);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050065}
66
67void ModemSimpleProxy::Proxy::ConnectCallback(const DBus::Error &dberror,
68 void *data) {
Rebecca Silbersteinc9c31d82014-10-21 15:01:00 -070069 SLOG(&path(), 2) << __func__;
Ben Chanc20ed132014-10-16 12:25:03 -070070 unique_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data));
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050071 Error error;
72 CellularError::FromDBusError(dberror, &error);
Eric Shienbrood9a245532012-03-07 14:20:39 -050073 callback->Run(error);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050074}
75
Darin Petkove604f702011-07-28 15:51:17 -070076} // namespace shill