Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Darin Petkov | e604f70 | 2011-07-28 15:51:17 -0700 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Ben Chan | c54afe5 | 2014-11-05 10:28:08 -0800 | [diff] [blame] | 5 | #include "shill/cellular/modem_simple_proxy.h" |
Darin Petkov | e604f70 | 2011-07-28 15:51:17 -0700 | [diff] [blame] | 6 | |
Ben Chan | c20ed13 | 2014-10-16 12:25:03 -0700 | [diff] [blame] | 7 | #include <memory> |
| 8 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 9 | #include <base/bind.h> |
| 10 | |
Ben Chan | c54afe5 | 2014-11-05 10:28:08 -0800 | [diff] [blame] | 11 | #include "shill/cellular/cellular_error.h" |
mukesh agrawal | 0e9e9d1 | 2014-04-18 16:09:58 -0700 | [diff] [blame] | 12 | #include "shill/dbus_async_call_helper.h" |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 13 | #include "shill/error.h" |
Christopher Wiley | b691efd | 2012-08-09 13:51:51 -0700 | [diff] [blame] | 14 | #include "shill/logging.h" |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 15 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 16 | using base::Bind; |
| 17 | using base::Callback; |
Darin Petkov | e604f70 | 2011-07-28 15:51:17 -0700 | [diff] [blame] | 18 | using std::string; |
Ben Chan | c20ed13 | 2014-10-16 12:25:03 -0700 | [diff] [blame] | 19 | using std::unique_ptr; |
Darin Petkov | e604f70 | 2011-07-28 15:51:17 -0700 | [diff] [blame] | 20 | |
| 21 | namespace shill { |
| 22 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 23 | typedef Callback<void(const DBusPropertiesMap &, |
| 24 | const Error &)> ModemStatusCallback; |
| 25 | |
| 26 | ModemSimpleProxy::ModemSimpleProxy(DBus::Connection *connection, |
Darin Petkov | e604f70 | 2011-07-28 15:51:17 -0700 | [diff] [blame] | 27 | const string &path, |
| 28 | const string &service) |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 29 | : proxy_(connection, path, service) {} |
Darin Petkov | e604f70 | 2011-07-28 15:51:17 -0700 | [diff] [blame] | 30 | |
| 31 | ModemSimpleProxy::~ModemSimpleProxy() {} |
| 32 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 33 | void ModemSimpleProxy::GetModemStatus(Error *error, |
| 34 | const DBusPropertyMapCallback &callback, |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 35 | int timeout) { |
mukesh agrawal | 0e9e9d1 | 2014-04-18 16:09:58 -0700 | [diff] [blame] | 36 | BeginAsyncDBusCall(__func__, proxy_, &Proxy::GetStatusAsync, callback, |
| 37 | error, &CellularError::FromDBusError, timeout); |
Darin Petkov | e604f70 | 2011-07-28 15:51:17 -0700 | [diff] [blame] | 38 | } |
| 39 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 40 | void ModemSimpleProxy::Connect(const DBusPropertiesMap &properties, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 41 | Error *error, |
| 42 | const ResultCallback &callback, |
| 43 | int timeout) { |
mukesh agrawal | 0e9e9d1 | 2014-04-18 16:09:58 -0700 | [diff] [blame] | 44 | BeginAsyncDBusCall(__func__, proxy_, &Proxy::ConnectAsync, callback, |
| 45 | error, &CellularError::FromDBusError, timeout, |
| 46 | properties); |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 47 | } |
| 48 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 49 | ModemSimpleProxy::Proxy::Proxy(DBus::Connection *connection, |
Darin Petkov | e604f70 | 2011-07-28 15:51:17 -0700 | [diff] [blame] | 50 | const string &path, |
| 51 | const string &service) |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 52 | : DBus::ObjectProxy(*connection, path, service.c_str()) {} |
Darin Petkov | e604f70 | 2011-07-28 15:51:17 -0700 | [diff] [blame] | 53 | |
| 54 | ModemSimpleProxy::Proxy::~Proxy() {} |
| 55 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 56 | void ModemSimpleProxy::Proxy::GetStatusCallback(const DBusPropertiesMap &props, |
| 57 | const DBus::Error &dberror, |
| 58 | void *data) { |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 59 | SLOG(&path(), 2) << __func__; |
Ben Chan | c20ed13 | 2014-10-16 12:25:03 -0700 | [diff] [blame] | 60 | unique_ptr<DBusPropertyMapCallback> callback( |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 61 | reinterpret_cast<DBusPropertyMapCallback *>(data)); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 62 | Error error; |
| 63 | CellularError::FromDBusError(dberror, &error); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 64 | callback->Run(props, error); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | void ModemSimpleProxy::Proxy::ConnectCallback(const DBus::Error &dberror, |
| 68 | void *data) { |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 69 | SLOG(&path(), 2) << __func__; |
Ben Chan | c20ed13 | 2014-10-16 12:25:03 -0700 | [diff] [blame] | 70 | unique_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data)); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 71 | Error error; |
| 72 | CellularError::FromDBusError(dberror, &error); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 73 | callback->Run(error); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 74 | } |
| 75 | |
Darin Petkov | e604f70 | 2011-07-28 15:51:17 -0700 | [diff] [blame] | 76 | } // namespace shill |