blob: 57a3aa5276fa6a0f9d63007f02386a62ada7770f [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
5#include "shill/modem_simple_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"
mukesh agrawal0e9e9d12014-04-18 16:09:58 -070010#include "shill/dbus_async_call_helper.h"
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050011#include "shill/error.h"
Christopher Wileyb691efd2012-08-09 13:51:51 -070012#include "shill/logging.h"
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050013
Eric Shienbrood9a245532012-03-07 14:20:39 -050014using base::Bind;
15using base::Callback;
Darin Petkove604f702011-07-28 15:51:17 -070016using std::string;
17
18namespace shill {
19
Eric Shienbrood9a245532012-03-07 14:20:39 -050020typedef Callback<void(const DBusPropertiesMap &,
21 const Error &)> ModemStatusCallback;
22
23ModemSimpleProxy::ModemSimpleProxy(DBus::Connection *connection,
Darin Petkove604f702011-07-28 15:51:17 -070024 const string &path,
25 const string &service)
Eric Shienbrood9a245532012-03-07 14:20:39 -050026 : proxy_(connection, path, service) {}
Darin Petkove604f702011-07-28 15:51:17 -070027
28ModemSimpleProxy::~ModemSimpleProxy() {}
29
Eric Shienbrood9a245532012-03-07 14:20:39 -050030void ModemSimpleProxy::GetModemStatus(Error *error,
31 const DBusPropertyMapCallback &callback,
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050032 int timeout) {
mukesh agrawal0e9e9d12014-04-18 16:09:58 -070033 BeginAsyncDBusCall(__func__, proxy_, &Proxy::GetStatusAsync, callback,
34 error, &CellularError::FromDBusError, timeout);
Darin Petkove604f702011-07-28 15:51:17 -070035}
36
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050037void ModemSimpleProxy::Connect(const DBusPropertiesMap &properties,
Eric Shienbrood9a245532012-03-07 14:20:39 -050038 Error *error,
39 const ResultCallback &callback,
40 int timeout) {
mukesh agrawal0e9e9d12014-04-18 16:09:58 -070041 BeginAsyncDBusCall(__func__, proxy_, &Proxy::ConnectAsync, callback,
42 error, &CellularError::FromDBusError, timeout,
43 properties);
Darin Petkovc5f56562011-08-06 16:40:05 -070044}
45
Eric Shienbrood9a245532012-03-07 14:20:39 -050046ModemSimpleProxy::Proxy::Proxy(DBus::Connection *connection,
Darin Petkove604f702011-07-28 15:51:17 -070047 const string &path,
48 const string &service)
Eric Shienbrood9a245532012-03-07 14:20:39 -050049 : DBus::ObjectProxy(*connection, path, service.c_str()) {}
Darin Petkove604f702011-07-28 15:51:17 -070050
51ModemSimpleProxy::Proxy::~Proxy() {}
52
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050053void ModemSimpleProxy::Proxy::GetStatusCallback(const DBusPropertiesMap &props,
54 const DBus::Error &dberror,
55 void *data) {
mukesh agrawal06175d72012-04-23 16:46:01 -070056 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -050057 scoped_ptr<DBusPropertyMapCallback> callback(
58 reinterpret_cast<DBusPropertyMapCallback *>(data));
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050059 Error error;
60 CellularError::FromDBusError(dberror, &error);
Eric Shienbrood9a245532012-03-07 14:20:39 -050061 callback->Run(props, error);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050062}
63
64void ModemSimpleProxy::Proxy::ConnectCallback(const DBus::Error &dberror,
65 void *data) {
mukesh agrawal06175d72012-04-23 16:46:01 -070066 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -050067 scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data));
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050068 Error error;
69 CellularError::FromDBusError(dberror, &error);
Eric Shienbrood9a245532012-03-07 14:20:39 -050070 callback->Run(error);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050071}
72
Darin Petkove604f702011-07-28 15:51:17 -070073} // namespace shill