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