Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 1 | // Copyright 2014 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CHROMEOS_DBUS_BINDINGS_PROXY_GENERATOR_H_ |
| 6 | #define CHROMEOS_DBUS_BINDINGS_PROXY_GENERATOR_H_ |
| 7 | |
| 8 | #include <string> |
| 9 | #include <vector> |
| 10 | |
| 11 | #include <base/macros.h> |
| 12 | |
| 13 | #include "chromeos-dbus-bindings/header_generator.h" |
| 14 | #include "chromeos-dbus-bindings/indented_text.h" |
| 15 | #include "chromeos-dbus-bindings/interface.h" |
| 16 | |
| 17 | namespace base { |
| 18 | |
| 19 | class FilePath; |
| 20 | |
| 21 | } // namespace base |
| 22 | |
| 23 | namespace chromeos_dbus_bindings { |
| 24 | |
| 25 | class IndentedText; |
| 26 | struct Interface; |
| 27 | |
| 28 | class ProxyGenerator : public HeaderGenerator { |
| 29 | public: |
Alex Vakulenko | 6ef2d73 | 2014-11-25 14:04:27 -0800 | [diff] [blame] | 30 | static bool GenerateProxies(const ServiceConfig& config, |
| 31 | const std::vector<Interface>& interfaces, |
Alex Vakulenko | c95f06b | 2014-11-20 15:06:09 -0800 | [diff] [blame] | 32 | const base::FilePath& output_file); |
Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 33 | |
Alex Vakulenko | 008e19d | 2015-01-21 10:37:00 -0800 | [diff] [blame] | 34 | static bool GenerateMocks(const ServiceConfig& config, |
| 35 | const std::vector<Interface>& interfaces, |
| 36 | const base::FilePath& mock_file, |
| 37 | const base::FilePath& proxy_file); |
| 38 | |
Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 39 | private: |
| 40 | friend class ProxyGeneratorTest; |
| 41 | |
Alex Vakulenko | 008e19d | 2015-01-21 10:37:00 -0800 | [diff] [blame] | 42 | // Generates an abstract interface for one D-Bus interface proxy. |
| 43 | static void GenerateInterfaceProxyInterface(const ServiceConfig& config, |
| 44 | const Interface& interface, |
| 45 | IndentedText* text); |
| 46 | |
Alex Vakulenko | c95f06b | 2014-11-20 15:06:09 -0800 | [diff] [blame] | 47 | // Generates one interface proxy. |
Alex Vakulenko | 6ef2d73 | 2014-11-25 14:04:27 -0800 | [diff] [blame] | 48 | static void GenerateInterfaceProxy(const ServiceConfig& config, |
| 49 | const Interface& interface, |
Alex Vakulenko | c95f06b | 2014-11-20 15:06:09 -0800 | [diff] [blame] | 50 | IndentedText* text); |
| 51 | |
Alex Vakulenko | 008e19d | 2015-01-21 10:37:00 -0800 | [diff] [blame] | 52 | // Generates one interface mock object. |
| 53 | static void GenerateInterfaceMock(const ServiceConfig& config, |
| 54 | const Interface& interface, |
| 55 | IndentedText* text); |
| 56 | |
Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 57 | // Generates the constructor and destructor for the proxy. |
Alex Vakulenko | 6ef2d73 | 2014-11-25 14:04:27 -0800 | [diff] [blame] | 58 | static void AddConstructor(const ServiceConfig& config, |
| 59 | const Interface& interface, |
Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 60 | const std::string& class_name, |
| 61 | IndentedText* text); |
| 62 | static void AddDestructor(const std::string& class_name, |
| 63 | IndentedText* text); |
| 64 | |
Alex Vakulenko | c95f06b | 2014-11-20 15:06:09 -0800 | [diff] [blame] | 65 | // Generates ReleaseObjectProxy() method to release ownership |
| 66 | // of the object proxy. |
| 67 | static void AddReleaseObjectProxy(IndentedText* text); |
Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 68 | |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 69 | // Generates AddGetObjectPath() method. |
| 70 | static void AddGetObjectPath(IndentedText* text); |
| 71 | |
| 72 | // Generates GetObjectProxy() method. |
| 73 | static void AddGetObjectProxy(IndentedText* text); |
| 74 | |
| 75 | // Generates SetPropertyChangedCallback/GetProperties() methods. |
| 76 | static void AddPropertyPublicMethods(const std::string& class_name, |
| 77 | IndentedText* text); |
| 78 | |
| 79 | // Generates OnPropertyChanged() method. |
| 80 | static void AddOnPropertyChanged(IndentedText* text); |
| 81 | |
Christopher Wiley | 824b524 | 2014-12-03 11:58:01 -0800 | [diff] [blame] | 82 | // Generates logic permitting users to register handlers for signals. |
| 83 | static void AddSignalHandlerRegistration(const Interface& interface, |
| 84 | IndentedText* text); |
Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 85 | |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 86 | // Generates the property set class to contain interface properties. |
| 87 | static void AddPropertySet(const ServiceConfig& config, |
| 88 | const Interface& interface, |
| 89 | IndentedText* text); |
| 90 | |
| 91 | // Generates the property accessors. |
| 92 | static void AddProperties(const ServiceConfig& config, |
| 93 | const Interface& interface, |
Alex Vakulenko | 008e19d | 2015-01-21 10:37:00 -0800 | [diff] [blame] | 94 | bool declaration_only, |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 95 | IndentedText* text); |
| 96 | |
Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 97 | // Generates a native C++ method which calls a D-Bus method on the proxy. |
| 98 | static void AddMethodProxy(const Interface::Method& interface, |
| 99 | const std::string& interface_name, |
Alex Vakulenko | 008e19d | 2015-01-21 10:37:00 -0800 | [diff] [blame] | 100 | bool declaration_only, |
Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 101 | IndentedText* text); |
| 102 | |
Alex Vakulenko | c4e32f5 | 2014-12-04 08:28:49 -0800 | [diff] [blame] | 103 | // Generates a native C++ method which calls a D-Bus method asynchronously. |
| 104 | static void AddAsyncMethodProxy(const Interface::Method& interface, |
| 105 | const std::string& interface_name, |
Alex Vakulenko | 008e19d | 2015-01-21 10:37:00 -0800 | [diff] [blame] | 106 | bool declaration_only, |
Alex Vakulenko | c4e32f5 | 2014-12-04 08:28:49 -0800 | [diff] [blame] | 107 | IndentedText* text); |
| 108 | |
Alex Vakulenko | 008e19d | 2015-01-21 10:37:00 -0800 | [diff] [blame] | 109 | // Generates a mock for blocking D-Bus method. |
| 110 | static void AddMethodMock(const Interface::Method& interface, |
| 111 | const std::string& interface_name, |
| 112 | IndentedText* text); |
| 113 | |
| 114 | // Generates a mock for asynchronous D-Bus method. |
| 115 | static void AddAsyncMethodMock(const Interface::Method& interface, |
| 116 | const std::string& interface_name, |
| 117 | IndentedText* text); |
| 118 | |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 119 | // Generates the Object Manager proxy class. |
| 120 | struct ObjectManager { |
| 121 | // Generates the top-level class for Object Manager proxy. |
| 122 | static void GenerateProxy(const ServiceConfig& config, |
| 123 | const std::vector<Interface>& interfaces, |
| 124 | IndentedText* text); |
| 125 | |
| 126 | // Generates Object Manager constructor. |
| 127 | static void AddConstructor(const ServiceConfig& config, |
| 128 | const std::string& class_name, |
| 129 | const std::vector<Interface>& interfaces, |
| 130 | IndentedText* text); |
| 131 | |
Christopher Wiley | e11e81c | 2014-12-19 13:10:52 -0800 | [diff] [blame] | 132 | // Generates Object Manager destructor. |
| 133 | static void AddDestructor(const std::string& class_name, |
| 134 | const std::vector<Interface>& interfaces, |
| 135 | IndentedText* text); |
| 136 | |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 137 | // Generates GetObjectManagerProxy() method. |
| 138 | static void AddGetObjectManagerProxy(IndentedText* text); |
| 139 | |
| 140 | // Generates code for interface-specific accessor methods |
| 141 | static void AddInterfaceAccessors(const Interface& interface, |
| 142 | IndentedText* text); |
| 143 | |
| 144 | // Generates OnPropertyChanged() method. |
| 145 | static void AddOnPropertyChanged(const std::vector<Interface>& interfaces, |
| 146 | IndentedText* text); |
| 147 | |
| 148 | // Generates ObjectAdded() method. |
Christopher Wiley | efe9df5 | 2015-03-12 16:02:22 -0700 | [diff] [blame] | 149 | static void AddObjectAdded(const ServiceConfig& config, |
| 150 | const std::vector<Interface>& interfaces, |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 151 | IndentedText* text); |
| 152 | |
| 153 | // Generates ObjectRemoved() method. |
| 154 | static void AddObjectRemoved(const std::vector<Interface>& interfaces, |
| 155 | IndentedText* text); |
| 156 | |
| 157 | // Generates CreateProperties() method. |
| 158 | static void AddCreateProperties(const std::vector<Interface>& interfaces, |
| 159 | const std::string& class_name, |
| 160 | IndentedText* text); |
| 161 | |
| 162 | // Generates data members of the class. |
Christopher Wiley | efe9df5 | 2015-03-12 16:02:22 -0700 | [diff] [blame] | 163 | static void AddDataMembers(const ServiceConfig& config, |
| 164 | const std::vector<Interface>& interfaces, |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 165 | const std::string& class_name, |
| 166 | IndentedText* text); |
| 167 | }; |
Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 168 | // Generates the signal handler name for a given signal name. |
| 169 | static std::string GetHandlerNameForSignal(const std::string& signal); |
| 170 | |
| 171 | DISALLOW_COPY_AND_ASSIGN(ProxyGenerator); |
| 172 | }; |
| 173 | |
| 174 | } // namespace chromeos_dbus_bindings |
| 175 | |
| 176 | #endif // CHROMEOS_DBUS_BINDINGS_PROXY_GENERATOR_H_ |