Johan Euphrosine | 09fcef6 | 2015-10-15 00:14:27 -0700 | [diff] [blame] | 1 | // Copyright 2015 The Weave 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 LIBWEAVE_EXAMPLES_UBUNTU_WIFI_MANAGER_H_ |
| 6 | #define LIBWEAVE_EXAMPLES_UBUNTU_WIFI_MANAGER_H_ |
| 7 | |
| 8 | #include <string> |
| 9 | #include <vector> |
| 10 | |
| 11 | #include <base/memory/weak_ptr.h> |
| 12 | #include <base/time/time.h> |
| 13 | #include <weave/provider/wifi.h> |
| 14 | |
| 15 | namespace weave { |
| 16 | |
| 17 | namespace provider { |
| 18 | class TaskRunner; |
| 19 | } |
| 20 | |
| 21 | namespace examples { |
| 22 | |
Vitaly Buka | 3d8feaf | 2015-10-28 13:10:53 -0700 | [diff] [blame] | 23 | class EventNetworkImpl; |
| 24 | |
Johan Euphrosine | 09fcef6 | 2015-10-15 00:14:27 -0700 | [diff] [blame] | 25 | // Basic weave::Wifi implementation. |
| 26 | // Production version of SSL socket needs secure server certificate check. |
| 27 | class WifiImpl : public provider::Wifi { |
| 28 | public: |
Vitaly Buka | 3d8feaf | 2015-10-28 13:10:53 -0700 | [diff] [blame] | 29 | WifiImpl(provider::TaskRunner* task_runner, EventNetworkImpl* network); |
Johan Euphrosine | 09fcef6 | 2015-10-15 00:14:27 -0700 | [diff] [blame] | 30 | ~WifiImpl(); |
| 31 | |
| 32 | // Wifi implementation. |
| 33 | void Connect(const std::string& ssid, |
| 34 | const std::string& passphrase, |
| 35 | const DoneCallback& callback) override; |
| 36 | void StartAccessPoint(const std::string& ssid) override; |
| 37 | void StopAccessPoint() override; |
| 38 | |
| 39 | static bool HasWifiCapability(); |
| 40 | |
| 41 | private: |
| 42 | void TryToConnect(const std::string& ssid, |
| 43 | const std::string& passphrase, |
| 44 | int pid, |
| 45 | base::Time until, |
| 46 | const DoneCallback& callback); |
Johan Euphrosine | 09fcef6 | 2015-10-15 00:14:27 -0700 | [diff] [blame] | 47 | bool hostapd_started_{false}; |
| 48 | provider::TaskRunner* task_runner_{nullptr}; |
Vitaly Buka | 3d8feaf | 2015-10-28 13:10:53 -0700 | [diff] [blame] | 49 | EventNetworkImpl* network_{nullptr}; |
Johan Euphrosine | 09fcef6 | 2015-10-15 00:14:27 -0700 | [diff] [blame] | 50 | base::WeakPtrFactory<WifiImpl> weak_ptr_factory_{this}; |
Johan Euphrosine | ec47eb0 | 2015-12-11 09:17:44 +0000 | [diff] [blame] | 51 | std::string iface_; |
Johan Euphrosine | 09fcef6 | 2015-10-15 00:14:27 -0700 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | } // namespace examples |
| 55 | } // namespace weave |
| 56 | |
| 57 | #endif // LIBWEAVE_EXAMPLES_UBUNTU_WIFI_MANAGER_H_ |