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

{%- if variant -%}
{%-   set variant_path = "%s-%s"|format(module.path, variant) -%}
{%- else -%}
{%-   set variant_path = module.path -%}
{%- endif %}

#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-private-field"
#elif defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable:4056)
#pragma warning(disable:4065)
#pragma warning(disable:4756)
#endif

#include "{{variant_path}}.h"

#include <math.h>
#include <stdint.h>
#include <utility>

#include "base/logging.h"
#include "base/run_loop.h"
#include "mojo/public/cpp/bindings/lib/message_internal.h"
#include "mojo/public/cpp/bindings/lib/serialization_util.h"
#include "mojo/public/cpp/bindings/lib/unserialized_message_context.h"
#include "mojo/public/cpp/bindings/lib/validate_params.h"
#include "mojo/public/cpp/bindings/lib/validation_context.h"
#include "mojo/public/cpp/bindings/lib/validation_errors.h"
#include "mojo/public/interfaces/bindings/interface_control_messages.mojom.h"

#include "{{module.path}}-shared-message-ids.h"

{%- if for_blink %}
#include "mojo/public/cpp/bindings/lib/wtf_serialization.h"
{%- endif %}

{%- for header in extra_traits_headers %}
#include "{{header}}"
{%- endfor %}

{%- for namespace in namespaces_as_array %}
namespace {{namespace}} {
{%- endfor %}
{%- if variant %}
namespace {{variant}} {
{%- endif %}

{#--- Constants #}
{%- for constant in module.constants %}
{%-   if constant.kind|is_string_kind %}
const char {{constant.name}}[] = {{constant|constant_value}};
{%-   endif %}
{%- endfor %}

{#--- Struct Constants #}
{%- for struct in structs %}
{%-   for constant in struct.constants %}
{%-     if constant.kind|is_string_kind %}
const char {{struct.name}}::{{constant.name}}[] = {{constant|constant_value}};
{%-     else %}
constexpr {{constant.kind|cpp_pod_type}} {{struct.name}}::{{constant.name}};
{%-     endif %}
{%-   endfor %}
{%- endfor %}

{#--- Struct builder definitions #}
{%- for struct in structs %}
{%-   if not struct|is_native_only_kind %}
{%-     include "wrapper_class_definition.tmpl" %}
{%-   endif %}
{%- endfor %}

{#--- Union builder definitions #}
{%- for union in unions %}
{%-   include "wrapper_union_class_definition.tmpl" %}
{%- endfor %}

{#--- Interface definitions #}
{%- for interface in interfaces %}
{%-   include "interface_definition.tmpl" %}
{%- endfor %}

{%- if variant %}
}  // namespace {{variant}}
{%- endif %}
{%- for namespace in namespaces_as_array|reverse %}
}  // namespace {{namespace}}
{%- endfor %}

namespace mojo {

{#--- Struct Serialization Helpers -#}
{%  for struct in structs %}
{%-   if not struct|is_native_only_kind %}
{%      include "struct_traits_definition.tmpl" %}
{%-   endif %}
{%- endfor %}

{#--- Union Serialization Helpers #}
{%- for union in unions %}
{%-   include "union_traits_definition.tmpl" %}
{%- endfor %}

}  // namespace mojo

#if defined(__clang__)
#pragma clang diagnostic pop
#elif defined(_MSC_VER)
#pragma warning(pop)
#endif
