buffet: Moved D-Bus definitions to XML/Code generator

Moved D-Bus interface definitions for buffet to XML files and using
the code generator to produce adaptors/proxies. Switched over the
implementations of objects to using the generated adaptors and using
the generated proxies in buffet_client.

Some more work on proxy generator is required to switch over the
usage of Command/CommandListener in libbuffet to using the generated
proxies, since the generator does not support D-Bus properties or
Object Manager yet.

BUG=chromium:435591
TEST=FEATURES=test emerge-link buffet

Change-Id: If010ee70b356d146e4a35a7301a753c9c54377f5
Reviewed-on: https://chromium-review.googlesource.com/231350
Reviewed-by: Alex Vakulenko <avakulenko@chromium.org>
Commit-Queue: Alex Vakulenko <avakulenko@chromium.org>
Tested-by: Alex Vakulenko <avakulenko@chromium.org>
diff --git a/buffet/buffet_client.cc b/buffet/buffet_client.cc
index e32082d..72e3c88 100644
--- a/buffet/buffet_client.cc
+++ b/buffet/buffet_client.cc
@@ -23,6 +23,7 @@
 #include <dbus/object_manager.h>
 #include <dbus/values_util.h>
 
+#include "buffet/dbus-proxies.h"
 #include "buffet/libbuffet/dbus_constants.h"
 
 using namespace buffet::dbus_constants;  // NOLINT(build/namespaces)
@@ -57,13 +58,13 @@
     dbus::Bus::Options options;
     options.bus_type = dbus::Bus::SYSTEM;
     bus_ = new dbus::Bus(options);
-    manager_proxy_ = bus_->GetObjectProxy(
-        kServiceName,
-        dbus::ObjectPath(kManagerServicePath));
+    manager_proxy_.reset(
+      new org::chromium::Buffet::ManagerProxy{bus_, kServiceName,
+                                              kManagerServicePath});
     root_proxy_ = bus_->GetObjectProxy(
         kServiceName,
         dbus::ObjectPath(kRootServicePath));
-    return EX_OK;
+  return EX_OK;
   }
 
   int CallTestMethod(const CommandLine::StringVector& args) {
@@ -72,13 +73,8 @@
       message = args.front();
 
     ErrorPtr error;
-    auto response = CallMethodAndBlock(
-        manager_proxy_,
-        kManagerInterface, kManagerTestMethod, &error,
-        message);
     std::string response_message;
-    if (!response ||
-        !ExtractMethodCallResults(response.get(), &error, &response_message)) {
+    if (!manager_proxy_->TestMethod(message, &response_message, &error)) {
       std::cout << "Failed to receive a response:"
                 << error->GetMessage() << std::endl;
       return EX_UNAVAILABLE;
@@ -97,14 +93,12 @@
     }
 
     ErrorPtr error;
-    auto response = CallMethodAndBlock(
-        manager_proxy_,
-        kManagerInterface, kManagerStartDevice, &error);
-    if (!response || !ExtractMethodCallResults(response.get(), &error)) {
+    if (!manager_proxy_->StartDevice(&error)) {
       std::cout << "Failed to receive a response:"
                 << error->GetMessage() << std::endl;
       return EX_UNAVAILABLE;
     }
+
     return EX_OK;
   }
 
@@ -117,12 +111,8 @@
     }
 
     ErrorPtr error;
-    auto response = CallMethodAndBlock(
-        manager_proxy_,
-        kManagerInterface, kManagerCheckDeviceRegistered, &error);
     std::string device_id;
-    if (!response ||
-        !ExtractMethodCallResults(response.get(), &error, &device_id)) {
+    if (!manager_proxy_->CheckDeviceRegistered(&device_id, &error)) {
       std::cout << "Failed to receive a response:"
                 << error->GetMessage() << std::endl;
       return EX_UNAVAILABLE;
@@ -143,11 +133,8 @@
     }
 
     ErrorPtr error;
-    auto response = CallMethodAndBlock(
-        manager_proxy_, kManagerInterface, kManagerGetDeviceInfo, &error);
     std::string device_info;
-    if (!response ||
-        !ExtractMethodCallResults(response.get(), &error, &device_info)) {
+    if (!manager_proxy_->GetDeviceInfo(&device_info, &error)) {
       std::cout << "Failed to receive a response:"
                 << error->GetMessage() << std::endl;
       return EX_UNAVAILABLE;
@@ -176,15 +163,8 @@
     }
 
     ErrorPtr error;
-    static const int timeout_ms = 3000;
-    auto response = CallMethodAndBlockWithTimeout(
-        timeout_ms,
-        manager_proxy_,
-        kManagerInterface, kManagerRegisterDevice, &error,
-        params);
     std::string device_id;
-    if (!response ||
-        !ExtractMethodCallResults(response.get(), &error, &device_id)) {
+    if (!manager_proxy_->RegisterDevice(params, &device_id, &error)) {
       std::cout << "Failed to receive a response:"
                 << error->GetMessage() << std::endl;
       return EX_UNAVAILABLE;
@@ -204,11 +184,7 @@
 
     ErrorPtr error;
     VariantDictionary property_set{{args.front(), args.back()}};
-    auto response = CallMethodAndBlock(
-        manager_proxy_,
-        kManagerInterface, kManagerUpdateStateMethod, &error,
-        property_set);
-    if (!response || !ExtractMethodCallResults(response.get(), &error)) {
+    if (!manager_proxy_->UpdateState(property_set, &error)) {
       std::cout << "Failed to receive a response:"
                 << error->GetMessage() << std::endl;
       return EX_UNAVAILABLE;
@@ -225,11 +201,7 @@
     }
 
     ErrorPtr error;
-    auto response = CallMethodAndBlock(
-        manager_proxy_,
-        kManagerInterface, kManagerAddCommand, &error,
-        args.front());
-    if (!response || !ExtractMethodCallResults(response.get(), &error)) {
+    if (!manager_proxy_->AddCommand(args.front(), &error)) {
       std::cout << "Failed to receive a response:"
                 << error->GetMessage() << std::endl;
       return EX_UNAVAILABLE;
@@ -247,7 +219,7 @@
 
     ErrorPtr error;
     auto response = CallMethodAndBlock(
-        manager_proxy_,
+        root_proxy_,
         dbus::kObjectManagerInterface, dbus::kObjectManagerGetManagedObjects,
         &error);
     if (!response) {
@@ -261,7 +233,7 @@
 
  private:
   scoped_refptr<dbus::Bus> bus_;
-  dbus::ObjectProxy* manager_proxy_{nullptr};
+  std::unique_ptr<org::chromium::Buffet::ManagerProxy> manager_proxy_;
   dbus::ObjectProxy* root_proxy_{nullptr};
 };