buffet: Add CommandInstance::ToJson
Method is needed to implement commands status requests from
privetd. Current implementation generates JSON on request.
BUG=brillo:430
TEST=unittest
Change-Id: Iee4a788792a33278c997ad535abe11f26fa7f422
Reviewed-on: https://chromium-review.googlesource.com/262215
Reviewed-by: Vitaly Buka <vitalybuka@chromium.org>
Tested-by: Vitaly Buka <vitalybuka@chromium.org>
Commit-Queue: Vitaly Buka <vitalybuka@chromium.org>
diff --git a/buffet/commands/cloud_command_proxy.cc b/buffet/commands/cloud_command_proxy.cc
index 8aa27ba..d3cd5a6 100644
--- a/buffet/commands/cloud_command_proxy.cc
+++ b/buffet/commands/cloud_command_proxy.cc
@@ -7,6 +7,7 @@
#include "buffet/commands/command_instance.h"
#include "buffet/commands/prop_constraints.h"
#include "buffet/commands/prop_types.h"
+#include "buffet/commands/schema_constants.h"
#include "buffet/device_registration_info.h"
namespace buffet {
@@ -20,20 +21,21 @@
void CloudCommandProxy::OnResultsChanged(const native_types::Object& results) {
base::DictionaryValue patch;
- patch.Set("results", TypedValueToJson(results, nullptr).get());
+ patch.Set(commands::attributes::kCommand_Results,
+ TypedValueToJson(results, nullptr).get());
device_registration_info_->UpdateCommand(command_instance_->GetID(), patch);
}
void CloudCommandProxy::OnStatusChanged(const std::string& status) {
base::DictionaryValue patch;
// TODO(antonm): Change status to state.
- patch.SetString("state", status);
+ patch.SetString(commands::attributes::kCommand_State, status);
device_registration_info_->UpdateCommand(command_instance_->GetID(), patch);
}
void CloudCommandProxy::OnProgressChanged(int progress) {
base::DictionaryValue patch;
- patch.SetInteger("progress", progress);
+ patch.SetInteger(commands::attributes::kCommand_Progress, progress);
// TODO(antonm): Consider batching progress change updates.
device_registration_info_->UpdateCommand(command_instance_->GetID(), patch);
}