blob: ba9a2244986864b7fcbfc8fe4a3dcaee6645d4df [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 Deymoce286b92015-07-28 15:04:07 -0700121 // 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 Vakulenko99e8fb02014-12-01 17:22:03 -0800131 // 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 Wileye11e81c2014-12-19 13:10:52 -0800144 // Generates Object Manager destructor.
145 static void AddDestructor(const std::string& class_name,
146 const std::vector<Interface>& interfaces,
147 IndentedText* text);
148
Alex Vakulenko99e8fb02014-12-01 17:22:03 -0800149 // 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 Wileyefe9df52015-03-12 16:02:22 -0700161 static void AddObjectAdded(const ServiceConfig& config,
162 const std::vector<Interface>& interfaces,
Alex Vakulenko99e8fb02014-12-01 17:22:03 -0800163 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 Wileyefe9df52015-03-12 16:02:22 -0700175 static void AddDataMembers(const ServiceConfig& config,
176 const std::vector<Interface>& interfaces,
Alex Vakulenko99e8fb02014-12-01 17:22:03 -0800177 const std::string& class_name,
178 IndentedText* text);
179 };
Paul Stewart1dce1ae2014-10-01 05:30:18 -0700180 // 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_