Arman Uguray | 2c39fab | 2012-12-12 16:56:34 -0800 | [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 "mm1_modem_location_proxy.h" |
| 6 | |
| 7 | #include "shill/cellular_error.h" |
| 8 | #include "shill/logging.h" |
| 9 | |
| 10 | using std::string; |
| 11 | |
| 12 | namespace shill { |
| 13 | namespace mm1 { |
| 14 | |
| 15 | ModemLocationProxy::ModemLocationProxy(DBus::Connection *connection, |
| 16 | const string &path, |
| 17 | const string &service) |
| 18 | : proxy_(connection, path, service) {} |
| 19 | |
| 20 | ModemLocationProxy::~ModemLocationProxy() {} |
| 21 | |
| 22 | void ModemLocationProxy::Setup(uint32_t sources, |
| 23 | bool signal_location, |
| 24 | Error *error, |
| 25 | const ResultCallback &callback, |
| 26 | int timeout) { |
| 27 | SLOG(Modem, 2) << __func__; |
| 28 | scoped_ptr<ResultCallback> cb(new ResultCallback(callback)); |
| 29 | try { |
| 30 | SLOG(DBus, 2) << __func__; |
| 31 | proxy_.Setup(sources, signal_location, cb.get(), timeout); |
| 32 | cb.release(); |
| 33 | } catch (const DBus::Error &e) { |
| 34 | if (error) |
Arman Uguray | 763df86 | 2013-07-02 12:49:10 -0700 | [diff] [blame] | 35 | CellularError::FromMM1DBusError(e, error); |
Arman Uguray | 2c39fab | 2012-12-12 16:56:34 -0800 | [diff] [blame] | 36 | } |
| 37 | } |
| 38 | |
| 39 | void ModemLocationProxy::GetLocation(Error *error, |
| 40 | const DBusEnumValueMapCallback &callback, |
| 41 | int timeout) { |
| 42 | SLOG(Modem, 2) << __func__; |
| 43 | scoped_ptr<DBusEnumValueMapCallback> cb( |
| 44 | new DBusEnumValueMapCallback(callback)); |
| 45 | try { |
| 46 | SLOG(DBus, 2) << __func__; |
| 47 | proxy_.GetLocation(cb.get(), timeout); |
| 48 | cb.release(); |
| 49 | } catch (const DBus::Error &e) { |
| 50 | if (error) |
Arman Uguray | 763df86 | 2013-07-02 12:49:10 -0700 | [diff] [blame] | 51 | CellularError::FromMM1DBusError(e, error); |
Arman Uguray | 2c39fab | 2012-12-12 16:56:34 -0800 | [diff] [blame] | 52 | } |
| 53 | } |
| 54 | |
Arman Uguray | 2c39fab | 2012-12-12 16:56:34 -0800 | [diff] [blame] | 55 | ModemLocationProxy::Proxy::Proxy(DBus::Connection *connection, |
| 56 | const string &path, |
| 57 | const string &service) |
| 58 | : DBus::ObjectProxy(*connection, path, service.c_str()) {} |
| 59 | |
| 60 | ModemLocationProxy::Proxy::~Proxy() {} |
| 61 | |
| 62 | // Method callbacks inherited from |
| 63 | // org::freedesktop::ModemManager1::Modem:LocationProxy |
| 64 | void ModemLocationProxy::Proxy::SetupCallback(const ::DBus::Error &dberror, |
| 65 | void *data) { |
| 66 | SLOG(DBus, 2) << __func__; |
| 67 | scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data)); |
| 68 | Error error; |
Arman Uguray | 763df86 | 2013-07-02 12:49:10 -0700 | [diff] [blame] | 69 | CellularError::FromMM1DBusError(dberror, &error); |
Arman Uguray | 2c39fab | 2012-12-12 16:56:34 -0800 | [diff] [blame] | 70 | callback->Run(error); |
| 71 | } |
| 72 | |
| 73 | void ModemLocationProxy::Proxy::GetLocationCallback( |
| 74 | const DBusEnumValueMap &location, |
| 75 | const ::DBus::Error &dberror, |
| 76 | void *data) { |
| 77 | SLOG(DBus, 2) << __func__; |
| 78 | scoped_ptr<DBusEnumValueMapCallback> callback( |
| 79 | reinterpret_cast<DBusEnumValueMapCallback *>(data)); |
| 80 | Error error; |
Arman Uguray | 763df86 | 2013-07-02 12:49:10 -0700 | [diff] [blame] | 81 | CellularError::FromMM1DBusError(dberror, &error); |
Arman Uguray | 2c39fab | 2012-12-12 16:56:34 -0800 | [diff] [blame] | 82 | callback->Run(location, error); |
| 83 | } |
| 84 | |
| 85 | } // namespace mm1 |
| 86 | } // namespace shill |