blob: d65925743b15e3eb00465fc4d4d11dbe53490432 [file] [log] [blame]
// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "shill/mm1_modem_time_proxy.h"
#include "shill/cellular_error.h"
#include "shill/logging.h"
using std::string;
namespace shill {
namespace mm1 {
ModemTimeProxy::ModemTimeProxy(DBus::Connection *connection,
const string &path,
const string &service)
: proxy_(connection, path, service) {}
ModemTimeProxy::~ModemTimeProxy() {}
void ModemTimeProxy::set_network_time_changed_callback(
const NetworkTimeChangedSignalCallback &callback) {
proxy_.set_network_time_changed_callback(callback);
}
void ModemTimeProxy::GetNetworkTime(Error *error,
const StringCallback &callback,
int timeout) {
SLOG(Modem, 2) << __func__;
scoped_ptr<StringCallback> cb(new StringCallback(callback));
try {
SLOG(DBus, 2) << __func__;
proxy_.GetNetworkTime(cb.get(), timeout);
cb.release();
} catch (const DBus::Error &e) {
if (error)
CellularError::FromDBusError(e, error);
}
}
const DBusPropertiesMap ModemTimeProxy::NetworkTimezone() {
SLOG(DBus, 2) << __func__;
try {
return proxy_.NetworkTimezone();
} catch (const DBus::Error &e) {
LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what();
return DBusPropertiesMap(); // Make the compiler happy.
}
}
ModemTimeProxy::Proxy::Proxy(DBus::Connection *connection,
const string &path,
const string &service)
: DBus::ObjectProxy(*connection, path, service.c_str()) {}
ModemTimeProxy::Proxy::~Proxy() {}
void ModemTimeProxy::Proxy::set_network_time_changed_callback(
const NetworkTimeChangedSignalCallback &callback) {
network_time_changed_callback_ = callback;
}
// Signal callbacks inherited from Proxy
void ModemTimeProxy::Proxy::NetworkTimeChanged(const string &time) {
SLOG(DBus, 2) << __func__;
if (!network_time_changed_callback_.is_null())
network_time_changed_callback_.Run(time);
}
// Method callbacks inherited from
// org::freedesktop::ModemManager1::Modem::TimeProxy
void ModemTimeProxy::Proxy::GetNetworkTimeCallback(const string &time,
const ::DBus::Error &dberror,
void *data) {
SLOG(DBus, 2) << __func__;
scoped_ptr<StringCallback> callback(reinterpret_cast<StringCallback *>(data));
Error error;
CellularError::FromDBusError(dberror, &error);
callback->Run(time, error);
}
} // namespace mm1
} // namespace shill