Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Darin Petkov | c37a9c4 | 2012-09-06 15:28:22 +0200 | [diff] [blame] | 5 | #ifndef SHILL_CELLULAR_CAPABILITY_CLASSIC_H_ |
| 6 | #define SHILL_CELLULAR_CAPABILITY_CLASSIC_H_ |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 7 | |
| 8 | #include <string> |
| 9 | #include <vector> |
| 10 | |
| 11 | #include <base/basictypes.h> |
| 12 | #include <base/callback.h> |
| 13 | #include <base/memory/scoped_ptr.h> |
| 14 | #include <base/memory/weak_ptr.h> |
| 15 | #include <gtest/gtest_prod.h> // for FRIEND_TEST |
| 16 | |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 17 | #include "shill/cellular.h" |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 18 | #include "shill/cellular_capability.h" |
| 19 | #include "shill/dbus_properties.h" |
| 20 | #include "shill/modem_proxy_interface.h" |
| 21 | #include "shill/modem_simple_proxy_interface.h" |
| 22 | |
| 23 | namespace shill { |
| 24 | |
| 25 | class Cellular; |
| 26 | class Error; |
| 27 | class EventDispatcher; |
Darin Petkov | c37a9c4 | 2012-09-06 15:28:22 +0200 | [diff] [blame] | 28 | class ModemGobiProxyInterface; |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 29 | class ModemInfo; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 30 | class ProxyFactory; |
| 31 | |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 32 | enum ModemClassicState { |
| 33 | kModemClassicStateUnknown = 0, |
| 34 | kModemClassicStateDisabled = 10, |
| 35 | kModemClassicStateDisabling = 20, |
| 36 | kModemClassicStateEnabling = 30, |
| 37 | kModemClassicStateEnabled = 40, |
| 38 | kModemClassicStateSearching = 50, |
| 39 | kModemClassicStateRegistered = 60, |
| 40 | kModemClassicStateDisconnecting = 70, |
| 41 | kModemClassicStateConnecting = 80, |
| 42 | kModemClassicStateConnected = 90, |
| 43 | }; |
| 44 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 45 | // CellularCapabilityClassic handles modems using the |
| 46 | // org.chromium.ModemManager DBUS interface. |
| 47 | class CellularCapabilityClassic : public CellularCapability { |
| 48 | public: |
| 49 | static const char kConnectPropertyApn[]; |
| 50 | static const char kConnectPropertyApnUsername[]; |
| 51 | static const char kConnectPropertyApnPassword[]; |
| 52 | static const char kConnectPropertyHomeOnly[]; |
| 53 | static const char kConnectPropertyPhoneNumber[]; |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 54 | static const char kModemPropertyEnabled[]; |
Darin Petkov | c37a9c4 | 2012-09-06 15:28:22 +0200 | [diff] [blame] | 55 | static const int kTimeoutSetCarrierMilliseconds; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 56 | |
| 57 | // |cellular| is the parent Cellular device. |
Thieu Le | ce4483e | 2013-01-23 15:12:03 -0800 | [diff] [blame] | 58 | CellularCapabilityClassic(Cellular *cellular, |
| 59 | ProxyFactory *proxy_factory, |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 60 | ModemInfo *modem_info); |
Ben Chan | 5ea763b | 2014-08-13 11:07:54 -0700 | [diff] [blame] | 61 | ~CellularCapabilityClassic() override; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 62 | |
Ben Chan | f98f00e | 2014-02-05 14:48:43 -0800 | [diff] [blame] | 63 | // Inherited from CellularCapability. |
Alex Vakulenko | 016fa0e | 2014-08-11 15:59:58 -0700 | [diff] [blame] | 64 | void OnDBusPropertiesChanged( |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 65 | const std::string &interface, |
Ben Chan | f98f00e | 2014-02-05 14:48:43 -0800 | [diff] [blame] | 66 | const DBusPropertiesMap &changed_properties, |
| 67 | const std::vector<std::string> &invalidated_properties) override; |
Alex Vakulenko | 016fa0e | 2014-08-11 15:59:58 -0700 | [diff] [blame] | 68 | void StopModem(Error *error, const ResultCallback &callback) override; |
| 69 | bool AreProxiesInitialized() const override; |
| 70 | void SetCarrier(const std::string &carrier, |
| 71 | Error *error, |
| 72 | const ResultCallback &callback) override; |
| 73 | void Connect(const DBusPropertiesMap &properties, |
| 74 | Error *error, |
| 75 | const ResultCallback &callback) override; |
| 76 | void Disconnect(Error *error, |
| 77 | const ResultCallback &callback) override; |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 78 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 79 | protected: |
Jason Glasgow | a0caabf | 2012-05-04 11:31:41 -0400 | [diff] [blame] | 80 | typedef std::vector<base::Closure> CellularTaskList; |
| 81 | |
Jason Glasgow | 4380f0d | 2012-05-03 18:05:04 -0400 | [diff] [blame] | 82 | virtual void GetRegistrationState() = 0; |
| 83 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 84 | // The following five methods are only ever called as |
| 85 | // callbacks (from the main loop), which is why they |
| 86 | // don't take an Error * argument. |
| 87 | virtual void EnableModem(const ResultCallback &callback); |
| 88 | virtual void DisableModem(const ResultCallback &callback); |
| 89 | virtual void GetModemStatus(const ResultCallback &callback); |
| 90 | virtual void GetModemInfo(const ResultCallback &callback); |
| 91 | virtual void GetProperties(const ResultCallback &callback) = 0; |
| 92 | |
| 93 | void FinishEnable(const ResultCallback &callback); |
| 94 | void FinishDisable(const ResultCallback &callback); |
| 95 | virtual void InitProxies(); |
| 96 | virtual void ReleaseProxies(); |
Prathmesh Prabhu | 6e0a8ef | 2014-05-05 22:30:07 -0700 | [diff] [blame] | 97 | |
| 98 | // Default implementation is no-op. |
| 99 | virtual void UpdateStatus(const DBusPropertiesMap &properties); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 100 | |
Jason Glasgow | a0caabf | 2012-05-04 11:31:41 -0400 | [diff] [blame] | 101 | // Runs the next task in a list. |
| 102 | // Precondition: |tasks| is not empty. |
| 103 | void RunNextStep(CellularTaskList *tasks); |
| 104 | // StepCompletedCallback is called after a task completes. |
| 105 | // |callback| is the original callback that needs to be invoked when all of |
| 106 | // the tasks complete or if there is a failure. |ignore_error| will be set |
| 107 | // to true if the next task should be run regardless of the result of the |
| 108 | // just-completed task. |tasks| is the list of tasks remaining. |error| is |
| 109 | // the result of the just-completed task. |
Ben Chan | f98f00e | 2014-02-05 14:48:43 -0800 | [diff] [blame] | 110 | void StepCompletedCallback(const ResultCallback &callback, |
| 111 | bool ignore_error, |
| 112 | CellularTaskList *tasks, |
| 113 | const Error &error); |
Jason Glasgow | a0caabf | 2012-05-04 11:31:41 -0400 | [diff] [blame] | 114 | |
Nathan Williams | b54974f | 2012-04-19 11:16:30 -0400 | [diff] [blame] | 115 | scoped_ptr<ModemSimpleProxyInterface> simple_proxy_; |
| 116 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 117 | private: |
| 118 | friend class CellularTest; |
Christopher Wiley | 7d0953e | 2012-11-16 00:37:10 -0800 | [diff] [blame] | 119 | friend class CellularCapabilityCDMATest; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 120 | friend class CellularCapabilityTest; |
| 121 | friend class CellularCapabilityGSMTest; |
| 122 | FRIEND_TEST(CellularCapabilityGSMTest, SetProxy); |
| 123 | FRIEND_TEST(CellularCapabilityGSMTest, SetStorageIdentifier); |
| 124 | FRIEND_TEST(CellularCapabilityGSMTest, UpdateStatus); |
| 125 | FRIEND_TEST(CellularCapabilityTest, AllowRoaming); |
| 126 | FRIEND_TEST(CellularCapabilityTest, EnableModemFail); |
| 127 | FRIEND_TEST(CellularCapabilityTest, EnableModemSucceed); |
| 128 | FRIEND_TEST(CellularCapabilityTest, FinishEnable); |
| 129 | FRIEND_TEST(CellularCapabilityTest, GetModemInfo); |
| 130 | FRIEND_TEST(CellularCapabilityTest, GetModemStatus); |
| 131 | FRIEND_TEST(CellularCapabilityTest, TryApns); |
| 132 | FRIEND_TEST(CellularServiceTest, FriendlyName); |
| 133 | FRIEND_TEST(CellularTest, StartCDMARegister); |
| 134 | FRIEND_TEST(CellularTest, StartConnected); |
| 135 | FRIEND_TEST(CellularTest, StartGSMRegister); |
| 136 | FRIEND_TEST(CellularTest, StartLinked); |
| 137 | FRIEND_TEST(CellularTest, Connect); |
| 138 | FRIEND_TEST(CellularTest, ConnectFailure); |
Thieu Le | b5954a2 | 2012-05-18 10:37:34 -0700 | [diff] [blame] | 139 | FRIEND_TEST(CellularTest, ConnectFailureNoService); |
Thieu Le | d4974cd | 2013-05-23 10:39:28 -0700 | [diff] [blame] | 140 | FRIEND_TEST(CellularTest, ConnectSuccessNoService); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 141 | FRIEND_TEST(CellularTest, Disconnect); |
Arman Uguray | 539c423 | 2012-09-11 10:00:22 -0700 | [diff] [blame] | 142 | FRIEND_TEST(CellularTest, DisconnectFailure); |
Christopher Wiley | 7d0953e | 2012-11-16 00:37:10 -0800 | [diff] [blame] | 143 | FRIEND_TEST(CellularTest, DisconnectWithCallback); |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 144 | FRIEND_TEST(CellularTest, ModemStateChangeEnable); |
| 145 | FRIEND_TEST(CellularTest, ModemStateChangeDisable); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 146 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 147 | // Method reply and signal callbacks from Modem interface |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 148 | void OnModemStateChangedSignal(uint32_t old_state, |
| 149 | uint32_t new_state, |
| 150 | uint32_t reason); |
Nathan Williams | 3022be5 | 2012-04-19 17:40:49 -0400 | [diff] [blame] | 151 | void OnGetModemInfoReply(const ResultCallback &callback, |
| 152 | const ModemHardwareInfo &info, |
| 153 | const Error &error); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 154 | |
| 155 | // Method reply callbacks from Modem.Simple interface |
Nathan Williams | 3022be5 | 2012-04-19 17:40:49 -0400 | [diff] [blame] | 156 | void OnGetModemStatusReply(const ResultCallback &callback, |
| 157 | const DBusPropertiesMap &props, |
| 158 | const Error &error); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 159 | |
| 160 | Cellular *cellular_; |
| 161 | base::WeakPtrFactory<CellularCapabilityClassic> weak_ptr_factory_; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 162 | scoped_ptr<ModemProxyInterface> proxy_; |
Darin Petkov | c37a9c4 | 2012-09-06 15:28:22 +0200 | [diff] [blame] | 163 | scoped_ptr<ModemGobiProxyInterface> gobi_proxy_; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 164 | |
| 165 | DISALLOW_COPY_AND_ASSIGN(CellularCapabilityClassic); |
| 166 | }; |
| 167 | |
| 168 | } // namespace shill |
| 169 | |
Darin Petkov | c37a9c4 | 2012-09-06 15:28:22 +0200 | [diff] [blame] | 170 | #endif // SHILL_CELLULAR_CAPABILITY_CLASSIC_H_ |