Ben Chan | 99c8a4d | 2012-05-01 08:11:53 -0700 | [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 | |
| 5 | #ifndef SHILL_WIMAX_H_ |
| 6 | #define SHILL_WIMAX_H_ |
| 7 | |
Darin Petkov | c63dcf0 | 2012-05-24 11:51:43 +0200 | [diff] [blame] | 8 | #include <set> |
| 9 | |
Darin Petkov | 3a4100c | 2012-06-14 11:36:59 +0200 | [diff] [blame] | 10 | #include <base/cancelable_callback.h> |
| 11 | #include <base/memory/weak_ptr.h> |
Darin Petkov | 8ea0eaf | 2012-05-29 11:21:33 +0200 | [diff] [blame] | 12 | #include <chromeos/dbus/service_constants.h> |
Darin Petkov | b72b62e | 2012-05-15 16:55:36 +0200 | [diff] [blame] | 13 | #include <gtest/gtest_prod.h> // for FRIEND_TEST |
| 14 | |
Ben Chan | 99c8a4d | 2012-05-01 08:11:53 -0700 | [diff] [blame] | 15 | #include "shill/device.h" |
| 16 | |
| 17 | namespace shill { |
| 18 | |
Darin Petkov | b72b62e | 2012-05-15 16:55:36 +0200 | [diff] [blame] | 19 | class ProxyFactory; |
| 20 | class WiMaxDeviceProxyInterface; |
| 21 | |
Ben Chan | 99c8a4d | 2012-05-01 08:11:53 -0700 | [diff] [blame] | 22 | class WiMax : public Device { |
| 23 | public: |
| 24 | WiMax(ControlInterface *control, |
| 25 | EventDispatcher *dispatcher, |
| 26 | Metrics *metrics, |
| 27 | Manager *manager, |
| 28 | const std::string &link_name, |
Ben Chan | 4e64d2d | 2012-05-16 00:02:25 -0700 | [diff] [blame] | 29 | const std::string &address, |
Darin Petkov | b72b62e | 2012-05-15 16:55:36 +0200 | [diff] [blame] | 30 | int interface_index, |
| 31 | const RpcIdentifier &path); |
Ben Chan | 99c8a4d | 2012-05-01 08:11:53 -0700 | [diff] [blame] | 32 | |
| 33 | virtual ~WiMax(); |
| 34 | |
Darin Petkov | 9893d9c | 2012-05-17 15:27:31 -0700 | [diff] [blame] | 35 | // Inherited from Device. |
Ben Chan | 99c8a4d | 2012-05-01 08:11:53 -0700 | [diff] [blame] | 36 | virtual void Start(Error *error, const EnabledStateChangedCallback &callback); |
| 37 | virtual void Stop(Error *error, const EnabledStateChangedCallback &callback); |
Wade Guthrie | 68d4109 | 2013-04-02 12:56:02 -0700 | [diff] [blame] | 38 | virtual void Scan(ScanType scan_type, Error *error); |
Ben Chan | 99c8a4d | 2012-05-01 08:11:53 -0700 | [diff] [blame] | 39 | |
Darin Petkov | 9893d9c | 2012-05-17 15:27:31 -0700 | [diff] [blame] | 40 | virtual void ConnectTo(const WiMaxServiceRefPtr &service, Error *error); |
Darin Petkov | c63dcf0 | 2012-05-24 11:51:43 +0200 | [diff] [blame] | 41 | virtual void DisconnectFrom(const ServiceRefPtr &service, Error *error); |
Ben Chan | 99c8a4d | 2012-05-01 08:11:53 -0700 | [diff] [blame] | 42 | |
Darin Petkov | c63dcf0 | 2012-05-24 11:51:43 +0200 | [diff] [blame] | 43 | // Signaled by |service| when stopped. |
| 44 | virtual void OnServiceStopped(const WiMaxServiceRefPtr &service); |
Darin Petkov | d1cd797 | 2012-05-22 15:26:15 +0200 | [diff] [blame] | 45 | |
Darin Petkov | b96a451 | 2012-06-04 11:02:49 +0200 | [diff] [blame] | 46 | // Signaled by WiMaxProvider when the RPC device disappears. The provider will |
| 47 | // deregister and destroy the device after invoking this method. |
| 48 | virtual void OnDeviceVanished(); |
| 49 | |
Darin Petkov | 6b9b2e1 | 2012-07-10 15:51:42 +0200 | [diff] [blame] | 50 | // Returns true if this device is not connecting or connected to a service. |
| 51 | virtual bool IsIdle() const; |
| 52 | |
Darin Petkov | b72b62e | 2012-05-15 16:55:36 +0200 | [diff] [blame] | 53 | const RpcIdentifier &path() const { return path_; } |
Darin Petkov | 9893d9c | 2012-05-17 15:27:31 -0700 | [diff] [blame] | 54 | bool scanning() const { return scanning_; } |
Darin Petkov | c63dcf0 | 2012-05-24 11:51:43 +0200 | [diff] [blame] | 55 | const std::set<RpcIdentifier> &networks() const { return networks_; } |
Darin Petkov | b72b62e | 2012-05-15 16:55:36 +0200 | [diff] [blame] | 56 | |
Ben Chan | 99c8a4d | 2012-05-01 08:11:53 -0700 | [diff] [blame] | 57 | private: |
Darin Petkov | b72b62e | 2012-05-15 16:55:36 +0200 | [diff] [blame] | 58 | friend class WiMaxTest; |
Darin Petkov | c63dcf0 | 2012-05-24 11:51:43 +0200 | [diff] [blame] | 59 | FRIEND_TEST(WiMaxProviderTest, OnNetworksChanged); |
Darin Petkov | 3a4100c | 2012-06-14 11:36:59 +0200 | [diff] [blame] | 60 | FRIEND_TEST(WiMaxTest, ConnectTimeout); |
| 61 | FRIEND_TEST(WiMaxTest, ConnectTo); |
Darin Petkov | b96a451 | 2012-06-04 11:02:49 +0200 | [diff] [blame] | 62 | FRIEND_TEST(WiMaxTest, DropService); |
Darin Petkov | 6b9b2e1 | 2012-07-10 15:51:42 +0200 | [diff] [blame] | 63 | FRIEND_TEST(WiMaxTest, IsIdle); |
Darin Petkov | 8ea0eaf | 2012-05-29 11:21:33 +0200 | [diff] [blame] | 64 | FRIEND_TEST(WiMaxTest, OnConnectComplete); |
Darin Petkov | b96a451 | 2012-06-04 11:02:49 +0200 | [diff] [blame] | 65 | FRIEND_TEST(WiMaxTest, OnDeviceVanished); |
Darin Petkov | 59f2d69 | 2012-06-07 15:57:46 +0200 | [diff] [blame] | 66 | FRIEND_TEST(WiMaxTest, OnEnableComplete); |
Darin Petkov | 9893d9c | 2012-05-17 15:27:31 -0700 | [diff] [blame] | 67 | FRIEND_TEST(WiMaxTest, OnNetworksChanged); |
Darin Petkov | c63dcf0 | 2012-05-24 11:51:43 +0200 | [diff] [blame] | 68 | FRIEND_TEST(WiMaxTest, OnServiceStopped); |
Darin Petkov | a3f9f77 | 2012-05-31 12:11:28 +0200 | [diff] [blame] | 69 | FRIEND_TEST(WiMaxTest, OnStatusChanged); |
Darin Petkov | b72b62e | 2012-05-15 16:55:36 +0200 | [diff] [blame] | 70 | FRIEND_TEST(WiMaxTest, StartStop); |
| 71 | |
Darin Petkov | 3a4100c | 2012-06-14 11:36:59 +0200 | [diff] [blame] | 72 | static const int kDefaultConnectTimeoutSeconds; |
| 73 | static const int kDefaultRPCTimeoutSeconds; |
Darin Petkov | 912f0de | 2012-05-16 14:12:14 +0200 | [diff] [blame] | 74 | |
Darin Petkov | 9893d9c | 2012-05-17 15:27:31 -0700 | [diff] [blame] | 75 | void OnScanNetworksComplete(const Error &error); |
Darin Petkov | 912f0de | 2012-05-16 14:12:14 +0200 | [diff] [blame] | 76 | void OnConnectComplete(const Error &error); |
| 77 | void OnDisconnectComplete(const Error &error); |
| 78 | void OnEnableComplete(const EnabledStateChangedCallback &callback, |
| 79 | const Error &error); |
| 80 | void OnDisableComplete(const EnabledStateChangedCallback &callback, |
| 81 | const Error &error); |
| 82 | |
Darin Petkov | 9893d9c | 2012-05-17 15:27:31 -0700 | [diff] [blame] | 83 | void OnNetworksChanged(const RpcIdentifiers &networks); |
Darin Petkov | 8ea0eaf | 2012-05-29 11:21:33 +0200 | [diff] [blame] | 84 | void OnStatusChanged(wimax_manager::DeviceStatus status); |
Darin Petkov | 9893d9c | 2012-05-17 15:27:31 -0700 | [diff] [blame] | 85 | |
Darin Petkov | b96a451 | 2012-06-04 11:02:49 +0200 | [diff] [blame] | 86 | void DropService(Service::ConnectState state); |
Darin Petkov | 9893d9c | 2012-05-17 15:27:31 -0700 | [diff] [blame] | 87 | |
Darin Petkov | 3a4100c | 2012-06-14 11:36:59 +0200 | [diff] [blame] | 88 | // Initializes a callback that will invoke OnConnectTimeout. The timeout will |
| 89 | // not be restarted if it's already scheduled. |
| 90 | void StartConnectTimeout(); |
| 91 | // Cancels the connect timeout callback, if any, previously scheduled through |
| 92 | // StartConnectTimeout. |
| 93 | void StopConnectTimeout(); |
| 94 | // Returns true if a connect timeout is scheduled, false otherwise. |
| 95 | bool IsConnectTimeoutStarted() const; |
| 96 | // Called if a connect timeout scheduled through StartConnectTimeout |
| 97 | // fires. Marks the callback as stopped and invokes DropService. |
| 98 | void OnConnectTimeout(); |
| 99 | |
Darin Petkov | b72b62e | 2012-05-15 16:55:36 +0200 | [diff] [blame] | 100 | const RpcIdentifier path_; |
| 101 | |
Darin Petkov | 3a4100c | 2012-06-14 11:36:59 +0200 | [diff] [blame] | 102 | base::WeakPtrFactory<WiMax> weak_ptr_factory_; |
Darin Petkov | b72b62e | 2012-05-15 16:55:36 +0200 | [diff] [blame] | 103 | scoped_ptr<WiMaxDeviceProxyInterface> proxy_; |
Darin Petkov | 9893d9c | 2012-05-17 15:27:31 -0700 | [diff] [blame] | 104 | bool scanning_; |
Darin Petkov | 9893d9c | 2012-05-17 15:27:31 -0700 | [diff] [blame] | 105 | WiMaxServiceRefPtr pending_service_; |
Darin Petkov | c63dcf0 | 2012-05-24 11:51:43 +0200 | [diff] [blame] | 106 | std::set<RpcIdentifier> networks_; |
Darin Petkov | 3a4100c | 2012-06-14 11:36:59 +0200 | [diff] [blame] | 107 | wimax_manager::DeviceStatus status_; |
Darin Petkov | b72b62e | 2012-05-15 16:55:36 +0200 | [diff] [blame] | 108 | |
| 109 | ProxyFactory *proxy_factory_; |
| 110 | |
Darin Petkov | 3a4100c | 2012-06-14 11:36:59 +0200 | [diff] [blame] | 111 | base::CancelableClosure connect_timeout_callback_; |
| 112 | int connect_timeout_seconds_; |
| 113 | |
Ben Chan | 99c8a4d | 2012-05-01 08:11:53 -0700 | [diff] [blame] | 114 | DISALLOW_COPY_AND_ASSIGN(WiMax); |
| 115 | }; |
| 116 | |
| 117 | } // namespace shill |
| 118 | |
| 119 | #endif // SHILL_WIMAX_H_ |