chromeos-dbus-bindings: Use object path and service name in generated code

To eliminate unnecessary dependencies on string constants from D-Bus
service providers, allow generated proxies extract fixed object paths
from the 'name' attribute of <node> in the XML file (if available) and
be able to pass in additional the D-Bus service configuration parameters
(such as D-Bus service name) as input to the generator, so that the proxy
code knows these values too and the caller doesn't have to provide this
information.

With these changes the object path and/or service names become embedded
into the generated proxies and are no longer required to be provided as
parameters to the constructors. If there are multiple instances of D-Bus
objects with the same interface are available (or the object could
appear at different bus paths), the path cannot be embedded into
the proxy and must still be provided in the constructor of the generated
class.

The service config can now be provided in --service-config=... argument
to the generator which is expected to be a JSON file.
If the service name it is not specified, the generated proxy code will
require this parameter in the constructor call, as before.

Also updated other targets that use the proxy generator to follow the
new constructor syntax (buffet, peerd, privetd).

BUG=chromium:431737
TEST=FEATURES=test emerge-link chromeos-dbus-bindings peerd buffet privetd

Change-Id: I4bb8387a9b21b75e3508fa13d14b79fbe653c929
Reviewed-on: https://chromium-review.googlesource.com/231920
Reviewed-by: Christopher Wiley <wiley@chromium.org>
Reviewed-by: Vitaly Buka <vitalybuka@chromium.org>
Commit-Queue: Alex Vakulenko <avakulenko@chromium.org>
Tested-by: Alex Vakulenko <avakulenko@chromium.org>
diff --git a/buffet/buffet.gyp b/buffet/buffet.gyp
index 5072ba5..c928ec4 100644
--- a/buffet/buffet.gyp
+++ b/buffet/buffet.gyp
@@ -22,19 +22,15 @@
       'actions': [
         {
           'action_name': 'generate-buffet-proxies',
-          'inputs': [
+          'variables': {
+            'dbus_service_config': 'dbus_bindings/dbus-service-config.json',
+            'proxy_output_file': 'include/buffet/dbus-proxies.h'
+          },
+          'sources': [
             'dbus_bindings/org.chromium.Buffet.Command.xml',
             'dbus_bindings/org.chromium.Buffet.Manager.xml',
           ],
-          'outputs': [
-            '<(SHARED_INTERMEDIATE_DIR)/include/buffet/dbus-proxies.h',
-          ],
-          'action': [
-            '<!(which generate-chromeos-dbus-bindings)',
-            '>@(_inputs)',
-            '--proxy=>(_outputs)'
-          ],
-          'hard_dependency': 1,
+          'includes': ['../common-mk/generate-dbus-proxies.gypi'],
         },
       ],
       'includes': ['../common-mk/deps.gypi'],
@@ -44,6 +40,7 @@
       'type': 'static_library',
       'variables': {
         'dbus_adaptors_out_dir': 'include/buffet',
+        'dbus_service_config': 'dbus_bindings/dbus-service-config.json',
       },
       'sources': [
         'commands/command_definition.cc',
diff --git a/buffet/buffet_client.cc b/buffet/buffet_client.cc
index 72e3c88..3edbbc3 100644
--- a/buffet/buffet_client.cc
+++ b/buffet/buffet_client.cc
@@ -58,9 +58,7 @@
     dbus::Bus::Options options;
     options.bus_type = dbus::Bus::SYSTEM;
     bus_ = new dbus::Bus(options);
-    manager_proxy_.reset(
-      new org::chromium::Buffet::ManagerProxy{bus_, kServiceName,
-                                              kManagerServicePath});
+    manager_proxy_.reset(new org::chromium::Buffet::ManagerProxy{bus_});
     root_proxy_ = bus_->GetObjectProxy(
         kServiceName,
         dbus::ObjectPath(kRootServicePath));
diff --git a/buffet/dbus_bindings/dbus-service-config.json b/buffet/dbus_bindings/dbus-service-config.json
new file mode 100644
index 0000000..7b1ce6b
--- /dev/null
+++ b/buffet/dbus_bindings/dbus-service-config.json
@@ -0,0 +1,3 @@
+{
+  "service_name": "org.chromium.Buffet"
+}
\ No newline at end of file
diff --git a/buffet/dbus_bindings/org.chromium.Buffet.Command.xml b/buffet/dbus_bindings/org.chromium.Buffet.Command.xml
index 2f8ce2b..467be44 100644
--- a/buffet/dbus_bindings/org.chromium.Buffet.Command.xml
+++ b/buffet/dbus_bindings/org.chromium.Buffet.Command.xml
@@ -1,7 +1,6 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 
-<node name="/"
-      xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0">
+<node xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0">
   <interface name="org.chromium.Buffet.Command">
     <method name="SetProgress">
       <arg name="progress" type="i" direction="in"/>
diff --git a/buffet/manager.cc b/buffet/manager.cc
index 35010d4..0a0f5fb 100644
--- a/buffet/manager.cc
+++ b/buffet/manager.cc
@@ -38,7 +38,7 @@
 Manager::Manager(const base::WeakPtr<ExportedObjectManager>& object_manager)
     : dbus_object_(object_manager.get(),
                    object_manager->GetBus(),
-                   dbus::ObjectPath(dbus_constants::kManagerServicePath)) {}
+                   org::chromium::Buffet::ManagerAdaptor::GetObjectPath()) {}
 
 Manager::~Manager() {}