blob: de3adc19ffb63903b8114bd1eccf795ba3c7fe83 [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
9#include "cellular_error.h"
Jason Glasgowee1081c2012-03-06 15:14:53 -050010
11using std::string;
12
13namespace shill {
14namespace mm1 {
15
Eric Shienbrood9a245532012-03-07 14:20:39 -050016ModemSimpleProxy::ModemSimpleProxy(DBus::Connection *connection,
Jason Glasgowee1081c2012-03-06 15:14:53 -050017 const string &path,
18 const string &service)
Eric Shienbrood9a245532012-03-07 14:20:39 -050019 : proxy_(connection, path, service) {}
Jason Glasgowee1081c2012-03-06 15:14:53 -050020
21ModemSimpleProxy::~ModemSimpleProxy() {}
22
23void ModemSimpleProxy::Connect(
24 const DBusPropertiesMap &properties,
Eric Shienbrood9a245532012-03-07 14:20:39 -050025 Error *error,
26 const DBusPathCallback &callback,
Jason Glasgowee1081c2012-03-06 15:14:53 -050027 int timeout) {
Eric Shienbrood9a245532012-03-07 14:20:39 -050028 scoped_ptr<DBusPathCallback> cb(new DBusPathCallback(callback));
29 try {
30 proxy_.Connect(properties, cb.get(), timeout);
31 cb.release();
32 } catch (DBus::Error e) {
33 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 {
44 proxy_.Disconnect(bearer, cb.get(), timeout);
45 cb.release();
46 } catch (DBus::Error e) {
47 if (error)
48 CellularError::FromDBusError(e, error);
49 }
Jason Glasgowee1081c2012-03-06 15:14:53 -050050}
51
Eric Shienbrood9a245532012-03-07 14:20:39 -050052void ModemSimpleProxy::GetStatus(Error *error,
53 const DBusPropertyMapCallback &callback,
54 int timeout) {
55 scoped_ptr<DBusPropertyMapCallback> cb(new DBusPropertyMapCallback(callback));
56 try {
57 proxy_.GetStatus(cb.get(), timeout);
58 cb.release();
59 } catch (DBus::Error e) {
60 if (error)
61 CellularError::FromDBusError(e, error);
62 }
Jason Glasgowee1081c2012-03-06 15:14:53 -050063}
64
65
66// ModemSimpleProxy::Proxy
Eric Shienbrood9a245532012-03-07 14:20:39 -050067ModemSimpleProxy::Proxy::Proxy(DBus::Connection *connection,
Jason Glasgowee1081c2012-03-06 15:14:53 -050068 const std::string &path,
69 const std::string &service)
Eric Shienbrood9a245532012-03-07 14:20:39 -050070 : DBus::ObjectProxy(*connection, path, service.c_str()) {}
Jason Glasgowee1081c2012-03-06 15:14:53 -050071
72ModemSimpleProxy::Proxy::~Proxy() {}
73
74// Method callbacks inherited from
75// org::freedesktop::ModemManager1::Modem::ModemSimpleProxy
76void ModemSimpleProxy::Proxy::ConnectCallback(const ::DBus::Path &bearer,
77 const ::DBus::Error &dberror,
78 void *data) {
Eric Shienbrood9a245532012-03-07 14:20:39 -050079 scoped_ptr<DBusPathCallback> callback(
80 reinterpret_cast<DBusPathCallback *>(data));
Jason Glasgowee1081c2012-03-06 15:14:53 -050081 Error error;
Eric Shienbrood9a245532012-03-07 14:20:39 -050082 CellularError::FromDBusError(dberror, &error);
83 callback->Run(bearer, error);
Jason Glasgowee1081c2012-03-06 15:14:53 -050084}
85
86void ModemSimpleProxy::Proxy::DisconnectCallback(const ::DBus::Error &dberror,
87 void *data) {
Eric Shienbrood9a245532012-03-07 14:20:39 -050088 scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data));
Jason Glasgowee1081c2012-03-06 15:14:53 -050089 Error error;
Eric Shienbrood9a245532012-03-07 14:20:39 -050090 CellularError::FromDBusError(dberror, &error);
91 callback->Run(error);
Jason Glasgowee1081c2012-03-06 15:14:53 -050092}
93
94void ModemSimpleProxy::Proxy::GetStatusCallback(
95 const DBusPropertiesMap &properties,
96 const ::DBus::Error &dberror,
97 void *data) {
Eric Shienbrood9a245532012-03-07 14:20:39 -050098 scoped_ptr<DBusPropertyMapCallback> callback(
99 reinterpret_cast<DBusPropertyMapCallback *>(data));
Jason Glasgowee1081c2012-03-06 15:14:53 -0500100 Error error;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500101 CellularError::FromDBusError(dberror, &error);
102 callback->Run(properties, error);
Jason Glasgowee1081c2012-03-06 15:14:53 -0500103}
104
105} // namespace mm1
106} // namespace shill