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_SRC_PRIVET_PRIVET_MANAGER_H_
6 #define LIBWEAVE_SRC_PRIVET_PRIVET_MANAGER_H_
7 
8 #include <memory>
9 #include <set>
10 #include <string>
11 #include <vector>
12 
13 #include <base/memory/weak_ptr.h>
14 #include <base/scoped_observer.h>
15 #include <weave/device.h>
16 
17 #include "src/privet/cloud_delegate.h"
18 #include "src/privet/security_manager.h"
19 #include "src/privet/wifi_bootstrap_manager.h"
20 
21 namespace libwebserv {
22 class ProtocolHandler;
23 class Request;
24 class Response;
25 class Server;
26 }
27 
28 namespace weave {
29 
30 class ComponentManager;
31 class DeviceRegistrationInfo;
32 class DnsServiceDiscovery;
33 class Network;
34 
35 namespace privet {
36 
37 class CloudDelegate;
38 class DaemonState;
39 class DeviceDelegate;
40 class PrivetHandler;
41 class Publisher;
42 class SecurityManager;
43 
44 class Manager : public CloudDelegate::Observer {
45  public:
46   explicit Manager(provider::TaskRunner* task_runner);
47   ~Manager() override;
48 
49   void Start(provider::Network* network,
50              provider::DnsServiceDiscovery* dns_sd,
51              provider::HttpServer* http_server,
52              provider::Wifi* wifi,
53              AuthManager* auth_manager,
54              DeviceRegistrationInfo* device,
55              ComponentManager* component_manager);
56 
57   std::string GetCurrentlyConnectedSsid() const;
58 
59   void AddOnPairingChangedCallbacks(
60       const Device::PairingBeginCallback& begin_callback,
61       const Device::PairingEndCallback& end_callback);
62 
63  private:
64   // CloudDelegate::Observer
65   void OnDeviceInfoChanged() override;
66 
67   void PrivetRequestHandler(
68       std::unique_ptr<provider::HttpServer::Request> request);
69 
70   void PrivetRequestHandlerWithData(
71       const std::shared_ptr<provider::HttpServer::Request>& request,
72       const std::string& data);
73 
74   void PrivetResponseHandler(
75       const std::shared_ptr<provider::HttpServer::Request>& request,
76       int status,
77       const base::DictionaryValue& output);
78 
79   void OnChanged();
80   void OnConnectivityChanged();
81 
82   provider::TaskRunner* task_runner_{nullptr};
83   std::unique_ptr<CloudDelegate> cloud_;
84   std::unique_ptr<DeviceDelegate> device_;
85   std::unique_ptr<SecurityManager> security_;
86   std::unique_ptr<WifiBootstrapManager> wifi_bootstrap_manager_;
87   std::unique_ptr<Publisher> publisher_;
88   std::unique_ptr<PrivetHandler> privet_handler_;
89 
90   ScopedObserver<CloudDelegate, CloudDelegate::Observer> cloud_observer_{this};
91 
92   base::WeakPtrFactory<Manager> weak_ptr_factory_{this};
93   DISALLOW_COPY_AND_ASSIGN(Manager);
94 };
95 
96 }  // namespace privet
97 }  // namespace weave
98 
99 #endif  // LIBWEAVE_SRC_PRIVET_PRIVET_MANAGER_H_
100