chromium/mojo/public/tools/bindings/generators/mojolpm_templates/mojolpm.h.tmpl

// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

{%- set header_guard = "%s_MOJOLPM_H_"|format(
        module.path|upper|replace("/","_")|replace(".","_")|
            replace("-", "_")) %}

{%- macro namespace_begin() %}
namespace mojolpm {
{%-   for namespace in namespaces_as_array %}
namespace {{namespace}} {
{%-   endfor %}
{%- endmacro %}

{%- macro namespace_end() %}
{%-   for namespace in namespaces_as_array|reverse %}
}  // namespace {{namespace}}
{%-   endfor %}
}  // namespace mojolpm
{%- endmacro %}

#ifndef {{header_guard}}
#define {{header_guard}}

#include "mojo/public/cpp/bindings/associated_receiver.h"
#include "mojo/public/cpp/bindings/associated_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/tools/fuzzers/mojolpm.h"

{% for extra_public_header in extra_public_headers %}
#include "{{extra_public_header}}"
{%- endfor %}

{% for import in imports %}
#include "{{import.path}}-mojolpm.h"
#include "{{import.path}}.h"
{%- endfor %}

#include "{{module.path}}.mojolpm.pb.h"
#include "{{module.path}}.h"

{%- import "mojolpm_macros.tmpl" as util %}
{%- import "mojolpm_from_proto_macros.tmpl" as from_proto %}
{%- import "mojolpm_to_proto_macros.tmpl" as to_proto %}

