Add "component" property to command instance
When sending commands, we'll use "component" to route the command to
the target component it was designated for.
As a temporary stop-gap, use "device" as the component name before
we have full implementation of component/trait schema model.
Also removed CommandDictionary from CommandInstance::FromJson since
the validation will be done outside of JSON parsing code in the future
Component Manager class.
BUG: 25841719
Change-Id: I5c649c257fb48ecaaedc1ced84931009f94c2bb3
Reviewed-on: https://weave-review.googlesource.com/1764
Reviewed-by: Vitaly Buka <vitalybuka@google.com>
diff --git a/src/commands/command_instance.cc b/src/commands/command_instance.cc
index 1f2e4a2..702a819 100644
--- a/src/commands/command_instance.cc
+++ b/src/commands/command_instance.cc
@@ -74,6 +74,10 @@
return name_;
}
+const std::string& CommandInstance::GetComponent() const {
+ return component_;
+}
+
Command::State CommandInstance::GetState() const {
return state_;
}
@@ -169,7 +173,6 @@
std::unique_ptr<CommandInstance> CommandInstance::FromJson(
const base::Value* value,
Command::Origin origin,
- const CommandDictionary& dictionary,
std::string* command_id,
ErrorPtr* error) {
std::unique_ptr<CommandInstance> instance;
@@ -198,14 +201,6 @@
errors::commands::kPropertyMissing, "Command name is missing");
return instance;
}
- // Make sure we know how to handle the command with this name.
- auto command_def = dictionary.FindCommand(command_name);
- if (!command_def) {
- Error::AddToPrintf(error, FROM_HERE, errors::commands::kDomain,
- errors::commands::kInvalidCommandName,
- "Unknown command received: %s", command_name.c_str());
- return instance;
- }
auto parameters = GetCommandParameters(json, error);
if (!parameters) {
@@ -220,6 +215,11 @@
if (!command_id->empty())
instance->SetID(*command_id);
+ // Get the component name this command is for.
+ std::string component;
+ if (json->GetString(commands::attributes::kCommand_Component, &component))
+ instance->SetComponent(component);
+
return instance;
}