blob: b1701d57ff5cec7c0d12aca05a8324ca1950d906 [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);
Darin Petkov9893d9c2012-05-17 15:27:31 -070038 virtual void Scan(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 Petkovb72b62e2012-05-15 16:55:36 +020050 const RpcIdentifier &path() const { return path_; }
Darin Petkov9893d9c2012-05-17 15:27:31 -070051 bool scanning() const { return scanning_; }
Darin Petkovc63dcf02012-05-24 11:51:43 +020052 const std::set<RpcIdentifier> &networks() const { return networks_; }
Darin Petkovb72b62e2012-05-15 16:55:36 +020053
Ben Chan99c8a4d2012-05-01 08:11:53 -070054 private:
Darin Petkovb72b62e2012-05-15 16:55:36 +020055 friend class WiMaxTest;
Darin Petkovc63dcf02012-05-24 11:51:43 +020056 FRIEND_TEST(WiMaxProviderTest, OnNetworksChanged);
Darin Petkov3a4100c2012-06-14 11:36:59 +020057 FRIEND_TEST(WiMaxTest, ConnectTimeout);
58 FRIEND_TEST(WiMaxTest, ConnectTo);
Darin Petkovb96a4512012-06-04 11:02:49 +020059 FRIEND_TEST(WiMaxTest, DropService);
Darin Petkov8ea0eaf2012-05-29 11:21:33 +020060 FRIEND_TEST(WiMaxTest, OnConnectComplete);
Darin Petkovb96a4512012-06-04 11:02:49 +020061 FRIEND_TEST(WiMaxTest, OnDeviceVanished);
Darin Petkov59f2d692012-06-07 15:57:46 +020062 FRIEND_TEST(WiMaxTest, OnEnableComplete);
Darin Petkov9893d9c2012-05-17 15:27:31 -070063 FRIEND_TEST(WiMaxTest, OnNetworksChanged);
Darin Petkovc63dcf02012-05-24 11:51:43 +020064 FRIEND_TEST(WiMaxTest, OnServiceStopped);
Darin Petkova3f9f772012-05-31 12:11:28 +020065 FRIEND_TEST(WiMaxTest, OnStatusChanged);
Darin Petkovb72b62e2012-05-15 16:55:36 +020066 FRIEND_TEST(WiMaxTest, StartStop);
67
Darin Petkov3a4100c2012-06-14 11:36:59 +020068 static const int kDefaultConnectTimeoutSeconds;
69 static const int kDefaultRPCTimeoutSeconds;
Darin Petkov912f0de2012-05-16 14:12:14 +020070
Darin Petkov9893d9c2012-05-17 15:27:31 -070071 void OnScanNetworksComplete(const Error &error);
Darin Petkov912f0de2012-05-16 14:12:14 +020072 void OnConnectComplete(const Error &error);
73 void OnDisconnectComplete(const Error &error);
74 void OnEnableComplete(const EnabledStateChangedCallback &callback,
75 const Error &error);
76 void OnDisableComplete(const EnabledStateChangedCallback &callback,
77 const Error &error);
78
Darin Petkov9893d9c2012-05-17 15:27:31 -070079 void OnNetworksChanged(const RpcIdentifiers &networks);
Darin Petkov8ea0eaf2012-05-29 11:21:33 +020080 void OnStatusChanged(wimax_manager::DeviceStatus status);
Darin Petkov9893d9c2012-05-17 15:27:31 -070081
Darin Petkovb96a4512012-06-04 11:02:49 +020082 void DropService(Service::ConnectState state);
Darin Petkov9893d9c2012-05-17 15:27:31 -070083
Darin Petkov3a4100c2012-06-14 11:36:59 +020084 // Initializes a callback that will invoke OnConnectTimeout. The timeout will
85 // not be restarted if it's already scheduled.
86 void StartConnectTimeout();
87 // Cancels the connect timeout callback, if any, previously scheduled through
88 // StartConnectTimeout.
89 void StopConnectTimeout();
90 // Returns true if a connect timeout is scheduled, false otherwise.
91 bool IsConnectTimeoutStarted() const;
92 // Called if a connect timeout scheduled through StartConnectTimeout
93 // fires. Marks the callback as stopped and invokes DropService.
94 void OnConnectTimeout();
95
Darin Petkovb72b62e2012-05-15 16:55:36 +020096 const RpcIdentifier path_;
97
Darin Petkov3a4100c2012-06-14 11:36:59 +020098 base::WeakPtrFactory<WiMax> weak_ptr_factory_;
Darin Petkovb72b62e2012-05-15 16:55:36 +020099 scoped_ptr<WiMaxDeviceProxyInterface> proxy_;
Darin Petkov9893d9c2012-05-17 15:27:31 -0700100 bool scanning_;
Darin Petkov9893d9c2012-05-17 15:27:31 -0700101 WiMaxServiceRefPtr pending_service_;
Darin Petkovc63dcf02012-05-24 11:51:43 +0200102 std::set<RpcIdentifier> networks_;
Darin Petkov3a4100c2012-06-14 11:36:59 +0200103 wimax_manager::DeviceStatus status_;
Darin Petkovb72b62e2012-05-15 16:55:36 +0200104
105 ProxyFactory *proxy_factory_;
106
Darin Petkov3a4100c2012-06-14 11:36:59 +0200107 base::CancelableClosure connect_timeout_callback_;
108 int connect_timeout_seconds_;
109
Ben Chan99c8a4d2012-05-01 08:11:53 -0700110 DISALLOW_COPY_AND_ASSIGN(WiMax);
111};
112
113} // namespace shill
114
115#endif // SHILL_WIMAX_H_