blob: 56fce06f067edefc1e8c294914b06083f58804e6 [file] [log] [blame]
Paul Stewart1dce1ae2014-10-01 05:30:18 -07001// 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
17namespace base {
18
19class FilePath;
20
21} // namespace base
22
23namespace chromeos_dbus_bindings {
24
25class IndentedText;
26struct Interface;
27
28class ProxyGenerator : public HeaderGenerator {
29 public:
Alex Vakulenko6ef2d732014-11-25 14:04:27 -080030 static bool GenerateProxies(const ServiceConfig& config,
31 const std::vector<Interface>& interfaces,
Alex Vakulenkoc95f06b2014-11-20 15:06:09 -080032 const base::FilePath& output_file);
Paul Stewart1dce1ae2014-10-01 05:30:18 -070033
Alex Vakulenko008e19d2015-01-21 10:37:00 -080034 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 Stewart1dce1ae2014-10-01 05:30:18 -070039 private:
40 friend class ProxyGeneratorTest;
41
Alex Vakulenko008e19d2015-01-21 10:37:00 -080042 // 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 Vakulenkoc95f06b2014-11-20 15:06:09 -080047 // Generates one interface proxy.
Alex Vakulenko6ef2d732014-11-25 14:04:27 -080048 static void GenerateInterfaceProxy(const ServiceConfig& config,
49 const Interface& interface,
Alex Vakulenkoc95f06b2014-11-20 15:06:09 -080050 IndentedText* text);
51
Alex Vakulenko008e19d2015-01-21 10:37:00 -080052 // Generates one interface mock object.
53 static void GenerateInterfaceMock(const ServiceConfig& config,
54 const Interface& interface,
55 IndentedText* text);
56
Paul Stewart1dce1ae2014-10-01 05:30:18 -070057 // Generates the constructor and destructor for the proxy.
Alex Vakulenko6ef2d732014-11-25 14:04:27 -080058 static void AddConstructor(const ServiceConfig& config,
59 const Interface& interface,
Paul Stewart1dce1ae2014-10-01 05:30:18 -070060 const std::string& class_name,
61 IndentedText* text);
62 static void AddDestructor(const std::string& class_name,
63 IndentedText* text);
64
Alex Vakulenkoc95f06b2014-11-20 15:06:09 -080065 // Generates ReleaseObjectProxy() method to release ownership
66 // of the object proxy.
67 static void AddReleaseObjectProxy(IndentedText* text);
Paul Stewart1dce1ae2014-10-01 05:30:18 -070068
Alex Vakulenko99e8fb02014-12-01 17:22:03 -080069 // 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 Wiley824b5242014-12-03 11:58:01 -080082 // Generates logic permitting users to register handlers for signals.
Alex Deymoce286b92015-07-28 15:04:07 -070083 static void AddSignalHandlerRegistration(const Interface::Signal& signal,
84 const std::string& interface_name,
85 bool declaration_only,
Christopher Wiley824b5242014-12-03 11:58:01 -080086 IndentedText* text);
Paul Stewart1dce1ae2014-10-01 05:30:18 -070087
Alex Vakulenko99e8fb02014-12-01 17:22:03 -080088 // 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 Vakulenko008e19d2015-01-21 10:37:00 -080096 bool declaration_only,
Alex Vakulenko99e8fb02014-12-01 17:22:03 -080097 IndentedText* text);
98
Paul Stewart1dce1ae2014-10-01 05:30:18 -070099 // 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 Vakulenko008e19d2015-01-21 10:37:00 -0800102 bool declaration_only,
Paul Stewart1dce1ae2014-10-01 05:30:18 -0700103 IndentedText* text);
104
Alex Vakulenkoc4e32f52014-12-04 08:28:49 -0800105 // 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 Vakulenko008e19d2015-01-21 10:37:00 -0800108 bool declaration_only,
Alex Vakulenkoc4e32f52014-12-04 08:28:49 -0800109 IndentedText* text);
110
Alex Vakulenko008e19d2015-01-21 10:37:00 -0800111 // 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 Deymo464405e2015-07-30 11:21:51 -0700121 // Generates the MOCK_METHOD entry for the given arguments handling methods
122 // with more than 10 arguments.
123 static void AddMockMethodDeclaration(
124 const std::string& method_name,
125 const std::string& return_type,
126 const std::vector<std::string>& arguments,
127 IndentedText* text);
128
Alex Deymoce286b92015-07-28 15:04:07 -0700129 // Generates a mock for the signal handler registration method.
130 static void AddSignalHandlerRegistrationMock(
131 const Interface::Signal& signal,
132 IndentedText* text);
133
134 // Generate the signal callback argument of a signal handler.
135 static void AddSignalCallbackArg(const Interface::Signal& signal,
136 bool comment_arg_name,
137 IndentedText* block);
138
Alex Vakulenko99e8fb02014-12-01 17:22:03 -0800139 // Generates the Object Manager proxy class.
140 struct ObjectManager {
141 // Generates the top-level class for Object Manager proxy.
142 static void GenerateProxy(const ServiceConfig& config,
143 const std::vector<Interface>& interfaces,
144 IndentedText* text);
145
146 // Generates Object Manager constructor.
147 static void AddConstructor(const ServiceConfig& config,
148 const std::string& class_name,
149 const std::vector<Interface>& interfaces,
150 IndentedText* text);
151
Christopher Wileye11e81c2014-12-19 13:10:52 -0800152 // Generates Object Manager destructor.
153 static void AddDestructor(const std::string& class_name,
154 const std::vector<Interface>& interfaces,
155 IndentedText* text);
156
Alex Vakulenko99e8fb02014-12-01 17:22:03 -0800157 // Generates GetObjectManagerProxy() method.
158 static void AddGetObjectManagerProxy(IndentedText* text);
159
160 // Generates code for interface-specific accessor methods
161 static void AddInterfaceAccessors(const Interface& interface,
162 IndentedText* text);
163
164 // Generates OnPropertyChanged() method.
165 static void AddOnPropertyChanged(const std::vector<Interface>& interfaces,
166 IndentedText* text);
167
168 // Generates ObjectAdded() method.
Christopher Wileyefe9df52015-03-12 16:02:22 -0700169 static void AddObjectAdded(const ServiceConfig& config,
170 const std::vector<Interface>& interfaces,
Alex Vakulenko99e8fb02014-12-01 17:22:03 -0800171 IndentedText* text);
172
173 // Generates ObjectRemoved() method.
174 static void AddObjectRemoved(const std::vector<Interface>& interfaces,
175 IndentedText* text);
176
177 // Generates CreateProperties() method.
178 static void AddCreateProperties(const std::vector<Interface>& interfaces,
179 const std::string& class_name,
180 IndentedText* text);
181
182 // Generates data members of the class.
Christopher Wileyefe9df52015-03-12 16:02:22 -0700183 static void AddDataMembers(const ServiceConfig& config,
184 const std::vector<Interface>& interfaces,
Alex Vakulenko99e8fb02014-12-01 17:22:03 -0800185 const std::string& class_name,
186 IndentedText* text);
187 };
Paul Stewart1dce1ae2014-10-01 05:30:18 -0700188 // Generates the signal handler name for a given signal name.
189 static std::string GetHandlerNameForSignal(const std::string& signal);
190
191 DISALLOW_COPY_AND_ASSIGN(ProxyGenerator);
192};
193
194} // namespace chromeos_dbus_bindings
195
196#endif // CHROMEOS_DBUS_BINDINGS_PROXY_GENERATOR_H_