• 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 #include "chromeos-dbus-bindings/method_name_generator.h"
6 
7 #include <base/files/file_path.h>
8 #include <base/strings/stringprintf.h>
9 
10 #include "chromeos-dbus-bindings/indented_text.h"
11 #include "chromeos-dbus-bindings/interface.h"
12 #include "chromeos-dbus-bindings/name_parser.h"
13 
14 using std::string;
15 using std::vector;
16 
17 namespace chromeos_dbus_bindings {
18 
19 // static
GenerateMethodNameConstant(const string & method_name)20 string MethodNameGenerator::GenerateMethodNameConstant(
21     const string& method_name) {
22   return "k" + method_name + "Method";
23 }
24 
25 // static
GenerateMethodNames(const vector<Interface> & interfaces,const base::FilePath & output_file)26 bool MethodNameGenerator::GenerateMethodNames(
27     const vector<Interface>& interfaces,
28     const base::FilePath& output_file) {
29   string contents;
30   IndentedText text;
31   for (const auto& interface : interfaces) {
32     text.AddBlankLine();
33     NameParser parser{interface.name};
34     parser.AddOpenNamespaces(&text, true);
35     for (const auto& method : interface.methods) {
36       text.AddLine(
37         base::StringPrintf("const char %s[] = \"%s\";",
38                             GenerateMethodNameConstant(method.name).c_str(),
39                             method.name.c_str()));
40     }
41     parser.AddCloseNamespaces(&text, true);
42   }
43   return HeaderGenerator::WriteTextToFile(output_file, text);
44 }
45 
46 }  // namespace chromeos_dbus_bindings
47