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 | |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 7 | #include "shill/cellular_error.h" |
Christopher Wiley | b691efd | 2012-08-09 13:51:51 -0700 | [diff] [blame] | 8 | #include "shill/logging.h" |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 9 | |
| 10 | using std::string; |
| 11 | |
| 12 | namespace shill { |
| 13 | namespace mm1 { |
| 14 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 15 | ModemSimpleProxy::ModemSimpleProxy(DBus::Connection *connection, |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 16 | const string &path, |
| 17 | const string &service) |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 18 | : proxy_(connection, path, service) {} |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 19 | |
| 20 | ModemSimpleProxy::~ModemSimpleProxy() {} |
| 21 | |
| 22 | void ModemSimpleProxy::Connect( |
| 23 | const DBusPropertiesMap &properties, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 24 | Error *error, |
| 25 | const DBusPathCallback &callback, |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 26 | int timeout) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 27 | scoped_ptr<DBusPathCallback> cb(new DBusPathCallback(callback)); |
| 28 | try { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 29 | SLOG(DBus, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 30 | proxy_.Connect(properties, cb.get(), timeout); |
| 31 | cb.release(); |
Ben Chan | 80326f3 | 2012-05-04 17:51:32 -0700 | [diff] [blame] | 32 | } catch (const DBus::Error &e) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 33 | if (error) |
Arman Uguray | 763df86 | 2013-07-02 12:49:10 -0700 | [diff] [blame] | 34 | CellularError::FromMM1DBusError(e, error); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 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 { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 44 | SLOG(DBus, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 45 | proxy_.Disconnect(bearer, cb.get(), timeout); |
| 46 | cb.release(); |
Ben Chan | 80326f3 | 2012-05-04 17:51:32 -0700 | [diff] [blame] | 47 | } catch (const DBus::Error &e) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 48 | if (error) |
Arman Uguray | 763df86 | 2013-07-02 12:49:10 -0700 | [diff] [blame] | 49 | CellularError::FromMM1DBusError(e, error); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 50 | } |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 51 | } |
| 52 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 53 | void ModemSimpleProxy::GetStatus(Error *error, |
| 54 | const DBusPropertyMapCallback &callback, |
| 55 | int timeout) { |
| 56 | scoped_ptr<DBusPropertyMapCallback> cb(new DBusPropertyMapCallback(callback)); |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 57 | try { |
| 58 | SLOG(DBus, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 59 | proxy_.GetStatus(cb.get(), timeout); |
| 60 | cb.release(); |
Ben Chan | 80326f3 | 2012-05-04 17:51:32 -0700 | [diff] [blame] | 61 | } catch (const DBus::Error &e) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 62 | if (error) |
Arman Uguray | 763df86 | 2013-07-02 12:49:10 -0700 | [diff] [blame] | 63 | CellularError::FromMM1DBusError(e, error); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 64 | } |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | |
| 68 | // ModemSimpleProxy::Proxy |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 69 | ModemSimpleProxy::Proxy::Proxy(DBus::Connection *connection, |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 70 | const std::string &path, |
| 71 | const std::string &service) |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 72 | : DBus::ObjectProxy(*connection, path, service.c_str()) {} |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 73 | |
| 74 | ModemSimpleProxy::Proxy::~Proxy() {} |
| 75 | |
| 76 | // Method callbacks inherited from |
| 77 | // org::freedesktop::ModemManager1::Modem::ModemSimpleProxy |
| 78 | void ModemSimpleProxy::Proxy::ConnectCallback(const ::DBus::Path &bearer, |
| 79 | const ::DBus::Error &dberror, |
| 80 | void *data) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 81 | SLOG(DBus, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 82 | scoped_ptr<DBusPathCallback> callback( |
| 83 | reinterpret_cast<DBusPathCallback *>(data)); |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 84 | Error error; |
Arman Uguray | 763df86 | 2013-07-02 12:49:10 -0700 | [diff] [blame] | 85 | CellularError::FromMM1DBusError(dberror, &error); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 86 | callback->Run(bearer, error); |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | void ModemSimpleProxy::Proxy::DisconnectCallback(const ::DBus::Error &dberror, |
| 90 | void *data) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 91 | SLOG(DBus, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 92 | scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data)); |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 93 | Error error; |
Arman Uguray | 763df86 | 2013-07-02 12:49:10 -0700 | [diff] [blame] | 94 | CellularError::FromMM1DBusError(dberror, &error); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 95 | callback->Run(error); |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | void ModemSimpleProxy::Proxy::GetStatusCallback( |
| 99 | const DBusPropertiesMap &properties, |
| 100 | const ::DBus::Error &dberror, |
| 101 | void *data) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 102 | SLOG(DBus, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 103 | scoped_ptr<DBusPropertyMapCallback> callback( |
| 104 | reinterpret_cast<DBusPropertyMapCallback *>(data)); |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 105 | Error error; |
Arman Uguray | 763df86 | 2013-07-02 12:49:10 -0700 | [diff] [blame] | 106 | CellularError::FromMM1DBusError(dberror, &error); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 107 | callback->Run(properties, error); |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | } // namespace mm1 |
| 111 | } // namespace shill |