blob: 3470e2998ec70fa40183f6a63b6cfa757acc5647 [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"
11
Eric Shienbrood9a245532012-03-07 14:20:39 -050012using base::Bind;
13using base::Callback;
Darin Petkove604f702011-07-28 15:51:17 -070014using std::string;
15
16namespace shill {
17
Eric Shienbrood9a245532012-03-07 14:20:39 -050018typedef Callback<void(const DBusPropertiesMap &,
19 const Error &)> ModemStatusCallback;
20
21ModemSimpleProxy::ModemSimpleProxy(DBus::Connection *connection,
Darin Petkove604f702011-07-28 15:51:17 -070022 const string &path,
23 const string &service)
Eric Shienbrood9a245532012-03-07 14:20:39 -050024 : proxy_(connection, path, service) {}
Darin Petkove604f702011-07-28 15:51:17 -070025
26ModemSimpleProxy::~ModemSimpleProxy() {}
27
Eric Shienbrood9a245532012-03-07 14:20:39 -050028void ModemSimpleProxy::GetModemStatus(Error *error,
29 const DBusPropertyMapCallback &callback,
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050030 int timeout) {
Eric Shienbrood9a245532012-03-07 14:20:39 -050031 scoped_ptr<DBusPropertyMapCallback> cb(new DBusPropertyMapCallback(callback));
32 try {
33 proxy_.GetStatus(cb.get(), timeout);
34 cb.release();
35 } catch (DBus::Error e) {
36 if (error)
37 CellularError::FromDBusError(e, error);
38 }
Darin Petkove604f702011-07-28 15:51:17 -070039}
40
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050041void ModemSimpleProxy::Connect(const DBusPropertiesMap &properties,
Eric Shienbrood9a245532012-03-07 14:20:39 -050042 Error *error,
43 const ResultCallback &callback,
44 int timeout) {
45 scoped_ptr<ResultCallback> cb(new ResultCallback(callback));
46 try {
47 proxy_.Connect(properties, cb.get(), timeout);
48 cb.release();
49 } catch (DBus::Error e) {
50 if (error)
51 CellularError::FromDBusError(e, error);
52 }
Darin Petkovc5f56562011-08-06 16:40:05 -070053}
54
Eric Shienbrood9a245532012-03-07 14:20:39 -050055ModemSimpleProxy::Proxy::Proxy(DBus::Connection *connection,
Darin Petkove604f702011-07-28 15:51:17 -070056 const string &path,
57 const string &service)
Eric Shienbrood9a245532012-03-07 14:20:39 -050058 : DBus::ObjectProxy(*connection, path, service.c_str()) {}
Darin Petkove604f702011-07-28 15:51:17 -070059
60ModemSimpleProxy::Proxy::~Proxy() {}
61
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050062void ModemSimpleProxy::Proxy::GetStatusCallback(const DBusPropertiesMap &props,
63 const DBus::Error &dberror,
64 void *data) {
Eric Shienbrood9a245532012-03-07 14:20:39 -050065 scoped_ptr<DBusPropertyMapCallback> callback(
66 reinterpret_cast<DBusPropertyMapCallback *>(data));
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050067 Error error;
68 CellularError::FromDBusError(dberror, &error);
Eric Shienbrood9a245532012-03-07 14:20:39 -050069 callback->Run(props, error);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050070}
71
72void ModemSimpleProxy::Proxy::ConnectCallback(const DBus::Error &dberror,
73 void *data) {
Eric Shienbrood9a245532012-03-07 14:20:39 -050074 scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data));
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050075 Error error;
76 CellularError::FromDBusError(dberror, &error);
Eric Shienbrood9a245532012-03-07 14:20:39 -050077 callback->Run(error);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050078}
79
Darin Petkove604f702011-07-28 15:51:17 -070080} // namespace shill