namespace mojolpm {

{%- for enum in all_enums %}
{%-   set mojom_type = enum|cpp_wrapper_type(add_same_module_namespaces=true) %}
{%-   set proto_type = "::mojolpm" ~ (enum|get_qualified_name_for_kind(flatten_nested_kind=True)) %}
// enum {{enum.name}}
bool FromProto(
  const {{proto_type}}& input,
  {{mojom_type}}& output);

bool ToProto(
  const {{mojom_type}}& input,
  {{proto_type}}& output);
{% endfor %}

{%- for struct in structs %}
{%-   set mojom_in_type = struct|cpp_wrapper_param_type(add_same_module_namespaces=true) %}
{%-   set mojom_out_type = struct|cpp_wrapper_call_type(add_same_module_namespaces=true) %}
{%-   set maybe_const = "const " if not struct|contains_handles_or_interfaces else "" %}
{%-   set proto_type = "::mojolpm" ~ (struct|get_qualified_name_for_kind(flatten_nested_kind=True)) %}
{%-   set struct_type = proto_type ~ "_ProtoStruct" %}
// struct {{struct.name}}
bool FromProto(
  const {{proto_type}}& input,
  {{mojom_out_type}}& output);

bool ToProto(
  {{mojom_in_type}} input,
  {{proto_type}}& output);{{"\n"-}}
{%-   for field in struct.fields %}
{%-     set name = field.name %}
{%-     set kind = field.kind %}
{%-     if kind|is_array_kind or kind|is_map_kind %}
{{- from_proto.declare(struct_type, kind, name) }}
{{- to_proto.declare(struct_type, kind, name) }}
{%-     endif %}
{%-   endfor %}
{%- endfor %}

{%- for union in unions %}
{%-   set mojom_in_type = union|cpp_wrapper_param_type(add_same_module_namespaces=true) %}
{%-   set mojom_out_type = union|cpp_wrapper_call_type(add_same_module_namespaces=true) %}
{%-   set maybe_const = "const " if not union|contains_handles_or_interfaces else "" %}
{%-   set proto_type = "::mojolpm" ~ (union|get_qualified_name_for_kind(flatten_nested_kind=True)) %}
{%-   set union_type = proto_type ~ "_ProtoUnion" %}
{%-   if union|is_native_only_kind %}
#error "Mojo native-only union {{union.name}} - don't think this is possible"
{%-   else %}
// union {{union.name}}
bool FromProto(
  const {{proto_type}}& input,
  {{mojom_out_type}}& output);

bool ToProto(
  {{mojom_in_type}} input,
  {{proto_type}}& output);{{"\n"-}}
{%-   endif %}
{%-   for field in union.fields %}
{%-     set name = field.name %}
{%-     set kind = field.kind %}
{%-     if kind|is_array_kind or kind|is_map_kind %}
{{- from_proto.declare(union_type, kind, name) }}
{{- to_proto.declare(union_type, kind, name) }}
{%-     endif %}
{%-   endfor %}
{%- endfor %}

{%- for interface in interfaces %}
{%-   set mojom_type = interface|get_qualified_name_for_kind(flatten_nested_kind=True) %}
{%-   set proto_type = "::mojolpm" ~ (interface|get_qualified_name_for_kind(flatten_nested_kind=True)) %}
// interface {{interface.name}}
bool FromProto(
  uint32_t input,
  ::mojo::PendingRemote<{{mojom_type}}>& output);

bool ToProto(
  ::mojo::PendingRemote<{{mojom_type}}>&& input,
  uint32_t& output);

bool FromProto(
  uint32_t input,
  ::mojo::PendingReceiver<{{mojom_type}}>& output);

bool ToProto(
  ::mojo::PendingReceiver<{{mojom_type}}>&& input,
  uint32_t& output);

bool FromProto(
  uint32_t input,
  ::mojo::PendingAssociatedRemote<{{mojom_type}}>& output);

bool ToProto(
  ::mojo::PendingAssociatedRemote<{{mojom_type}}>&& input,
  uint32_t& output);

bool FromProto(
  uint32_t input,
  ::mojo::PendingAssociatedReceiver<{{mojom_type}}>& output);

bool ToProto(
  ::mojo::PendingAssociatedReceiver<{{mojom_type}}>&& input,
  uint32_t& output);{{"\n"-}}
{%-   for method in interface.methods %}
{%-     set method_type = proto_type ~ "::" ~ interface.name ~ "_" ~ method.name %}
{%-     for param in method.parameters %}
{%-       set name = param.name %}
{%-       set kind = param.kind %}
{%-       if kind|is_array_kind or kind|is_map_kind -%}
{{- from_proto.declare(method_type, kind, name)}}
{{- to_proto.declare(method_type, kind, name)}}
{%-       endif %}
{%-     endfor %}
{%-   endfor %}
{%-   for method in interface.methods %}
{%-     if method.response_parameters != None %}
{%-       set method_type = proto_type ~ "::" ~ interface.name ~ "_" ~ method.name ~ "Response" %}
{%-       for param in method.response_parameters %}
{%-         set name = param.name %}
{%-         set kind = param.kind %}
{%-         if kind|is_array_kind or kind|is_map_kind -%}
{{- from_proto.declare(method_type, kind, name)}}
{{- to_proto.declare(method_type, kind, name)}}
{%-         endif %}
{%-       endfor %}
{%-     endif %}
{%-   endfor %}
{%- endfor %}

{%- for interface in interfaces %}
{%-   set mojom_type = interface|get_qualified_name_for_kind(flatten_nested_kind=True) %}
{%-   set proto_type = "::mojolpm" ~ (interface|get_qualified_name_for_kind(flatten_nested_kind=True)) %}
{%-   if interface.methods %}
bool HandleRemoteAction(
  const {{proto_type}}::RemoteAction& input);

bool HandleAssociatedRemoteAction(
  const {{proto_type}}::AssociatedRemoteAction& input);

bool HandleReceiverAction(
  const {{proto_type}}::ReceiverAction& input);{{"\n"-}}
{%-     for method in interface.methods %}
bool HandleRemoteCall(
  uint32_t instance_id,
  const {{proto_type}}::{{interface.name}}_{{method.name}}& input);

bool HandleAssociatedRemoteCall(
  uint32_t instance_id,
  const {{proto_type}}::{{interface.name}}_{{method.name}}& input);

bool HandleResponse(
  uint32_t callback_id,
  const {{proto_type}}::{{interface.name}}_{{method.name}}Response& input);{{"\n"-}}
{%-     endfor %}
{%-   endif %}
{%- endfor -%}
}  // namespace mojolpm

#endif  // {{header_guard}}