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_DEVICE_MANAGER_H_
6 #define LIBWEAVE_SRC_DEVICE_MANAGER_H_
7 
8 #include <base/memory/weak_ptr.h>
9 #include <weave/device.h>
10 
11 namespace weave {
12 
13 class AccessApiHandler;
14 class AccessBlackListManager;
15 class BaseApiHandler;
16 class Config;
17 class ComponentManager;
18 class DeviceRegistrationInfo;
19 
20 namespace privet {
21 class AuthManager;
22 class Manager;
23 }  // namespace privet
24 
25 class DeviceManager final : public Device {
26  public:
27   DeviceManager(provider::ConfigStore* config_store,
28                 provider::TaskRunner* task_runner,
29                 provider::HttpClient* http_client,
30                 provider::Network* network,
31                 provider::DnsServiceDiscovery* dns_sd,
32                 provider::HttpServer* http_server,
33                 provider::Wifi* wifi,
34                 provider::Bluetooth* bluetooth);
35   ~DeviceManager() override;
36 
37   // Device implementation.
38   const Settings& GetSettings() const override;
39   void AddSettingsChangedCallback(
40       const SettingsChangedCallback& callback) override;
41   void AddTraitDefinitionsFromJson(const std::string& json) override;
42   void AddTraitDefinitions(const base::DictionaryValue& dict) override;
43   const base::DictionaryValue& GetTraits() const override;
44   void AddTraitDefsChangedCallback(const base::Closure& callback) override;
45   bool AddComponent(const std::string& name,
46                     const std::vector<std::string>& traits,
47                     ErrorPtr* error) override;
48   bool RemoveComponent(const std::string& name, ErrorPtr* error) override;
49   void AddComponentTreeChangedCallback(const base::Closure& callback) override;
50   const base::DictionaryValue& GetComponents() const override;
51   bool SetStatePropertiesFromJson(const std::string& component,
52                                   const std::string& json,
53                                   ErrorPtr* error) override;
54   bool SetStateProperties(const std::string& component,
55                           const base::DictionaryValue& dict,
56                           ErrorPtr* error) override;
57   const base::Value* GetStateProperty(const std::string& component,
58                                       const std::string& name,
59                                       ErrorPtr* error) const override;
60   bool SetStateProperty(const std::string& component,
61                         const std::string& name,
62                         const base::Value& value,
63                         ErrorPtr* error) override;
64   void AddCommandHandler(const std::string& component,
65                          const std::string& command_name,
66                          const CommandHandlerCallback& callback) override;
67   bool AddCommand(const base::DictionaryValue& command,
68                   std::string* id,
69                   ErrorPtr* error) override;
70   Command* FindCommand(const std::string& id) override;
71   void AddStateChangedCallback(const base::Closure& callback) override;
72   void Register(const std::string& ticket_id,
73                 const DoneCallback& callback) override;
74   GcdState GetGcdState() const override;
75   void AddGcdStateChangedCallback(
76       const GcdStateChangedCallback& callback) override;
77   void AddPairingChangedCallbacks(
78       const PairingBeginCallback& begin_callback,
79       const PairingEndCallback& end_callback) override;
80 
81   void AddCommandDefinitionsFromJson(const std::string& json) override;
82   void AddCommandDefinitions(const base::DictionaryValue& dict) override;
83   void AddCommandHandler(const std::string& command_name,
84                          const CommandHandlerCallback& callback) override;
85   void AddStateDefinitionsFromJson(const std::string& json) override;
86   void AddStateDefinitions(const base::DictionaryValue& dict) override;
87   bool SetStatePropertiesFromJson(const std::string& json,
88                                   ErrorPtr* error) override;
89   bool SetStateProperties(const base::DictionaryValue& dict,
90                           ErrorPtr* error) override;
91   const base::Value* GetStateProperty(const std::string& name) const override;
92   bool SetStateProperty(const std::string& name,
93                         const base::Value& value,
94                         ErrorPtr* error) override;
95   const base::DictionaryValue& GetState() const override;
96 
97   Config* GetConfig();
98 
99  private:
100   void StartPrivet(provider::TaskRunner* task_runner,
101                    provider::Network* network,
102                    provider::DnsServiceDiscovery* dns_sd,
103                    provider::HttpServer* http_server,
104                    provider::Wifi* wifi,
105                    provider::Bluetooth* bluetooth);
106 
107   std::unique_ptr<Config> config_;
108   std::unique_ptr<privet::AuthManager> auth_manager_;
109   std::unique_ptr<ComponentManager> component_manager_;
110   std::unique_ptr<DeviceRegistrationInfo> device_info_;
111   std::unique_ptr<BaseApiHandler> base_api_handler_;
112   std::unique_ptr<AccessBlackListManager> black_list_manager_;
113   std::unique_ptr<AccessApiHandler> access_api_handler_;
114   std::unique_ptr<privet::Manager> privet_;
115 
116   base::WeakPtrFactory<DeviceManager> weak_ptr_factory_{this};
117   DISALLOW_COPY_AND_ASSIGN(DeviceManager);
118 };
119 
120 }  // namespace weave
121 
122 #endif  // LIBWEAVE_SRC_DEVICE_MANAGER_H_
123