Add new component-based APIs to Device interface
This change just adds ComponentManager to DeviceManager and adds
new APIs that forward the calls to the component manager. The old
APIs are still intact and work with the old StateManager and Command
Manager.
BUG: 25916427, 25917240, 25917419, 25917523, 25917601
BUG: 25917650, 25917243, 25917525, 25917247
Change-Id: I88ce4bc6c447335e8b48ad5b1555eaa6331e447f
Reviewed-on: https://weave-review.googlesource.com/1782
Reviewed-by: Vitaly Buka <vitalybuka@google.com>
diff --git a/src/device_manager.cc b/src/device_manager.cc
index 52b2882..64a8093 100644
--- a/src/device_manager.cc
+++ b/src/device_manager.cc
@@ -10,6 +10,7 @@
#include "src/base_api_handler.h"
#include "src/commands/command_manager.h"
+#include "src/component_manager.h"
#include "src/config.h"
#include "src/device_registration_info.h"
#include "src/privet/privet_manager.h"
@@ -33,6 +34,7 @@
provider::HttpServer* http_server,
provider::Wifi* wifi,
provider::Bluetooth* bluetooth) {
+ component_manager_.reset(new ComponentManager);
command_manager_ = std::make_shared<CommandManager>();
state_change_queue_.reset(new StateChangeQueue(kMaxStateChangeQueueSize));
state_manager_ = std::make_shared<StateManager>(state_change_queue_.get());
@@ -89,6 +91,65 @@
device_info_->AddGcdStateChangedCallback(callback);
}
+void DeviceManager::AddTraitDefinitionsFromJson(const std::string& json) {
+ CHECK(component_manager_->LoadTraits(json, nullptr));
+}
+
+void DeviceManager::AddTraitDefinitions(const base::DictionaryValue& dict) {
+ CHECK(component_manager_->LoadTraits(dict, nullptr));
+}
+
+const base::DictionaryValue& DeviceManager::GetTraits() const {
+ return component_manager_->GetTraits();
+}
+
+bool DeviceManager::AddComponent(const std::string& name,
+ const std::vector<std::string>& traits,
+ ErrorPtr* error) {
+ return component_manager_->AddComponent("", name, traits, error);
+}
+
+void DeviceManager::AddComponentTreeChangedCallback(
+ const base::Closure& callback) {
+ component_manager_->AddComponentTreeChangedCallback(callback);
+}
+
+const base::DictionaryValue& DeviceManager::GetComponents() const {
+ return component_manager_->GetComponents();
+}
+
+bool DeviceManager::SetStatePropertiesFromJson(const std::string& component,
+ const std::string& json,
+ ErrorPtr* error) {
+ return component_manager_->SetStatePropertiesFromJson(component, json, error);
+}
+
+bool DeviceManager::SetStateProperties(const std::string& component,
+ const base::DictionaryValue& dict,
+ ErrorPtr* error) {
+ return component_manager_->SetStateProperties(component, dict, error);
+}
+
+const base::Value* DeviceManager::GetStateProperty(
+ const std::string& component,
+ const std::string& name,
+ ErrorPtr* error) const {
+ return component_manager_->GetStateProperty(component, name, error);
+}
+
+bool DeviceManager::SetStateProperty(const std::string& component,
+ const std::string& name,
+ const base::Value& value,
+ ErrorPtr* error) {
+ return component_manager_->SetStateProperty(component, name, value, error);
+}
+
+void DeviceManager::AddCommandHandler(const std::string& component,
+ const std::string& command_name,
+ const CommandHandlerCallback& callback) {
+ component_manager_->AddCommandHandler(component, command_name, callback);
+}
+
void DeviceManager::AddCommandDefinitionsFromJson(const std::string& json) {
CHECK(command_manager_->LoadCommands(json, nullptr));
}