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_MM1_MODEM_PROXY_H_ 18 #define SHILL_DBUS_CHROMEOS_MM1_MODEM_PROXY_H_ 19 20 #include <string> 21 #include <vector> 22 23 #include "cellular/dbus-proxies.h" 24 #include "shill/cellular/mm1_modem_proxy_interface.h" 25 26 namespace shill { 27 namespace mm1 { 28 29 // A proxy to org.freedesktop.ModemManager1.Modem. 30 class ChromeosModemProxy : public ModemProxyInterface { 31 public: 32 // Constructs a org.freedesktop.ModemManager1.Modem DBus object 33 // proxy at |path| owned by |service|. 34 ChromeosModemProxy(const scoped_refptr<dbus::Bus>& bus, 35 const std::string& path, 36 const std::string& service); 37 ~ChromeosModemProxy() override; 38 39 // Inherited methods from ModemProxyInterface. 40 void Enable(bool enable, 41 Error* error, 42 const ResultCallback& callback, 43 int timeout) override; 44 void CreateBearer(const KeyValueStore& properties, 45 Error* error, 46 const RpcIdentifierCallback& callback, 47 int timeout) override; 48 void DeleteBearer(const std::string& bearer, 49 Error* error, 50 const ResultCallback& callback, 51 int timeout) override; 52 void Reset(Error* error, 53 const ResultCallback& callback, 54 int timeout) override; 55 void FactoryReset(const std::string& code, 56 Error* error, 57 const ResultCallback& callback, 58 int timeout) override; 59 void SetCurrentCapabilities(uint32_t capabilities, 60 Error* error, 61 const ResultCallback& callback, 62 int timeout) override; 63 void SetCurrentModes(uint32_t allowed_modes, 64 uint32_t preferred_mode, 65 Error* error, 66 const ResultCallback& callback, 67 int timeout) override; 68 void SetCurrentBands(const std::vector<uint32_t>& bands, 69 Error* error, 70 const ResultCallback& callback, 71 int timeout) override; 72 void Command(const std::string& cmd, 73 uint32_t user_timeout, 74 Error* error, 75 const StringCallback& callback, 76 int timeout) override; 77 void SetPowerState(uint32_t power_state, 78 Error* error, 79 const ResultCallback& callback, 80 int timeout) override; 81 set_state_changed_callback(const ModemStateChangedSignalCallback & callback)82 void set_state_changed_callback( 83 const ModemStateChangedSignalCallback& callback) override { 84 state_changed_callback_ = callback; 85 } 86 87 private: 88 // Signal handler. 89 void StateChanged(int32_t old, int32_t _new, uint32_t reason); 90 91 // Callbacks for CreateBearer async call. 92 void OnCreateBearerSuccess(const RpcIdentifierCallback& callback, 93 const dbus::ObjectPath& path); 94 void OnCreateBearerFailure(const RpcIdentifierCallback& callback, 95 brillo::Error* dbus_error); 96 97 // Callbacks for Command async call. 98 void OnCommandSuccess(const StringCallback& callback, 99 const std::string& response); 100 void OnCommandFailure(const StringCallback& callback, 101 brillo::Error* dbus_error); 102 103 // Callbacks for various async calls that uses ResultCallback. 104 void OnOperationSuccess(const ResultCallback& callback, 105 const std::string& operation); 106 void OnOperationFailure(const ResultCallback& callback, 107 const std::string& operation, 108 brillo::Error* dbus_error); 109 110 // Called when signal is connected to the ObjectProxy. 111 void OnSignalConnected(const std::string& interface_name, 112 const std::string& signal_name, 113 bool success); 114 115 ModemStateChangedSignalCallback state_changed_callback_; 116 117 std::unique_ptr<org::freedesktop::ModemManager1::ModemProxy> proxy_; 118 119 base::WeakPtrFactory<ChromeosModemProxy> weak_factory_{this}; 120 DISALLOW_COPY_AND_ASSIGN(ChromeosModemProxy); 121 }; 122 123 } // namespace mm1 124 } // namespace shill 125 126 #endif // SHILL_DBUS_CHROMEOS_MM1_MODEM_PROXY_H_ 127