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); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 61 | virtual ~CellularCapabilityClassic(); |
| 62 | |
Ben Chan | f98f00e | 2014-02-05 14:48:43 -0800 | [diff] [blame] | 63 | // Inherited from CellularCapability. |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 64 | virtual void OnDBusPropertiesChanged( |
| 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; |
| 68 | virtual void StopModem(Error *error, const ResultCallback &callback) override; |
| 69 | virtual void SetCarrier(const std::string &carrier, |
| 70 | Error *error, |
| 71 | const ResultCallback &callback) override; |
| 72 | virtual void Connect(const DBusPropertiesMap &properties, |
| 73 | Error *error, |
| 74 | const ResultCallback &callback) override; |
| 75 | virtual void Disconnect(Error *error, |
| 76 | const ResultCallback &callback) override; |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 77 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 78 | protected: |
Jason Glasgow | a0caabf | 2012-05-04 11:31:41 -0400 | [diff] [blame] | 79 | typedef std::vector<base::Closure> CellularTaskList; |
| 80 | |
Jason Glasgow | 4380f0d | 2012-05-03 18:05:04 -0400 | [diff] [blame] | 81 | virtual void GetRegistrationState() = 0; |
| 82 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 83 | // The following five methods are only ever called as |
| 84 | // callbacks (from the main loop), which is why they |
| 85 | // don't take an Error * argument. |
| 86 | virtual void EnableModem(const ResultCallback &callback); |
| 87 | virtual void DisableModem(const ResultCallback &callback); |
| 88 | virtual void GetModemStatus(const ResultCallback &callback); |
| 89 | virtual void GetModemInfo(const ResultCallback &callback); |
| 90 | virtual void GetProperties(const ResultCallback &callback) = 0; |
| 91 | |
| 92 | void FinishEnable(const ResultCallback &callback); |
| 93 | void FinishDisable(const ResultCallback &callback); |
| 94 | virtual void InitProxies(); |
| 95 | virtual void ReleaseProxies(); |
Jason Glasgow | 4380f0d | 2012-05-03 18:05:04 -0400 | [diff] [blame] | 96 | virtual void UpdateStatus(const DBusPropertiesMap &properties) = 0; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 97 | |
Jason Glasgow | a0caabf | 2012-05-04 11:31:41 -0400 | [diff] [blame] | 98 | // Runs the next task in a list. |
| 99 | // Precondition: |tasks| is not empty. |
| 100 | void RunNextStep(CellularTaskList *tasks); |
| 101 | // StepCompletedCallback is called after a task completes. |
| 102 | // |callback| is the original callback that needs to be invoked when all of |
| 103 | // the tasks complete or if there is a failure. |ignore_error| will be set |
| 104 | // to true if the next task should be run regardless of the result of the |
| 105 | // just-completed task. |tasks| is the list of tasks remaining. |error| is |
| 106 | // the result of the just-completed task. |
Ben Chan | f98f00e | 2014-02-05 14:48:43 -0800 | [diff] [blame] | 107 | void StepCompletedCallback(const ResultCallback &callback, |
| 108 | bool ignore_error, |
| 109 | CellularTaskList *tasks, |
| 110 | const Error &error); |
Jason Glasgow | a0caabf | 2012-05-04 11:31:41 -0400 | [diff] [blame] | 111 | |
Nathan Williams | b54974f | 2012-04-19 11:16:30 -0400 | [diff] [blame] | 112 | scoped_ptr<ModemSimpleProxyInterface> simple_proxy_; |
| 113 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 114 | private: |
| 115 | friend class CellularTest; |
Christopher Wiley | 7d0953e | 2012-11-16 00:37:10 -0800 | [diff] [blame] | 116 | friend class CellularCapabilityCDMATest; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 117 | friend class CellularCapabilityTest; |
| 118 | friend class CellularCapabilityGSMTest; |
| 119 | FRIEND_TEST(CellularCapabilityGSMTest, SetProxy); |
| 120 | FRIEND_TEST(CellularCapabilityGSMTest, SetStorageIdentifier); |
| 121 | FRIEND_TEST(CellularCapabilityGSMTest, UpdateStatus); |
| 122 | FRIEND_TEST(CellularCapabilityTest, AllowRoaming); |
| 123 | FRIEND_TEST(CellularCapabilityTest, EnableModemFail); |
| 124 | FRIEND_TEST(CellularCapabilityTest, EnableModemSucceed); |
| 125 | FRIEND_TEST(CellularCapabilityTest, FinishEnable); |
| 126 | FRIEND_TEST(CellularCapabilityTest, GetModemInfo); |
| 127 | FRIEND_TEST(CellularCapabilityTest, GetModemStatus); |
| 128 | FRIEND_TEST(CellularCapabilityTest, TryApns); |
| 129 | FRIEND_TEST(CellularServiceTest, FriendlyName); |
| 130 | FRIEND_TEST(CellularTest, StartCDMARegister); |
| 131 | FRIEND_TEST(CellularTest, StartConnected); |
| 132 | FRIEND_TEST(CellularTest, StartGSMRegister); |
| 133 | FRIEND_TEST(CellularTest, StartLinked); |
| 134 | FRIEND_TEST(CellularTest, Connect); |
| 135 | FRIEND_TEST(CellularTest, ConnectFailure); |
Thieu Le | b5954a2 | 2012-05-18 10:37:34 -0700 | [diff] [blame] | 136 | FRIEND_TEST(CellularTest, ConnectFailureNoService); |
Thieu Le | d4974cd | 2013-05-23 10:39:28 -0700 | [diff] [blame] | 137 | FRIEND_TEST(CellularTest, ConnectSuccessNoService); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 138 | FRIEND_TEST(CellularTest, Disconnect); |
Arman Uguray | 539c423 | 2012-09-11 10:00:22 -0700 | [diff] [blame] | 139 | FRIEND_TEST(CellularTest, DisconnectFailure); |
Christopher Wiley | 7d0953e | 2012-11-16 00:37:10 -0800 | [diff] [blame] | 140 | FRIEND_TEST(CellularTest, DisconnectWithCallback); |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 141 | FRIEND_TEST(CellularTest, ModemStateChangeEnable); |
| 142 | FRIEND_TEST(CellularTest, ModemStateChangeDisable); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 143 | |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 144 | // Method reply and signal callbacks from Modem interface |
Ben Chan | f98f00e | 2014-02-05 14:48:43 -0800 | [diff] [blame] | 145 | void OnModemStateChangedSignal(uint32 old_state, |
| 146 | uint32 new_state, |
| 147 | uint32 reason); |
Nathan Williams | 3022be5 | 2012-04-19 17:40:49 -0400 | [diff] [blame] | 148 | void OnGetModemInfoReply(const ResultCallback &callback, |
| 149 | const ModemHardwareInfo &info, |
| 150 | const Error &error); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 151 | |
| 152 | // Method reply callbacks from Modem.Simple interface |
Nathan Williams | 3022be5 | 2012-04-19 17:40:49 -0400 | [diff] [blame] | 153 | void OnGetModemStatusReply(const ResultCallback &callback, |
| 154 | const DBusPropertiesMap &props, |
| 155 | const Error &error); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 156 | |
| 157 | Cellular *cellular_; |
| 158 | base::WeakPtrFactory<CellularCapabilityClassic> weak_ptr_factory_; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 159 | scoped_ptr<ModemProxyInterface> proxy_; |
Darin Petkov | c37a9c4 | 2012-09-06 15:28:22 +0200 | [diff] [blame] | 160 | scoped_ptr<ModemGobiProxyInterface> gobi_proxy_; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 161 | |
| 162 | DISALLOW_COPY_AND_ASSIGN(CellularCapabilityClassic); |
| 163 | }; |
| 164 | |
| 165 | } // namespace shill |
| 166 | |
Darin Petkov | c37a9c4 | 2012-09-06 15:28:22 +0200 | [diff] [blame] | 167 | #endif // SHILL_CELLULAR_CAPABILITY_CLASSIC_H_ |