aboutsummaryrefslogtreecommitdiff
path: root/src/privet/privet_manager.h
blob: 0d95f7abcb267cf8478799293595927d47312390 (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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// 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_SRC_PRIVET_PRIVET_MANAGER_H_
#define LIBWEAVE_SRC_PRIVET_PRIVET_MANAGER_H_

#include <memory>
#include <set>
#include <string>
#include <vector>

#include <base/memory/weak_ptr.h>
#include <weave/device.h>

#include "src/privet/cloud_delegate.h"
#include "src/privet/security_manager.h"
#include "src/privet/wifi_bootstrap_manager.h"

namespace libwebserv {
class ProtocolHandler;
class Request;
class Response;
class Server;
}

namespace weave {

class ComponentManager;
class DeviceRegistrationInfo;
class DnsServiceDiscovery;
class Network;

namespace privet {

class CloudDelegate;
class DaemonState;
class DeviceDelegate;
class PrivetHandler;
class Publisher;
class SecurityManager;

class Manager {
 public:
  explicit Manager(provider::TaskRunner* task_runner);
  ~Manager();

  void Start(provider::Network* network,
             provider::DnsServiceDiscovery* dns_sd,
             provider::HttpServer* http_server,
             provider::Wifi* wifi,
             AuthManager* auth_manager,
             DeviceRegistrationInfo* device,
             ComponentManager* component_manager);

  std::string GetCurrentlyConnectedSsid() const;

  void AddOnPairingChangedCallbacks(
      const Device::PairingBeginCallback& begin_callback,
      const Device::PairingEndCallback& end_callback);

 private:
  void OnDeviceInfoChanged(const weave::Settings&);

  void PrivetRequestHandler(
      std::unique_ptr<provider::HttpServer::Request> request);

  void PrivetRequestHandlerWithData(
      const std::shared_ptr<provider::HttpServer::Request>& request,
      const std::string& data);

  void PrivetResponseHandler(
      const std::shared_ptr<provider::HttpServer::Request>& request,
      int status,
      const base::DictionaryValue& output);

  void OnChanged();
  void OnConnectivityChanged();

  provider::TaskRunner* task_runner_{nullptr};
  provider::HttpServer* http_server_{nullptr};
  std::unique_ptr<CloudDelegate> cloud_;
  std::unique_ptr<DeviceDelegate> device_;
  std::unique_ptr<SecurityManager> security_;
  std::unique_ptr<WifiBootstrapManager> wifi_bootstrap_manager_;
  std::unique_ptr<Publisher> publisher_;
  std::unique_ptr<PrivetHandler> privet_handler_;

  base::WeakPtrFactory<Manager> weak_ptr_factory_{this};
  DISALLOW_COPY_AND_ASSIGN(Manager);
};

}  // namespace privet
}  // namespace weave

#endif  // LIBWEAVE_SRC_PRIVET_PRIVET_MANAGER_H_