blob: d51860f5b9830d3ba0ae14cfbfad623e12e83d51 [file] [log] [blame]
Eric Shienbrood5de44ab2011-12-05 10:46:27 -05001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Darin Petkove604f702011-07-28 15:51:17 -07002// 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/modem_simple_proxy.h"
6
Eric Shienbrood9a245532012-03-07 14:20:39 -05007#include <base/bind.h>
8
Eric Shienbrood5de44ab2011-12-05 10:46:27 -05009#include "shill/cellular_error.h"
10#include "shill/error.h"
mukesh agrawal06175d72012-04-23 16:46:01 -070011#include "shill/scope_logger.h"
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050012
Eric Shienbrood9a245532012-03-07 14:20:39 -050013using base::Bind;
14using base::Callback;
Darin Petkove604f702011-07-28 15:51:17 -070015using std::string;
16
17namespace shill {
18
Eric Shienbrood9a245532012-03-07 14:20:39 -050019typedef Callback<void(const DBusPropertiesMap &,
20 const Error &)> ModemStatusCallback;
21
22ModemSimpleProxy::ModemSimpleProxy(DBus::Connection *connection,
Darin Petkove604f702011-07-28 15:51:17 -070023 const string &path,
24 const string &service)
Eric Shienbrood9a245532012-03-07 14:20:39 -050025 : proxy_(connection, path, service) {}
Darin Petkove604f702011-07-28 15:51:17 -070026
27ModemSimpleProxy::~ModemSimpleProxy() {}
28
Eric Shienbrood9a245532012-03-07 14:20:39 -050029void ModemSimpleProxy::GetModemStatus(Error *error,
30 const DBusPropertyMapCallback &callback,
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050031 int timeout) {
Eric Shienbrood9a245532012-03-07 14:20:39 -050032 scoped_ptr<DBusPropertyMapCallback> cb(new DBusPropertyMapCallback(callback));
33 try {
mukesh agrawal06175d72012-04-23 16:46:01 -070034 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -050035 proxy_.GetStatus(cb.get(), timeout);
36 cb.release();
37 } catch (DBus::Error e) {
38 if (error)
39 CellularError::FromDBusError(e, error);
40 }
Darin Petkove604f702011-07-28 15:51:17 -070041}
42
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050043void ModemSimpleProxy::Connect(const DBusPropertiesMap &properties,
Eric Shienbrood9a245532012-03-07 14:20:39 -050044 Error *error,
45 const ResultCallback &callback,
46 int timeout) {
47 scoped_ptr<ResultCallback> cb(new ResultCallback(callback));
48 try {
mukesh agrawal06175d72012-04-23 16:46:01 -070049 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -050050 proxy_.Connect(properties, cb.get(), timeout);
51 cb.release();
52 } catch (DBus::Error e) {
53 if (error)
54 CellularError::FromDBusError(e, error);
55 }
Darin Petkovc5f56562011-08-06 16:40:05 -070056}
57
Eric Shienbrood9a245532012-03-07 14:20:39 -050058ModemSimpleProxy::Proxy::Proxy(DBus::Connection *connection,
Darin Petkove604f702011-07-28 15:51:17 -070059 const string &path,
60 const string &service)
Eric Shienbrood9a245532012-03-07 14:20:39 -050061 : DBus::ObjectProxy(*connection, path, service.c_str()) {}
Darin Petkove604f702011-07-28 15:51:17 -070062
63ModemSimpleProxy::Proxy::~Proxy() {}
64
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050065void ModemSimpleProxy::Proxy::GetStatusCallback(const DBusPropertiesMap &props,
66 const DBus::Error &dberror,
67 void *data) {
mukesh agrawal06175d72012-04-23 16:46:01 -070068 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -050069 scoped_ptr<DBusPropertyMapCallback> callback(
70 reinterpret_cast<DBusPropertyMapCallback *>(data));
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050071 Error error;
72 CellularError::FromDBusError(dberror, &error);
Eric Shienbrood9a245532012-03-07 14:20:39 -050073 callback->Run(props, error);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050074}
75
76void ModemSimpleProxy::Proxy::ConnectCallback(const DBus::Error &dberror,
77 void *data) {
mukesh agrawal06175d72012-04-23 16:46:01 -070078 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -050079 scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data));
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050080 Error error;
81 CellularError::FromDBusError(dberror, &error);
Eric Shienbrood9a245532012-03-07 14:20:39 -050082 callback->Run(error);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050083}
84
Darin Petkove604f702011-07-28 15:51:17 -070085} // namespace shill