privetd: Implement privet/v3/commands/execute

Privetd forwards JSON with command to buffet. Buffet updates command and
returns JSON representation of the command.

BUG=brillo:428
TEST=unittest

Change-Id: I7bdd4a70dd94e3dc3b4a974c7ac734e44564ac6e
Reviewed-on: https://chromium-review.googlesource.com/262216
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/buffet_client.cc b/buffet/buffet_client.cc
index 79e7cdf..355d39b 100644
--- a/buffet/buffet_client.cc
+++ b/buffet/buffet_client.cc
@@ -356,7 +356,8 @@
 
   void CallAddCommand(const std::string& command, ManagerProxy* manager_proxy) {
     ErrorPtr error;
-    if (!manager_proxy->AddCommand(command, &error)) {
+    std::string id;
+    if (!manager_proxy->AddCommand(command, &id, &error)) {
       return ReportError(error.get());
     }
     OnJobComplete();
diff --git a/buffet/dbus_bindings/org.chromium.Buffet.Manager.xml b/buffet/dbus_bindings/org.chromium.Buffet.Manager.xml
index 8b59b42..249700c 100644
--- a/buffet/dbus_bindings/org.chromium.Buffet.Manager.xml
+++ b/buffet/dbus_bindings/org.chromium.Buffet.Manager.xml
@@ -31,6 +31,7 @@
     </method>
     <method name="AddCommand">
       <arg name="json_command" type="s" direction="in"/>
+      <arg name="id" type="s" direction="out"/>
       <annotation name="org.chromium.DBus.Method.Kind" value="async"/>
     </method>
     <method name="GetCommand">
diff --git a/buffet/manager.cc b/buffet/manager.cc
index 01f73b1..e486d5a 100644
--- a/buffet/manager.cc
+++ b/buffet/manager.cc
@@ -165,7 +165,7 @@
   return true;
 }
 
-void Manager::AddCommand(DBusMethodResponse<> response,
+void Manager::AddCommand(DBusMethodResponse<std::string> response,
                          const std::string& json_command) {
   static int next_id = 0;
   std::string error_message;
@@ -184,9 +184,10 @@
     response->ReplyWithError(error.get());
     return;
   }
-  command_instance->SetID(std::to_string(++next_id));
+  std::string id = std::to_string(++next_id);
+  command_instance->SetID(id);
   command_manager_->AddCommand(std::move(command_instance));
-  response->Return();
+  response->Return(id);
 }
 
 void Manager::GetCommand(DBusMethodResponse<std::string> response,
diff --git a/buffet/manager.h b/buffet/manager.h
index d61c6fa..f44e075 100644
--- a/buffet/manager.h
+++ b/buffet/manager.h
@@ -68,7 +68,7 @@
   // Handles calls to org.chromium.Buffet.Manager.GetState().
   bool GetState(chromeos::ErrorPtr* error, std::string* state) override;
   // Handles calls to org.chromium.Buffet.Manager.AddCommand().
-  void AddCommand(DBusMethodResponse<> response,
+  void AddCommand(DBusMethodResponse<std::string> response,
                   const std::string& json_command) override;
   // Handles calls to org.chromium.Buffet.Manager.GetCommand().
   void GetCommand(DBusMethodResponse<std::string> response,