aboutsummaryrefslogtreecommitdiff
path: root/src/device_manager.h
blob: d40ba8e897f8a6b47618f29ea46b5a93eb8eda1e (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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// 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_DEVICE_MANAGER_H_
#define LIBWEAVE_SRC_DEVICE_MANAGER_H_

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

namespace weave {

class BaseApiHandler;
class Config;
class ComponentManager;
class DeviceRegistrationInfo;

namespace privet {
class AuthManager;
class Manager;
}  // namespace privet

class DeviceManager final : public Device {
 public:
  DeviceManager(provider::ConfigStore* config_store,
                provider::TaskRunner* task_runner,
                provider::HttpClient* http_client,
                provider::Network* network,
                provider::DnsServiceDiscovery* dns_sd,
                provider::HttpServer* http_server,
                provider::Wifi* wifi,
                provider::Bluetooth* bluetooth);
  ~DeviceManager() override;

  // Device implementation.
  const Settings& GetSettings() const override;
  void AddSettingsChangedCallback(
      const SettingsChangedCallback& callback) override;
  void AddTraitDefinitionsFromJson(const std::string& json) override;
  void AddTraitDefinitions(const base::DictionaryValue& dict) override;
  const base::DictionaryValue& GetTraits() const override;
  void AddTraitDefsChangedCallback(const base::Closure& callback) override;
  bool AddComponent(const std::string& name,
                    const std::vector<std::string>& traits,
                    ErrorPtr* error) override;
  bool RemoveComponent(const std::string& name, ErrorPtr* error) override;
  void AddComponentTreeChangedCallback(const base::Closure& callback) override;
  const base::DictionaryValue& GetComponents() const override;
  bool SetStatePropertiesFromJson(const std::string& component,
                                  const std::string& json,
                                  ErrorPtr* error) override;
  bool SetStateProperties(const std::string& component,
                          const base::DictionaryValue& dict,
                          ErrorPtr* error) override;
  const base::Value* GetStateProperty(const std::string& component,
                                      const std::string& name,
                                      ErrorPtr* error) const override;
  bool SetStateProperty(const std::string& component,
                        const std::string& name,
                        const base::Value& value,
                        ErrorPtr* error) override;
  void AddCommandHandler(const std::string& component,
                         const std::string& command_name,
                         const CommandHandlerCallback& callback) override;
  bool AddCommand(const base::DictionaryValue& command,
                  std::string* id,
                  ErrorPtr* error) override;
  Command* FindCommand(const std::string& id) override;
  void AddStateChangedCallback(const base::Closure& callback) override;
  void Register(const std::string& ticket_id,
                const DoneCallback& callback) override;
  GcdState GetGcdState() const override;
  void AddGcdStateChangedCallback(
      const GcdStateChangedCallback& callback) override;
  void AddPairingChangedCallbacks(
      const PairingBeginCallback& begin_callback,
      const PairingEndCallback& end_callback) override;

  void AddCommandDefinitionsFromJson(const std::string& json) override;
  void AddCommandDefinitions(const base::DictionaryValue& dict) override;
  void AddCommandHandler(const std::string& command_name,
                         const CommandHandlerCallback& callback) override;
  void AddStateDefinitionsFromJson(const std::string& json) override;
  void AddStateDefinitions(const base::DictionaryValue& dict) override;
  bool SetStatePropertiesFromJson(const std::string& json,
                                  ErrorPtr* error) override;
  bool SetStateProperties(const base::DictionaryValue& dict,
                          ErrorPtr* error) override;
  const base::Value* GetStateProperty(const std::string& name) const override;
  bool SetStateProperty(const std::string& name,
                        const base::Value& value,
                        ErrorPtr* error) override;
  const base::DictionaryValue& GetState() const override;

  Config* GetConfig();

 private:
  void StartPrivet(provider::TaskRunner* task_runner,
                   provider::Network* network,
                   provider::DnsServiceDiscovery* dns_sd,
                   provider::HttpServer* http_server,
                   provider::Wifi* wifi,
                   provider::Bluetooth* bluetooth);

  std::unique_ptr<Config> config_;
  std::unique_ptr<privet::AuthManager> auth_manager_;
  std::unique_ptr<ComponentManager> component_manager_;
  std::unique_ptr<DeviceRegistrationInfo> device_info_;
  std::unique_ptr<BaseApiHandler> base_api_handler_;
  std::unique_ptr<privet::Manager> privet_;

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

}  // namespace weave

#endif  // LIBWEAVE_SRC_DEVICE_MANAGER_H_