aboutsummaryrefslogtreecommitdiff
path: root/mojo/public/tools/bindings/generators/cpp_templates/interface_declaration.tmpl
blob: 7f6497475a62f318d71dc3a9e486148af8bd628c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
{%- import "interface_macros.tmpl" as interface_macros %}
class {{interface.name}}Proxy;

template <typename ImplRefTraits>
class {{interface.name}}Stub;

class {{interface.name}}RequestValidator;
{%- if interface|has_callbacks %}
class {{interface.name}}ResponseValidator;
{%- endif %}

class {{export_attribute}} {{interface.name}}
    : public {{interface.name}}InterfaceBase {
 public:
  static const char Name_[];
  static constexpr uint32_t Version_ = {{interface.version}};
  static constexpr bool PassesAssociatedKinds_ = {% if interface|passes_associated_kinds %}true{% else %}false{% endif %};
  static constexpr bool HasSyncMethods_ = {% if interface|has_sync_methods %}true{% else %}false{% endif %};

  using Proxy_ = {{interface.name}}Proxy;

  template <typename ImplRefTraits>
  using Stub_ = {{interface.name}}Stub<ImplRefTraits>;

  using RequestValidator_ = {{interface.name}}RequestValidator;
{%- if interface|has_callbacks %}
  using ResponseValidator_ = {{interface.name}}ResponseValidator;
{%- else %}
  using ResponseValidator_ = mojo::PassThroughFilter;
{%- endif %}

{#--- Metadata #}
  enum MethodMinVersions : uint32_t {
{%- for method in interface.methods %}
    k{{method.name}}MinVersion = {{method.min_version|default(0, true)}},
{%- endfor %}
  };

{#--- Enums #}
{%- for enum in interface.enums %}
  using {{enum.name}} = {{enum|get_name_for_kind(flatten_nested_kind=True)}};
{%- endfor %}

{#--- Constants #}
{%- for constant in interface.constants %}
  static {{constant|format_constant_declaration(nested=True)}};
{%- endfor %}

{#--- Methods #}
  virtual ~{{interface.name}}() {}

{%- for method in interface.methods %}
{%    if method.response_parameters != None %}
{%-     if method.sync %}
  // Sync method. This signature is used by the client side; the service side
  // should implement the signature with callback below.
  virtual bool {{method.name}}({{interface_macros.declare_sync_method_params("", method)}});
{%-     endif %}

  using {{method.name}}Callback = {{interface_macros.declare_callback(method,
      for_blink, use_once_callback)}};
{%-   endif %}
  virtual void {{method.name}}({{interface_macros.declare_request_params("", method, use_once_callback)}}) = 0;
{%- endfor %}
};