blob: 7d4549bedae2592c0ed8594fa2074e1e8f1fd8d0 [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
34 private:
35 friend class ProxyGeneratorTest;
36
Alex Vakulenkoc95f06b2014-11-20 15:06:09 -080037 // Generates one interface proxy.
Alex Vakulenko6ef2d732014-11-25 14:04:27 -080038 static void GenerateInterfaceProxy(const ServiceConfig& config,
39 const Interface& interface,
Alex Vakulenkoc95f06b2014-11-20 15:06:09 -080040 IndentedText* text);
41
Paul Stewart1dce1ae2014-10-01 05:30:18 -070042 // Generates the constructor and destructor for the proxy.
Alex Vakulenko6ef2d732014-11-25 14:04:27 -080043 static void AddConstructor(const ServiceConfig& config,
44 const Interface& interface,
Paul Stewart1dce1ae2014-10-01 05:30:18 -070045 const std::string& class_name,
46 IndentedText* text);
47 static void AddDestructor(const std::string& class_name,
48 IndentedText* text);
49
50 // Generates a callback for signal receiver registration completion.
Alex Vakulenkoc95f06b2014-11-20 15:06:09 -080051 static void AddSignalConnectedCallback(IndentedText* text);
52
53 // Generates ReleaseObjectProxy() method to release ownership
54 // of the object proxy.
55 static void AddReleaseObjectProxy(IndentedText* text);
Paul Stewart1dce1ae2014-10-01 05:30:18 -070056
Alex Vakulenko99e8fb02014-12-01 17:22:03 -080057 // Generates AddGetObjectPath() method.
58 static void AddGetObjectPath(IndentedText* text);
59
60 // Generates GetObjectProxy() method.
61 static void AddGetObjectProxy(IndentedText* text);
62
63 // Generates SetPropertyChangedCallback/GetProperties() methods.
64 static void AddPropertyPublicMethods(const std::string& class_name,
65 IndentedText* text);
66
67 // Generates OnPropertyChanged() method.
68 static void AddOnPropertyChanged(IndentedText* text);
69
Paul Stewart1dce1ae2014-10-01 05:30:18 -070070 // Generates the method signatures for signal receivers.
Alex Vakulenkoc95f06b2014-11-20 15:06:09 -080071 static void AddSignalReceiver(const Interface& interface,
Alex Vakulenkofafef132014-11-03 14:52:09 -080072 IndentedText* text);
Paul Stewart1dce1ae2014-10-01 05:30:18 -070073
Alex Vakulenko99e8fb02014-12-01 17:22:03 -080074 // Generates the property set class to contain interface properties.
75 static void AddPropertySet(const ServiceConfig& config,
76 const Interface& interface,
77 IndentedText* text);
78
79 // Generates the property accessors.
80 static void AddProperties(const ServiceConfig& config,
81 const Interface& interface,
82 IndentedText* text);
83
Paul Stewart1dce1ae2014-10-01 05:30:18 -070084 // Generates a native C++ method which calls a D-Bus method on the proxy.
85 static void AddMethodProxy(const Interface::Method& interface,
86 const std::string& interface_name,
87 IndentedText* text);
88
Alex Vakulenko99e8fb02014-12-01 17:22:03 -080089 // Generates the Object Manager proxy class.
90 struct ObjectManager {
91 // Generates the top-level class for Object Manager proxy.
92 static void GenerateProxy(const ServiceConfig& config,
93 const std::vector<Interface>& interfaces,
94 IndentedText* text);
95
96 // Generates Object Manager constructor.
97 static void AddConstructor(const ServiceConfig& config,
98 const std::string& class_name,
99 const std::vector<Interface>& interfaces,
100 IndentedText* text);
101
102 // Generates GetObjectManagerProxy() method.
103 static void AddGetObjectManagerProxy(IndentedText* text);
104
105 // Generates code for interface-specific accessor methods
106 static void AddInterfaceAccessors(const Interface& interface,
107 IndentedText* text);
108
109 // Generates OnPropertyChanged() method.
110 static void AddOnPropertyChanged(const std::vector<Interface>& interfaces,
111 IndentedText* text);
112
113 // Generates ObjectAdded() method.
114 static void AddObjectAdded(const std::vector<Interface>& interfaces,
115 IndentedText* text);
116
117 // Generates ObjectRemoved() method.
118 static void AddObjectRemoved(const std::vector<Interface>& interfaces,
119 IndentedText* text);
120
121 // Generates CreateProperties() method.
122 static void AddCreateProperties(const std::vector<Interface>& interfaces,
123 const std::string& class_name,
124 IndentedText* text);
125
126 // Generates data members of the class.
127 static void AddDataMembers(const std::vector<Interface>& interfaces,
128 const std::string& class_name,
129 IndentedText* text);
130 };
Paul Stewart1dce1ae2014-10-01 05:30:18 -0700131 // Generates the signal handler name for a given signal name.
132 static std::string GetHandlerNameForSignal(const std::string& signal);
133
134 DISALLOW_COPY_AND_ASSIGN(ProxyGenerator);
135};
136
137} // namespace chromeos_dbus_bindings
138
139#endif // CHROMEOS_DBUS_BINDINGS_PROXY_GENERATOR_H_