Darin Petkov | 9893d9c | 2012-05-17 15:27:31 -0700 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
| 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/wimax_network_proxy.h" |
| 6 | |
Darin Petkov | 9893d9c | 2012-05-17 15:27:31 -0700 | [diff] [blame] | 7 | #include <chromeos/dbus/service_constants.h> |
| 8 | |
| 9 | #include "shill/error.h" |
Christopher Wiley | b691efd | 2012-08-09 13:51:51 -0700 | [diff] [blame] | 10 | #include "shill/logging.h" |
Darin Petkov | 9893d9c | 2012-05-17 15:27:31 -0700 | [diff] [blame] | 11 | |
| 12 | using std::string; |
| 13 | |
| 14 | namespace shill { |
| 15 | |
| 16 | WiMaxNetworkProxy::WiMaxNetworkProxy(DBus::Connection *connection, |
| 17 | const DBus::Path &path) |
| 18 | : proxy_(connection, path) {} |
| 19 | |
| 20 | WiMaxNetworkProxy::~WiMaxNetworkProxy() {} |
| 21 | |
Darin Petkov | 1e52a1b | 2012-05-21 10:35:56 +0200 | [diff] [blame] | 22 | RpcIdentifier WiMaxNetworkProxy::path() const { |
Ben Chan | 4e5c131 | 2012-05-18 18:45:38 -0700 | [diff] [blame] | 23 | return proxy_.path(); |
| 24 | } |
| 25 | |
Darin Petkov | 1e52a1b | 2012-05-21 10:35:56 +0200 | [diff] [blame] | 26 | void WiMaxNetworkProxy::set_signal_strength_changed_callback( |
| 27 | const SignalStrengthChangedCallback &callback) { |
| 28 | proxy_.set_signal_strength_changed_callback(callback); |
| 29 | } |
| 30 | |
Darin Petkov | 9893d9c | 2012-05-17 15:27:31 -0700 | [diff] [blame] | 31 | uint32 WiMaxNetworkProxy::Identifier(Error *error) { |
| 32 | SLOG(DBus, 2) << __func__; |
| 33 | try { |
| 34 | return proxy_.Identifier(); |
| 35 | } catch (const DBus::Error &e) { |
| 36 | FromDBusError(e, error); |
| 37 | } |
| 38 | return 0; |
| 39 | } |
| 40 | |
| 41 | string WiMaxNetworkProxy::Name(Error *error) { |
| 42 | SLOG(DBus, 2) << __func__; |
| 43 | try { |
| 44 | return proxy_.Name(); |
| 45 | } catch (const DBus::Error &e) { |
| 46 | FromDBusError(e, error); |
| 47 | } |
| 48 | return string(); |
| 49 | } |
| 50 | |
| 51 | int WiMaxNetworkProxy::Type(Error *error) { |
| 52 | SLOG(DBus, 2) << __func__; |
| 53 | try { |
| 54 | return proxy_.Type(); |
| 55 | } catch (const DBus::Error &e) { |
| 56 | FromDBusError(e, error); |
| 57 | } |
| 58 | return 0; |
| 59 | } |
| 60 | |
| 61 | int WiMaxNetworkProxy::CINR(Error *error) { |
| 62 | SLOG(DBus, 2) << __func__; |
| 63 | try { |
| 64 | return proxy_.CINR(); |
| 65 | } catch (const DBus::Error &e) { |
| 66 | FromDBusError(e, error); |
| 67 | } |
| 68 | return 0; |
| 69 | } |
| 70 | |
| 71 | int WiMaxNetworkProxy::RSSI(Error *error) { |
| 72 | SLOG(DBus, 2) << __func__; |
| 73 | try { |
| 74 | return proxy_.RSSI(); |
| 75 | } catch (const DBus::Error &e) { |
| 76 | FromDBusError(e, error); |
| 77 | } |
| 78 | return 0; |
| 79 | } |
| 80 | |
Ben Chan | ac6e836 | 2012-05-20 00:39:58 -0700 | [diff] [blame] | 81 | int WiMaxNetworkProxy::SignalStrength(Error *error) { |
| 82 | SLOG(DBus, 2) << __func__; |
| 83 | try { |
| 84 | return proxy_.SignalStrength(); |
| 85 | } catch (const DBus::Error &e) { |
| 86 | FromDBusError(e, error); |
| 87 | } |
| 88 | return 0; |
| 89 | } |
| 90 | |
Darin Petkov | 9893d9c | 2012-05-17 15:27:31 -0700 | [diff] [blame] | 91 | // static |
| 92 | void WiMaxNetworkProxy::FromDBusError(const DBus::Error &dbus_error, |
| 93 | Error *error) { |
| 94 | if (!error) { |
| 95 | return; |
| 96 | } |
| 97 | if (!dbus_error.is_set()) { |
| 98 | error->Reset(); |
| 99 | return; |
| 100 | } |
| 101 | Error::PopulateAndLog(error, Error::kOperationFailed, dbus_error.what()); |
| 102 | } |
| 103 | |
| 104 | WiMaxNetworkProxy::Proxy::Proxy(DBus::Connection *connection, |
| 105 | const DBus::Path &path) |
| 106 | : DBus::ObjectProxy(*connection, path, |
| 107 | wimax_manager::kWiMaxManagerServiceName) {} |
| 108 | |
| 109 | WiMaxNetworkProxy::Proxy::~Proxy() {} |
| 110 | |
Darin Petkov | 1e52a1b | 2012-05-21 10:35:56 +0200 | [diff] [blame] | 111 | void WiMaxNetworkProxy::Proxy::set_signal_strength_changed_callback( |
| 112 | const SignalStrengthChangedCallback &callback) { |
| 113 | signal_strength_changed_callback_ = callback; |
| 114 | } |
| 115 | |
| 116 | void WiMaxNetworkProxy::Proxy::SignalStrengthChanged( |
| 117 | const int32 &signal_strength) { |
| 118 | SLOG(DBus, 2) << __func__ << "(" << signal_strength << ")"; |
| 119 | if (!signal_strength_changed_callback_.is_null()) { |
| 120 | signal_strength_changed_callback_.Run(signal_strength); |
| 121 | } |
| 122 | } |
| 123 | |
Darin Petkov | 9893d9c | 2012-05-17 15:27:31 -0700 | [diff] [blame] | 124 | } // namespace shill |