blob: ca365d87739211045721306f072577c775a915f7 [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
7#include <base/logging.h>
8
mukesh agrawal06175d72012-04-23 16:46:01 -07009#include "shill/cellular_error.h"
10#include "shill/scope_logger.h"
Jason Glasgowee1081c2012-03-06 15:14:53 -050011
12using std::string;
13
14namespace shill {
15namespace mm1 {
16
Eric Shienbrood9a245532012-03-07 14:20:39 -050017ModemSimpleProxy::ModemSimpleProxy(DBus::Connection *connection,
Jason Glasgowee1081c2012-03-06 15:14:53 -050018 const string &path,
19 const string &service)
Eric Shienbrood9a245532012-03-07 14:20:39 -050020 : proxy_(connection, path, service) {}
Jason Glasgowee1081c2012-03-06 15:14:53 -050021
22ModemSimpleProxy::~ModemSimpleProxy() {}
23
24void ModemSimpleProxy::Connect(
25 const DBusPropertiesMap &properties,
Eric Shienbrood9a245532012-03-07 14:20:39 -050026 Error *error,
27 const DBusPathCallback &callback,
Jason Glasgowee1081c2012-03-06 15:14:53 -050028 int timeout) {
Eric Shienbrood9a245532012-03-07 14:20:39 -050029 scoped_ptr<DBusPathCallback> cb(new DBusPathCallback(callback));
30 try {
mukesh agrawal06175d72012-04-23 16:46:01 -070031 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -050032 proxy_.Connect(properties, cb.get(), timeout);
33 cb.release();
Ben Chan80326f32012-05-04 17:51:32 -070034 } catch (const DBus::Error &e) {
Eric Shienbrood9a245532012-03-07 14:20:39 -050035 if (error)
36 CellularError::FromDBusError(e, error);
37 }
Jason Glasgowee1081c2012-03-06 15:14:53 -050038}
39
40void ModemSimpleProxy::Disconnect(const ::DBus::Path &bearer,
Eric Shienbrood9a245532012-03-07 14:20:39 -050041 Error *error,
42 const ResultCallback &callback,
Jason Glasgowee1081c2012-03-06 15:14:53 -050043 int timeout) {
Eric Shienbrood9a245532012-03-07 14:20:39 -050044 scoped_ptr<ResultCallback> cb(new ResultCallback(callback));
45 try {
mukesh agrawal06175d72012-04-23 16:46:01 -070046 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -050047 proxy_.Disconnect(bearer, cb.get(), timeout);
48 cb.release();
Ben Chan80326f32012-05-04 17:51:32 -070049 } catch (const DBus::Error &e) {
Eric Shienbrood9a245532012-03-07 14:20:39 -050050 if (error)
51 CellularError::FromDBusError(e, error);
52 }
Jason Glasgowee1081c2012-03-06 15:14:53 -050053}
54
Eric Shienbrood9a245532012-03-07 14:20:39 -050055void ModemSimpleProxy::GetStatus(Error *error,
56 const DBusPropertyMapCallback &callback,
57 int timeout) {
58 scoped_ptr<DBusPropertyMapCallback> cb(new DBusPropertyMapCallback(callback));
mukesh agrawal06175d72012-04-23 16:46:01 -070059 try {
60 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -050061 proxy_.GetStatus(cb.get(), timeout);
62 cb.release();
Ben Chan80326f32012-05-04 17:51:32 -070063 } catch (const DBus::Error &e) {
Eric Shienbrood9a245532012-03-07 14:20:39 -050064 if (error)
65 CellularError::FromDBusError(e, error);
66 }
Jason Glasgowee1081c2012-03-06 15:14:53 -050067}
68
69
70// ModemSimpleProxy::Proxy
Eric Shienbrood9a245532012-03-07 14:20:39 -050071ModemSimpleProxy::Proxy::Proxy(DBus::Connection *connection,
Jason Glasgowee1081c2012-03-06 15:14:53 -050072 const std::string &path,
73 const std::string &service)
Eric Shienbrood9a245532012-03-07 14:20:39 -050074 : DBus::ObjectProxy(*connection, path, service.c_str()) {}
Jason Glasgowee1081c2012-03-06 15:14:53 -050075
76ModemSimpleProxy::Proxy::~Proxy() {}
77
78// Method callbacks inherited from
79// org::freedesktop::ModemManager1::Modem::ModemSimpleProxy
80void ModemSimpleProxy::Proxy::ConnectCallback(const ::DBus::Path &bearer,
81 const ::DBus::Error &dberror,
82 void *data) {
mukesh agrawal06175d72012-04-23 16:46:01 -070083 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -050084 scoped_ptr<DBusPathCallback> callback(
85 reinterpret_cast<DBusPathCallback *>(data));
Jason Glasgowee1081c2012-03-06 15:14:53 -050086 Error error;
Eric Shienbrood9a245532012-03-07 14:20:39 -050087 CellularError::FromDBusError(dberror, &error);
88 callback->Run(bearer, error);
Jason Glasgowee1081c2012-03-06 15:14:53 -050089}
90
91void ModemSimpleProxy::Proxy::DisconnectCallback(const ::DBus::Error &dberror,
92 void *data) {
mukesh agrawal06175d72012-04-23 16:46:01 -070093 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -050094 scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data));
Jason Glasgowee1081c2012-03-06 15:14:53 -050095 Error error;
Eric Shienbrood9a245532012-03-07 14:20:39 -050096 CellularError::FromDBusError(dberror, &error);
97 callback->Run(error);
Jason Glasgowee1081c2012-03-06 15:14:53 -050098}
99
100void ModemSimpleProxy::Proxy::GetStatusCallback(
101 const DBusPropertiesMap &properties,
102 const ::DBus::Error &dberror,
103 void *data) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700104 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500105 scoped_ptr<DBusPropertyMapCallback> callback(
106 reinterpret_cast<DBusPropertyMapCallback *>(data));
Jason Glasgowee1081c2012-03-06 15:14:53 -0500107 Error error;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500108 CellularError::FromDBusError(dberror, &error);
109 callback->Run(properties, error);
Jason Glasgowee1081c2012-03-06 15:14:53 -0500110}
111
112} // namespace mm1
113} // namespace shill