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#ifndef SHILL_DBUS_CHROMEOS_MODEM_GSM_NETWORK_PROXY_H_
18#define SHILL_DBUS_CHROMEOS_MODEM_GSM_NETWORK_PROXY_H_
19
20#include <string>
21#include <tuple>
22
23#include "cellular/dbus-proxies.h"
24#include "shill/cellular/modem_gsm_network_proxy_interface.h"
25
26namespace shill {
27
28// A proxy to (old) ModemManager.Modem.Gsm.Network.
29class ChromeosModemGSMNetworkProxy : public ModemGSMNetworkProxyInterface {
30 public:
31  // Constructs a ModemManager.Modem.Gsm.Network DBus object proxy at |path|
32  // owned by |service|.
33  ChromeosModemGSMNetworkProxy(const scoped_refptr<dbus::Bus>& bus,
34                               const std::string& path,
35                               const std::string& service);
36  ~ChromeosModemGSMNetworkProxy() override;
37
38  // Inherited from ModemGSMNetworkProxyInterface.
39  void GetRegistrationInfo(Error* error,
40                           const RegistrationInfoCallback& callback,
41                           int timeout) override;
42  void GetSignalQuality(Error* error,
43                        const SignalQualityCallback& callback,
44                        int timeout) override;
45  void Register(const std::string& network_id,
46                Error* error,
47                const ResultCallback& callback,
48                int timeout) override;
49  void Scan(Error* error,
50            const ScanResultsCallback& callback,
51            int timeout) override;
52  uint32_t AccessTechnology() override;
53
54  void set_signal_quality_callback(
55      const SignalQualitySignalCallback& callback) override {
56    signal_quality_callback_ = callback;
57  }
58
59  void set_network_mode_callback(
60      const NetworkModeSignalCallback& callback) override {
61    network_mode_callback_ = callback;
62  }
63
64  void set_registration_info_callback(
65      const RegistrationInfoSignalCallback& callback) override {
66    registration_info_callback_ = callback;
67  }
68
69 private:
70  typedef std::tuple<uint32_t, std::string, std::string> GSMRegistrationInfo;
71
72  class PropertySet : public dbus::PropertySet {
73   public:
74    PropertySet(dbus::ObjectProxy* object_proxy,
75                const std::string& interface_name,
76                const PropertyChangedCallback& callback);
77    brillo::dbus_utils::Property<uint32_t> access_technology;
78
79   private:
80    DISALLOW_COPY_AND_ASSIGN(PropertySet);
81  };
82
83  static const char kPropertyAccessTechnology[];
84
85  // Signal handlers.
86  void SignalQuality(uint32_t quality);
87  void RegistrationInfo(uint32_t status,
88                        const std::string& operator_code,
89                        const std::string& operator_name);
90  void NetworkMode(uint32_t mode);
91
92  // Callbacks for Register async call.
93  void OnRegisterSuccess(const ResultCallback& callback);
94  void OnRegisterFailure(const ResultCallback& callback,
95                         brillo::Error* dbus_error);
96
97  // Callbacks for GetRegistrationInfo async call.
98  void OnGetRegistrationInfoSuccess(
99      const RegistrationInfoCallback& callback,
100      const GSMRegistrationInfo& info);
101  void OnGetRegistrationInfoFailure(
102      const RegistrationInfoCallback& callback, brillo::Error* dbus_error);
103
104  // Callbacks for GetSignalQuality async call.
105  void OnGetSignalQualitySuccess(const SignalQualityCallback& callback,
106                                 uint32_t quality);
107  void OnGetSignalQualityFailure(const SignalQualityCallback& callback,
108                                 brillo::Error* dbus_error);
109
110  // Callbacks for Scan async call.
111  void OnScanSuccess(const ScanResultsCallback& callback,
112                     const GSMScanResults& results);
113  void OnScanFailure(const ScanResultsCallback& callback,
114                     brillo::Error* dbus_error);
115
116  // Called when signal is connected to the ObjectProxy.
117  void OnSignalConnected(const std::string& interface_name,
118                         const std::string& signal_name,
119                         bool success);
120
121  // Callback invoked when the value of property |property_name| is changed.
122  void OnPropertyChanged(const std::string& property_name);
123
124  SignalQualitySignalCallback signal_quality_callback_;
125  RegistrationInfoSignalCallback registration_info_callback_;
126  NetworkModeSignalCallback network_mode_callback_;
127
128  std::unique_ptr<org::freedesktop::ModemManager::Modem::Gsm::NetworkProxy>
129      proxy_;
130  std::unique_ptr<PropertySet> properties_;
131
132  base::WeakPtrFactory<ChromeosModemGSMNetworkProxy> weak_factory_{this};
133  DISALLOW_COPY_AND_ASSIGN(ChromeosModemGSMNetworkProxy);
134};
135
136}  // namespace shill
137
138#endif  // SHILL_DBUS_CHROMEOS_MODEM_GSM_NETWORK_PROXY_H_
139