• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // 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 
17 namespace base {
18 
19 class FilePath;
20 
21 }  // namespace base
22 
23 namespace chromeos_dbus_bindings {
24 
25 class IndentedText;
26 struct Interface;
27 
28 class ProxyGenerator : public HeaderGenerator {
29  public:
30   static bool GenerateProxies(const ServiceConfig& config,
31                               const std::vector<Interface>& interfaces,
32                               const base::FilePath& output_file);
33 
34   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                             bool use_literal_proxy_file);
39 
40  private:
41   friend class ProxyGeneratorTest;
42 
43   // 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 
48   // Generates one interface proxy.
49   static void GenerateInterfaceProxy(const ServiceConfig& config,
50                                      const Interface& interface,
51                                      IndentedText* text);
52 
53   // Generates one interface mock object.
54   static void GenerateInterfaceMock(const ServiceConfig& config,
55                                     const Interface& interface,
56                                     IndentedText* text);
57 
58   // Generates the constructor and destructor for the proxy.
59   static void AddConstructor(const ServiceConfig& config,
60                              const Interface& interface,
61                              const std::string& class_name,
62                              IndentedText* text);
63   static void AddDestructor(const std::string& class_name,
64                             IndentedText* text);
65 
66   // Generates ReleaseObjectProxy() method to release ownership
67   // of the object proxy.
68   static void AddReleaseObjectProxy(IndentedText* text);
69 
70   // 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                                        bool declaration_only,
79                                        IndentedText* text);
80 
81   // Generates OnPropertyChanged() method.
82   static void AddOnPropertyChanged(IndentedText* text);
83 
84   // Generates logic permitting users to register handlers for signals.
85   static void AddSignalHandlerRegistration(const Interface::Signal& signal,
86                                            const std::string& interface_name,
87                                            bool declaration_only,
88                                            IndentedText* text);
89 
90   // 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,
98                             bool declaration_only,
99                             IndentedText* text);
100 
101   // 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,
104                              bool declaration_only,
105                              IndentedText* text);
106 
107   // 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,
110                                   bool declaration_only,
111                                   IndentedText* text);
112 
113   // 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 
123   // 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 
131   // 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 
141   // 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 
154     // Generates Object Manager destructor.
155     static void AddDestructor(const std::string& class_name,
156                               const std::vector<Interface>& interfaces,
157                               IndentedText* text);
158 
159     // 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.
171     static void AddObjectAdded(const ServiceConfig& config,
172                                const std::vector<Interface>& interfaces,
173                                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.
185     static void AddDataMembers(const ServiceConfig& config,
186                                const std::vector<Interface>& interfaces,
187                                const std::string& class_name,
188                                IndentedText* text);
189   };
190   // 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_
199