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