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_HEADER_GENERATOR_H_ 6 #define CHROMEOS_DBUS_BINDINGS_HEADER_GENERATOR_H_ 7 8 #include <string> 9 #include <vector> 10 11 #include <base/macros.h> 12 13 namespace base { 14 15 class FilePath; 16 17 }; 18 19 namespace chromeos_dbus_bindings { 20 21 struct Interface; 22 class IndentedText; 23 24 // General D-Bus service configuration settings used by Adaptor/Proxy code 25 // generators. 26 struct ServiceConfig { 27 // D-Bus service name to be used when constructing proxy objects. 28 // If omitted (empty), the service name parameter will be added to the 29 // constructor of generated proxy class(es). 30 std::string service_name; 31 // Object Manager settings. 32 struct { 33 // The name of the Object Manager class to use. If empty, no object manager 34 // is generated in the proxy code (this also disables property support on 35 // proxy objects). 36 // This is a "fake" name used to generate namespaces and the actual class 37 // name for the object manager proxy. This name has no relationship to the 38 // actual D-Bus properties of the actual object manager. 39 std::string name; 40 // The D-Bus path to Object Manager instance. 41 std::string object_path; 42 } object_manager; 43 44 // A list of interfaces we should ignore and not generate any adaptors and 45 // proxies for. 46 std::vector<std::string> ignore_interfaces; 47 }; 48 49 class HeaderGenerator { 50 protected: 51 // Create a unique header guard string to protect multiple includes of header. 52 static std::string GenerateHeaderGuard(const base::FilePath& output_file); 53 54 // Used to decide whether the argument should be a const reference. 55 static bool IsIntegralType(const std::string& type); 56 57 // If |type| is a non-integral type, converts it into a const reference. 58 static void MakeConstReferenceIfNeeded(std::string* type); 59 60 // Writes indented text to a file. 61 static bool WriteTextToFile(const base::FilePath& output_file, 62 const IndentedText& text); 63 64 // Generate a name of a method/signal argument based on the name provided in 65 // the XML file. If |arg_name| is empty, it generates a name using 66 // the |arg_index| counter. 67 static std::string GetArgName(const char* prefix, 68 const std::string& arg_name, 69 int arg_index); 70 71 static const int kScopeOffset = 1; 72 static const int kBlockOffset = 2; 73 static const int kLineContinuationOffset = 4; 74 75 private: 76 DISALLOW_COPY_AND_ASSIGN(HeaderGenerator); 77 }; 78 79 } // namespace chromeos_dbus_bindings 80 81 #endif // CHROMEOS_DBUS_BINDINGS_HEADER_GENERATOR_H_ 82