blob: 0a7b85a461d19133a08dfabcf421911d125fd0a2 [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
7#include <base/logging.h>
8
Eric Shienbrood5de44ab2011-12-05 10:46:27 -05009#include "shill/cellular_error.h"
10#include "shill/error.h"
11
Darin Petkove9d12e02011-07-27 15:09:37 -070012using std::string;
13
14namespace shill {
15
Darin Petkov580c7af2011-10-24 12:32:50 +020016ModemProxy::ModemProxy(ModemProxyDelegate *delegate,
Darin Petkovc5f56562011-08-06 16:40:05 -070017 DBus::Connection *connection,
Darin Petkove9d12e02011-07-27 15:09:37 -070018 const string &path,
19 const string &service)
Darin Petkov580c7af2011-10-24 12:32:50 +020020 : proxy_(delegate, connection, path, service) {}
Darin Petkove9d12e02011-07-27 15:09:37 -070021
22ModemProxy::~ModemProxy() {}
23
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050024// TODO(ers): Need to handle dbus errors that occur and prevent the
25// RPC from going out. These currently result in exceptions being thrown.
26// We need a way to let the upper layers know that the operation
27// failed in such a case.
28void ModemProxy::Enable(bool enable, AsyncCallHandler *call_handler,
29 int timeout) {
30 VLOG(2) << __func__ << "(" << enable << ", " << timeout << ")";
31 proxy_.Enable(enable, call_handler, timeout);
32}
33
34// TODO(ers): temporarily support the blocking version
35// of Enable, until Cellular::Stop is converted for async.
36void ModemProxy::Enable(bool enable) {
37 VLOG(2) << __func__ << "(" << enable << ")";
Darin Petkove9d12e02011-07-27 15:09:37 -070038 proxy_.Enable(enable);
39}
40
Darin Petkovfb0625e2012-01-16 13:05:56 +010041void ModemProxy::Disconnect() {
42 proxy_.Disconnect();
43}
44
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050045void ModemProxy::GetModemInfo(AsyncCallHandler *call_handler, int timeout) {
46 proxy_.GetInfo(call_handler, timeout);
Darin Petkovceb68172011-07-29 14:47:48 -070047}
48
Darin Petkov580c7af2011-10-24 12:32:50 +020049ModemProxy::Proxy::Proxy(ModemProxyDelegate *delegate,
Darin Petkovc5f56562011-08-06 16:40:05 -070050 DBus::Connection *connection,
Darin Petkove9d12e02011-07-27 15:09:37 -070051 const string &path,
52 const string &service)
Darin Petkovc5f56562011-08-06 16:40:05 -070053 : DBus::ObjectProxy(*connection, path, service.c_str()),
Darin Petkov580c7af2011-10-24 12:32:50 +020054 delegate_(delegate) {}
Darin Petkove9d12e02011-07-27 15:09:37 -070055
56ModemProxy::Proxy::~Proxy() {}
57
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050058void ModemProxy::Proxy::StateChanged(
59 const uint32 &old, const uint32 &_new, const uint32 &reason) {
Darin Petkovc5f56562011-08-06 16:40:05 -070060 VLOG(2) << __func__ << "(" << old << ", " << _new << ", " << reason << ")";
Darin Petkov580c7af2011-10-24 12:32:50 +020061 delegate_->OnModemStateChanged(old, _new, reason);
Darin Petkove9d12e02011-07-27 15:09:37 -070062}
63
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050064void ModemProxy::Proxy::EnableCallback(const DBus::Error &dberror, void *data) {
65 VLOG(2) << __func__;
66 AsyncCallHandler *call_handler = reinterpret_cast<AsyncCallHandler *>(data);
67 Error error;
68 CellularError::FromDBusError(dberror, &error);
69 delegate_->OnModemEnableCallback(error, call_handler);
70}
71
72void ModemProxy::Proxy::GetInfoCallback(const ModemHardwareInfo &info,
73 const DBus::Error &dberror,
74 void *data) {
75 AsyncCallHandler *call_handler = reinterpret_cast<AsyncCallHandler *>(data);
76 Error error;
77 CellularError::FromDBusError(dberror, &error);
78 delegate_->OnGetModemInfoCallback(info, error, call_handler);
79}
80
81void ModemProxy::Proxy::DisconnectCallback(const DBus::Error &dberror,
82 void *data) {
83 AsyncCallHandler *call_handler = reinterpret_cast<AsyncCallHandler *>(data);
84 Error error;
85 CellularError::FromDBusError(dberror, &error);
86 delegate_->OnDisconnectCallback(error, call_handler);
87}
88
Darin Petkove9d12e02011-07-27 15:09:37 -070089} // namespace shill