aboutsummaryrefslogtreecommitdiff
path: root/examples/provider/wifi_manager.h
blob: 2bfc5ca6b750abca8357fa3174c06df25d9de99d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright 2015 The Weave Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef LIBWEAVE_EXAMPLES_UBUNTU_WIFI_MANAGER_H_
#define LIBWEAVE_EXAMPLES_UBUNTU_WIFI_MANAGER_H_

#include <string>
#include <vector>

#include <base/memory/weak_ptr.h>
#include <base/time/time.h>
#include <weave/provider/wifi.h>

namespace weave {

namespace provider {
class TaskRunner;
}

namespace examples {

class EventNetworkImpl;

// Basic weave::Wifi implementation.
// Production version of SSL socket needs secure server certificate check.
class WifiImpl : public provider::Wifi {
 public:
  WifiImpl(provider::TaskRunner* task_runner, EventNetworkImpl* network);
  ~WifiImpl();

  // Wifi implementation.
  void Connect(const std::string& ssid,
               const std::string& passphrase,
               const DoneCallback& callback) override;
  void StartAccessPoint(const std::string& ssid) override;
  void StopAccessPoint() override;

  static bool HasWifiCapability();

 private:
  void TryToConnect(const std::string& ssid,
                    const std::string& passphrase,
                    int pid,
                    base::Time until,
                    const DoneCallback& callback);
  bool hostapd_started_{false};
  provider::TaskRunner* task_runner_{nullptr};
  EventNetworkImpl* network_{nullptr};
  base::WeakPtrFactory<WifiImpl> weak_ptr_factory_{this};
  std::string iface_;
};

}  // namespace examples
}  // namespace weave

#endif  // LIBWEAVE_EXAMPLES_UBUNTU_WIFI_MANAGER_H_