blob: b9044723cbf8d6db50b4b47413a8508333ce135c [file] [log] [blame]
Darin Petkovfb0625e2012-01-16 13:05:56 +01001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Darin Petkove9d12e02011-07-27 15:09:37 -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_proxy.h"
6
Eric Shienbrood9a245532012-03-07 14:20:39 -05007#include <base/bind.h>
Darin Petkove9d12e02011-07-27 15:09:37 -07008
Eric Shienbrood5de44ab2011-12-05 10:46:27 -05009#include "shill/cellular_error.h"
10#include "shill/error.h"
Christopher Wileyb691efd2012-08-09 13:51:51 -070011#include "shill/logging.h"
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050012
Eric Shienbrood9a245532012-03-07 14:20:39 -050013using base::Bind;
14using base::Callback;
Darin Petkove9d12e02011-07-27 15:09:37 -070015using std::string;
16
17namespace shill {
18
Eric Shienbrood9a245532012-03-07 14:20:39 -050019typedef Callback<void(const ModemHardwareInfo &,
20 const Error &)> ModemInfoCallback;
21
22ModemProxy::ModemProxy(DBus::Connection *connection,
Darin Petkove9d12e02011-07-27 15:09:37 -070023 const string &path,
24 const string &service)
Eric Shienbrood9a245532012-03-07 14:20:39 -050025 : proxy_(connection, path, service) {}
Darin Petkove9d12e02011-07-27 15:09:37 -070026
27ModemProxy::~ModemProxy() {}
28
Eric Shienbrood9a245532012-03-07 14:20:39 -050029void ModemProxy::set_state_changed_callback(
30 const ModemStateChangedSignalCallback &callback) {
31 proxy_.set_state_changed_callback(callback);
32}
33
34void ModemProxy::Enable(bool enable, Error *error,
35 const ResultCallback &callback, int timeout) {
Ben Chanfad4a0b2012-04-18 15:49:59 -070036 SLOG(Modem, 2) << __func__ << "(" << enable << ", " << timeout << ")";
Eric Shienbrood9a245532012-03-07 14:20:39 -050037 scoped_ptr<ResultCallback> cb(new ResultCallback(callback));
38 try {
mukesh agrawal06175d72012-04-23 16:46:01 -070039 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -050040 proxy_.Enable(enable, cb.get(), timeout);
41 cb.release();
Ben Chan80326f32012-05-04 17:51:32 -070042 } catch (const DBus::Error &e) {
Eric Shienbrood9a245532012-03-07 14:20:39 -050043 if (error)
44 CellularError::FromDBusError(e, error);
45 }
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050046}
47
Eric Shienbrood9a245532012-03-07 14:20:39 -050048void ModemProxy::Disconnect(Error *error, const ResultCallback &callback,
49 int timeout) {
50 scoped_ptr<ResultCallback> cb(new ResultCallback(callback));
51 try {
mukesh agrawal06175d72012-04-23 16:46:01 -070052 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -050053 proxy_.Disconnect(cb.get(), timeout);
54 cb.release();
Ben Chan80326f32012-05-04 17:51:32 -070055 } catch (const DBus::Error &e) {
Eric Shienbrood9a245532012-03-07 14:20:39 -050056 if (error)
57 CellularError::FromDBusError(e, error);
58 }
Darin Petkove9d12e02011-07-27 15:09:37 -070059}
60
Eric Shienbrood9a245532012-03-07 14:20:39 -050061void ModemProxy::GetModemInfo(Error *error,
62 const ModemInfoCallback &callback,
63 int timeout) {
64 scoped_ptr<ModemInfoCallback> cb(new ModemInfoCallback(callback));
65 try {
mukesh agrawal06175d72012-04-23 16:46:01 -070066 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -050067 proxy_.GetInfo(cb.get(), timeout);
68 cb.release();
Ben Chan80326f32012-05-04 17:51:32 -070069 } catch (const DBus::Error &e) {
Eric Shienbrood9a245532012-03-07 14:20:39 -050070 if (error)
71 CellularError::FromDBusError(e, error);
72 }
Darin Petkovfb0625e2012-01-16 13:05:56 +010073}
74
Eric Shienbrood9a245532012-03-07 14:20:39 -050075ModemProxy::Proxy::Proxy(DBus::Connection *connection,
Darin Petkove9d12e02011-07-27 15:09:37 -070076 const string &path,
77 const string &service)
Eric Shienbrood9a245532012-03-07 14:20:39 -050078 : DBus::ObjectProxy(*connection, path, service.c_str()) {}
Darin Petkove9d12e02011-07-27 15:09:37 -070079
80ModemProxy::Proxy::~Proxy() {}
81
Eric Shienbrood9a245532012-03-07 14:20:39 -050082void ModemProxy::Proxy::set_state_changed_callback(
83 const ModemStateChangedSignalCallback &callback) {
84 state_changed_callback_ = callback;
85}
86
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050087void ModemProxy::Proxy::StateChanged(
88 const uint32 &old, const uint32 &_new, const uint32 &reason) {
mukesh agrawal06175d72012-04-23 16:46:01 -070089 SLOG(DBus, 2) << __func__ << "(" << old << ", " << _new << ", "
Ben Chanfad4a0b2012-04-18 15:49:59 -070090 << reason << ")";
Eric Shienbrood9a245532012-03-07 14:20:39 -050091 state_changed_callback_.Run(old, _new, reason);
Darin Petkove9d12e02011-07-27 15:09:37 -070092}
93
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050094void ModemProxy::Proxy::EnableCallback(const DBus::Error &dberror, void *data) {
mukesh agrawal06175d72012-04-23 16:46:01 -070095 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -050096 scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data));
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050097 Error error;
98 CellularError::FromDBusError(dberror, &error);
Eric Shienbrood9a245532012-03-07 14:20:39 -050099 callback->Run(error);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500100}
101
102void ModemProxy::Proxy::GetInfoCallback(const ModemHardwareInfo &info,
103 const DBus::Error &dberror,
104 void *data) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700105 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500106 scoped_ptr<ModemInfoCallback> callback(
107 reinterpret_cast<ModemInfoCallback *>(data));
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500108 Error error;
109 CellularError::FromDBusError(dberror, &error);
Eric Shienbrood9a245532012-03-07 14:20:39 -0500110 callback->Run(info, error);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500111}
112
113void ModemProxy::Proxy::DisconnectCallback(const DBus::Error &dberror,
114 void *data) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700115 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500116 scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data));
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500117 Error error;
118 CellularError::FromDBusError(dberror, &error);
Eric Shienbrood9a245532012-03-07 14:20:39 -0500119 callback->Run(error);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500120}
121
Darin Petkove9d12e02011-07-27 15:09:37 -0700122} // namespace shill