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_PROXY_H_
18 #define SHILL_DBUS_CHROMEOS_MODEM_PROXY_H_
19 
20 #include <string>
21 #include <tuple>
22 
23 #include <base/macros.h>
24 
25 #include "cellular/dbus-proxies.h"
26 #include "shill/cellular/modem_proxy_interface.h"
27 
28 namespace shill {
29 
30 // A proxy to (old) ModemManager.Modem.
31 class ChromeosModemProxy : public ModemProxyInterface {
32  public:
33   // Constructs a ModemManager.Modem DBus object proxy at |path| owned by
34   // |service|.
35   ChromeosModemProxy(const scoped_refptr<dbus::Bus>& bus,
36                      const std::string& path,
37                      const std::string& service);
38   ~ChromeosModemProxy() override;
39 
40   // Inherited from ModemProxyInterface.
41   void Enable(bool enable,
42               Error* error,
43               const ResultCallback& callback,
44               int timeout) override;
45   void Disconnect(Error* error,
46                   const ResultCallback& callback,
47                   int timeout) override;
48   void GetModemInfo(Error* error,
49                     const ModemInfoCallback& callback,
50                     int timeout) override;
51 
set_state_changed_callback(const ModemStateChangedSignalCallback & callback)52   void set_state_changed_callback(
53       const ModemStateChangedSignalCallback& callback) override {
54     state_changed_callback_ = callback;
55   }
56 
57  private:
58   typedef std::tuple<std::string, std::string, std::string> ModemHardwareInfo;
59 
60   // Signal handler.
61   void StateChanged(uint32_t old, uint32_t _new, uint32_t reason);
62 
63   // Callbacks for Enable async call.
64   void OnEnableSuccess(const ResultCallback& callback);
65   void OnEnableFailure(const ResultCallback& callback,
66                        brillo::Error* dbus_error);
67 
68   // Callback for GetInfo async call.
69   void OnGetInfoSuccess(const ModemInfoCallback& callback,
70                         const ModemHardwareInfo& info);
71   void OnGetInfoFailure(const ModemInfoCallback& callback,
72                         brillo::Error* dbus_error);
73 
74   // Callback for Disconnect async call.
75   void OnDisconnectSuccess(const ResultCallback& callback);
76   void OnDisconnectFailure(const ResultCallback& callback,
77                            brillo::Error* dbus_error);
78 
79   // Called when signal is connected to the ObjectProxy.
80   void OnSignalConnected(const std::string& interface_name,
81                          const std::string& signal_name,
82                          bool success);
83 
84   ModemStateChangedSignalCallback state_changed_callback_;
85 
86   std::unique_ptr<org::freedesktop::ModemManager::ModemProxy> proxy_;
87 
88   base::WeakPtrFactory<ChromeosModemProxy> weak_factory_{this};
89   DISALLOW_COPY_AND_ASSIGN(ChromeosModemProxy);
90 };
91 
92 }  // namespace shill
93 
94 #endif  // SHILL_DBUS_CHROMEOS_MODEM_PROXY_H_
95