blob: 2bfc5ca6b750abca8357fa3174c06df25d9de99d [file] [log] [blame]
Johan Euphrosine09fcef62015-10-15 00:14:27 -07001// 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
15namespace weave {
16
17namespace provider {
18class TaskRunner;
19}
20
21namespace examples {
22
Vitaly Buka3d8feaf2015-10-28 13:10:53 -070023class EventNetworkImpl;
24
Johan Euphrosine09fcef62015-10-15 00:14:27 -070025// Basic weave::Wifi implementation.
26// Production version of SSL socket needs secure server certificate check.
27class WifiImpl : public provider::Wifi {
28 public:
Vitaly Buka3d8feaf2015-10-28 13:10:53 -070029 WifiImpl(provider::TaskRunner* task_runner, EventNetworkImpl* network);
Johan Euphrosine09fcef62015-10-15 00:14:27 -070030 ~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 Euphrosine09fcef62015-10-15 00:14:27 -070047 bool hostapd_started_{false};
48 provider::TaskRunner* task_runner_{nullptr};
Vitaly Buka3d8feaf2015-10-28 13:10:53 -070049 EventNetworkImpl* network_{nullptr};
Johan Euphrosine09fcef62015-10-15 00:14:27 -070050 base::WeakPtrFactory<WifiImpl> weak_ptr_factory_{this};
Johan Euphrosineec47eb02015-12-11 09:17:44 +000051 std::string iface_;
Johan Euphrosine09fcef62015-10-15 00:14:27 -070052};
53
54} // namespace examples
55} // namespace weave
56
57#endif // LIBWEAVE_EXAMPLES_UBUNTU_WIFI_MANAGER_H_