blob: 4e4d781ccc8b9723f759eb6beb5283ca2ede6917 [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)
Arman Uguray763df862013-07-02 12:49:10 -070034 CellularError::FromMM1DBusError(e, error);
Eric Shienbrood9a245532012-03-07 14:20:39 -050035 }
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)
Arman Uguray763df862013-07-02 12:49:10 -070049 CellularError::FromMM1DBusError(e, error);
Eric Shienbrood9a245532012-03-07 14:20:39 -050050 }
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)
Arman Uguray763df862013-07-02 12:49:10 -070063 CellularError::FromMM1DBusError(e, error);
Eric Shienbrood9a245532012-03-07 14:20:39 -050064 }
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;
Arman Uguray763df862013-07-02 12:49:10 -070085 CellularError::FromMM1DBusError(dberror, &error);
Eric Shienbrood9a245532012-03-07 14:20:39 -050086 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;
Arman Uguray763df862013-07-02 12:49:10 -070094 CellularError::FromMM1DBusError(dberror, &error);
Eric Shienbrood9a245532012-03-07 14:20:39 -050095 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;
Arman Uguray763df862013-07-02 12:49:10 -0700106 CellularError::FromMM1DBusError(dberror, &error);
Eric Shienbrood9a245532012-03-07 14:20:39 -0500107 callback->Run(properties, error);
Jason Glasgowee1081c2012-03-06 15:14:53 -0500108}
109
110} // namespace mm1
111} // namespace shill