blob: 57af0e00a56fd4961b6b78a5116df335ae8802d1 [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,
Christopher Wileya30e09d2015-08-03 19:37:03 -070037 const base::FilePath& proxy_file,
38 bool use_literal_proxy_file);
Alex Vakulenko008e19d2015-01-21 10:37:00 -080039
Paul Stewart1dce1ae2014-10-01 05:30:18 -070040 private:
41 friend class ProxyGeneratorTest;
42
Alex Vakulenko008e19d2015-01-21 10:37:00 -080043 // 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 Vakulenkoc95f06b2014-11-20 15:06:09 -080048 // Generates one interface proxy.
Alex Vakulenko6ef2d732014-11-25 14:04:27 -080049 static void GenerateInterfaceProxy(const ServiceConfig& config,
50 const Interface& interface,
Alex Vakulenkoc95f06b2014-11-20 15:06:09 -080051 IndentedText* text);
52
Alex Vakulenko008e19d2015-01-21 10:37:00 -080053 // Generates one interface mock object.
54 static void GenerateInterfaceMock(const ServiceConfig& config,
55 const Interface& interface,
56 IndentedText* text);
57
Paul Stewart1dce1ae2014-10-01 05:30:18 -070058 // Generates the constructor and destructor for the proxy.
Alex Vakulenko6ef2d732014-11-25 14:04:27 -080059 static void AddConstructor(const ServiceConfig& config,
60 const Interface& interface,
Paul Stewart1dce1ae2014-10-01 05:30:18 -070061 const std::string& class_name,
62 IndentedText* text);
63 static void AddDestructor(const std::string& class_name,
64 IndentedText* text);
65
Alex Vakulenkoc95f06b2014-11-20 15:06:09 -080066 // Generates ReleaseObjectProxy() method to release ownership
67 // of the object proxy.
68 static void AddReleaseObjectProxy(IndentedText* text);
Paul Stewart1dce1ae2014-10-01 05:30:18 -070069
Alex Vakulenko99e8fb02014-12-01 17:22:03 -080070 // 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 Vakulenkodaea81b2015-12-10 10:49:40 -080078 bool declaration_only,
Alex Vakulenko99e8fb02014-12-01 17:22:03 -080079 IndentedText* text);
80
81 // Generates OnPropertyChanged() method.
82 static void AddOnPropertyChanged(IndentedText* text);
83
Christopher Wiley824b5242014-12-03 11:58:01 -080084 // Generates logic permitting users to register handlers for signals.
Alex Deymoce286b92015-07-28 15:04:07 -070085 static void AddSignalHandlerRegistration(const Interface::Signal& signal,
86 const std::string& interface_name,
87 bool declaration_only,
Christopher Wiley824b5242014-12-03 11:58:01 -080088 IndentedText* text);
Paul Stewart1dce1ae2014-10-01 05:30:18 -070089
Alex Vakulenko99e8fb02014-12-01 17:22:03 -080090 // 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 Vakulenko008e19d2015-01-21 10:37:00 -080098 bool declaration_only,
Alex Vakulenko99e8fb02014-12-01 17:22:03 -080099 IndentedText* text);
100
Paul Stewart1dce1ae2014-10-01 05:30:18 -0700101 // 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 Vakulenko008e19d2015-01-21 10:37:00 -0800104 bool declaration_only,
Paul Stewart1dce1ae2014-10-01 05:30:18 -0700105 IndentedText* text);
106
Alex Vakulenkoc4e32f52014-12-04 08:28:49 -0800107 // 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 Vakulenko008e19d2015-01-21 10:37:00 -0800110 bool declaration_only,
Alex Vakulenkoc4e32f52014-12-04 08:28:49 -0800111 IndentedText* text);
112
Alex Vakulenko008e19d2015-01-21 10:37:00 -0800113 // 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 Deymo464405e2015-07-30 11:21:51 -0700123 // 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 Deymoce286b92015-07-28 15:04:07 -0700131 // 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 Vakulenko99e8fb02014-12-01 17:22:03 -0800141 // 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 Wileye11e81c2014-12-19 13:10:52 -0800154 // Generates Object Manager destructor.
155 static void AddDestructor(const std::string& class_name,
156 const std::vector<Interface>& interfaces,
157 IndentedText* text);
158
Alex Vakulenko99e8fb02014-12-01 17:22:03 -0800159 // 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 Wileyefe9df52015-03-12 16:02:22 -0700171 static void AddObjectAdded(const ServiceConfig& config,
172 const std::vector<Interface>& interfaces,
Alex Vakulenko99e8fb02014-12-01 17:22:03 -0800173 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 Wileyefe9df52015-03-12 16:02:22 -0700185 static void AddDataMembers(const ServiceConfig& config,
186 const std::vector<Interface>& interfaces,
Alex Vakulenko99e8fb02014-12-01 17:22:03 -0800187 const std::string& class_name,
188 IndentedText* text);
189 };
Paul Stewart1dce1ae2014-10-01 05:30:18 -0700190 // 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_