// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
{%- from 'cpp_macros.tmpl' import
namespace_begin, namespace_end, include_guard, variant_path %}
{%- set header_guard = include_guard('', module.path, variant) %}
{%- macro kythe_annotation(name) %}
{%- if enable_kythe_annotations %}
// @generated_from: {{name}}
{%- endif %}
{%- endmacro %}
#ifndef {{header_guard}}
#define {{header_guard}}
#include <stdint.h>
#include <limits>
#include <optional>
#include <type_traits>
#include <utility>
#include "base/types/cxx23_to_underlying.h"
{%- if contains_only_enums %}
#include "mojo/public/cpp/bindings/type_converter.h"
{%- else %}
#include "mojo/public/cpp/bindings/clone_traits.h"
#include "mojo/public/cpp/bindings/equals_traits.h"
#include "mojo/public/cpp/bindings/lib/serialization.h"
#include "mojo/public/cpp/bindings/struct_ptr.h"
#include "mojo/public/cpp/bindings/struct_traits.h"
#include "mojo/public/cpp/bindings/union_traits.h"
{%- endif %}
#include "third_party/perfetto/include/perfetto/tracing/traced_value_forward.h"
#include "{{module.path}}-features.h" // IWYU pragma: export
#include "{{module.path}}-shared.h" // IWYU pragma: export
#include "{{variant_path(module.path, variant)}}-forward.h" // IWYU pragma: export
{%- for import in imports %}
{%- if import|is_full_header_required_for_import %}
#include "{{variant_path(import.path, variant)}}.h"
{%- else %}
#include "{{variant_path(import.path, variant)}}-forward.h"
{%- endif %}
{%- endfor %}
{%- if not for_blink %}
#include <string>
#include <vector>
{%- else %}
{# hash_util.h includes template specializations that should be present for
every use of {Inlined}StructPtr. #}
#include "mojo/public/cpp/bindings/lib/wtf_clone_equals_util.h"
#include "mojo/public/cpp/bindings/lib/wtf_hash_util.h"
#include "third_party/blink/renderer/platform/wtf/hash_functions.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
{%- endif %}
{% if not disallow_interfaces and uses_interfaces -%}
#include "mojo/public/cpp/bindings/lib/control_message_handler.h"
#include "mojo/public/cpp/bindings/lib/message_size_estimator.h"
#include "mojo/public/cpp/bindings/raw_ptr_impl_ref_traits.h"
{%- endif %}
{% if not disallow_native_types and uses_native_types %}
#include "mojo/public/cpp/bindings/lib/native_enum_serialization.h"
#include "mojo/public/cpp/bindings/lib/native_struct_serialization.h"
{%- endif %}
{%- for header in extra_public_headers %}
#include "{{header}}"
{%- endfor %}
{%- if export_header %}
#include "{{export_header}}"
{%- endif %}
{% if enable_kythe_annotations -%}
#ifdef KYTHE_IS_RUNNING
#pragma kythe_inline_metadata "Metadata comment"
#endif
{%- endif %}
{%- for forward_declaration in typemap_forward_declarations %}
{{forward_declaration}}
{%- endfor %}
{#--- Constants that need headers (enum types) (basic types go in forward.h) #}
{%- for constant in module.constants %}
{%- if constant.kind|is_enum_kind %}
{{ kythe_annotation("%s.%s"|format(module_prefix, constant.name)) }}
{{constant|format_enum_constant_declaration}};
{%- endif %}
{%- endfor %}
{{namespace_begin(namespaces_as_array, variant)}}
{%- set module_prefix = "%s"|format(namespaces_as_array|join(".")) %}
{#--- Interfaces -#}
{% for interface in interfaces %}
{% include "interface_declaration.tmpl" %}
{%- endfor %}
{#--- Interface Proxies -#}
{% for interface in interfaces %}
{% include "interface_proxy_declaration.tmpl" %}
{%- endfor %}
{#--- Interface Stubs -#}
{% for interface in interfaces %}
{% include "interface_stub_declaration.tmpl" %}
{%- endfor %}
{#--- Interface Request Validators -#}
{% for interface in interfaces %}
{% include "interface_request_validator_declaration.tmpl" %}
{%- endfor %}
{#--- Interface Response Validators -#}
{% for interface in interfaces if interface|has_callbacks %}
{% include "interface_response_validator_declaration.tmpl" %}
{%- endfor %}
{#--- NOTE: Unions and non-inlined structs may have pointers to inlined structs,
so we need to fully define inlined structs ahead of the others. #}
{#--- Inlined structs #}
{% for struct in structs %}
{% if struct|should_inline and not struct|is_native_only_kind %}
{% include "wrapper_class_declaration.tmpl" %}
{% endif %}
{%- endfor %}
{#--- Unions must be declared before non-inlined structs because they can be
members of structs. #}
{#--- Unions #}
{% for union in unions %}
{% include "wrapper_union_class_declaration.tmpl" %}
{%- endfor %}
{#--- Non-inlined structs #}
{% for struct in structs %}
{% if not struct|should_inline and not struct|is_native_only_kind %}
{% include "wrapper_class_declaration.tmpl" %}
{% endif %}
{%- endfor %}
{%- for union in unions %}
{% include "wrapper_union_class_template_definition.tmpl" %}
{%- endfor %}
{%- for struct in structs %}
{%- if not struct|is_native_only_kind %}
{% include "wrapper_class_template_definition.tmpl" %}
{%- endif %}
{%- endfor %}
{{namespace_end(namespaces_as_array, variant)}}
namespace mojo {
{#--- Struct Serialization Helpers -#}
{% for struct in structs %}
{%- if not struct|is_native_only_kind %}
{% include "struct_traits_declaration.tmpl" %}
{%- endif %}
{%- endfor %}
{#--- Union Serialization Helpers -#}
{% if unions %}
{%- for union in unions %}
{% include "union_traits_declaration.tmpl" %}
{%- endfor %}
{%- endif %}
{#--- Feature helper template overrides -#}
{%- if interfaces|selectattr('runtime_feature')|list|length %}
namespace internal {
{%- for interface in interfaces if interface.runtime_feature -%}
{% include "interface_feature_declaration.tmpl" %}
{%- endfor %}
} // namespace internal
{%- endif %}
} // namespace mojo
#endif // {{header_guard}}