Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 1 | // 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 Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 10 | |
| 11 | using std::string; |
| 12 | |
| 13 | namespace shill { |
| 14 | namespace mm1 { |
| 15 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame^] | 16 | ModemSimpleProxy::ModemSimpleProxy(DBus::Connection *connection, |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 17 | const string &path, |
| 18 | const string &service) |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame^] | 19 | : proxy_(connection, path, service) {} |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 20 | |
| 21 | ModemSimpleProxy::~ModemSimpleProxy() {} |
| 22 | |
| 23 | void ModemSimpleProxy::Connect( |
| 24 | const DBusPropertiesMap &properties, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame^] | 25 | Error *error, |
| 26 | const DBusPathCallback &callback, |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 27 | int timeout) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame^] | 28 | 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 Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | void ModemSimpleProxy::Disconnect(const ::DBus::Path &bearer, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame^] | 39 | Error *error, |
| 40 | const ResultCallback &callback, |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 41 | int timeout) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame^] | 42 | 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 Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 50 | } |
| 51 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame^] | 52 | void 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 Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | |
| 66 | // ModemSimpleProxy::Proxy |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame^] | 67 | ModemSimpleProxy::Proxy::Proxy(DBus::Connection *connection, |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 68 | const std::string &path, |
| 69 | const std::string &service) |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame^] | 70 | : DBus::ObjectProxy(*connection, path, service.c_str()) {} |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 71 | |
| 72 | ModemSimpleProxy::Proxy::~Proxy() {} |
| 73 | |
| 74 | // Method callbacks inherited from |
| 75 | // org::freedesktop::ModemManager1::Modem::ModemSimpleProxy |
| 76 | void ModemSimpleProxy::Proxy::ConnectCallback(const ::DBus::Path &bearer, |
| 77 | const ::DBus::Error &dberror, |
| 78 | void *data) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame^] | 79 | scoped_ptr<DBusPathCallback> callback( |
| 80 | reinterpret_cast<DBusPathCallback *>(data)); |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 81 | Error error; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame^] | 82 | CellularError::FromDBusError(dberror, &error); |
| 83 | callback->Run(bearer, error); |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | void ModemSimpleProxy::Proxy::DisconnectCallback(const ::DBus::Error &dberror, |
| 87 | void *data) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame^] | 88 | scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data)); |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 89 | Error error; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame^] | 90 | CellularError::FromDBusError(dberror, &error); |
| 91 | callback->Run(error); |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | void ModemSimpleProxy::Proxy::GetStatusCallback( |
| 95 | const DBusPropertiesMap &properties, |
| 96 | const ::DBus::Error &dberror, |
| 97 | void *data) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame^] | 98 | scoped_ptr<DBusPropertyMapCallback> callback( |
| 99 | reinterpret_cast<DBusPropertyMapCallback *>(data)); |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 100 | Error error; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame^] | 101 | CellularError::FromDBusError(dberror, &error); |
| 102 | callback->Run(properties, error); |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | } // namespace mm1 |
| 106 | } // namespace shill |