blob: 4bfad57d0e51ebea278a9d9af3dbf2c4f0088ee7 [file] [log] [blame]
Jason Glasgowee1081c2012-03-06 15:14:53 -05001// 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 agrawal06175d72012-04-23 16:46:01 -07009#include "shill/cellular_error.h"
10#include "shill/scope_logger.h"
Jason Glasgowee1081c2012-03-06 15:14:53 -050011
12using std::string;
13
14namespace shill {
15namespace mm1 {
16
17ModemModem3gppProxy::ModemModem3gppProxy(
Jason Glasgowee1081c2012-03-06 15:14:53 -050018 DBus::Connection *connection,
19 const string &path,
20 const string &service)
Eric Shienbrood9a245532012-03-07 14:20:39 -050021 : proxy_(connection, path, service) {}
Jason Glasgowee1081c2012-03-06 15:14:53 -050022
23ModemModem3gppProxy::~ModemModem3gppProxy() {}
24
25void ModemModem3gppProxy::Register(const std::string &operator_id,
Eric Shienbrood9a245532012-03-07 14:20:39 -050026 Error *error,
27 const ResultCallback &callback,
Jason Glasgowee1081c2012-03-06 15:14:53 -050028 int timeout) {
Eric Shienbrood9a245532012-03-07 14:20:39 -050029 scoped_ptr<ResultCallback> cb(new ResultCallback(callback));
30 try {
mukesh agrawal06175d72012-04-23 16:46:01 -070031 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -050032 proxy_.Register(operator_id, cb.get(), timeout);
33 cb.release();
Ben Chan80326f32012-05-04 17:51:32 -070034 } catch (const DBus::Error &e) {
Eric Shienbrood9a245532012-03-07 14:20:39 -050035 if (error)
36 CellularError::FromDBusError(e, error);
37 }
Jason Glasgowee1081c2012-03-06 15:14:53 -050038}
39
Eric Shienbrood9a245532012-03-07 14:20:39 -050040void ModemModem3gppProxy::Scan(Error *error,
41 const DBusPropertyMapsCallback &callback,
42 int timeout) {
43 scoped_ptr<DBusPropertyMapsCallback> cb(
44 new DBusPropertyMapsCallback(callback));
45 try {
mukesh agrawal06175d72012-04-23 16:46:01 -070046 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -050047 proxy_.Scan(cb.get(), timeout);
48 cb.release();
Ben Chan80326f32012-05-04 17:51:32 -070049 } catch (const DBus::Error &e) {
Eric Shienbrood9a245532012-03-07 14:20:39 -050050 if (error)
51 CellularError::FromDBusError(e, error);
52 }
Jason Glasgowee1081c2012-03-06 15:14:53 -050053}
54
55// Inherited properties from ModemModem3gppProxyInterface.
56std::string ModemModem3gppProxy::Imei() {
mukesh agrawal06175d72012-04-23 16:46:01 -070057 SLOG(DBus, 2) << __func__;
Gary Morain610977f2012-05-04 16:03:52 -070058 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 Glasgowee1081c2012-03-06 15:14:53 -050064};
65uint32_t ModemModem3gppProxy::RegistrationState() {
mukesh agrawal06175d72012-04-23 16:46:01 -070066 SLOG(DBus, 2) << __func__;
Gary Morain610977f2012-05-04 16:03:52 -070067 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 Glasgowee1081c2012-03-06 15:14:53 -050073};
74std::string ModemModem3gppProxy::OperatorCode() {
mukesh agrawal06175d72012-04-23 16:46:01 -070075 SLOG(DBus, 2) << __func__;
Gary Morain610977f2012-05-04 16:03:52 -070076 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 Glasgowee1081c2012-03-06 15:14:53 -050082};
83std::string ModemModem3gppProxy::OperatorName() {
mukesh agrawal06175d72012-04-23 16:46:01 -070084 SLOG(DBus, 2) << __func__;
Gary Morain610977f2012-05-04 16:03:52 -070085 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 Glasgowee1081c2012-03-06 15:14:53 -050091};
92uint32_t ModemModem3gppProxy::EnabledFacilityLocks() {
mukesh agrawal06175d72012-04-23 16:46:01 -070093 SLOG(DBus, 2) << __func__;
Gary Morain610977f2012-05-04 16:03:52 -070094 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 Glasgowee1081c2012-03-06 15:14:53 -0500100};
101
102// ModemModem3gppProxy::Proxy
Eric Shienbrood9a245532012-03-07 14:20:39 -0500103ModemModem3gppProxy::Proxy::Proxy(DBus::Connection *connection,
Jason Glasgowee1081c2012-03-06 15:14:53 -0500104 const std::string &path,
105 const std::string &service)
Eric Shienbrood9a245532012-03-07 14:20:39 -0500106 : DBus::ObjectProxy(*connection, path, service.c_str()) {}
Jason Glasgowee1081c2012-03-06 15:14:53 -0500107
108ModemModem3gppProxy::Proxy::~Proxy() {}
109
110// Method callbacks inherited from
111// org::freedesktop::ModemManager1::Modem::ModemModem3gppProxy
112void ModemModem3gppProxy::Proxy::RegisterCallback(const ::DBus::Error& dberror,
113 void *data) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700114 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500115 scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data));
Jason Glasgowee1081c2012-03-06 15:14:53 -0500116 Error error;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500117 CellularError::FromDBusError(dberror, &error);
118 callback->Run(error);
Jason Glasgowee1081c2012-03-06 15:14:53 -0500119}
120
121void ModemModem3gppProxy::Proxy::ScanCallback(
122 const std::vector<DBusPropertiesMap> &results,
123 const ::DBus::Error& dberror, void *data) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700124 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500125 scoped_ptr<DBusPropertyMapsCallback> callback(
126 reinterpret_cast<DBusPropertyMapsCallback *>(data));
Jason Glasgowee1081c2012-03-06 15:14:53 -0500127 Error error;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500128 CellularError::FromDBusError(dberror, &error);
129 callback->Run(results, error);
Jason Glasgowee1081c2012-03-06 15:14:53 -0500130}
131
132} // namespace mm1
133} // namespace shill