blob: 4ef2bbd6bf02814575b822d7ff27ecb1962cd2d7 [file] [log] [blame]
Jason Glasgowee1081c2012-03-06 15:14:53 -05001// 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_modem_simple_proxy.h"
6
mukesh agrawal06175d72012-04-23 16:46:01 -07007#include "shill/cellular_error.h"
Christopher Wileyb691efd2012-08-09 13:51:51 -07008#include "shill/logging.h"
Jason Glasgowee1081c2012-03-06 15:14:53 -05009
10using std::string;
11
12namespace shill {
13namespace mm1 {
14
Eric Shienbrood9a245532012-03-07 14:20:39 -050015ModemSimpleProxy::ModemSimpleProxy(DBus::Connection *connection,
Jason Glasgowee1081c2012-03-06 15:14:53 -050016 const string &path,
17 const string &service)
Eric Shienbrood9a245532012-03-07 14:20:39 -050018 : proxy_(connection, path, service) {}
Jason Glasgowee1081c2012-03-06 15:14:53 -050019
20ModemSimpleProxy::~ModemSimpleProxy() {}
21
22void ModemSimpleProxy::Connect(
23 const DBusPropertiesMap &properties,
Eric Shienbrood9a245532012-03-07 14:20:39 -050024 Error *error,
25 const DBusPathCallback &callback,
Jason Glasgowee1081c2012-03-06 15:14:53 -050026 int timeout) {
Eric Shienbrood9a245532012-03-07 14:20:39 -050027 scoped_ptr<DBusPathCallback> cb(new DBusPathCallback(callback));
28 try {
mukesh agrawal06175d72012-04-23 16:46:01 -070029 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -050030 proxy_.Connect(properties, cb.get(), timeout);
31 cb.release();
Ben Chan80326f32012-05-04 17:51:32 -070032 } catch (const DBus::Error &e) {
Eric Shienbrood9a245532012-03-07 14:20:39 -050033 if (error)
34 CellularError::FromDBusError(e, error);
35 }
Jason Glasgowee1081c2012-03-06 15:14:53 -050036}
37
38void ModemSimpleProxy::Disconnect(const ::DBus::Path &bearer,
Eric Shienbrood9a245532012-03-07 14:20:39 -050039 Error *error,
40 const ResultCallback &callback,
Jason Glasgowee1081c2012-03-06 15:14:53 -050041 int timeout) {
Eric Shienbrood9a245532012-03-07 14:20:39 -050042 scoped_ptr<ResultCallback> cb(new ResultCallback(callback));
43 try {
mukesh agrawal06175d72012-04-23 16:46:01 -070044 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -050045 proxy_.Disconnect(bearer, cb.get(), timeout);
46 cb.release();
Ben Chan80326f32012-05-04 17:51:32 -070047 } catch (const DBus::Error &e) {
Eric Shienbrood9a245532012-03-07 14:20:39 -050048 if (error)
49 CellularError::FromDBusError(e, error);
50 }
Jason Glasgowee1081c2012-03-06 15:14:53 -050051}
52
Eric Shienbrood9a245532012-03-07 14:20:39 -050053void ModemSimpleProxy::GetStatus(Error *error,
54 const DBusPropertyMapCallback &callback,
55 int timeout) {
56 scoped_ptr<DBusPropertyMapCallback> cb(new DBusPropertyMapCallback(callback));
mukesh agrawal06175d72012-04-23 16:46:01 -070057 try {
58 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -050059 proxy_.GetStatus(cb.get(), timeout);
60 cb.release();
Ben Chan80326f32012-05-04 17:51:32 -070061 } catch (const DBus::Error &e) {
Eric Shienbrood9a245532012-03-07 14:20:39 -050062 if (error)
63 CellularError::FromDBusError(e, error);
64 }
Jason Glasgowee1081c2012-03-06 15:14:53 -050065}
66
67
68// ModemSimpleProxy::Proxy
Eric Shienbrood9a245532012-03-07 14:20:39 -050069ModemSimpleProxy::Proxy::Proxy(DBus::Connection *connection,
Jason Glasgowee1081c2012-03-06 15:14:53 -050070 const std::string &path,
71 const std::string &service)
Eric Shienbrood9a245532012-03-07 14:20:39 -050072 : DBus::ObjectProxy(*connection, path, service.c_str()) {}
Jason Glasgowee1081c2012-03-06 15:14:53 -050073
74ModemSimpleProxy::Proxy::~Proxy() {}
75
76// Method callbacks inherited from
77// org::freedesktop::ModemManager1::Modem::ModemSimpleProxy
78void ModemSimpleProxy::Proxy::ConnectCallback(const ::DBus::Path &bearer,
79 const ::DBus::Error &dberror,
80 void *data) {
mukesh agrawal06175d72012-04-23 16:46:01 -070081 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -050082 scoped_ptr<DBusPathCallback> callback(
83 reinterpret_cast<DBusPathCallback *>(data));
Jason Glasgowee1081c2012-03-06 15:14:53 -050084 Error error;
Eric Shienbrood9a245532012-03-07 14:20:39 -050085 CellularError::FromDBusError(dberror, &error);
86 callback->Run(bearer, error);
Jason Glasgowee1081c2012-03-06 15:14:53 -050087}
88
89void ModemSimpleProxy::Proxy::DisconnectCallback(const ::DBus::Error &dberror,
90 void *data) {
mukesh agrawal06175d72012-04-23 16:46:01 -070091 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -050092 scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data));
Jason Glasgowee1081c2012-03-06 15:14:53 -050093 Error error;
Eric Shienbrood9a245532012-03-07 14:20:39 -050094 CellularError::FromDBusError(dberror, &error);
95 callback->Run(error);
Jason Glasgowee1081c2012-03-06 15:14:53 -050096}
97
98void ModemSimpleProxy::Proxy::GetStatusCallback(
99 const DBusPropertiesMap &properties,
100 const ::DBus::Error &dberror,
101 void *data) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700102 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500103 scoped_ptr<DBusPropertyMapCallback> callback(
104 reinterpret_cast<DBusPropertyMapCallback *>(data));
Jason Glasgowee1081c2012-03-06 15:14:53 -0500105 Error error;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500106 CellularError::FromDBusError(dberror, &error);
107 callback->Run(properties, error);
Jason Glasgowee1081c2012-03-06 15:14:53 -0500108}
109
110} // namespace mm1
111} // namespace shill