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_modem3gpp_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 | |
| 15 | ModemModem3gppProxy::ModemModem3gppProxy( |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 16 | DBus::Connection *connection, |
| 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 | ModemModem3gppProxy::~ModemModem3gppProxy() {} |
| 22 | |
| 23 | void ModemModem3gppProxy::Register(const std::string &operator_id, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 24 | Error *error, |
| 25 | const ResultCallback &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<ResultCallback> cb(new ResultCallback(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_.Register(operator_id, 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) |
| 34 | CellularError::FromDBusError(e, error); |
| 35 | } |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 36 | } |
| 37 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 38 | void ModemModem3gppProxy::Scan(Error *error, |
| 39 | const DBusPropertyMapsCallback &callback, |
| 40 | int timeout) { |
| 41 | scoped_ptr<DBusPropertyMapsCallback> cb( |
| 42 | new DBusPropertyMapsCallback(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_.Scan(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) |
| 49 | CellularError::FromDBusError(e, error); |
| 50 | } |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | // Inherited properties from ModemModem3gppProxyInterface. |
| 54 | std::string ModemModem3gppProxy::Imei() { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 55 | SLOG(DBus, 2) << __func__; |
Gary Morain | 610977f | 2012-05-04 16:03:52 -0700 | [diff] [blame] | 56 | try { |
| 57 | return proxy_.Imei(); |
| 58 | } catch (const DBus::Error &e) { |
| 59 | LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what(); |
| 60 | return std::string(); // Make the compiler happy. |
| 61 | } |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 62 | }; |
| 63 | uint32_t ModemModem3gppProxy::RegistrationState() { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 64 | SLOG(DBus, 2) << __func__; |
Gary Morain | 610977f | 2012-05-04 16:03:52 -0700 | [diff] [blame] | 65 | try { |
| 66 | return proxy_.RegistrationState(); |
| 67 | } catch (const DBus::Error &e) { |
| 68 | LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what(); |
| 69 | return 0; // Make the compiler happy. |
| 70 | } |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 71 | }; |
| 72 | std::string ModemModem3gppProxy::OperatorCode() { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 73 | SLOG(DBus, 2) << __func__; |
Gary Morain | 610977f | 2012-05-04 16:03:52 -0700 | [diff] [blame] | 74 | try { |
| 75 | return proxy_.OperatorCode(); |
| 76 | } catch (const DBus::Error &e) { |
| 77 | LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what(); |
| 78 | return std::string(); // Make the compiler happy. |
| 79 | } |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 80 | }; |
| 81 | std::string ModemModem3gppProxy::OperatorName() { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 82 | SLOG(DBus, 2) << __func__; |
Gary Morain | 610977f | 2012-05-04 16:03:52 -0700 | [diff] [blame] | 83 | try { |
| 84 | return proxy_.OperatorName(); |
| 85 | } catch (const DBus::Error &e) { |
| 86 | LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what(); |
| 87 | return std::string(); // Make the compiler happy. |
| 88 | } |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 89 | }; |
| 90 | uint32_t ModemModem3gppProxy::EnabledFacilityLocks() { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 91 | SLOG(DBus, 2) << __func__; |
Gary Morain | 610977f | 2012-05-04 16:03:52 -0700 | [diff] [blame] | 92 | try { |
| 93 | return proxy_.EnabledFacilityLocks(); |
| 94 | } catch (const DBus::Error &e) { |
| 95 | LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what(); |
| 96 | return 0; // Make the compiler happy. |
| 97 | } |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 98 | }; |
| 99 | |
| 100 | // ModemModem3gppProxy::Proxy |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 101 | ModemModem3gppProxy::Proxy::Proxy(DBus::Connection *connection, |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 102 | const std::string &path, |
| 103 | const std::string &service) |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 104 | : DBus::ObjectProxy(*connection, path, service.c_str()) {} |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 105 | |
| 106 | ModemModem3gppProxy::Proxy::~Proxy() {} |
| 107 | |
| 108 | // Method callbacks inherited from |
| 109 | // org::freedesktop::ModemManager1::Modem::ModemModem3gppProxy |
| 110 | void ModemModem3gppProxy::Proxy::RegisterCallback(const ::DBus::Error& dberror, |
| 111 | void *data) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 112 | SLOG(DBus, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 113 | scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data)); |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 114 | Error error; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 115 | CellularError::FromDBusError(dberror, &error); |
| 116 | callback->Run(error); |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | void ModemModem3gppProxy::Proxy::ScanCallback( |
| 120 | const std::vector<DBusPropertiesMap> &results, |
| 121 | const ::DBus::Error& dberror, void *data) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 122 | SLOG(DBus, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 123 | scoped_ptr<DBusPropertyMapsCallback> callback( |
| 124 | reinterpret_cast<DBusPropertyMapsCallback *>(data)); |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 125 | Error error; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 126 | CellularError::FromDBusError(dberror, &error); |
| 127 | callback->Run(results, error); |
Jason Glasgow | ee1081c | 2012-03-06 15:14:53 -0500 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | } // namespace mm1 |
| 131 | } // namespace shill |