blob: f9b6e2cb5d4be2686c7f4696e3357a289953f273 [file] [log] [blame]
Jason Glasgow82f9ab32012-04-04 14:27:19 -04001// 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 Petkovc37a9c42012-09-06 15:28:22 +02005#ifndef SHILL_CELLULAR_CAPABILITY_CLASSIC_H_
6#define SHILL_CELLULAR_CAPABILITY_CLASSIC_H_
Jason Glasgow82f9ab32012-04-04 14:27:19 -04007
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 Shienbrood7fce52c2012-04-13 19:11:02 -040017#include "shill/cellular.h"
Jason Glasgow82f9ab32012-04-04 14:27:19 -040018#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
23namespace shill {
24
25class Cellular;
26class Error;
27class EventDispatcher;
Darin Petkovc37a9c42012-09-06 15:28:22 +020028class ModemGobiProxyInterface;
Prathmesh Prabhu27526f12013-03-25 19:42:18 -070029class ModemInfo;
Jason Glasgow82f9ab32012-04-04 14:27:19 -040030class ProxyFactory;
31
Eric Shienbrood7fce52c2012-04-13 19:11:02 -040032enum 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 Glasgow82f9ab32012-04-04 14:27:19 -040045// CellularCapabilityClassic handles modems using the
46// org.chromium.ModemManager DBUS interface.
47class 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 Shienbrood7fce52c2012-04-13 19:11:02 -040054 static const char kModemPropertyEnabled[];
Darin Petkovc37a9c42012-09-06 15:28:22 +020055 static const int kTimeoutSetCarrierMilliseconds;
Jason Glasgow82f9ab32012-04-04 14:27:19 -040056
57 // |cellular| is the parent Cellular device.
Thieu Lece4483e2013-01-23 15:12:03 -080058 CellularCapabilityClassic(Cellular *cellular,
59 ProxyFactory *proxy_factory,
Prathmesh Prabhu27526f12013-03-25 19:42:18 -070060 ModemInfo *modem_info);
Jason Glasgow82f9ab32012-04-04 14:27:19 -040061 virtual ~CellularCapabilityClassic();
62
Ben Chanf98f00e2014-02-05 14:48:43 -080063 // Inherited from CellularCapability.
Eric Shienbrood7fce52c2012-04-13 19:11:02 -040064 virtual void OnDBusPropertiesChanged(
65 const std::string &interface,
Ben Chanf98f00e2014-02-05 14:48:43 -080066 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 Shienbrood7fce52c2012-04-13 19:11:02 -040077
Jason Glasgow82f9ab32012-04-04 14:27:19 -040078 protected:
Jason Glasgowa0caabf2012-05-04 11:31:41 -040079 typedef std::vector<base::Closure> CellularTaskList;
80
Jason Glasgow4380f0d2012-05-03 18:05:04 -040081 virtual void GetRegistrationState() = 0;
82
Jason Glasgow82f9ab32012-04-04 14:27:19 -040083 // 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 Glasgow4380f0d2012-05-03 18:05:04 -040096 virtual void UpdateStatus(const DBusPropertiesMap &properties) = 0;
Jason Glasgow82f9ab32012-04-04 14:27:19 -040097
Jason Glasgowa0caabf2012-05-04 11:31:41 -040098 // 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 Chanf98f00e2014-02-05 14:48:43 -0800107 void StepCompletedCallback(const ResultCallback &callback,
108 bool ignore_error,
109 CellularTaskList *tasks,
110 const Error &error);
Jason Glasgowa0caabf2012-05-04 11:31:41 -0400111
Nathan Williamsb54974f2012-04-19 11:16:30 -0400112 scoped_ptr<ModemSimpleProxyInterface> simple_proxy_;
113
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400114 private:
115 friend class CellularTest;
Christopher Wiley7d0953e2012-11-16 00:37:10 -0800116 friend class CellularCapabilityCDMATest;
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400117 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 Leb5954a22012-05-18 10:37:34 -0700136 FRIEND_TEST(CellularTest, ConnectFailureNoService);
Thieu Led4974cd2013-05-23 10:39:28 -0700137 FRIEND_TEST(CellularTest, ConnectSuccessNoService);
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400138 FRIEND_TEST(CellularTest, Disconnect);
Arman Uguray539c4232012-09-11 10:00:22 -0700139 FRIEND_TEST(CellularTest, DisconnectFailure);
Christopher Wiley7d0953e2012-11-16 00:37:10 -0800140 FRIEND_TEST(CellularTest, DisconnectWithCallback);
Eric Shienbrood7fce52c2012-04-13 19:11:02 -0400141 FRIEND_TEST(CellularTest, ModemStateChangeEnable);
142 FRIEND_TEST(CellularTest, ModemStateChangeDisable);
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400143
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400144 // Method reply and signal callbacks from Modem interface
Ben Chanf98f00e2014-02-05 14:48:43 -0800145 void OnModemStateChangedSignal(uint32 old_state,
146 uint32 new_state,
147 uint32 reason);
Nathan Williams3022be52012-04-19 17:40:49 -0400148 void OnGetModemInfoReply(const ResultCallback &callback,
149 const ModemHardwareInfo &info,
150 const Error &error);
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400151
152 // Method reply callbacks from Modem.Simple interface
Nathan Williams3022be52012-04-19 17:40:49 -0400153 void OnGetModemStatusReply(const ResultCallback &callback,
154 const DBusPropertiesMap &props,
155 const Error &error);
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400156
157 Cellular *cellular_;
158 base::WeakPtrFactory<CellularCapabilityClassic> weak_ptr_factory_;
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400159 scoped_ptr<ModemProxyInterface> proxy_;
Darin Petkovc37a9c42012-09-06 15:28:22 +0200160 scoped_ptr<ModemGobiProxyInterface> gobi_proxy_;
Jason Glasgow82f9ab32012-04-04 14:27:19 -0400161
162 DISALLOW_COPY_AND_ASSIGN(CellularCapabilityClassic);
163};
164
165} // namespace shill
166
Darin Petkovc37a9c42012-09-06 15:28:22 +0200167#endif // SHILL_CELLULAR_CAPABILITY_CLASSIC_H_