Vitaly Buka | 7b6b3f0 | 2015-06-09 15:50:20 -0700 | [diff] [blame] | 1 | // Copyright 2014 The Chromium OS 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 BUFFET_PRIVET_PRIVET_MANAGER_H_ |
| 6 | #define BUFFET_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> |
Vitaly Buka | 7b6b3f0 | 2015-06-09 15:50:20 -0700 | [diff] [blame] | 15 | |
| 16 | #include "buffet/privet/cloud_delegate.h" |
| 17 | |
Vitaly Buka | ae96cc3 | 2015-06-09 17:22:18 -0700 | [diff] [blame] | 18 | namespace buffet { |
| 19 | class CommandManager; |
| 20 | class DeviceRegistrationInfo; |
Vitaly Buka | 7ab89ff | 2015-06-09 22:11:40 -0700 | [diff] [blame] | 21 | class StateManager; |
Vitaly Buka | ae96cc3 | 2015-06-09 17:22:18 -0700 | [diff] [blame] | 22 | } |
| 23 | |
Vitaly Buka | 7b6b3f0 | 2015-06-09 15:50:20 -0700 | [diff] [blame] | 24 | namespace chromeos { |
| 25 | namespace dbus_utils { |
| 26 | class AsyncEventSequencer; |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | namespace libwebserv { |
| 31 | class ProtocolHandler; |
| 32 | class Request; |
| 33 | class Response; |
| 34 | class Server; |
| 35 | } |
| 36 | |
| 37 | namespace privetd { |
| 38 | |
Vitaly Buka | 7b6b3f0 | 2015-06-09 15:50:20 -0700 | [diff] [blame] | 39 | class ApManagerClient; |
Vitaly Buka | ae96cc3 | 2015-06-09 17:22:18 -0700 | [diff] [blame] | 40 | class CloudDelegate; |
| 41 | class DaemonState; |
| 42 | class DeviceDelegate; |
Vitaly Buka | 7b6b3f0 | 2015-06-09 15:50:20 -0700 | [diff] [blame] | 43 | class PeerdClient; |
| 44 | class PrivetHandler; |
Vitaly Buka | ae96cc3 | 2015-06-09 17:22:18 -0700 | [diff] [blame] | 45 | class SecurityManager; |
| 46 | class ShillClient; |
| 47 | class WifiBootstrapManager; |
Vitaly Buka | 7b6b3f0 | 2015-06-09 15:50:20 -0700 | [diff] [blame] | 48 | |
Vitaly Buka | ae96cc3 | 2015-06-09 17:22:18 -0700 | [diff] [blame] | 49 | class Manager : public CloudDelegate::Observer { |
Vitaly Buka | 7b6b3f0 | 2015-06-09 15:50:20 -0700 | [diff] [blame] | 50 | public: |
Vitaly Buka | ae96cc3 | 2015-06-09 17:22:18 -0700 | [diff] [blame] | 51 | struct Options { |
| 52 | bool disable_privet{false}; |
| 53 | bool disable_security{false}; |
| 54 | bool enable_ping{false}; |
| 55 | std::set<std::string> device_whitelist; |
Vitaly Buka | 3d2cd66 | 2015-06-16 16:23:03 -0700 | [diff] [blame] | 56 | base::FilePath config_path; |
Vitaly Buka | ae96cc3 | 2015-06-09 17:22:18 -0700 | [diff] [blame] | 57 | }; |
Vitaly Buka | 7b6b3f0 | 2015-06-09 15:50:20 -0700 | [diff] [blame] | 58 | |
Vitaly Buka | ae96cc3 | 2015-06-09 17:22:18 -0700 | [diff] [blame] | 59 | Manager(); |
| 60 | ~Manager(); |
Vitaly Buka | 7b6b3f0 | 2015-06-09 15:50:20 -0700 | [diff] [blame] | 61 | |
Vitaly Buka | ae96cc3 | 2015-06-09 17:22:18 -0700 | [diff] [blame] | 62 | void Start(const Options& options, |
| 63 | const scoped_refptr<dbus::Bus>& bus, |
Vitaly Buka | 7ab89ff | 2015-06-09 22:11:40 -0700 | [diff] [blame] | 64 | buffet::DeviceRegistrationInfo* device, |
| 65 | buffet::CommandManager* command_manager, |
| 66 | buffet::StateManager* state_manager, |
Vitaly Buka | ae96cc3 | 2015-06-09 17:22:18 -0700 | [diff] [blame] | 67 | chromeos::dbus_utils::AsyncEventSequencer* sequencer); |
| 68 | |
| 69 | void OnShutdown(); |
Vitaly Buka | 7b6b3f0 | 2015-06-09 15:50:20 -0700 | [diff] [blame] | 70 | |
| 71 | void OnDeviceInfoChanged() override; |
| 72 | |
Vitaly Buka | ae96cc3 | 2015-06-09 17:22:18 -0700 | [diff] [blame] | 73 | privetd::WifiBootstrapManager* GetWifiBootstrapManager() { |
| 74 | return wifi_bootstrap_manager_.get(); |
| 75 | } |
| 76 | |
| 77 | privetd::SecurityManager* GetSecurityManager() { return security_.get(); } |
| 78 | |
Vitaly Buka | 7b6b3f0 | 2015-06-09 15:50:20 -0700 | [diff] [blame] | 79 | private: |
| 80 | void PrivetRequestHandler(std::unique_ptr<libwebserv::Request> request, |
| 81 | std::unique_ptr<libwebserv::Response> response); |
| 82 | |
| 83 | void PrivetResponseHandler(std::unique_ptr<libwebserv::Response> response, |
| 84 | int status, |
| 85 | const base::DictionaryValue& output); |
| 86 | |
| 87 | void HelloWorldHandler(std::unique_ptr<libwebserv::Request> request, |
| 88 | std::unique_ptr<libwebserv::Response> response); |
| 89 | |
| 90 | void OnChanged(); |
| 91 | |
| 92 | void OnConnectivityChanged(bool online); |
| 93 | |
| 94 | void OnProtocolHandlerConnected( |
| 95 | libwebserv::ProtocolHandler* protocol_handler); |
| 96 | |
| 97 | void OnProtocolHandlerDisconnected( |
| 98 | libwebserv::ProtocolHandler* protocol_handler); |
| 99 | |
Vitaly Buka | ae96cc3 | 2015-06-09 17:22:18 -0700 | [diff] [blame] | 100 | bool disable_security_{false}; |
Vitaly Buka | 7b6b3f0 | 2015-06-09 15:50:20 -0700 | [diff] [blame] | 101 | std::unique_ptr<CloudDelegate> cloud_; |
| 102 | std::unique_ptr<DeviceDelegate> device_; |
| 103 | std::unique_ptr<SecurityManager> security_; |
| 104 | std::unique_ptr<ShillClient> shill_client_; |
| 105 | std::unique_ptr<ApManagerClient> ap_manager_client_; |
| 106 | std::unique_ptr<WifiBootstrapManager> wifi_bootstrap_manager_; |
| 107 | std::unique_ptr<PeerdClient> peerd_client_; |
| 108 | std::unique_ptr<PrivetHandler> privet_handler_; |
| 109 | std::unique_ptr<libwebserv::Server> web_server_; |
| 110 | |
| 111 | ScopedObserver<CloudDelegate, CloudDelegate::Observer> cloud_observer_{this}; |
| 112 | |
| 113 | base::WeakPtrFactory<Manager> weak_ptr_factory_{this}; |
| 114 | DISALLOW_COPY_AND_ASSIGN(Manager); |
| 115 | }; |
| 116 | |
| 117 | } // namespace privetd |
| 118 | |
| 119 | #endif // BUFFET_PRIVET_PRIVET_MANAGER_H_ |