Arman Uguray | 6e5639f | 2012-11-15 20:30:19 -0800 | [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/mm1_bearer_proxy.h" |
| 6 | |
| 7 | #include "shill/cellular_error.h" |
| 8 | #include "shill/logging.h" |
| 9 | |
| 10 | using std::string; |
| 11 | |
| 12 | namespace shill { |
| 13 | namespace mm1 { |
| 14 | |
| 15 | BearerProxy::BearerProxy(DBus::Connection *connection, |
| 16 | const std::string &path, |
| 17 | const std::string &service) |
| 18 | : proxy_(connection, path, service) {} |
| 19 | |
| 20 | BearerProxy::~BearerProxy() {} |
| 21 | |
| 22 | |
| 23 | // Inherited methods from BearerProxyInterface |
| 24 | void BearerProxy::Connect(Error *error, |
| 25 | const ResultCallback &callback, |
| 26 | int timeout) { |
| 27 | SLOG(Modem, 2) << __func__; |
| 28 | scoped_ptr<ResultCallback> cb(new ResultCallback(callback)); |
| 29 | try { |
| 30 | SLOG(DBus, 2) << __func__; |
| 31 | proxy_.Connect(cb.get(), timeout); |
| 32 | cb.release(); |
| 33 | } catch (const DBus::Error &e) { |
| 34 | if (error) |
| 35 | CellularError::FromDBusError(e, error); |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | void BearerProxy::Disconnect(Error *error, |
| 40 | const ResultCallback &callback, |
| 41 | int timeout) { |
| 42 | SLOG(Modem, 2) << __func__; |
| 43 | scoped_ptr<ResultCallback> cb(new ResultCallback(callback)); |
| 44 | try { |
| 45 | SLOG(DBus, 2) << __func__; |
| 46 | proxy_.Disconnect(cb.get(), timeout); |
| 47 | cb.release(); |
| 48 | } catch (const DBus::Error &e) { |
| 49 | if (error) |
| 50 | CellularError::FromDBusError(e, error); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | // Inherited properties from BearerProxyInterface |
| 55 | const string BearerProxy::Interface() { |
| 56 | SLOG(DBus, 2) << __func__; |
| 57 | try { |
| 58 | return proxy_.Interface(); |
| 59 | } catch (const DBus::Error &e) { |
| 60 | LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what(); |
| 61 | return string(); // Make the compiler happy. |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | bool BearerProxy::Connected() { |
| 66 | SLOG(DBus, 2) << __func__; |
| 67 | try { |
| 68 | return proxy_.Connected(); |
| 69 | } catch (const DBus::Error &e) { |
| 70 | LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what(); |
| 71 | return false; // Make the compiler happy. |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | bool BearerProxy::Suspended() { |
| 76 | SLOG(DBus, 2) << __func__; |
| 77 | try { |
| 78 | return proxy_.Suspended(); |
| 79 | } catch (const DBus::Error &e) { |
| 80 | LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what(); |
| 81 | return false; // Make the compiler happy. |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | const DBusPropertiesMap BearerProxy::Ip4Config() { |
| 86 | SLOG(DBus, 2) << __func__; |
| 87 | try { |
| 88 | return proxy_.Ip4Config(); |
| 89 | } catch (const DBus::Error &e) { |
| 90 | LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what(); |
| 91 | return DBusPropertiesMap(); // Make the compiler happy. |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | const DBusPropertiesMap BearerProxy::Ip6Config() { |
| 96 | SLOG(DBus, 2) << __func__; |
| 97 | try { |
| 98 | return proxy_.Ip6Config(); |
| 99 | } catch (const DBus::Error &e) { |
| 100 | LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what(); |
| 101 | return DBusPropertiesMap(); // Make the compiler happy. |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | uint32_t BearerProxy::IpTimeout() { |
| 106 | SLOG(DBus, 2) << __func__; |
| 107 | try { |
| 108 | return proxy_.IpTimeout(); |
| 109 | } catch (const DBus::Error &e) { |
| 110 | LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what(); |
| 111 | return 0; // Make the compiler happy. |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | const DBusPropertiesMap BearerProxy::Properties() { |
| 116 | SLOG(DBus, 2) << __func__; |
| 117 | try { |
| 118 | return proxy_.Properties(); |
| 119 | } catch (const DBus::Error &e) { |
| 120 | LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what(); |
| 121 | return DBusPropertiesMap(); // Make the compiler happy. |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | BearerProxy::Proxy::Proxy(DBus::Connection *connection, |
| 126 | const std::string &path, |
| 127 | const std::string &service) |
| 128 | : DBus::ObjectProxy(*connection, path, service.c_str()) {} |
| 129 | |
| 130 | BearerProxy::Proxy::~Proxy() {} |
| 131 | |
| 132 | |
| 133 | // Method callbacks inherited from |
| 134 | // org::freedesktop::ModemManager1::BearerProxy |
| 135 | void BearerProxy::Proxy::ConnectCallback(const ::DBus::Error &dberror, |
| 136 | void *data) { |
| 137 | SLOG(DBus, 2) << __func__; |
| 138 | scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data)); |
| 139 | Error error; |
| 140 | CellularError::FromDBusError(dberror, &error); |
| 141 | callback->Run(error); |
| 142 | } |
| 143 | |
| 144 | void BearerProxy::Proxy::DisconnectCallback(const ::DBus::Error &dberror, |
| 145 | void *data) { |
| 146 | SLOG(DBus, 2) << __func__; |
| 147 | scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data)); |
| 148 | Error error; |
| 149 | CellularError::FromDBusError(dberror, &error); |
| 150 | callback->Run(error); |
| 151 | } |
| 152 | |
| 153 | } // namespace mm1 |
| 154 | } // namespace shill |