blob: c1790c9de988fde45cce86ead41ba7362bbeb928 [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 Guthrie4823f4f2013-07-25 10:03:03 -070038 virtual void Scan(ScanType /*scan_type*/, Error *error,
39 const std::string &/*reason*/);
Ben Chan99c8a4d2012-05-01 08:11:53 -070040
Darin Petkov9893d9c2012-05-17 15:27:31 -070041 virtual void ConnectTo(const WiMaxServiceRefPtr &service, Error *error);
Darin Petkovc63dcf02012-05-24 11:51:43 +020042 virtual void DisconnectFrom(const ServiceRefPtr &service, Error *error);
Ben Chan99c8a4d2012-05-01 08:11:53 -070043
Darin Petkovc63dcf02012-05-24 11:51:43 +020044 // Signaled by |service| when stopped.
45 virtual void OnServiceStopped(const WiMaxServiceRefPtr &service);
Darin Petkovd1cd7972012-05-22 15:26:15 +020046
Darin Petkovb96a4512012-06-04 11:02:49 +020047 // 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 Petkov6b9b2e12012-07-10 15:51:42 +020051 // Returns true if this device is not connecting or connected to a service.
52 virtual bool IsIdle() const;
53
Darin Petkovb72b62e2012-05-15 16:55:36 +020054 const RpcIdentifier &path() const { return path_; }
Darin Petkov9893d9c2012-05-17 15:27:31 -070055 bool scanning() const { return scanning_; }
Darin Petkovc63dcf02012-05-24 11:51:43 +020056 const std::set<RpcIdentifier> &networks() const { return networks_; }
Darin Petkovb72b62e2012-05-15 16:55:36 +020057
Ben Chan99c8a4d2012-05-01 08:11:53 -070058 private:
Darin Petkovb72b62e2012-05-15 16:55:36 +020059 friend class WiMaxTest;
Darin Petkovc63dcf02012-05-24 11:51:43 +020060 FRIEND_TEST(WiMaxProviderTest, OnNetworksChanged);
Darin Petkov3a4100c2012-06-14 11:36:59 +020061 FRIEND_TEST(WiMaxTest, ConnectTimeout);
62 FRIEND_TEST(WiMaxTest, ConnectTo);
Darin Petkovb96a4512012-06-04 11:02:49 +020063 FRIEND_TEST(WiMaxTest, DropService);
Darin Petkov6b9b2e12012-07-10 15:51:42 +020064 FRIEND_TEST(WiMaxTest, IsIdle);
Darin Petkov8ea0eaf2012-05-29 11:21:33 +020065 FRIEND_TEST(WiMaxTest, OnConnectComplete);
Darin Petkovb96a4512012-06-04 11:02:49 +020066 FRIEND_TEST(WiMaxTest, OnDeviceVanished);
Darin Petkov59f2d692012-06-07 15:57:46 +020067 FRIEND_TEST(WiMaxTest, OnEnableComplete);
Darin Petkov9893d9c2012-05-17 15:27:31 -070068 FRIEND_TEST(WiMaxTest, OnNetworksChanged);
Darin Petkovc63dcf02012-05-24 11:51:43 +020069 FRIEND_TEST(WiMaxTest, OnServiceStopped);
Darin Petkova3f9f772012-05-31 12:11:28 +020070 FRIEND_TEST(WiMaxTest, OnStatusChanged);
Darin Petkovb72b62e2012-05-15 16:55:36 +020071 FRIEND_TEST(WiMaxTest, StartStop);
72
Darin Petkov3a4100c2012-06-14 11:36:59 +020073 static const int kDefaultConnectTimeoutSeconds;
74 static const int kDefaultRPCTimeoutSeconds;
Darin Petkov912f0de2012-05-16 14:12:14 +020075
Darin Petkov9893d9c2012-05-17 15:27:31 -070076 void OnScanNetworksComplete(const Error &error);
Darin Petkov912f0de2012-05-16 14:12:14 +020077 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 Petkov9893d9c2012-05-17 15:27:31 -070084 void OnNetworksChanged(const RpcIdentifiers &networks);
Darin Petkov8ea0eaf2012-05-29 11:21:33 +020085 void OnStatusChanged(wimax_manager::DeviceStatus status);
Darin Petkov9893d9c2012-05-17 15:27:31 -070086
Darin Petkovb96a4512012-06-04 11:02:49 +020087 void DropService(Service::ConnectState state);
Darin Petkov9893d9c2012-05-17 15:27:31 -070088
Darin Petkov3a4100c2012-06-14 11:36:59 +020089 // 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 Petkovb72b62e2012-05-15 16:55:36 +0200101 const RpcIdentifier path_;
102
Darin Petkov3a4100c2012-06-14 11:36:59 +0200103 base::WeakPtrFactory<WiMax> weak_ptr_factory_;
Darin Petkovb72b62e2012-05-15 16:55:36 +0200104 scoped_ptr<WiMaxDeviceProxyInterface> proxy_;
Darin Petkov9893d9c2012-05-17 15:27:31 -0700105 bool scanning_;
Darin Petkov9893d9c2012-05-17 15:27:31 -0700106 WiMaxServiceRefPtr pending_service_;
Darin Petkovc63dcf02012-05-24 11:51:43 +0200107 std::set<RpcIdentifier> networks_;
Darin Petkov3a4100c2012-06-14 11:36:59 +0200108 wimax_manager::DeviceStatus status_;
Darin Petkovb72b62e2012-05-15 16:55:36 +0200109
110 ProxyFactory *proxy_factory_;
111
Darin Petkov3a4100c2012-06-14 11:36:59 +0200112 base::CancelableClosure connect_timeout_callback_;
113 int connect_timeout_seconds_;
114
Ben Chan99c8a4d2012-05-01 08:11:53 -0700115 DISALLOW_COPY_AND_ASSIGN(WiMax);
116};
117
118} // namespace shill
119
120#endif // SHILL_WIMAX_H_