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 | |
| 5 | #include "shill/modem_simple_proxy.h" |
| 6 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 7 | #include <base/bind.h> |
| 8 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 9 | #include "shill/cellular_error.h" |
| 10 | #include "shill/error.h" |
Christopher Wiley | b691efd | 2012-08-09 13:51:51 -0700 | [diff] [blame] | 11 | #include "shill/logging.h" |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 12 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 13 | using base::Bind; |
| 14 | using base::Callback; |
Darin Petkov | e604f70 | 2011-07-28 15:51:17 -0700 | [diff] [blame] | 15 | using std::string; |
| 16 | |
| 17 | namespace shill { |
| 18 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 19 | typedef Callback<void(const DBusPropertiesMap &, |
| 20 | const Error &)> ModemStatusCallback; |
| 21 | |
| 22 | ModemSimpleProxy::ModemSimpleProxy(DBus::Connection *connection, |
Darin Petkov | e604f70 | 2011-07-28 15:51:17 -0700 | [diff] [blame] | 23 | const string &path, |
| 24 | const string &service) |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 25 | : proxy_(connection, path, service) {} |
Darin Petkov | e604f70 | 2011-07-28 15:51:17 -0700 | [diff] [blame] | 26 | |
| 27 | ModemSimpleProxy::~ModemSimpleProxy() {} |
| 28 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 29 | void ModemSimpleProxy::GetModemStatus(Error *error, |
| 30 | const DBusPropertyMapCallback &callback, |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 31 | int timeout) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 32 | scoped_ptr<DBusPropertyMapCallback> cb(new DBusPropertyMapCallback(callback)); |
| 33 | try { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 34 | SLOG(DBus, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 35 | proxy_.GetStatus(cb.get(), timeout); |
| 36 | cb.release(); |
Ben Chan | 80326f3 | 2012-05-04 17:51:32 -0700 | [diff] [blame] | 37 | } catch (const DBus::Error &e) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 38 | if (error) |
| 39 | CellularError::FromDBusError(e, error); |
| 40 | } |
Darin Petkov | e604f70 | 2011-07-28 15:51:17 -0700 | [diff] [blame] | 41 | } |
| 42 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 43 | void ModemSimpleProxy::Connect(const DBusPropertiesMap &properties, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 44 | Error *error, |
| 45 | const ResultCallback &callback, |
| 46 | int timeout) { |
| 47 | scoped_ptr<ResultCallback> cb(new ResultCallback(callback)); |
| 48 | try { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 49 | SLOG(DBus, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 50 | proxy_.Connect(properties, cb.get(), timeout); |
| 51 | cb.release(); |
Ben Chan | 80326f3 | 2012-05-04 17:51:32 -0700 | [diff] [blame] | 52 | } catch (const DBus::Error &e) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 53 | if (error) |
| 54 | CellularError::FromDBusError(e, error); |
| 55 | } |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 56 | } |
| 57 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 58 | ModemSimpleProxy::Proxy::Proxy(DBus::Connection *connection, |
Darin Petkov | e604f70 | 2011-07-28 15:51:17 -0700 | [diff] [blame] | 59 | const string &path, |
| 60 | const string &service) |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 61 | : DBus::ObjectProxy(*connection, path, service.c_str()) {} |
Darin Petkov | e604f70 | 2011-07-28 15:51:17 -0700 | [diff] [blame] | 62 | |
| 63 | ModemSimpleProxy::Proxy::~Proxy() {} |
| 64 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 65 | void ModemSimpleProxy::Proxy::GetStatusCallback(const DBusPropertiesMap &props, |
| 66 | const DBus::Error &dberror, |
| 67 | void *data) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 68 | SLOG(DBus, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 69 | scoped_ptr<DBusPropertyMapCallback> callback( |
| 70 | reinterpret_cast<DBusPropertyMapCallback *>(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(props, error); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | void ModemSimpleProxy::Proxy::ConnectCallback(const DBus::Error &dberror, |
| 77 | void *data) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 78 | SLOG(DBus, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 79 | scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data)); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 80 | Error error; |
| 81 | CellularError::FromDBusError(dberror, &error); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 82 | callback->Run(error); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 83 | } |
| 84 | |
Darin Petkov | e604f70 | 2011-07-28 15:51:17 -0700 | [diff] [blame] | 85 | } // namespace shill |