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, |
Christopher Wiley | a30e09d | 2015-08-03 19:37:03 -0700 | [diff] [blame] | 37 | const base::FilePath& proxy_file, |
| 38 | bool use_literal_proxy_file); |
Alex Vakulenko | 008e19d | 2015-01-21 10:37:00 -0800 | [diff] [blame] | 39 | |
Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 40 | private: |
| 41 | friend class ProxyGeneratorTest; |
| 42 | |
Alex Vakulenko | 008e19d | 2015-01-21 10:37:00 -0800 | [diff] [blame] | 43 | // Generates an abstract interface for one D-Bus interface proxy. |
| 44 | static void GenerateInterfaceProxyInterface(const ServiceConfig& config, |
| 45 | const Interface& interface, |
| 46 | IndentedText* text); |
| 47 | |
Alex Vakulenko | c95f06b | 2014-11-20 15:06:09 -0800 | [diff] [blame] | 48 | // Generates one interface proxy. |
Alex Vakulenko | 6ef2d73 | 2014-11-25 14:04:27 -0800 | [diff] [blame] | 49 | static void GenerateInterfaceProxy(const ServiceConfig& config, |
| 50 | const Interface& interface, |
Alex Vakulenko | c95f06b | 2014-11-20 15:06:09 -0800 | [diff] [blame] | 51 | IndentedText* text); |
| 52 | |
Alex Vakulenko | 008e19d | 2015-01-21 10:37:00 -0800 | [diff] [blame] | 53 | // Generates one interface mock object. |
| 54 | static void GenerateInterfaceMock(const ServiceConfig& config, |
| 55 | const Interface& interface, |
| 56 | IndentedText* text); |
| 57 | |
Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 58 | // Generates the constructor and destructor for the proxy. |
Alex Vakulenko | 6ef2d73 | 2014-11-25 14:04:27 -0800 | [diff] [blame] | 59 | static void AddConstructor(const ServiceConfig& config, |
| 60 | const Interface& interface, |
Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 61 | const std::string& class_name, |
| 62 | IndentedText* text); |
| 63 | static void AddDestructor(const std::string& class_name, |
| 64 | IndentedText* text); |
| 65 | |
Alex Vakulenko | c95f06b | 2014-11-20 15:06:09 -0800 | [diff] [blame] | 66 | // Generates ReleaseObjectProxy() method to release ownership |
| 67 | // of the object proxy. |
| 68 | static void AddReleaseObjectProxy(IndentedText* text); |
Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 69 | |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 70 | // Generates AddGetObjectPath() method. |
| 71 | static void AddGetObjectPath(IndentedText* text); |
| 72 | |
| 73 | // Generates GetObjectProxy() method. |
| 74 | static void AddGetObjectProxy(IndentedText* text); |
| 75 | |
| 76 | // Generates SetPropertyChangedCallback/GetProperties() methods. |
| 77 | static void AddPropertyPublicMethods(const std::string& class_name, |
Alex Vakulenko | daea81b | 2015-12-10 10:49:40 -0800 | [diff] [blame^] | 78 | bool declaration_only, |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 79 | IndentedText* text); |
| 80 | |
| 81 | // Generates OnPropertyChanged() method. |
| 82 | static void AddOnPropertyChanged(IndentedText* text); |
| 83 | |
Christopher Wiley | 824b524 | 2014-12-03 11:58:01 -0800 | [diff] [blame] | 84 | // Generates logic permitting users to register handlers for signals. |
Alex Deymo | ce286b9 | 2015-07-28 15:04:07 -0700 | [diff] [blame] | 85 | static void AddSignalHandlerRegistration(const Interface::Signal& signal, |
| 86 | const std::string& interface_name, |
| 87 | bool declaration_only, |
Christopher Wiley | 824b524 | 2014-12-03 11:58:01 -0800 | [diff] [blame] | 88 | IndentedText* text); |
Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 89 | |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 90 | // Generates the property set class to contain interface properties. |
| 91 | static void AddPropertySet(const ServiceConfig& config, |
| 92 | const Interface& interface, |
| 93 | IndentedText* text); |
| 94 | |
| 95 | // Generates the property accessors. |
| 96 | static void AddProperties(const ServiceConfig& config, |
| 97 | const Interface& interface, |
Alex Vakulenko | 008e19d | 2015-01-21 10:37:00 -0800 | [diff] [blame] | 98 | bool declaration_only, |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 99 | IndentedText* text); |
| 100 | |
Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 101 | // Generates a native C++ method which calls a D-Bus method on the proxy. |
| 102 | static void AddMethodProxy(const Interface::Method& interface, |
| 103 | const std::string& interface_name, |
Alex Vakulenko | 008e19d | 2015-01-21 10:37:00 -0800 | [diff] [blame] | 104 | bool declaration_only, |
Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 105 | IndentedText* text); |
| 106 | |
Alex Vakulenko | c4e32f5 | 2014-12-04 08:28:49 -0800 | [diff] [blame] | 107 | // Generates a native C++ method which calls a D-Bus method asynchronously. |
| 108 | static void AddAsyncMethodProxy(const Interface::Method& interface, |
| 109 | const std::string& interface_name, |
Alex Vakulenko | 008e19d | 2015-01-21 10:37:00 -0800 | [diff] [blame] | 110 | bool declaration_only, |
Alex Vakulenko | c4e32f5 | 2014-12-04 08:28:49 -0800 | [diff] [blame] | 111 | IndentedText* text); |
| 112 | |
Alex Vakulenko | 008e19d | 2015-01-21 10:37:00 -0800 | [diff] [blame] | 113 | // Generates a mock for blocking D-Bus method. |
| 114 | static void AddMethodMock(const Interface::Method& interface, |
| 115 | const std::string& interface_name, |
| 116 | IndentedText* text); |
| 117 | |
| 118 | // Generates a mock for asynchronous D-Bus method. |
| 119 | static void AddAsyncMethodMock(const Interface::Method& interface, |
| 120 | const std::string& interface_name, |
| 121 | IndentedText* text); |
| 122 | |
Alex Deymo | 464405e | 2015-07-30 11:21:51 -0700 | [diff] [blame] | 123 | // Generates the MOCK_METHOD entry for the given arguments handling methods |
| 124 | // with more than 10 arguments. |
| 125 | static void AddMockMethodDeclaration( |
| 126 | const std::string& method_name, |
| 127 | const std::string& return_type, |
| 128 | const std::vector<std::string>& arguments, |
| 129 | IndentedText* text); |
| 130 | |
Alex Deymo | ce286b9 | 2015-07-28 15:04:07 -0700 | [diff] [blame] | 131 | // Generates a mock for the signal handler registration method. |
| 132 | static void AddSignalHandlerRegistrationMock( |
| 133 | const Interface::Signal& signal, |
| 134 | IndentedText* text); |
| 135 | |
| 136 | // Generate the signal callback argument of a signal handler. |
| 137 | static void AddSignalCallbackArg(const Interface::Signal& signal, |
| 138 | bool comment_arg_name, |
| 139 | IndentedText* block); |
| 140 | |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 141 | // Generates the Object Manager proxy class. |
| 142 | struct ObjectManager { |
| 143 | // Generates the top-level class for Object Manager proxy. |
| 144 | static void GenerateProxy(const ServiceConfig& config, |
| 145 | const std::vector<Interface>& interfaces, |
| 146 | IndentedText* text); |
| 147 | |
| 148 | // Generates Object Manager constructor. |
| 149 | static void AddConstructor(const ServiceConfig& config, |
| 150 | const std::string& class_name, |
| 151 | const std::vector<Interface>& interfaces, |
| 152 | IndentedText* text); |
| 153 | |
Christopher Wiley | e11e81c | 2014-12-19 13:10:52 -0800 | [diff] [blame] | 154 | // Generates Object Manager destructor. |
| 155 | static void AddDestructor(const std::string& class_name, |
| 156 | const std::vector<Interface>& interfaces, |
| 157 | IndentedText* text); |
| 158 | |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 159 | // Generates GetObjectManagerProxy() method. |
| 160 | static void AddGetObjectManagerProxy(IndentedText* text); |
| 161 | |
| 162 | // Generates code for interface-specific accessor methods |
| 163 | static void AddInterfaceAccessors(const Interface& interface, |
| 164 | IndentedText* text); |
| 165 | |
| 166 | // Generates OnPropertyChanged() method. |
| 167 | static void AddOnPropertyChanged(const std::vector<Interface>& interfaces, |
| 168 | IndentedText* text); |
| 169 | |
| 170 | // Generates ObjectAdded() method. |
Christopher Wiley | efe9df5 | 2015-03-12 16:02:22 -0700 | [diff] [blame] | 171 | static void AddObjectAdded(const ServiceConfig& config, |
| 172 | const std::vector<Interface>& interfaces, |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 173 | IndentedText* text); |
| 174 | |
| 175 | // Generates ObjectRemoved() method. |
| 176 | static void AddObjectRemoved(const std::vector<Interface>& interfaces, |
| 177 | IndentedText* text); |
| 178 | |
| 179 | // Generates CreateProperties() method. |
| 180 | static void AddCreateProperties(const std::vector<Interface>& interfaces, |
| 181 | const std::string& class_name, |
| 182 | IndentedText* text); |
| 183 | |
| 184 | // Generates data members of the class. |
Christopher Wiley | efe9df5 | 2015-03-12 16:02:22 -0700 | [diff] [blame] | 185 | static void AddDataMembers(const ServiceConfig& config, |
| 186 | const std::vector<Interface>& interfaces, |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 187 | const std::string& class_name, |
| 188 | IndentedText* text); |
| 189 | }; |
Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 190 | // Generates the signal handler name for a given signal name. |
| 191 | static std::string GetHandlerNameForSignal(const std::string& signal); |
| 192 | |
| 193 | DISALLOW_COPY_AND_ASSIGN(ProxyGenerator); |
| 194 | }; |
| 195 | |
| 196 | } // namespace chromeos_dbus_bindings |
| 197 | |
| 198 | #endif // CHROMEOS_DBUS_BINDINGS_PROXY_GENERATOR_H_ |