blob: 5dc04c9a1fda8b7486c467a92407b87905a09dbf [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.
83 static void AddSignalHandlerRegistration(const Interface& interface,
84 IndentedText* text);
Paul Stewart1dce1ae2014-10-01 05:30:18 -070085
Alex Vakulenko99e8fb02014-12-01 17:22:03 -080086 // Generates the property set class to contain interface properties.
87 static void AddPropertySet(const ServiceConfig& config,
88 const Interface& interface,
89 IndentedText* text);
90
91 // Generates the property accessors.
92 static void AddProperties(const ServiceConfig& config,
93 const Interface& interface,
Alex Vakulenko008e19d2015-01-21 10:37:00 -080094 bool declaration_only,
Alex Vakulenko99e8fb02014-12-01 17:22:03 -080095 IndentedText* text);
96
Paul Stewart1dce1ae2014-10-01 05:30:18 -070097 // Generates a native C++ method which calls a D-Bus method on the proxy.
98 static void AddMethodProxy(const Interface::Method& interface,
99 const std::string& interface_name,
Alex Vakulenko008e19d2015-01-21 10:37:00 -0800100 bool declaration_only,
Paul Stewart1dce1ae2014-10-01 05:30:18 -0700101 IndentedText* text);
102
Alex Vakulenkoc4e32f52014-12-04 08:28:49 -0800103 // Generates a native C++ method which calls a D-Bus method asynchronously.
104 static void AddAsyncMethodProxy(const Interface::Method& interface,
105 const std::string& interface_name,
Alex Vakulenko008e19d2015-01-21 10:37:00 -0800106 bool declaration_only,
Alex Vakulenkoc4e32f52014-12-04 08:28:49 -0800107 IndentedText* text);
108
Alex Vakulenko008e19d2015-01-21 10:37:00 -0800109 // Generates a mock for blocking D-Bus method.
110 static void AddMethodMock(const Interface::Method& interface,
111 const std::string& interface_name,
112 IndentedText* text);
113
114 // Generates a mock for asynchronous D-Bus method.
115 static void AddAsyncMethodMock(const Interface::Method& interface,
116 const std::string& interface_name,
117 IndentedText* text);
118
Alex Vakulenko99e8fb02014-12-01 17:22:03 -0800119 // Generates the Object Manager proxy class.
120 struct ObjectManager {
121 // Generates the top-level class for Object Manager proxy.
122 static void GenerateProxy(const ServiceConfig& config,
123 const std::vector<Interface>& interfaces,
124 IndentedText* text);
125
126 // Generates Object Manager constructor.
127 static void AddConstructor(const ServiceConfig& config,
128 const std::string& class_name,
129 const std::vector<Interface>& interfaces,
130 IndentedText* text);
131
Christopher Wileye11e81c2014-12-19 13:10:52 -0800132 // Generates Object Manager destructor.
133 static void AddDestructor(const std::string& class_name,
134 const std::vector<Interface>& interfaces,
135 IndentedText* text);
136
Alex Vakulenko99e8fb02014-12-01 17:22:03 -0800137 // Generates GetObjectManagerProxy() method.
138 static void AddGetObjectManagerProxy(IndentedText* text);
139
140 // Generates code for interface-specific accessor methods
141 static void AddInterfaceAccessors(const Interface& interface,
142 IndentedText* text);
143
144 // Generates OnPropertyChanged() method.
145 static void AddOnPropertyChanged(const std::vector<Interface>& interfaces,
146 IndentedText* text);
147
148 // Generates ObjectAdded() method.
Christopher Wileyefe9df52015-03-12 16:02:22 -0700149 static void AddObjectAdded(const ServiceConfig& config,
150 const std::vector<Interface>& interfaces,
Alex Vakulenko99e8fb02014-12-01 17:22:03 -0800151 IndentedText* text);
152
153 // Generates ObjectRemoved() method.
154 static void AddObjectRemoved(const std::vector<Interface>& interfaces,
155 IndentedText* text);
156
157 // Generates CreateProperties() method.
158 static void AddCreateProperties(const std::vector<Interface>& interfaces,
159 const std::string& class_name,
160 IndentedText* text);
161
162 // Generates data members of the class.
Christopher Wileyefe9df52015-03-12 16:02:22 -0700163 static void AddDataMembers(const ServiceConfig& config,
164 const std::vector<Interface>& interfaces,
Alex Vakulenko99e8fb02014-12-01 17:22:03 -0800165 const std::string& class_name,
166 IndentedText* text);
167 };
Paul Stewart1dce1ae2014-10-01 05:30:18 -0700168 // Generates the signal handler name for a given signal name.
169 static std::string GetHandlerNameForSignal(const std::string& signal);
170
171 DISALLOW_COPY_AND_ASSIGN(ProxyGenerator);
172};
173
174} // namespace chromeos_dbus_bindings
175
176#endif // CHROMEOS_DBUS_BINDINGS_PROXY_GENERATOR_H_