blob: 0f37bef270b96e0875e78c355da072de6b6d0cd6 [file] [log] [blame]
Arman Uguray2c39fab2012-12-12 16:56:34 -08001// 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
10using std::string;
11
12namespace shill {
13namespace mm1 {
14
15ModemLocationProxy::ModemLocationProxy(DBus::Connection *connection,
16 const string &path,
17 const string &service)
18 : proxy_(connection, path, service) {}
19
20ModemLocationProxy::~ModemLocationProxy() {}
21
22void 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 Uguray763df862013-07-02 12:49:10 -070035 CellularError::FromMM1DBusError(e, error);
Arman Uguray2c39fab2012-12-12 16:56:34 -080036 }
37}
38
39void 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 Uguray763df862013-07-02 12:49:10 -070051 CellularError::FromMM1DBusError(e, error);
Arman Uguray2c39fab2012-12-12 16:56:34 -080052 }
53}
54
55uint32_t ModemLocationProxy::Capabilities() {
56 SLOG(Modem, 2) << __func__;
57 try {
58 return proxy_.Capabilities();
59 } catch (const DBus::Error &e) {
60 LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what();
61 return 0; // Make the compiler happy.
62 }
63}
64
65uint32_t ModemLocationProxy::Enabled(){
66 SLOG(Modem, 2) << __func__;
67 try {
68 return proxy_.Enabled();
69 } catch (const DBus::Error &e) {
70 LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what();
71 return 0; // Make the compiler happy.
72 }
73}
74
75bool ModemLocationProxy::SignalsLocation() {
76 SLOG(Modem, 2) << __func__;
77 try {
78 return proxy_.SignalsLocation();
79 } catch (const DBus::Error &e) {
80 LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what();
81 return false; // Make the compiler happy.
82 }
83}
84
85const DBusEnumValueMap ModemLocationProxy::Location() {
86 SLOG(Modem, 2) << __func__;
87 try {
88 return proxy_.Location();
89 } catch (const DBus::Error &e) {
90 LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what();
91 return DBusEnumValueMap(); // Make the compiler happy.
92 }
93}
94
95ModemLocationProxy::Proxy::Proxy(DBus::Connection *connection,
96 const string &path,
97 const string &service)
98 : DBus::ObjectProxy(*connection, path, service.c_str()) {}
99
100ModemLocationProxy::Proxy::~Proxy() {}
101
102// Method callbacks inherited from
103// org::freedesktop::ModemManager1::Modem:LocationProxy
104void ModemLocationProxy::Proxy::SetupCallback(const ::DBus::Error &dberror,
105 void *data) {
106 SLOG(DBus, 2) << __func__;
107 scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data));
108 Error error;
Arman Uguray763df862013-07-02 12:49:10 -0700109 CellularError::FromMM1DBusError(dberror, &error);
Arman Uguray2c39fab2012-12-12 16:56:34 -0800110 callback->Run(error);
111}
112
113void ModemLocationProxy::Proxy::GetLocationCallback(
114 const DBusEnumValueMap &location,
115 const ::DBus::Error &dberror,
116 void *data) {
117 SLOG(DBus, 2) << __func__;
118 scoped_ptr<DBusEnumValueMapCallback> callback(
119 reinterpret_cast<DBusEnumValueMapCallback *>(data));
120 Error error;
Arman Uguray763df862013-07-02 12:49:10 -0700121 CellularError::FromMM1DBusError(dberror, &error);
Arman Uguray2c39fab2012-12-12 16:56:34 -0800122 callback->Run(location, error);
123}
124
125} // namespace mm1
126} // namespace shill