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