blob: 7f891674ac6223a8674f742458d439876fad624f [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
mukesh agrawal06175d72012-04-23 16:46:01 -07007#include "shill/cellular_error.h"
Christopher Wileyb691efd2012-08-09 13:51:51 -07008#include "shill/logging.h"
Jason Glasgowee1081c2012-03-06 15:14:53 -05009
10using std::string;
11
12namespace shill {
13namespace mm1 {
14
15ModemModem3gppProxy::ModemModem3gppProxy(
Jason Glasgowee1081c2012-03-06 15:14:53 -050016 DBus::Connection *connection,
17 const string &path,
18 const string &service)
Eric Shienbrood9a245532012-03-07 14:20:39 -050019 : proxy_(connection, path, service) {}
Jason Glasgowee1081c2012-03-06 15:14:53 -050020
21ModemModem3gppProxy::~ModemModem3gppProxy() {}
22
23void ModemModem3gppProxy::Register(const std::string &operator_id,
Eric Shienbrood9a245532012-03-07 14:20:39 -050024 Error *error,
25 const ResultCallback &callback,
Jason Glasgowee1081c2012-03-06 15:14:53 -050026 int timeout) {
Eric Shienbrood9a245532012-03-07 14:20:39 -050027 scoped_ptr<ResultCallback> cb(new ResultCallback(callback));
28 try {
mukesh agrawal06175d72012-04-23 16:46:01 -070029 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -050030 proxy_.Register(operator_id, cb.get(), timeout);
31 cb.release();
Ben Chan80326f32012-05-04 17:51:32 -070032 } catch (const DBus::Error &e) {
Eric Shienbrood9a245532012-03-07 14:20:39 -050033 if (error)
Arman Uguray763df862013-07-02 12:49:10 -070034 CellularError::FromMM1DBusError(e, error);
Eric Shienbrood9a245532012-03-07 14:20:39 -050035 }
Jason Glasgowee1081c2012-03-06 15:14:53 -050036}
37
Eric Shienbrood9a245532012-03-07 14:20:39 -050038void ModemModem3gppProxy::Scan(Error *error,
39 const DBusPropertyMapsCallback &callback,
40 int timeout) {
41 scoped_ptr<DBusPropertyMapsCallback> cb(
42 new DBusPropertyMapsCallback(callback));
43 try {
mukesh agrawal06175d72012-04-23 16:46:01 -070044 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -050045 proxy_.Scan(cb.get(), timeout);
46 cb.release();
Ben Chan80326f32012-05-04 17:51:32 -070047 } catch (const DBus::Error &e) {
Eric Shienbrood9a245532012-03-07 14:20:39 -050048 if (error)
Arman Uguray763df862013-07-02 12:49:10 -070049 CellularError::FromMM1DBusError(e, error);
Eric Shienbrood9a245532012-03-07 14:20:39 -050050 }
Jason Glasgowee1081c2012-03-06 15:14:53 -050051}
52
53// Inherited properties from ModemModem3gppProxyInterface.
54std::string ModemModem3gppProxy::Imei() {
mukesh agrawal06175d72012-04-23 16:46:01 -070055 SLOG(DBus, 2) << __func__;
Gary Morain610977f2012-05-04 16:03:52 -070056 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 Glasgowee1081c2012-03-06 15:14:53 -050062};
63uint32_t ModemModem3gppProxy::RegistrationState() {
mukesh agrawal06175d72012-04-23 16:46:01 -070064 SLOG(DBus, 2) << __func__;
Gary Morain610977f2012-05-04 16:03:52 -070065 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 Glasgowee1081c2012-03-06 15:14:53 -050071};
72std::string ModemModem3gppProxy::OperatorCode() {
mukesh agrawal06175d72012-04-23 16:46:01 -070073 SLOG(DBus, 2) << __func__;
Gary Morain610977f2012-05-04 16:03:52 -070074 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 Glasgowee1081c2012-03-06 15:14:53 -050080};
81std::string ModemModem3gppProxy::OperatorName() {
mukesh agrawal06175d72012-04-23 16:46:01 -070082 SLOG(DBus, 2) << __func__;
Gary Morain610977f2012-05-04 16:03:52 -070083 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 Glasgowee1081c2012-03-06 15:14:53 -050089};
90uint32_t ModemModem3gppProxy::EnabledFacilityLocks() {
mukesh agrawal06175d72012-04-23 16:46:01 -070091 SLOG(DBus, 2) << __func__;
Gary Morain610977f2012-05-04 16:03:52 -070092 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 Glasgowee1081c2012-03-06 15:14:53 -050098};
99
100// ModemModem3gppProxy::Proxy
Eric Shienbrood9a245532012-03-07 14:20:39 -0500101ModemModem3gppProxy::Proxy::Proxy(DBus::Connection *connection,
Jason Glasgowee1081c2012-03-06 15:14:53 -0500102 const std::string &path,
103 const std::string &service)
Eric Shienbrood9a245532012-03-07 14:20:39 -0500104 : DBus::ObjectProxy(*connection, path, service.c_str()) {}
Jason Glasgowee1081c2012-03-06 15:14:53 -0500105
106ModemModem3gppProxy::Proxy::~Proxy() {}
107
108// Method callbacks inherited from
109// org::freedesktop::ModemManager1::Modem::ModemModem3gppProxy
110void ModemModem3gppProxy::Proxy::RegisterCallback(const ::DBus::Error& dberror,
111 void *data) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700112 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500113 scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data));
Jason Glasgowee1081c2012-03-06 15:14:53 -0500114 Error error;
Arman Uguray763df862013-07-02 12:49:10 -0700115 CellularError::FromMM1DBusError(dberror, &error);
Eric Shienbrood9a245532012-03-07 14:20:39 -0500116 callback->Run(error);
Jason Glasgowee1081c2012-03-06 15:14:53 -0500117}
118
119void ModemModem3gppProxy::Proxy::ScanCallback(
120 const std::vector<DBusPropertiesMap> &results,
121 const ::DBus::Error& dberror, void *data) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700122 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500123 scoped_ptr<DBusPropertyMapsCallback> callback(
124 reinterpret_cast<DBusPropertyMapsCallback *>(data));
Jason Glasgowee1081c2012-03-06 15:14:53 -0500125 Error error;
Arman Uguray763df862013-07-02 12:49:10 -0700126 CellularError::FromMM1DBusError(dberror, &error);
Eric Shienbrood9a245532012-03-07 14:20:39 -0500127 callback->Run(results, error);
Jason Glasgowee1081c2012-03-06 15:14:53 -0500128}
129
130} // namespace mm1
131} // namespace shill