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