blob: b51a772eac8955812d60c84be46d21a869cb9df3 [file] [log] [blame]
Ben Chan99c8a4d2012-05-01 08:11:53 -07001// 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 Petkovc63dcf02012-05-24 11:51:43 +02008#include <set>
9
Darin Petkov3a4100c2012-06-14 11:36:59 +020010#include <base/cancelable_callback.h>
11#include <base/memory/weak_ptr.h>
Darin Petkov8ea0eaf2012-05-29 11:21:33 +020012#include <chromeos/dbus/service_constants.h>
Darin Petkovb72b62e2012-05-15 16:55:36 +020013#include <gtest/gtest_prod.h> // for FRIEND_TEST
14
Ben Chan99c8a4d2012-05-01 08:11:53 -070015#include "shill/device.h"
16
17namespace shill {
18
Darin Petkovb72b62e2012-05-15 16:55:36 +020019class ProxyFactory;
20class WiMaxDeviceProxyInterface;
21
Ben Chan99c8a4d2012-05-01 08:11:53 -070022class 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 Chan4e64d2d2012-05-16 00:02:25 -070029 const std::string &address,
Darin Petkovb72b62e2012-05-15 16:55:36 +020030 int interface_index,
31 const RpcIdentifier &path);
Ben Chan99c8a4d2012-05-01 08:11:53 -070032
33 virtual ~WiMax();
34
Darin Petkov9893d9c2012-05-17 15:27:31 -070035 // Inherited from Device.
Ben Chan99c8a4d2012-05-01 08:11:53 -070036 virtual void Start(Error *error, const EnabledStateChangedCallback &callback);
37 virtual void Stop(Error *error, const EnabledStateChangedCallback &callback);
Wade Guthrie68d41092013-04-02 12:56:02 -070038 virtual void Scan(ScanType scan_type, Error *error);
Ben Chan99c8a4d2012-05-01 08:11:53 -070039
Darin Petkov9893d9c2012-05-17 15:27:31 -070040 virtual void ConnectTo(const WiMaxServiceRefPtr &service, Error *error);
Darin Petkovc63dcf02012-05-24 11:51:43 +020041 virtual void DisconnectFrom(const ServiceRefPtr &service, Error *error);
Ben Chan99c8a4d2012-05-01 08:11:53 -070042
Darin Petkovc63dcf02012-05-24 11:51:43 +020043 // Signaled by |service| when stopped.
44 virtual void OnServiceStopped(const WiMaxServiceRefPtr &service);
Darin Petkovd1cd7972012-05-22 15:26:15 +020045
Darin Petkovb96a4512012-06-04 11:02:49 +020046 // 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 Petkov6b9b2e12012-07-10 15:51:42 +020050 // Returns true if this device is not connecting or connected to a service.
51 virtual bool IsIdle() const;
52
Darin Petkovb72b62e2012-05-15 16:55:36 +020053 const RpcIdentifier &path() const { return path_; }
Darin Petkov9893d9c2012-05-17 15:27:31 -070054 bool scanning() const { return scanning_; }
Darin Petkovc63dcf02012-05-24 11:51:43 +020055 const std::set<RpcIdentifier> &networks() const { return networks_; }
Darin Petkovb72b62e2012-05-15 16:55:36 +020056
Ben Chan99c8a4d2012-05-01 08:11:53 -070057 private:
Darin Petkovb72b62e2012-05-15 16:55:36 +020058 friend class WiMaxTest;
Darin Petkovc63dcf02012-05-24 11:51:43 +020059 FRIEND_TEST(WiMaxProviderTest, OnNetworksChanged);
Darin Petkov3a4100c2012-06-14 11:36:59 +020060 FRIEND_TEST(WiMaxTest, ConnectTimeout);
61 FRIEND_TEST(WiMaxTest, ConnectTo);
Darin Petkovb96a4512012-06-04 11:02:49 +020062 FRIEND_TEST(WiMaxTest, DropService);
Darin Petkov6b9b2e12012-07-10 15:51:42 +020063 FRIEND_TEST(WiMaxTest, IsIdle);
Darin Petkov8ea0eaf2012-05-29 11:21:33 +020064 FRIEND_TEST(WiMaxTest, OnConnectComplete);
Darin Petkovb96a4512012-06-04 11:02:49 +020065 FRIEND_TEST(WiMaxTest, OnDeviceVanished);
Darin Petkov59f2d692012-06-07 15:57:46 +020066 FRIEND_TEST(WiMaxTest, OnEnableComplete);
Darin Petkov9893d9c2012-05-17 15:27:31 -070067 FRIEND_TEST(WiMaxTest, OnNetworksChanged);
Darin Petkovc63dcf02012-05-24 11:51:43 +020068 FRIEND_TEST(WiMaxTest, OnServiceStopped);
Darin Petkova3f9f772012-05-31 12:11:28 +020069 FRIEND_TEST(WiMaxTest, OnStatusChanged);
Darin Petkovb72b62e2012-05-15 16:55:36 +020070 FRIEND_TEST(WiMaxTest, StartStop);
71
Darin Petkov3a4100c2012-06-14 11:36:59 +020072 static const int kDefaultConnectTimeoutSeconds;
73 static const int kDefaultRPCTimeoutSeconds;
Darin Petkov912f0de2012-05-16 14:12:14 +020074
Darin Petkov9893d9c2012-05-17 15:27:31 -070075 void OnScanNetworksComplete(const Error &error);
Darin Petkov912f0de2012-05-16 14:12:14 +020076 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 Petkov9893d9c2012-05-17 15:27:31 -070083 void OnNetworksChanged(const RpcIdentifiers &networks);
Darin Petkov8ea0eaf2012-05-29 11:21:33 +020084 void OnStatusChanged(wimax_manager::DeviceStatus status);
Darin Petkov9893d9c2012-05-17 15:27:31 -070085
Darin Petkovb96a4512012-06-04 11:02:49 +020086 void DropService(Service::ConnectState state);
Darin Petkov9893d9c2012-05-17 15:27:31 -070087
Darin Petkov3a4100c2012-06-14 11:36:59 +020088 // 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 Petkovb72b62e2012-05-15 16:55:36 +0200100 const RpcIdentifier path_;
101
Darin Petkov3a4100c2012-06-14 11:36:59 +0200102 base::WeakPtrFactory<WiMax> weak_ptr_factory_;
Darin Petkovb72b62e2012-05-15 16:55:36 +0200103 scoped_ptr<WiMaxDeviceProxyInterface> proxy_;
Darin Petkov9893d9c2012-05-17 15:27:31 -0700104 bool scanning_;
Darin Petkov9893d9c2012-05-17 15:27:31 -0700105 WiMaxServiceRefPtr pending_service_;
Darin Petkovc63dcf02012-05-24 11:51:43 +0200106 std::set<RpcIdentifier> networks_;
Darin Petkov3a4100c2012-06-14 11:36:59 +0200107 wimax_manager::DeviceStatus status_;
Darin Petkovb72b62e2012-05-15 16:55:36 +0200108
109 ProxyFactory *proxy_factory_;
110
Darin Petkov3a4100c2012-06-14 11:36:59 +0200111 base::CancelableClosure connect_timeout_callback_;
112 int connect_timeout_seconds_;
113
Ben Chan99c8a4d2012-05-01 08:11:53 -0700114 DISALLOW_COPY_AND_ASSIGN(WiMax);
115};
116
117} // namespace shill
118
119#endif // SHILL_WIMAX_H_