privetd: Implement privet/v3/commands/status
Privetd just forwards IDs to the buffet and buffet returns JSON
representation of the command.
BUG=brillo:430
TEST=unittest
Change-Id: I5698f9fc915ae32dc2b9be3cc35f8efe919ee4e3
Reviewed-on: https://chromium-review.googlesource.com/261641
Reviewed-by: Alex Vakulenko <avakulenko@chromium.org>
Reviewed-by: Vitaly Buka <vitalybuka@chromium.org>
Commit-Queue: Vitaly Buka <vitalybuka@chromium.org>
Tested-by: Vitaly Buka <vitalybuka@chromium.org>
diff --git a/buffet/dbus_bindings/org.chromium.Buffet.Manager.xml b/buffet/dbus_bindings/org.chromium.Buffet.Manager.xml
index 8473fe2..8b59b42 100644
--- a/buffet/dbus_bindings/org.chromium.Buffet.Manager.xml
+++ b/buffet/dbus_bindings/org.chromium.Buffet.Manager.xml
@@ -33,6 +33,11 @@
<arg name="json_command" type="s" direction="in"/>
<annotation name="org.chromium.DBus.Method.Kind" value="async"/>
</method>
+ <method name="GetCommand">
+ <arg name="id" type="s" direction="in"/>
+ <arg name="json_command" type="s" direction="out"/>
+ <annotation name="org.chromium.DBus.Method.Kind" value="async"/>
+ </method>
<method name="TestMethod">
<arg name="message" type="s" direction="in"/>
<arg name="echoed_message" type="s" direction="out"/>
diff --git a/buffet/manager.cc b/buffet/manager.cc
index 6097b09..01f73b1 100644
--- a/buffet/manager.cc
+++ b/buffet/manager.cc
@@ -189,6 +189,19 @@
response->Return();
}
+void Manager::GetCommand(DBusMethodResponse<std::string> response,
+ const std::string& id) {
+ const CommandInstance* command = command_manager_->FindCommand(id);
+ if (!command) {
+ response->ReplyWithError(FROM_HERE, kErrorDomainGCD, "unknown_command",
+ "Can't find command with id: " + id);
+ return;
+ }
+ std::string command_str;
+ base::JSONWriter::Write(command->ToJson().get(), &command_str);
+ response->Return(command_str);
+}
+
std::string Manager::TestMethod(const std::string& message) {
LOG(INFO) << "Received call to test method: " << message;
return message;
diff --git a/buffet/manager.h b/buffet/manager.h
index d307ca2..d61c6fa 100644
--- a/buffet/manager.h
+++ b/buffet/manager.h
@@ -70,6 +70,9 @@
// Handles calls to org.chromium.Buffet.Manager.AddCommand().
void AddCommand(DBusMethodResponse<> response,
const std::string& json_command) override;
+ // Handles calls to org.chromium.Buffet.Manager.GetCommand().
+ void GetCommand(DBusMethodResponse<std::string> response,
+ const std::string& id) override;
// Handles calls to org.chromium.Buffet.Manager.Test()
std::string TestMethod(const std::string& message) override;