blob: d65925743b15e3eb00465fc4d4d11dbe53490432 [file] [log] [blame]
Arman Uguray618af2b2012-12-11 19:20:42 -08001// 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
10using std::string;
11
12namespace shill {
13namespace mm1 {
14
15ModemTimeProxy::ModemTimeProxy(DBus::Connection *connection,
16 const string &path,
17 const string &service)
18 : proxy_(connection, path, service) {}
19
20ModemTimeProxy::~ModemTimeProxy() {}
21
22void ModemTimeProxy::set_network_time_changed_callback(
23 const NetworkTimeChangedSignalCallback &callback) {
24 proxy_.set_network_time_changed_callback(callback);
25}
26
27void 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)
38 CellularError::FromDBusError(e, error);
39 }
40}
41
42const 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
52ModemTimeProxy::Proxy::Proxy(DBus::Connection *connection,
53 const string &path,
54 const string &service)
55 : DBus::ObjectProxy(*connection, path, service.c_str()) {}
56
57ModemTimeProxy::Proxy::~Proxy() {}
58
59void 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
65void 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
73void 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;
79 CellularError::FromDBusError(dberror, &error);
80 callback->Run(time, error);
81}
82
83} // namespace mm1
84} // namespace shill