Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 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: |
Alex Vakulenko | 6ef2d73 | 2014-11-25 14:04:27 -0800 | [diff] [blame] | 30 | static bool GenerateProxies(const ServiceConfig& config, |
| 31 | const std::vector<Interface>& interfaces, |
Alex Vakulenko | c95f06b | 2014-11-20 15:06:09 -0800 | [diff] [blame] | 32 | const base::FilePath& output_file); |
Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 33 | |
| 34 | private: |
| 35 | friend class ProxyGeneratorTest; |
| 36 | |
Alex Vakulenko | c95f06b | 2014-11-20 15:06:09 -0800 | [diff] [blame] | 37 | // Generates one interface proxy. |
Alex Vakulenko | 6ef2d73 | 2014-11-25 14:04:27 -0800 | [diff] [blame] | 38 | static void GenerateInterfaceProxy(const ServiceConfig& config, |
| 39 | const Interface& interface, |
Alex Vakulenko | c95f06b | 2014-11-20 15:06:09 -0800 | [diff] [blame] | 40 | IndentedText* text); |
| 41 | |
Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 42 | // Generates the constructor and destructor for the proxy. |
Alex Vakulenko | 6ef2d73 | 2014-11-25 14:04:27 -0800 | [diff] [blame] | 43 | static void AddConstructor(const ServiceConfig& config, |
| 44 | const Interface& interface, |
Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 45 | const std::string& class_name, |
| 46 | IndentedText* text); |
| 47 | static void AddDestructor(const std::string& class_name, |
| 48 | IndentedText* text); |
| 49 | |
Alex Vakulenko | c95f06b | 2014-11-20 15:06:09 -0800 | [diff] [blame] | 50 | // Generates ReleaseObjectProxy() method to release ownership |
| 51 | // of the object proxy. |
| 52 | static void AddReleaseObjectProxy(IndentedText* text); |
Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 53 | |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 54 | // Generates AddGetObjectPath() method. |
| 55 | static void AddGetObjectPath(IndentedText* text); |
| 56 | |
| 57 | // Generates GetObjectProxy() method. |
| 58 | static void AddGetObjectProxy(IndentedText* text); |
| 59 | |
| 60 | // Generates SetPropertyChangedCallback/GetProperties() methods. |
| 61 | static void AddPropertyPublicMethods(const std::string& class_name, |
| 62 | IndentedText* text); |
| 63 | |
| 64 | // Generates OnPropertyChanged() method. |
| 65 | static void AddOnPropertyChanged(IndentedText* text); |
| 66 | |
Christopher Wiley | 824b524 | 2014-12-03 11:58:01 -0800 | [diff] [blame^] | 67 | // Generates logic permitting users to register handlers for signals. |
| 68 | static void AddSignalHandlerRegistration(const Interface& interface, |
| 69 | IndentedText* text); |
Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 70 | |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 71 | // Generates the property set class to contain interface properties. |
| 72 | static void AddPropertySet(const ServiceConfig& config, |
| 73 | const Interface& interface, |
| 74 | IndentedText* text); |
| 75 | |
| 76 | // Generates the property accessors. |
| 77 | static void AddProperties(const ServiceConfig& config, |
| 78 | const Interface& interface, |
| 79 | IndentedText* text); |
| 80 | |
Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 81 | // Generates a native C++ method which calls a D-Bus method on the proxy. |
| 82 | static void AddMethodProxy(const Interface::Method& interface, |
| 83 | const std::string& interface_name, |
| 84 | IndentedText* text); |
| 85 | |
Alex Vakulenko | 99e8fb0 | 2014-12-01 17:22:03 -0800 | [diff] [blame] | 86 | // Generates the Object Manager proxy class. |
| 87 | struct ObjectManager { |
| 88 | // Generates the top-level class for Object Manager proxy. |
| 89 | static void GenerateProxy(const ServiceConfig& config, |
| 90 | const std::vector<Interface>& interfaces, |
| 91 | IndentedText* text); |
| 92 | |
| 93 | // Generates Object Manager constructor. |
| 94 | static void AddConstructor(const ServiceConfig& config, |
| 95 | const std::string& class_name, |
| 96 | const std::vector<Interface>& interfaces, |
| 97 | IndentedText* text); |
| 98 | |
| 99 | // Generates GetObjectManagerProxy() method. |
| 100 | static void AddGetObjectManagerProxy(IndentedText* text); |
| 101 | |
| 102 | // Generates code for interface-specific accessor methods |
| 103 | static void AddInterfaceAccessors(const Interface& interface, |
| 104 | IndentedText* text); |
| 105 | |
| 106 | // Generates OnPropertyChanged() method. |
| 107 | static void AddOnPropertyChanged(const std::vector<Interface>& interfaces, |
| 108 | IndentedText* text); |
| 109 | |
| 110 | // Generates ObjectAdded() method. |
| 111 | static void AddObjectAdded(const std::vector<Interface>& interfaces, |
| 112 | IndentedText* text); |
| 113 | |
| 114 | // Generates ObjectRemoved() method. |
| 115 | static void AddObjectRemoved(const std::vector<Interface>& interfaces, |
| 116 | IndentedText* text); |
| 117 | |
| 118 | // Generates CreateProperties() method. |
| 119 | static void AddCreateProperties(const std::vector<Interface>& interfaces, |
| 120 | const std::string& class_name, |
| 121 | IndentedText* text); |
| 122 | |
| 123 | // Generates data members of the class. |
| 124 | static void AddDataMembers(const std::vector<Interface>& interfaces, |
| 125 | const std::string& class_name, |
| 126 | IndentedText* text); |
| 127 | }; |
Paul Stewart | 1dce1ae | 2014-10-01 05:30:18 -0700 | [diff] [blame] | 128 | // Generates the signal handler name for a given signal name. |
| 129 | static std::string GetHandlerNameForSignal(const std::string& signal); |
| 130 | |
| 131 | DISALLOW_COPY_AND_ASSIGN(ProxyGenerator); |
| 132 | }; |
| 133 | |
| 134 | } // namespace chromeos_dbus_bindings |
| 135 | |
| 136 | #endif // CHROMEOS_DBUS_BINDINGS_PROXY_GENERATOR_H_ |