blob: d6cfbafc54fcea6ffb1ede5329a00db2f38854f0 [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,
78 IndentedText* text);
79
80 // Generates OnPropertyChanged() method.
81 static void AddOnPropertyChanged(IndentedText* text);
82
Christopher Wiley824b5242014-12-03 11:58:01 -080083 // Generates logic permitting users to register handlers for signals.
Alex Deymoce286b92015-07-28 15:04:07 -070084 static void AddSignalHandlerRegistration(const Interface::Signal& signal,
85 const std::string& interface_name,
86 bool declaration_only,
Christopher Wiley824b5242014-12-03 11:58:01 -080087 IndentedText* text);
Paul Stewart1dce1ae2014-10-01 05:30:18 -070088
Alex Vakulenko99e8fb02014-12-01 17:22:03 -080089 // 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 Vakulenko008e19d2015-01-21 10:37:00 -080097 bool declaration_only,
Alex Vakulenko99e8fb02014-12-01 17:22:03 -080098 IndentedText* text);
99
Paul Stewart1dce1ae2014-10-01 05:30:18 -0700100 // 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 Vakulenko008e19d2015-01-21 10:37:00 -0800103 bool declaration_only,
Paul Stewart1dce1ae2014-10-01 05:30:18 -0700104 IndentedText* text);
105
Alex Vakulenkoc4e32f52014-12-04 08:28:49 -0800106 // 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 Vakulenko008e19d2015-01-21 10:37:00 -0800109 bool declaration_only,
Alex Vakulenkoc4e32f52014-12-04 08:28:49 -0800110 IndentedText* text);
111
Alex Vakulenko008e19d2015-01-21 10:37:00 -0800112 // 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 Deymo464405e2015-07-30 11:21:51 -0700122 // 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 Deymoce286b92015-07-28 15:04:07 -0700130 // 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 Vakulenko99e8fb02014-12-01 17:22:03 -0800140 // 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 Wileye11e81c2014-12-19 13:10:52 -0800153 // Generates Object Manager destructor.
154 static void AddDestructor(const std::string& class_name,
155 const std::vector<Interface>& interfaces,
156 IndentedText* text);
157
Alex Vakulenko99e8fb02014-12-01 17:22:03 -0800158 // 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 Wileyefe9df52015-03-12 16:02:22 -0700170 static void AddObjectAdded(const ServiceConfig& config,
171 const std::vector<Interface>& interfaces,
Alex Vakulenko99e8fb02014-12-01 17:22:03 -0800172 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 Wileyefe9df52015-03-12 16:02:22 -0700184 static void AddDataMembers(const ServiceConfig& config,
185 const std::vector<Interface>& interfaces,
Alex Vakulenko99e8fb02014-12-01 17:22:03 -0800186 const std::string& class_name,
187 IndentedText* text);
188 };
Paul Stewart1dce1ae2014-10-01 05:30:18 -0700189 // 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_