blob: 4a637fd2d81e8d3070fdaab55d5699e78d2fa6dd [file] [log] [blame]
// Copyright 2018 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package codegen
const fileHeaderTmpl = `
{{- define "Header" -}}
{{- UseWire -}}
// WARNING: This file is machine generated by fidlgen.
#pragma once
#include <algorithm>
#include <cstddef>
#include <variant>
#include <lib/fidl/internal.h>
#include <lib/fidl/llcpp/array.h>
#include <lib/fidl/llcpp/coding.h>
#include <lib/fidl/llcpp/envelope.h>
#include <lib/fidl/llcpp/errors.h>
#include <lib/fidl/llcpp/message.h>
#include <lib/fidl/llcpp/message_storage.h>
#include <lib/fidl/llcpp/object_view.h>
#include <lib/fidl/llcpp/string_view.h>
#include <lib/fidl/llcpp/traits.h>
#include <lib/fidl/llcpp/vector_view.h>
#include <lib/fit/function.h>
#include <lib/stdcompat/optional.h>
{{- IfdefFuchsia -}}
#include <lib/fidl/llcpp/client_end.h>
#include <lib/fidl/llcpp/client.h>
#include <lib/fidl/llcpp/connect_service.h>
#include <lib/fidl/llcpp/result.h>
#include <lib/fidl/llcpp/server_end.h>
#include <lib/fidl/llcpp/server.h>
#include <lib/fidl/llcpp/service_handler_interface.h>
#include <lib/fidl/llcpp/sync_call.h>
#include <lib/fidl/llcpp/transaction.h>
#include <lib/fidl/llcpp/wire_messaging.h>
#include <lib/fidl/txn_header.h>
{{ range .HandleTypes -}}
#include <lib/zx/{{ . }}.h>
{{ end -}}
{{- EndifFuchsia -}}
#include <zircon/fidl.h>
{{ if .Headers -}}
{{ "" }}
{{ $root := . -}}
{{ range .Headers -}}
#include <{{ . }}/{{ $root.IncludeStem }}.h>
{{ end -}}
{{ end -}}
{{- range .Decls }}
{{- if Eq .Kind Kinds.Bits }}{{ template "BitsForwardDeclaration" . }}{{- end }}
{{- if Eq .Kind Kinds.Enum }}{{ template "EnumForwardDeclaration" . }}{{- end }}
{{- if Eq .Kind Kinds.Protocol }}{{ template "ProtocolForwardDeclaration" . }}{{- end }}
{{- if Eq .Kind Kinds.Service }}{{ template "ServiceForwardDeclaration" . }}{{- end }}
{{- if Eq .Kind Kinds.Struct }}{{ template "StructForwardDeclaration" . }}{{- end }}
{{- if Eq .Kind Kinds.Table }}{{ template "TableForwardDeclaration" . }}{{- end }}
{{- if Eq .Kind Kinds.Union }}{{ template "UnionForwardDeclaration" . }}{{- end }}
{{- end }}
{{- /* Declare tables and unions first, since they store their members
out-of-line and so they only need forward declarations.
See fxbug.dev/7919 formore context. */}}
{{- range .Decls }}
{{- if Eq .Kind Kinds.Table }}{{ template "TableDeclaration" . }}{{- end }}
{{- if Eq .Kind Kinds.Union }}{{ template "UnionDeclaration" . }}{{- end }}
{{- end }}
{{- range .Decls }}
{{- if Eq .Kind Kinds.Const }}{{ template "ConstDeclaration" . }}{{- end }}
{{- if Eq .Kind Kinds.Protocol }}{{ template "ProtocolDeclaration" . }}{{- end }}
{{- if Eq .Kind Kinds.Service }}{{ template "ServiceDeclaration" . }}{{- end }}
{{- if Eq .Kind Kinds.Struct }}{{ template "StructDeclaration" . }}{{- end }}
{{- end }}
{{- /*
Some hacks to support migration of out-of-tree clients
*/}}
{{- range .Decls }}
{{- if (eq .String "::fuchsia_sysmem::wire::ImageFormat2") }}
{{ EnsureNamespace . }}
using ImageFormat_2 = ImageFormat2;
{{- end }}
{{- if (eq .String "::fuchsia_sysmem::wire::BufferCollectionInfo2") }}
{{ EnsureNamespace . }}
using BufferCollectionInfo_2 = BufferCollectionInfo2;
{{- end }}
{{- if (eq .String "::fuchsia_sysmem::wire::kCpuUsageReadOften") }}
{{ EnsureNamespace . }}
constexpr auto cpuUsageReadOften = kCpuUsageReadOften;
{{- end }}
{{- if (eq .String "::fuchsia_sysmem::wire::kCpuUsageWriteOften") }}
{{ EnsureNamespace . }}
constexpr auto cpuUsageWriteOften = kCpuUsageWriteOften;
{{- end }}
{{- if (eq .String "::fuchsia_sysmem::wire::kCpuUsageWrite") }}
{{ EnsureNamespace . }}
constexpr auto cpuUsageWrite = kCpuUsageWrite;
{{- end }}
{{- if (eq .String "::fuchsia_sysmem::wire::kCpuUsageRead") }}
{{ EnsureNamespace . }}
constexpr auto cpuUsageRead = kCpuUsageRead;
{{- end }}
{{- if (eq .String "::fuchsia_sysmem::wire::kFormatModifierLinear") }}
{{ EnsureNamespace . }}
constexpr auto FORMAT_MODIFIER_LINEAR = kFormatModifierLinear;
{{- end }}
{{- if (eq .String "::fuchsia_sysmem::wire::kFormatModifierGoogleGoldfishOptimal") }}
{{ EnsureNamespace . }}
constexpr auto FORMAT_MODIFIER_GOOGLE_GOLDFISH_OPTIMAL = kFormatModifierGoogleGoldfishOptimal;
{{- end }}
{{- if (eq .String "::fuchsia_sysmem::wire::kVulkanImageUsageSampled") }}
{{ EnsureNamespace . }}
constexpr auto VULKAN_IMAGE_USAGE_SAMPLED = kVulkanImageUsageSampled;
{{- end }}
{{- if (eq .String "::fuchsia_sysmem::wire::kVulkanImageUsageColorAttachment") }}
{{ EnsureNamespace . }}
constexpr auto VULKAN_IMAGE_USAGE_COLOR_ATTACHMENT = kVulkanImageUsageColorAttachment;
{{- end }}
{{- if (eq .String "::fuchsia_sysmem::wire::kVulkanImageUsageTransferSrc") }}
{{ EnsureNamespace . }}
constexpr auto VULKAN_IMAGE_USAGE_TRANSFER_SRC = kVulkanImageUsageTransferSrc;
{{- end }}
{{- if (eq .String "::fuchsia_sysmem::wire::kVulkanImageUsageTransferDst") }}
{{ EnsureNamespace . }}
constexpr auto VULKAN_IMAGE_USAGE_TRANSFER_DST = kVulkanImageUsageTransferDst;
{{- end }}
{{- if (eq .String "::fuchsia_sysmem::wire::kVulkanBufferUsageTransferSrc") }}
{{ EnsureNamespace . }}
constexpr auto VULKAN_BUFFER_USAGE_TRANSFER_SRC = kVulkanBufferUsageTransferSrc;
{{- end }}
{{- if (eq .String "::fuchsia_sysmem::wire::kVulkanBufferUsageTransferDst") }}
{{ EnsureNamespace . }}
constexpr auto VULKAN_BUFFER_USAGE_TRANSFER_DST = kVulkanBufferUsageTransferDst;
{{- end }}
{{- if (eq .String "::fuchsia_sysmem::wire::kVulkanBufferUsageUniformTexelBuffer") }}
{{ EnsureNamespace . }}
constexpr auto VULKAN_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER = kVulkanBufferUsageUniformTexelBuffer;
{{- end }}
{{- if (eq .String "::fuchsia_sysmem::wire::kVulkanBufferUsageStorageTexelBuffer") }}
{{ EnsureNamespace . }}
constexpr auto VULKAN_BUFFER_USAGE_STORAGE_TEXEL_BUFFER = kVulkanBufferUsageStorageTexelBuffer;
{{- end }}
{{- if (eq .String "::fuchsia_sysmem::wire::kVulkanBufferUsageUniformBuffer") }}
{{ EnsureNamespace . }}
constexpr auto VULKAN_BUFFER_USAGE_UNIFORM_BUFFER = kVulkanBufferUsageUniformBuffer;
{{- end }}
{{- if (eq .String "::fuchsia_sysmem::wire::kVulkanBufferUsageStorageBuffer") }}
{{ EnsureNamespace . }}
constexpr auto VULKAN_BUFFER_USAGE_STORAGE_BUFFER = kVulkanBufferUsageStorageBuffer;
{{- end }}
{{- if (eq .String "::fuchsia_sysmem::wire::kVulkanBufferUsageIndexBuffer") }}
{{ EnsureNamespace . }}
constexpr auto VULKAN_BUFFER_USAGE_INDEX_BUFFER = kVulkanBufferUsageIndexBuffer;
{{- end }}
{{- if (eq .String "::fuchsia_sysmem::wire::kVulkanBufferUsageVertexBuffer") }}
{{ EnsureNamespace . }}
constexpr auto VULKAN_BUFFER_USAGE_VERTEX_BUFFER = kVulkanBufferUsageVertexBuffer;
{{- end }}
{{- if (eq .String "::fuchsia_sysmem::wire::kVulkanBufferUsageIndirectBuffer") }}
{{ EnsureNamespace . }}
constexpr auto VULKAN_BUFFER_USAGE_INDIRECT_BUFFER = kVulkanBufferUsageIndirectBuffer;
{{- end }}
{{- if (eq .String "::fuchsia_io::wire::kOpenFlagCreate") }}
{{ EnsureNamespace . }}
constexpr auto OPEN_FLAG_CREATE = kOpenFlagCreate;
{{- end }}
{{- if (eq .String "::fuchsia_io::wire::kOpenRightWritable") }}
{{ EnsureNamespace . }}
constexpr auto OPEN_RIGHT_WRITABLE = kOpenRightWritable;
{{- end }}
{{- if (eq .String "::fuchsia_hardware_goldfish::wire::kMemoryPropertyDeviceLocal") }}
{{ EnsureNamespace . }}
constexpr auto MEMORY_PROPERTY_DEVICE_LOCAL = kMemoryPropertyDeviceLocal;
{{- end }}
{{- if (eq .String "::fuchsia_hardware_goldfish::wire::kMemoryPropertyHostVisible") }}
{{ EnsureNamespace . }}
constexpr auto MEMORY_PROPERTY_HOST_VISIBLE = kMemoryPropertyHostVisible;
{{- end }}
{{- if (eq .String "::fuchsia_hardware_goldfish::wire::kSignalReadable") }}
{{ EnsureNamespace . }}
constexpr auto SIGNAL_READABLE = kSignalReadable;
{{- end }}
{{- if (eq .String "::fuchsia_hardware_goldfish::wire::kSignalHangup") }}
{{ EnsureNamespace . }}
constexpr auto SIGNAL_HANGUP = kSignalHangup;
{{- end }}
{{- if (eq .String "::fuchsia_hardware_spi::wire::kMaxTransferSize") }}
{{ EnsureNamespace . }}
constexpr auto MAX_TRANSFER_SIZE = kMaxTransferSize;
{{- end }}
{{- if (eq .String "::fuchsia_hardware_radar::wire::kVmoVectorMaxCount") }}
{{ EnsureNamespace . }}
constexpr auto VMO_VECTOR_MAX_COUNT = kVmoVectorMaxCount;
{{- end }}
{{- end }}
{{ "" }}
{{ EnsureNamespace "fidl" }}
{{- range .Decls }}
{{- if Eq .Kind Kinds.Bits }}{{ template "BitsTraits" . }}{{- end }}
{{- if Eq .Kind Kinds.Protocol }}{{ template "ProtocolTraits" . }}{{- end }}
{{- if Eq .Kind Kinds.Struct }}{{ template "StructTraits" . }}{{- end }}
{{- if Eq .Kind Kinds.Table }}{{ template "TableTraits" . }}{{- end }}
{{- if Eq .Kind Kinds.Union }}{{ template "UnionTraits" . }}{{- end }}
{{- if Eq .Kind Kinds.Enum }}{{ template "EnumTraits" . }}{{- end }}
{{- end }}
{{- range .Decls }}
{{- if Eq .Kind Kinds.Protocol }}
{{- range .TwoWayMethods }}
{{ template "MethodResponseContextDeclaration" . }}
{{- end }}
{{ template "ClientDeclaration" . }}
{{ "" }}
{{ template "EventSenderDeclaration" . }}
{{ "" }}
{{- end }}
{{- end }}
{{ "" }}
{{ EndOfFile }}
{{ end }}
`