blob: cb3515660359d03a43dba839cea275929cb8397a [file] [log] [blame]
Arman Uguray6e5639f2012-11-15 20:30:19 -08001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
2// 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/mm1_bearer_proxy.h"
6
7#include "shill/cellular_error.h"
8#include "shill/logging.h"
9
10using std::string;
11
12namespace shill {
13namespace mm1 {
14
15BearerProxy::BearerProxy(DBus::Connection *connection,
16 const std::string &path,
17 const std::string &service)
18 : proxy_(connection, path, service) {}
19
20BearerProxy::~BearerProxy() {}
21
22
23// Inherited methods from BearerProxyInterface
24void BearerProxy::Connect(Error *error,
25 const ResultCallback &callback,
26 int timeout) {
27 SLOG(Modem, 2) << __func__;
28 scoped_ptr<ResultCallback> cb(new ResultCallback(callback));
29 try {
30 SLOG(DBus, 2) << __func__;
31 proxy_.Connect(cb.get(), timeout);
32 cb.release();
33 } catch (const DBus::Error &e) {
34 if (error)
Arman Uguray763df862013-07-02 12:49:10 -070035 CellularError::FromMM1DBusError(e, error);
Arman Uguray6e5639f2012-11-15 20:30:19 -080036 }
37}
38
39void BearerProxy::Disconnect(Error *error,
40 const ResultCallback &callback,
41 int timeout) {
42 SLOG(Modem, 2) << __func__;
43 scoped_ptr<ResultCallback> cb(new ResultCallback(callback));
44 try {
45 SLOG(DBus, 2) << __func__;
46 proxy_.Disconnect(cb.get(), timeout);
47 cb.release();
48 } catch (const DBus::Error &e) {
49 if (error)
Arman Uguray763df862013-07-02 12:49:10 -070050 CellularError::FromMM1DBusError(e, error);
Arman Uguray6e5639f2012-11-15 20:30:19 -080051 }
52}
53
54// Inherited properties from BearerProxyInterface
55const string BearerProxy::Interface() {
56 SLOG(DBus, 2) << __func__;
57 try {
58 return proxy_.Interface();
59 } catch (const DBus::Error &e) {
60 LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what();
61 return string(); // Make the compiler happy.
62 }
63}
64
65bool BearerProxy::Connected() {
66 SLOG(DBus, 2) << __func__;
67 try {
68 return proxy_.Connected();
69 } catch (const DBus::Error &e) {
70 LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what();
71 return false; // Make the compiler happy.
72 }
73}
74
75bool BearerProxy::Suspended() {
76 SLOG(DBus, 2) << __func__;
77 try {
78 return proxy_.Suspended();
79 } catch (const DBus::Error &e) {
80 LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what();
81 return false; // Make the compiler happy.
82 }
83}
84
85const DBusPropertiesMap BearerProxy::Ip4Config() {
86 SLOG(DBus, 2) << __func__;
87 try {
88 return proxy_.Ip4Config();
89 } catch (const DBus::Error &e) {
90 LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what();
91 return DBusPropertiesMap(); // Make the compiler happy.
92 }
93}
94
95const DBusPropertiesMap BearerProxy::Ip6Config() {
96 SLOG(DBus, 2) << __func__;
97 try {
98 return proxy_.Ip6Config();
99 } catch (const DBus::Error &e) {
100 LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what();
101 return DBusPropertiesMap(); // Make the compiler happy.
102 }
103}
104
105uint32_t BearerProxy::IpTimeout() {
106 SLOG(DBus, 2) << __func__;
107 try {
108 return proxy_.IpTimeout();
109 } catch (const DBus::Error &e) {
110 LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what();
111 return 0; // Make the compiler happy.
112 }
113}
114
115const DBusPropertiesMap BearerProxy::Properties() {
116 SLOG(DBus, 2) << __func__;
117 try {
118 return proxy_.Properties();
119 } catch (const DBus::Error &e) {
120 LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what();
121 return DBusPropertiesMap(); // Make the compiler happy.
122 }
123}
124
125BearerProxy::Proxy::Proxy(DBus::Connection *connection,
126 const std::string &path,
127 const std::string &service)
128 : DBus::ObjectProxy(*connection, path, service.c_str()) {}
129
130BearerProxy::Proxy::~Proxy() {}
131
132
133// Method callbacks inherited from
134// org::freedesktop::ModemManager1::BearerProxy
135void BearerProxy::Proxy::ConnectCallback(const ::DBus::Error &dberror,
136 void *data) {
137 SLOG(DBus, 2) << __func__;
138 scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data));
139 Error error;
Arman Uguray763df862013-07-02 12:49:10 -0700140 CellularError::FromMM1DBusError(dberror, &error);
Arman Uguray6e5639f2012-11-15 20:30:19 -0800141 callback->Run(error);
142}
143
144void BearerProxy::Proxy::DisconnectCallback(const ::DBus::Error &dberror,
145 void *data) {
146 SLOG(DBus, 2) << __func__;
147 scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data));
148 Error error;
Arman Uguray763df862013-07-02 12:49:10 -0700149 CellularError::FromMM1DBusError(dberror, &error);
Arman Uguray6e5639f2012-11-15 20:30:19 -0800150 callback->Run(error);
151}
152
153} // namespace mm1
154} // namespace shill