Arman Uguray | 618af2b | 2012-12-11 19:20:42 -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_modem_time_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 | ModemTimeProxy::ModemTimeProxy(DBus::Connection *connection, |
| 16 | const string &path, |
| 17 | const string &service) |
| 18 | : proxy_(connection, path, service) {} |
| 19 | |
| 20 | ModemTimeProxy::~ModemTimeProxy() {} |
| 21 | |
| 22 | void ModemTimeProxy::set_network_time_changed_callback( |
| 23 | const NetworkTimeChangedSignalCallback &callback) { |
| 24 | proxy_.set_network_time_changed_callback(callback); |
| 25 | } |
| 26 | |
| 27 | void ModemTimeProxy::GetNetworkTime(Error *error, |
| 28 | const StringCallback &callback, |
| 29 | int timeout) { |
| 30 | SLOG(Modem, 2) << __func__; |
| 31 | scoped_ptr<StringCallback> cb(new StringCallback(callback)); |
| 32 | try { |
| 33 | SLOG(DBus, 2) << __func__; |
| 34 | proxy_.GetNetworkTime(cb.get(), timeout); |
| 35 | cb.release(); |
| 36 | } catch (const DBus::Error &e) { |
| 37 | if (error) |
Arman Uguray | 763df86 | 2013-07-02 12:49:10 -0700 | [diff] [blame] | 38 | CellularError::FromMM1DBusError(e, error); |
Arman Uguray | 618af2b | 2012-12-11 19:20:42 -0800 | [diff] [blame] | 39 | } |
| 40 | } |
| 41 | |
| 42 | const DBusPropertiesMap ModemTimeProxy::NetworkTimezone() { |
| 43 | SLOG(DBus, 2) << __func__; |
| 44 | try { |
| 45 | return proxy_.NetworkTimezone(); |
| 46 | } catch (const DBus::Error &e) { |
| 47 | LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what(); |
| 48 | return DBusPropertiesMap(); // Make the compiler happy. |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | ModemTimeProxy::Proxy::Proxy(DBus::Connection *connection, |
| 53 | const string &path, |
| 54 | const string &service) |
| 55 | : DBus::ObjectProxy(*connection, path, service.c_str()) {} |
| 56 | |
| 57 | ModemTimeProxy::Proxy::~Proxy() {} |
| 58 | |
| 59 | void ModemTimeProxy::Proxy::set_network_time_changed_callback( |
| 60 | const NetworkTimeChangedSignalCallback &callback) { |
| 61 | network_time_changed_callback_ = callback; |
| 62 | } |
| 63 | |
| 64 | // Signal callbacks inherited from Proxy |
| 65 | void ModemTimeProxy::Proxy::NetworkTimeChanged(const string &time) { |
| 66 | SLOG(DBus, 2) << __func__; |
| 67 | if (!network_time_changed_callback_.is_null()) |
| 68 | network_time_changed_callback_.Run(time); |
| 69 | } |
| 70 | |
| 71 | // Method callbacks inherited from |
| 72 | // org::freedesktop::ModemManager1::Modem::TimeProxy |
| 73 | void ModemTimeProxy::Proxy::GetNetworkTimeCallback(const string &time, |
| 74 | const ::DBus::Error &dberror, |
| 75 | void *data) { |
| 76 | SLOG(DBus, 2) << __func__; |
| 77 | scoped_ptr<StringCallback> callback(reinterpret_cast<StringCallback *>(data)); |
| 78 | Error error; |
Arman Uguray | 763df86 | 2013-07-02 12:49:10 -0700 | [diff] [blame] | 79 | CellularError::FromMM1DBusError(dberror, &error); |
Arman Uguray | 618af2b | 2012-12-11 19:20:42 -0800 | [diff] [blame] | 80 | callback->Run(time, error); |
| 81 | } |
| 82 | |
| 83 | } // namespace mm1 |
| 84 | } // namespace shill |