1 //
2 // Copyright (C) 2015 The Android Open Source Project
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 #include "shill/dbus/chromeos_mm1_modem_modem3gpp_proxy.h"
18 
19 #include <memory>
20 
21 #include "shill/cellular/cellular_error.h"
22 #include "shill/logging.h"
23 
24 using std::string;
25 
26 namespace shill {
27 
28 namespace Logging {
29 static auto kModuleLogScope = ScopeLogger::kDBus;
ObjectID(const dbus::ObjectPath * p)30 static string ObjectID(const dbus::ObjectPath* p) { return p->value(); }
31 }  // namespace Logging
32 
33 namespace mm1 {
34 
ChromeosModemModem3gppProxy(const scoped_refptr<dbus::Bus> & bus,const string & path,const string & service)35 ChromeosModemModem3gppProxy::ChromeosModemModem3gppProxy(
36     const scoped_refptr<dbus::Bus>& bus,
37     const string& path,
38     const string& service)
39     : proxy_(
40         new org::freedesktop::ModemManager1::Modem::Modem3gppProxy(
41             bus, service, dbus::ObjectPath(path))) {}
42 
~ChromeosModemModem3gppProxy()43 ChromeosModemModem3gppProxy::~ChromeosModemModem3gppProxy() {}
44 
Register(const std::string & operator_id,Error * error,const ResultCallback & callback,int timeout)45 void ChromeosModemModem3gppProxy::Register(const std::string& operator_id,
46                                            Error* error,
47                                            const ResultCallback& callback,
48                                            int timeout) {
49   SLOG(&proxy_->GetObjectPath(), 2) << __func__ << ": " << operator_id;
50   proxy_->RegisterAsync(
51       operator_id,
52       base::Bind(&ChromeosModemModem3gppProxy::OnRegisterSuccess,
53                  weak_factory_.GetWeakPtr(),
54                  callback),
55       base::Bind(&ChromeosModemModem3gppProxy::OnRegisterFailure,
56                  weak_factory_.GetWeakPtr(),
57                  callback));
58 }
59 
Scan(Error * error,const KeyValueStoresCallback & callback,int timeout)60 void ChromeosModemModem3gppProxy::Scan(Error* error,
61                                        const KeyValueStoresCallback& callback,
62                                        int timeout) {
63   SLOG(&proxy_->GetObjectPath(), 2) << __func__;
64   proxy_->ScanAsync(base::Bind(&ChromeosModemModem3gppProxy::OnScanSuccess,
65                                weak_factory_.GetWeakPtr(),
66                                callback),
67                     base::Bind(&ChromeosModemModem3gppProxy::OnScanFailure,
68                                weak_factory_.GetWeakPtr(),
69                                callback));
70 }
71 
OnRegisterSuccess(const ResultCallback & callback)72 void ChromeosModemModem3gppProxy::OnRegisterSuccess(
73     const ResultCallback& callback) {
74   SLOG(&proxy_->GetObjectPath(), 2) << __func__;
75   callback.Run(Error());
76 }
77 
OnRegisterFailure(const ResultCallback & callback,brillo::Error * dbus_error)78 void ChromeosModemModem3gppProxy::OnRegisterFailure(
79     const ResultCallback& callback, brillo::Error* dbus_error) {
80   SLOG(&proxy_->GetObjectPath(), 2) << __func__;
81   Error error;
82   CellularError::FromMM1ChromeosDBusError(dbus_error, &error);
83   callback.Run(error);
84 }
85 
OnScanSuccess(const KeyValueStoresCallback & callback,const std::vector<brillo::VariantDictionary> & results)86 void ChromeosModemModem3gppProxy::OnScanSuccess(
87     const KeyValueStoresCallback& callback,
88     const std::vector<brillo::VariantDictionary>& results) {
89   SLOG(&proxy_->GetObjectPath(), 2) << __func__;
90   std::vector<KeyValueStore> result_stores;
91   for (const auto& result : results) {
92     KeyValueStore result_store;
93     KeyValueStore::ConvertFromVariantDictionary(result, &result_store);
94     result_stores.push_back(result_store);
95   }
96   callback.Run(result_stores, Error());
97 }
98 
OnScanFailure(const KeyValueStoresCallback & callback,brillo::Error * dbus_error)99 void ChromeosModemModem3gppProxy::OnScanFailure(
100     const KeyValueStoresCallback& callback, brillo::Error* dbus_error) {
101   SLOG(&proxy_->GetObjectPath(), 2) << __func__;
102   Error error;
103   CellularError::FromMM1ChromeosDBusError(dbus_error, &error);
104   callback.Run(std::vector<KeyValueStore>(), error);
105 }
106 
107 }  // namespace mm1
108 }  // namespace shill
109