buffet: Support cloud command proxy.
This proxy allows publishing command updates to cloud API.
BUG=chromium:432540
TEST=cros_workon_make buffet --test&&manual
Change-Id: Id5730df60c3d40dfb7254d5f65c84dc51aea09eb
Reviewed-on: https://chromium-review.googlesource.com/228462
Reviewed-by: Anton Muhin <antonm@chromium.org>
Commit-Queue: Anton Muhin <antonm@chromium.org>
Tested-by: Anton Muhin <antonm@chromium.org>
diff --git a/buffet/commands/cloud_command_proxy.cc b/buffet/commands/cloud_command_proxy.cc
new file mode 100644
index 0000000..5cbf6e6
--- /dev/null
+++ b/buffet/commands/cloud_command_proxy.cc
@@ -0,0 +1,35 @@
+// Copyright 2014 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "buffet/commands/cloud_command_proxy.h"
+
+#include "buffet/commands/command_instance.h"
+#include "buffet/commands/prop_constraints.h"
+#include "buffet/commands/prop_types.h"
+#include "buffet/device_registration_info.h"
+
+namespace buffet {
+
+CloudCommandProxy::CloudCommandProxy(
+ CommandInstance* command_instance,
+ DeviceRegistrationInfo* device_registration_info)
+ : command_instance_(command_instance),
+ device_registration_info_(device_registration_info) {
+}
+
+void CloudCommandProxy::OnStatusChanged(const std::string& status) {
+ base::DictionaryValue patch;
+ // TODO(antonm): Change status to state.
+ patch.SetString("state", status);
+ device_registration_info_->UpdateCommand(command_instance_->GetID(), patch);
+}
+
+void CloudCommandProxy::OnProgressChanged(int progress) {
+ base::DictionaryValue patch;
+ patch.SetInteger("progress", progress);
+ // TODO(antonm): Consider batching progress change updates.
+ device_registration_info_->UpdateCommand(command_instance_->GetID(), patch);
+}
+
+} // namespace buffet