chromeos-dbus-bindings: Create proxy generator
Consolidate common functions to a parent HeaderGenerator class,
and create a new ProxyGenerator class. This new class converts
from native C++ method calls to D-Bus method invocations. It
also takes an interface class (populated with default null
implementations) for all signals supported by the interface.
CQ-DEPEND=CL:221015
BUG=chromium:404505
TEST=New unit test
Change-Id: Id6ed1f6f6e0868f32911a96e23e3dc74c9df0212
Reviewed-on: https://chromium-review.googlesource.com/221365
Reviewed-by: Alex Vakulenko <avakulenko@chromium.org>
Commit-Queue: Paul Stewart <pstew@chromium.org>
Tested-by: Paul Stewart <pstew@chromium.org>
diff --git a/chromeos-dbus-bindings/proxy_generator.h b/chromeos-dbus-bindings/proxy_generator.h
new file mode 100644
index 0000000..66dd8ba
--- /dev/null
+++ b/chromeos-dbus-bindings/proxy_generator.h
@@ -0,0 +1,63 @@
+// Copyright 2014 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROMEOS_DBUS_BINDINGS_PROXY_GENERATOR_H_
+#define CHROMEOS_DBUS_BINDINGS_PROXY_GENERATOR_H_
+
+#include <string>
+#include <vector>
+
+#include <base/macros.h>
+
+#include "chromeos-dbus-bindings/header_generator.h"
+#include "chromeos-dbus-bindings/indented_text.h"
+#include "chromeos-dbus-bindings/interface.h"
+
+namespace base {
+
+class FilePath;
+
+} // namespace base
+
+namespace chromeos_dbus_bindings {
+
+class IndentedText;
+struct Interface;
+
+class ProxyGenerator : public HeaderGenerator {
+ public:
+ static bool GenerateProxy(const Interface& interface,
+ const base::FilePath& output_file);
+
+ private:
+ friend class ProxyGeneratorTest;
+
+ // Generates the constructor and destructor for the proxy.
+ static void AddConstructor(const Interface& interface,
+ const std::string& class_name,
+ IndentedText* text);
+ static void AddDestructor(const std::string& class_name,
+ IndentedText* text);
+
+ // Generates a callback for signal receiver registration completion.
+ static void AddSignalConnectedCallback(IndentedText *text);
+
+ // Generates the method signatures for signal receivers.
+ static void AddMethodInterface(const Interface& interface,
+ IndentedText* text);
+
+ // Generates a native C++ method which calls a D-Bus method on the proxy.
+ static void AddMethodProxy(const Interface::Method& interface,
+ const std::string& interface_name,
+ IndentedText* text);
+
+ // Generates the signal handler name for a given signal name.
+ static std::string GetHandlerNameForSignal(const std::string& signal);
+
+ DISALLOW_COPY_AND_ASSIGN(ProxyGenerator);
+};
+
+} // namespace chromeos_dbus_bindings
+
+#endif // CHROMEOS_DBUS_BINDINGS_PROXY_GENERATOR_H_