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_CDMA_PROXY_H_ 18 #define SHILL_DBUS_CHROMEOS_MODEM_CDMA_PROXY_H_ 19 20 #include <string> 21 22 #include "cellular/dbus-proxies.h" 23 #include "shill/cellular/modem_cdma_proxy_interface.h" 24 25 namespace shill { 26 27 // A proxy to (old) ModemManager.Modem.CDMA. 28 class ChromeosModemCDMAProxy : public ModemCDMAProxyInterface { 29 public: 30 // Constructs a ModemManager.Modem.CDMA DBus object proxy at |path| owned by 31 // |service|. 32 ChromeosModemCDMAProxy(const scoped_refptr<dbus::Bus>& bus, 33 const std::string& path, 34 const std::string& service); 35 ~ChromeosModemCDMAProxy() override; 36 37 // Inherited from ModemCDMAProxyInterface. 38 void Activate(const std::string& carrier, 39 Error* error, 40 const ActivationResultCallback& callback, 41 int timeout) override; 42 void GetRegistrationState(Error* error, 43 const RegistrationStateCallback& callback, 44 int timeout) override; 45 void GetSignalQuality(Error* error, 46 const SignalQualityCallback& callback, 47 int timeout) override; 48 const std::string MEID() override; 49 50 void set_activation_state_callback( 51 const ActivationStateSignalCallback& callback) override { 52 activation_state_callback_ = callback; 53 } 54 void set_signal_quality_callback( 55 const SignalQualitySignalCallback& callback) override { 56 signal_quality_callback_ = callback; 57 } 58 void set_registration_state_callback( 59 const RegistrationStateSignalCallback& callback) override { 60 registration_state_callback_ = callback; 61 } 62 63 private: 64 class PropertySet : public dbus::PropertySet { 65 public: 66 PropertySet(dbus::ObjectProxy* object_proxy, 67 const std::string& interface_name, 68 const PropertyChangedCallback& callback); 69 brillo::dbus_utils::Property<std::string> meid; 70 71 private: 72 DISALLOW_COPY_AND_ASSIGN(PropertySet); 73 }; 74 75 static const char kPropertyMeid[]; 76 77 // Signal handlers. 78 void ActivationStateChanged( 79 uint32_t activation_state, 80 uint32_t activation_error, 81 const brillo::VariantDictionary& status_changes); 82 void SignalQuality(uint32_t quality); 83 void RegistrationStateChanged(uint32_t cdma_1x_state, 84 uint32_t evdo_state); 85 86 // Callbacks for Activate async call. 87 void OnActivateSuccess(const ActivationResultCallback& callback, 88 uint32_t status); 89 void OnActivateFailure(const ActivationResultCallback& callback, 90 brillo::Error* dbus_error); 91 92 // Callbacks for GetRegistrationState async call. 93 void OnGetRegistrationStateSuccess(const RegistrationStateCallback& callback, 94 uint32_t state_1x, 95 uint32_t state_evdo); 96 void OnGetRegistrationStateFailure(const RegistrationStateCallback& callback, 97 brillo::Error* dbus_error); 98 99 // Callbacks for GetSignalQuality async call. 100 void OnGetSignalQualitySuccess(const SignalQualityCallback& callback, 101 uint32_t quality); 102 void OnGetSignalQualityFailure(const SignalQualityCallback& callback, 103 brillo::Error* dbus_error); 104 105 // Called when signal is connected to the ObjectProxy. 106 void OnSignalConnected(const std::string& interface_name, 107 const std::string& signal_name, 108 bool success); 109 110 // Callback invoked when the value of property |property_name| is changed. 111 void OnPropertyChanged(const std::string& property_name); 112 113 ActivationStateSignalCallback activation_state_callback_; 114 SignalQualitySignalCallback signal_quality_callback_; 115 RegistrationStateSignalCallback registration_state_callback_; 116 117 std::unique_ptr<org::freedesktop::ModemManager::Modem::CdmaProxy> proxy_; 118 std::unique_ptr<PropertySet> properties_; 119 120 base::WeakPtrFactory<ChromeosModemCDMAProxy> weak_factory_{this}; 121 DISALLOW_COPY_AND_ASSIGN(ChromeosModemCDMAProxy); 122 }; 123 124 } // namespace shill 125 126 #endif // SHILL_DBUS_CHROMEOS_MODEM_CDMA_PROXY_H_ 127