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