Add support for legacy state/commandDefs to ComponentManager
Added methods to convert legacy state/stateDefs/commandDefs to
the new trait definitions and components and functions to convert
the trait definitions/component tree back to old commandDefs and
state.
Change-Id: Ia03142c53d00bbc4f880389166982167e3c8b1e9
Reviewed-on: https://weave-review.googlesource.com/1787
Reviewed-by: Vitaly Buka <vitalybuka@google.com>
diff --git a/src/component_manager_impl.h b/src/component_manager_impl.h
index 4f15ecd..9778a93 100644
--- a/src/component_manager_impl.h
+++ b/src/component_manager_impl.h
@@ -147,6 +147,17 @@
// tree. No sub-components are searched.
std::string FindComponentWithTrait(const std::string& trait) const override;
+ // Support for legacy APIs. Setting command and state definitions.
+ // This translates into modifying a trait definition.
+ bool AddLegacyCommandDefinitions(const base::DictionaryValue& dict,
+ ErrorPtr* error) override;
+ bool AddLegacyStateDefinitions(const base::DictionaryValue& dict,
+ ErrorPtr* error) override;
+ // Returns device state for legacy APIs.
+ const base::DictionaryValue& GetLegacyState() const override;
+ // Returns command definitions for legacy APIs.
+ const base::DictionaryValue& GetLegacyCommandDefinitions() const override;
+
private:
// A helper method to find a JSON element of component at |path| to add new
// sub-components to.
@@ -155,6 +166,12 @@
base::DictionaryValue* FindMutableComponent(const std::string& path,
ErrorPtr* error);
+ // Legacy API support: Helper function to support state/command definitions.
+ // Adds the given trait to at least one component.
+ // Searches for available components and if none of them already supports this
+ // trait, it adds it to the first available component.
+ void AddTraitToLegacyComponent(const std::string& trait);
+
// Helper method to find a sub-component given a root node and a relative path
// from the root to the target component.
static const base::DictionaryValue* FindComponentAt(
@@ -178,6 +195,10 @@
// Callback list for state change queue event sinks.
base::CallbackList<void(UpdateID)> on_server_state_updated_;
+ // Legacy API support.
+ mutable base::DictionaryValue legacy_state_; // Device state.
+ mutable base::DictionaryValue legacy_command_defs_; // Command definitions.
+
DISALLOW_COPY_AND_ASSIGN(ComponentManagerImpl);
};