buffet: Use command schema to define "progress"
According to the GCD specification command progress is dictionary,
defined same way as parameters and results.
Mapping between "done" and "progress" dictionary is not obvious, so patch
removes updates of progress from CommandInstance::Done().
BUG=brillo:915
TEST=FEATURES=test emerge-gizmo buffet
Change-Id: If6f6d52dbc0595a8f1cf0cf949a741675c9e5f3c
Reviewed-on: https://chromium-review.googlesource.com/268352
Reviewed-by: Alex Vakulenko <avakulenko@chromium.org>
Commit-Queue: Vitaly Buka <vitalybuka@chromium.org>
Tested-by: Vitaly Buka <vitalybuka@chromium.org>
diff --git a/buffet/commands/dbus_command_proxy.cc b/buffet/commands/dbus_command_proxy.cc
index 33f197d..74278fe 100644
--- a/buffet/commands/dbus_command_proxy.cc
+++ b/buffet/commands/dbus_command_proxy.cc
@@ -35,7 +35,8 @@
dbus_adaptor_.SetCategory(command_instance_->GetCategory());
dbus_adaptor_.SetId(command_instance_->GetID());
dbus_adaptor_.SetStatus(command_instance_->GetStatus());
- dbus_adaptor_.SetProgress(command_instance_->GetProgress());
+ dbus_adaptor_.SetProgress(
+ ObjectToDBusVariant(command_instance_->GetProgress()));
dbus_adaptor_.SetOrigin(command_instance_->GetOrigin());
dbus_adaptor_.SetParameters(ObjectToDBusVariant(
@@ -57,22 +58,23 @@
}
void DBusCommandProxy::OnProgressChanged() {
- dbus_adaptor_.SetProgress(command_instance_->GetProgress());
+ dbus_adaptor_.SetProgress(
+ ObjectToDBusVariant(command_instance_->GetProgress()));
}
-bool DBusCommandProxy::SetProgress(chromeos::ErrorPtr* error,
- int32_t progress) {
- LOG(INFO) << "Received call to Command<"
- << command_instance_->GetName() << ">::SetProgress("
- << progress << ")";
+bool DBusCommandProxy::SetProgress(
+ chromeos::ErrorPtr* error,
+ const chromeos::VariantDictionary& progress) {
+ LOG(INFO) << "Received call to Command<" << command_instance_->GetName()
+ << ">::SetProgress()";
- // Validate |progress| parameter. Its value must be between 0 and 100.
- IntPropType progress_type;
- progress_type.AddMinMaxConstraint(0, 100);
- if (!progress_type.ValidateValue(progress, error))
+ auto progress_schema =
+ command_instance_->GetCommandDefinition()->GetProgress();
+ native_types::Object obj;
+ if (!ObjectFromDBusVariant(progress_schema, progress, &obj, error))
return false;
- command_instance_->SetProgress(progress);
+ command_instance_->SetProgress(obj);
return true;
}