OLD | NEW |
(Empty) | |
| 1 // This file is generated |
| 2 |
| 3 // Copyright (c) 2016 The Chromium Authors. All rights reserved. |
| 4 // Use of this source code is governed by a BSD-style license that can be |
| 5 // found in the LICENSE file. |
| 6 |
| 7 #ifndef HEADLESS_PUBLIC_DOMAINS_{{domain.domain | camelcase_to_hacker_style | up
per}}_H_ |
| 8 #define HEADLESS_PUBLIC_DOMAINS_{{domain.domain | camelcase_to_hacker_style | up
per}}_H_ |
| 9 |
| 10 #include "base/callback.h" |
| 11 #include "base/values.h" |
| 12 #include "headless/public/domains/types.h" |
| 13 #include "headless/public/headless_export.h" |
| 14 #include "headless/public/internal/message_dispatcher.h" |
| 15 |
| 16 namespace headless { |
| 17 namespace {{domain.domain | camelcase_to_hacker_style}} { |
| 18 |
| 19 {% if domain.description %} |
| 20 // {{domain.description}} |
| 21 {% endif %} |
| 22 class HEADLESS_EXPORT Domain { |
| 23 public: |
| 24 Domain(internal::MessageDispatcher* dispatcher); |
| 25 ~Domain(); |
| 26 |
| 27 {# Generate methods for each command. #} |
| 28 {% for command in domain.commands %} |
| 29 {# Skip redirected commands. #} |
| 30 {% if "redirect" in command %}{% continue %}{% endif %} |
| 31 {% set method_name = command.name | to_title_case %} |
| 32 {% if command.description %} |
| 33 // {{ command.description }} |
| 34 {% endif %} |
| 35 {% if "parameters" in command and "returns" in command %} |
| 36 void {{method_name}}(std::unique_ptr<{{method_name}}Params> params, base::Call
back<void(std::unique_ptr<{{method_name}}Result>)> callback = base::Callback<voi
d(std::unique_ptr<{{method_name}}Result>)>()); |
| 37 {% elif "parameters" in command %} |
| 38 void {{method_name}}(std::unique_ptr<{{method_name}}Params> params, base::Call
back<void()> callback = base::Callback<void()>()); |
| 39 {% elif "returns" in command %} |
| 40 void {{method_name}}(base::Callback<void(std::unique_ptr<{{method_name}}Result
>)> callback = base::Callback<void(std::unique_ptr<{{method_name}}Result>)>()); |
| 41 {% else %} |
| 42 void {{method_name}}(base::Callback<void()> callback = base::Callback<void()>(
)); |
| 43 {% endif %} |
| 44 {# Generate convenience methods that take the required parameters directly.
#} |
| 45 {% if not "parameters" in command %}{% continue %}{% endif %} |
| 46 void {{method_name}}({##} |
| 47 {% for parameter in command.parameters -%} |
| 48 {% if parameter.get("optional", False) -%} |
| 49 {% break %} |
| 50 {% endif %} |
| 51 {% if not loop.first %}, {% endif %} |
| 52 {{resolve_type(parameter).pass_type}} {{parameter.name -}} |
| 53 {% endfor %} |
| 54 {% if "parameters" in command and not command.parameters[0].get("optional",
False) %}, {% endif %}{# -#} |
| 55 {% if "returns" in command -%} |
| 56 base::Callback<void(std::unique_ptr<{{method_name}}Result>)> callback = ba
se::Callback<void(std::unique_ptr<{{method_name}}Result>)>(){##} |
| 57 {% else -%} |
| 58 base::Callback<void()> callback = base::Callback<void()>(){##} |
| 59 {% endif %}); |
| 60 {% endfor %} |
| 61 private: |
| 62 {# Generate response handlers for commands that need them. #} |
| 63 {% for command in domain.commands %} |
| 64 {% if not "returns" in command %}{% continue %}{% endif %} |
| 65 {% set method_name = command.name | to_title_case %} |
| 66 static void Handle{{method_name}}Response(base::Callback<void(std::unique_ptr<
{{method_name}}Result>)> callback, const base::Value& response); |
| 67 {% endfor %} |
| 68 |
| 69 internal::MessageDispatcher* dispatcher_; // Not owned. |
| 70 |
| 71 DISALLOW_COPY_AND_ASSIGN(Domain); |
| 72 }; |
| 73 |
| 74 } // namespace {{domain.domain | camelcase_to_hacker_style}} |
| 75 } // namespace headless |
| 76 |
| 77 #endif // HEADLESS_PUBLIC_DOMAINS_{{domain.domain | camelcase_to_hacker_style |
upper}}_H_ |
OLD | NEW |