Darin Petkov | fb0625e | 2012-01-16 13:05:56 +0100 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -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_proxy.h" |
| 6 | |
| 7 | #include <base/logging.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" |
| 11 | |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 12 | using std::string; |
| 13 | |
| 14 | namespace shill { |
| 15 | |
Darin Petkov | 580c7af | 2011-10-24 12:32:50 +0200 | [diff] [blame] | 16 | ModemProxy::ModemProxy(ModemProxyDelegate *delegate, |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 17 | DBus::Connection *connection, |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 18 | const string &path, |
| 19 | const string &service) |
Darin Petkov | 580c7af | 2011-10-24 12:32:50 +0200 | [diff] [blame] | 20 | : proxy_(delegate, connection, path, service) {} |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 21 | |
| 22 | ModemProxy::~ModemProxy() {} |
| 23 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 24 | // TODO(ers): Need to handle dbus errors that occur and prevent the |
| 25 | // RPC from going out. These currently result in exceptions being thrown. |
| 26 | // We need a way to let the upper layers know that the operation |
| 27 | // failed in such a case. |
| 28 | void ModemProxy::Enable(bool enable, AsyncCallHandler *call_handler, |
| 29 | int timeout) { |
| 30 | VLOG(2) << __func__ << "(" << enable << ", " << timeout << ")"; |
| 31 | proxy_.Enable(enable, call_handler, timeout); |
| 32 | } |
| 33 | |
| 34 | // TODO(ers): temporarily support the blocking version |
| 35 | // of Enable, until Cellular::Stop is converted for async. |
| 36 | void ModemProxy::Enable(bool enable) { |
| 37 | VLOG(2) << __func__ << "(" << enable << ")"; |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 38 | proxy_.Enable(enable); |
| 39 | } |
| 40 | |
Darin Petkov | fb0625e | 2012-01-16 13:05:56 +0100 | [diff] [blame] | 41 | void ModemProxy::Disconnect() { |
| 42 | proxy_.Disconnect(); |
| 43 | } |
| 44 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 45 | void ModemProxy::GetModemInfo(AsyncCallHandler *call_handler, int timeout) { |
| 46 | proxy_.GetInfo(call_handler, timeout); |
Darin Petkov | ceb6817 | 2011-07-29 14:47:48 -0700 | [diff] [blame] | 47 | } |
| 48 | |
Darin Petkov | 580c7af | 2011-10-24 12:32:50 +0200 | [diff] [blame] | 49 | ModemProxy::Proxy::Proxy(ModemProxyDelegate *delegate, |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 50 | DBus::Connection *connection, |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 51 | const string &path, |
| 52 | const string &service) |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 53 | : DBus::ObjectProxy(*connection, path, service.c_str()), |
Darin Petkov | 580c7af | 2011-10-24 12:32:50 +0200 | [diff] [blame] | 54 | delegate_(delegate) {} |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 55 | |
| 56 | ModemProxy::Proxy::~Proxy() {} |
| 57 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 58 | void ModemProxy::Proxy::StateChanged( |
| 59 | const uint32 &old, const uint32 &_new, const uint32 &reason) { |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 60 | VLOG(2) << __func__ << "(" << old << ", " << _new << ", " << reason << ")"; |
Darin Petkov | 580c7af | 2011-10-24 12:32:50 +0200 | [diff] [blame] | 61 | delegate_->OnModemStateChanged(old, _new, reason); |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 62 | } |
| 63 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 64 | void ModemProxy::Proxy::EnableCallback(const DBus::Error &dberror, void *data) { |
| 65 | VLOG(2) << __func__; |
| 66 | AsyncCallHandler *call_handler = reinterpret_cast<AsyncCallHandler *>(data); |
| 67 | Error error; |
| 68 | CellularError::FromDBusError(dberror, &error); |
| 69 | delegate_->OnModemEnableCallback(error, call_handler); |
| 70 | } |
| 71 | |
| 72 | void ModemProxy::Proxy::GetInfoCallback(const ModemHardwareInfo &info, |
| 73 | const DBus::Error &dberror, |
| 74 | void *data) { |
| 75 | AsyncCallHandler *call_handler = reinterpret_cast<AsyncCallHandler *>(data); |
| 76 | Error error; |
| 77 | CellularError::FromDBusError(dberror, &error); |
| 78 | delegate_->OnGetModemInfoCallback(info, error, call_handler); |
| 79 | } |
| 80 | |
| 81 | void ModemProxy::Proxy::DisconnectCallback(const DBus::Error &dberror, |
| 82 | void *data) { |
| 83 | AsyncCallHandler *call_handler = reinterpret_cast<AsyncCallHandler *>(data); |
| 84 | Error error; |
| 85 | CellularError::FromDBusError(dberror, &error); |
| 86 | delegate_->OnDisconnectCallback(error, call_handler); |
| 87 | } |
| 88 | |
Darin Petkov | e9d12e0 | 2011-07-27 15:09:37 -0700 | [diff] [blame] | 89 | } // namespace shill |